Skip to content
Snippets Groups Projects
Commit 6322b07d authored by Patrick Dular's avatar Patrick Dular
Browse files

ElseIf and Else now possible in If EndIf

parent 317d9788
No related branches found
No related tags found
No related merge requests found
......@@ -156,6 +156,7 @@ Exp return tExp;
Ellipsis return tEllipse;
Ellipse return tEllipse;
Else return tElse;
ElseIf return tElseIf;
Extrude return tExtrude;
Elliptic return tElliptic;
EndFor return tEndFor;
......@@ -380,6 +381,12 @@ void skip_until(const char *skip, const char *until)
l_skip = (skip)? strlen(skip) : 0;
l_until = strlen(until);
l = std::max(l_skip,l_until);
if(l >= (int)sizeof(chars)){
Msg::Error("Search pattern too long in skip_until");
return;
}
while(1){
while (1){
chars[0] = yyinput();
......@@ -400,11 +407,6 @@ void skip_until(const char *skip, const char *until)
c_previous = chars[0];
}
l = std::max(l_skip,l_until);
if(l >= (int)sizeof(chars)){
Msg::Error("Search pattern too long in skip_until");
return;
}
for(i=1; i<l; i++){
chars[i] = yyinput();
if(gmsheof(yyin)){
......@@ -427,6 +429,7 @@ void skip_until(const char *skip, const char *until)
}
else if(skip && !strncmp(chars,skip,l_skip) && !is_alpha(c_next_skip)){
nb_skip++;
// Attention: unput(.) should be applied a number of times equal to l-l_skip (always >0 for skip="For" and until="EndFor", or skip="If" and until="EndIf"); in particular, because "If" is followed by a minimum of 3 chars (e.g., '(1)'), with a total lenght thus exactly equal to the one of "EndIf", one avoid an error when looking then for "EndIf". (Patrick)
}
else{
for(i=1;i<l-1;i++){
......@@ -437,8 +440,8 @@ void skip_until(const char *skip, const char *until)
}
}
// Patrick: to be unified soon with skip_until (or perhaps made particular when ElseIf will be added)
void skip_until_test(const char *skip, const char *until, const char *until2, int *flag_until2)
void skip_until_test(const char *skip, const char *until,
const char *until2, int l_until2_sub, int *type_until2)
{
int i, nb_skip = 0;
int l, l_skip, l_until, l_until2;
......@@ -446,10 +449,16 @@ void skip_until_test(const char *skip, const char *until, const char *until2, in
int c_next, c_next_skip, c_next_until, c_next_until2, c_previous = 0;
l_skip = (skip)? strlen(skip) : 0;
l_until = strlen(until);
l_until2 = (until2)? strlen(until2) : 0;
l = std::max(l_skip,l_until);
l = std::max(l,l_until2);
if(l >= (int)sizeof(chars)){
Msg::Error("Search pattern too long in skip_until_test");
return;
}
while(1){
while (1){
chars[0] = yyinput();
......@@ -466,17 +475,12 @@ void skip_until_test(const char *skip, const char *until, const char *until2, in
if(!c_previous || !is_alpha(c_previous)){
if(chars[0] == until[0]) break;
if(skip && chars[0] == skip[0]) break;
if(until2 && chars[0] == until2[0]) break;
if(!nb_skip && until2 && chars[0] == until2[0]) break;
// Useless to search for until2 if nb_skip!=0
}
c_previous = chars[0];
}
l = std::max(l_skip,l_until);
l = std::max(l,l_until2);
if(l >= (int)sizeof(chars)){
Msg::Error("Search pattern too long in skip_until");
return;
}
for(i=1; i<l; i++){
chars[i] = yyinput();
if(gmsheof(yyin)){
......@@ -488,13 +492,22 @@ void skip_until_test(const char *skip, const char *until, const char *until2, in
c_next = yyinput(); unput(c_next);
c_next_skip = (l_skip<l)? chars[l_skip] : c_next;
c_next_until = (l_until<l)? chars[l_until] : c_next;
if (!nb_skip)
c_next_until2 = (l_until2<l)? chars[l_until2] : c_next;
if(!strncmp(chars,until2,l_until2) && !is_alpha(c_next_until2)){
if(!nb_skip){
*flag_until2 = 1;
if(!nb_skip && !strncmp(chars,until2,l_until2) && !is_alpha(c_next_until2)){
*type_until2 = 1; // Found word is full until2 (e.g., "ElseIf")
for(int i = 1; i <= l; i++){ // Only correct if l == l_until2
unput(chars[l-i]);
} // New file position points "ElseIf", that will be then analysed by the parser
return;
}
else if(!nb_skip && !strncmp(chars,until2,l_until2_sub) && !is_alpha(chars[l_until2_sub])){
*type_until2 = 2; // Found word is subword from until2 (e.g., "Else")
for(int i = 1; i <= l-l_until2_sub; i++){ // Only correct if l_until2_sub < l
unput(chars[l-i]);
}
return;
}
else if(!strncmp(chars,until,l_until) && !is_alpha(c_next_until)){
if(!nb_skip){
......
This diff is collapsed.
......@@ -182,46 +182,47 @@
tIn = 398,
tEndFor = 399,
tIf = 400,
tElse = 401,
tEndIf = 402,
tExit = 403,
tAbort = 404,
tField = 405,
tReturn = 406,
tCall = 407,
tMacro = 408,
tShow = 409,
tHide = 410,
tGetValue = 411,
tGetEnv = 412,
tGetString = 413,
tGetNumber = 414,
tHomology = 415,
tCohomology = 416,
tBetti = 417,
tSetOrder = 418,
tExists = 419,
tFileExists = 420,
tGMSH_MAJOR_VERSION = 421,
tGMSH_MINOR_VERSION = 422,
tGMSH_PATCH_VERSION = 423,
tGmshExecutableName = 424,
tSetPartition = 425,
tNameFromString = 426,
tStringFromName = 427,
tAFFECTDIVIDE = 428,
tAFFECTTIMES = 429,
tAFFECTMINUS = 430,
tAFFECTPLUS = 431,
tOR = 432,
tAND = 433,
tNOTEQUAL = 434,
tEQUAL = 435,
tGREATEROREQUAL = 436,
tLESSOREQUAL = 437,
UNARYPREC = 438,
tMINUSMINUS = 439,
tPLUSPLUS = 440
tElseIf = 401,
tElse = 402,
tEndIf = 403,
tExit = 404,
tAbort = 405,
tField = 406,
tReturn = 407,
tCall = 408,
tMacro = 409,
tShow = 410,
tHide = 411,
tGetValue = 412,
tGetEnv = 413,
tGetString = 414,
tGetNumber = 415,
tHomology = 416,
tCohomology = 417,
tBetti = 418,
tSetOrder = 419,
tExists = 420,
tFileExists = 421,
tGMSH_MAJOR_VERSION = 422,
tGMSH_MINOR_VERSION = 423,
tGMSH_PATCH_VERSION = 424,
tGmshExecutableName = 425,
tSetPartition = 426,
tNameFromString = 427,
tStringFromName = 428,
tAFFECTDIVIDE = 429,
tAFFECTTIMES = 430,
tAFFECTMINUS = 431,
tAFFECTPLUS = 432,
tOR = 433,
tAND = 434,
tNOTEQUAL = 435,
tEQUAL = 436,
tGREATEROREQUAL = 437,
tLESSOREQUAL = 438,
UNARYPREC = 439,
tMINUSMINUS = 440,
tPLUSPLUS = 441
};
#endif
/* Tokens. */
......@@ -368,53 +369,54 @@
#define tIn 398
#define tEndFor 399
#define tIf 400
#define tElse 401
#define tEndIf 402
#define tExit 403
#define tAbort 404
#define tField 405
#define tReturn 406
#define tCall 407
#define tMacro 408
#define tShow 409
#define tHide 410
#define tGetValue 411
#define tGetEnv 412
#define tGetString 413
#define tGetNumber 414
#define tHomology 415
#define tCohomology 416
#define tBetti 417
#define tSetOrder 418
#define tExists 419
#define tFileExists 420
#define tGMSH_MAJOR_VERSION 421
#define tGMSH_MINOR_VERSION 422
#define tGMSH_PATCH_VERSION 423
#define tGmshExecutableName 424
#define tSetPartition 425
#define tNameFromString 426
#define tStringFromName 427
#define tAFFECTDIVIDE 428
#define tAFFECTTIMES 429
#define tAFFECTMINUS 430
#define tAFFECTPLUS 431
#define tOR 432
#define tAND 433
#define tNOTEQUAL 434
#define tEQUAL 435
#define tGREATEROREQUAL 436
#define tLESSOREQUAL 437
#define UNARYPREC 438
#define tMINUSMINUS 439
#define tPLUSPLUS 440
#define tElseIf 401
#define tElse 402
#define tEndIf 403
#define tExit 404
#define tAbort 405
#define tField 406
#define tReturn 407
#define tCall 408
#define tMacro 409
#define tShow 410
#define tHide 411
#define tGetValue 412
#define tGetEnv 413
#define tGetString 414
#define tGetNumber 415
#define tHomology 416
#define tCohomology 417
#define tBetti 418
#define tSetOrder 419
#define tExists 420
#define tFileExists 421
#define tGMSH_MAJOR_VERSION 422
#define tGMSH_MINOR_VERSION 423
#define tGMSH_PATCH_VERSION 424
#define tGmshExecutableName 425
#define tSetPartition 426
#define tNameFromString 427
#define tStringFromName 428
#define tAFFECTDIVIDE 429
#define tAFFECTTIMES 430
#define tAFFECTMINUS 431
#define tAFFECTPLUS 432
#define tOR 433
#define tAND 434
#define tNOTEQUAL 435
#define tEQUAL 436
#define tGREATEROREQUAL 437
#define tLESSOREQUAL 438
#define UNARYPREC 439
#define tMINUSMINUS 440
#define tPLUSPLUS 441
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
#line 109 "Gmsh.y"
#line 110 "Gmsh.y"
{
char *c;
int i;
......@@ -425,7 +427,7 @@ typedef union YYSTYPE
List_T *l;
}
/* Line 1529 of yacc.c. */
#line 429 "Gmsh.tab.hpp"
#line 431 "Gmsh.tab.hpp"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
......
......@@ -84,7 +84,8 @@ void yyerror(const char *s);
void yymsg(int level, const char *fmt, ...);
bool is_alpha(const int c);
void skip_until(const char *skip, const char *until);
void skip_until_test(const char *skip, const char *until, const char *until2, int *flag_until2);
void skip_until_test(const char *skip, const char *until,
const char *until2, int l_until2_sub, int *type_until2);
void assignVariable(const std::string &name, int index, int assignType,
double value);
void assignVariables(const std::string &name, List_T *indices, int assignType,
......@@ -146,7 +147,7 @@ struct doubleXstring{
%token tRecombLaterals tTransfQuadTri
%token tText2D tText3D tInterpolationScheme tTime tCombine
%token tBSpline tBezier tNurbs tNurbsOrder tNurbsKnots
%token tColor tColorTable tFor tIn tEndFor tIf tElse tEndIf tExit tAbort
%token tColor tColorTable tFor tIn tEndFor tIf tElseIf tElse tEndIf tExit tAbort
%token tField tReturn tCall tMacro tShow tHide tGetValue tGetEnv tGetString tGetNumber
%token tHomology tCohomology tBetti tSetOrder tExists tFileExists
%token tGMSH_MAJOR_VERSION tGMSH_MINOR_VERSION tGMSH_PATCH_VERSION
......@@ -3240,17 +3241,43 @@ Loop :
ImbricatedTest = MAX_RECUR_TESTS-1;
}
if(!$3){
statusImbricatedTests[ImbricatedTest] = 0; // Will be useful later for ElseIf
int flag_until2 = 0;
skip_until_test("If", "EndIf", "Else", &flag_until2);
if(!flag_until2)
if($3){
// Current test is true
statusImbricatedTests[ImbricatedTest] = 1;
}
else{
statusImbricatedTests[ImbricatedTest] = 0;
// Go after the next ElseIf or Else or EndIf
int type_until2 = 0;
skip_until_test("If", "EndIf", "ElseIf", 4, &type_until2);
if(!type_until2) ImbricatedTest--;
}
}
| tElseIf '(' FExpr ')'
{
if(ImbricatedTest > 0){
if (statusImbricatedTests[ImbricatedTest]){
// Last test (If or ElseIf) was true, thus go after EndIf (out of If EndIf)
skip_until("If", "EndIf");
ImbricatedTest--;
}
else{
// Previous test(s) (If and ElseIf) not yet true
if($3){
statusImbricatedTests[ImbricatedTest] = 1;
}
else{
// Current test still not true: statusImbricatedTests[ImbricatedTest] = 0;
// Go after the next ElseIf or Else or EndIf
int type_until2 = 0;
skip_until_test("If", "EndIf", "ElseIf", 4, &type_until2);
if(!type_until2) ImbricatedTest--;
}
}
}
else{
yymsg(0, "Orphan ElseIf");
}
}
| tElse
{
......
This diff is collapsed.
Geometry.OldNewReg = 1;
//-*- C++ -*-
/*********************************************
Cube uniformly meshed along all three axes
......@@ -28,9 +31,8 @@ EndFor
out[] = Extrude{0, 0, L}{Line{1:4}; Layers{nb_layers};};
Extrude { Surface{out[{1, 5, 9, 13}]}; Layers{5, 0.1}; Recombine; Using Index[0]; }
Extrude { Surface{- out[{1, 5, 9, 13}]}; Layers{5, 0.1}; Recombine; Using Index[1]; }
out0[] = Extrude { Surface{out[{1, 5, 9, 13}]}; Layers{5, 0.1}; Recombine; Using Index[0]; };
out1[] = Extrude { Surface{- out[{1, 5, 9, 13}]}; Layers{5, 0.1}; Recombine; Using Index[1]; };
Line Loop(197) = {132, 154, 176, 110};
Plane Surface(198) = {197};
......
//Geometry.OldNewReg = 1;
// Define parameters
charLength = 1.0;
......
......@@ -5,7 +5,7 @@
* Extruded meshes, parameters, options
*
*********************************************************************/
Geometry.OldNewReg = 1;
// Again, we start by including the first tutorial:
Include "t1.geo";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment