From 4ed2ebdd98102e753b8ef685cae92d539a6d48bf Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Thu, 20 May 1999 07:27:30 +0000 Subject: [PATCH] May 19, 1999 Ron Pinkas corrected problem with "[]" String Delimiters conflict with array names of reserved words (next, while, etc.) Please note to check i_INDEX_STATE before a "BEGIN 0;" as in the followings: if( iINDEX_STATE ) BEGIN INDEX; else BEGIN 0; --- harbour/source/compiler/harbour.l | 113 +++++++++++++++++++----------- 1 file changed, 71 insertions(+), 42 deletions(-) diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index 173a2b3b81..4549933f9d 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -111,16 +111,37 @@ Separator {SpaceTab}|{Comment}|{LineCont} \" BEGIN STRING2; \[ BEGIN STRING3; -[^'^\n]* GenError( ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; -[^\"^\n]* GenError( ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; -[^\]]*\n GenError( ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; +[^'^\n]* { GenError( ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; } +[^\"^\n]* { GenError( ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; } +[^\]]*\n { GenError( ERR_STRING_TERMINATOR, yytext, NULL ); BEGIN 0; } -[^']*' { BEGIN 0; yylval.string = strdup( yytext ); - yylval.string[ yyleng - 1 ] = 0; return LITERAL; } -[^\"]*\" { BEGIN 0; yylval.string = strdup( yytext ); - yylval.string[ yyleng - 1 ] = 0; return LITERAL; } -[^\]]*\] { BEGIN 0; yylval.string = strdup( yytext ); - yylval.string[ yyleng - 1 ] = 0; return LITERAL; } +[^']*' { if( i_INDEX_STATE ) + BEGIN INDEX; + else + BEGIN 0; + + yylval.string = strdup( yytext ); + yylval.string[ yyleng - 1 ] = 0; return LITERAL; + } + +[^\"]*\" { if( i_INDEX_STATE ) + BEGIN INDEX; + else + BEGIN 0; + + yylval.string = strdup( yytext ); + yylval.string[ yyleng - 1 ] = 0; + return LITERAL; + } + +[^\]]*\] { if( i_INDEX_STATE ) + BEGIN INDEX; + else + BEGIN 0; + + yylval.string = strdup( yytext ); + yylval.string[ yyleng - 1 ] = 0; return LITERAL; + } \n { yyerror( "Unterminated Array Index" ); exit(1); } @@ -130,7 +151,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} iIndexSets-- ; if( iIndexSets == 0 ) { - /* printf( "\nIndex End\n" ); */ + /*printf( "\nIndex End\n" );*/ /* No longer in this state. */ i_INDEX_STATE = 0; @@ -140,7 +161,15 @@ Separator {SpaceTab}|{Comment}|{LineCont} } "/*" BEGIN COMMENT3; -"*"["*"]*"/" { if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; } +"*"["*"]*"/" { if( i_INDEX_STATE ) + { + BEGIN INDEX; + /*printf( "\nRESUMING INDEX STATE\n" );*/ + } + else + BEGIN 0; + } + [^"*/"\n]* ; "*" ; [\/\"]+ ; @@ -196,7 +225,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} {Separator}*\n { /* at the end of line */ yy_lex_count_lf(); --iLine; - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; unput( yytext[ yyleng-1 ] ); if( _iState == LOOKUP ) { /* it is first item in the line */ @@ -210,13 +239,13 @@ Separator {SpaceTab}|{Comment}|{LineCont} } {Separator}*[\[] { /* array */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; /* Clipper does not like break[] at all */ GenError( ERR_SYNTAX, yytext, NULL ); } {Separator}*[^_a-zA-Z\[] { /* there is no identifier after "break" */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; yylval.string = strdup( "BREAK" ); _iState =IDENTIFIER; unput( yytext[ yyleng-1 ] ); @@ -224,19 +253,19 @@ Separator {SpaceTab}|{Comment}|{LineCont} } {Separator}*. { /* an identifier follows BREAK statement */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; unput( yytext[ yyleng-1 ] ); _iState =BREAK; return BREAK; } -. { BEGIN 0; unput( yytext[ yyleng-1 ] ); } +. { if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; unput( yytext[ yyleng-1 ] ); } %{ /* ************************************************************************ */ %} "case" { BEGIN CASE_; } {Separator}*[\:\=\|\$\%\*\,\/\]\)\}\^] { /* there is an operator after "case" */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; yylval.string = strdup( "CASE" ); _iState =IDENTIFIER; unput( yytext[ yyleng-1 ] ); @@ -244,13 +273,13 @@ Separator {SpaceTab}|{Comment}|{LineCont} } {Separator}*[\[] { /* array */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; /* Clipper does not like case[] at all */ GenError( ERR_SYNTAX, yytext, NULL ); } {Separator}*("+="|"-="|"->") { /* operators */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; yylval.string = strdup( "CASE" ); _iState =IDENTIFIER; unput( yytext[ yyleng-1 ] ); @@ -259,7 +288,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} } {Separator}*(\n|.) { /* not operator */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; if( yytext[ yyleng-1 ] == '\n' ) --iLine; unput( yytext[ yyleng-1 ] ); @@ -279,7 +308,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} %} "do" BEGIN DO_; {Separator}+"case" { /* DO CASE statement */ - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; yy_lex_count_lf(); _iState =DOCASE; return DOCASE; @@ -289,13 +318,13 @@ Separator {SpaceTab}|{Comment}|{LineCont} * or DO while [WITH ] */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; _iState =DO; yyless( yyleng-5 ); } {Separator}+[_a-zA-Z] { /* an identifier DO id WITH */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; unput( yytext[ yyleng-1 ] ); if( _iState == LOOKUP ) { /* it is first item in the line */ @@ -311,7 +340,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} } {Separator}*(.|\n) { /* end of line or any operator */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; if( yytext[ yyleng-1 ] == '\n' ) --iLine; unput( yytext[ yyleng-1 ] ); @@ -345,7 +374,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} "end" { BEGIN END_; } {Separator}*[\[\(] { /* array, function call */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; if( _iState == LOOKUP ) { /* Clipper does not like end[] & end() at the begining of line */ GenError( ERR_ENDIF, NULL, NULL ); @@ -357,7 +386,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} } {Separator}*("->"|"++"|"--") { /* operators */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; if( _iState == LOOKUP ) { /* Clipper does not like end-> & end++ at the begining of line */ GenError( ERR_ENDIF, NULL, NULL ); @@ -370,7 +399,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} } {Separator}*[\+\-\:\=\|\$\%\*\,\/\[\]\)\}\^] { /* there is an operator after "end" */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; yylval.string = strdup( "END" ); _iState =IDENTIFIER; unput( yytext[ yyleng-1 ] ); @@ -378,7 +407,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} } {Separator}*(\n|.) { /* not operator */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; if( yytext[ yyleng-1 ] == '\n' ) --iLine; unput( yytext[ yyleng-1 ] ); @@ -478,7 +507,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} %} "next" BEGIN NEXT_; {Separator}*[\n\;] { /* at the end of line */ - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; if( _iState == LOOKUP ) { /* it is first item in the line */ ++iLine; @@ -496,7 +525,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} } {Separator}*[\[\(] { /* array, function call */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; if( _iState == LOOKUP ) { /* Clipper does not like NEXT[] & NEXT() at the begining of line */ GenError( ERR_NEXTFOR, NULL, NULL ); @@ -508,7 +537,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} } {Separator}*("->"|"++"|"--") { /* operators */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; if( _iState == LOOKUP ) { /* Clipper does not like next-> & next++ at the begining of line */ GenError( ERR_NEXTFOR, NULL, NULL ); @@ -521,14 +550,14 @@ Separator {SpaceTab}|{Comment}|{LineCont} } {Separator}*[^_a-zA-Z] { /* there is no identifier after "next" */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; yylval.string = strdup( "NEXT" ); unput( yytext[ yyleng-1 ] ); return IDENTIFIER; } {Separator}*. { /* an identifier follows NEXT statement */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; if( _wForCounter == 0 ) GenError( ERR_NEXTFOR, NULL, NULL ); unput( yytext[ yyleng-1 ] ); @@ -558,7 +587,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} {Separator}*\n { /* end of line */ yy_lex_count_lf(); --iLine; - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; unput( '\n' ); if( _iState == DO ) { /* we have DO while - replace it with while() */ @@ -569,20 +598,20 @@ Separator {SpaceTab}|{Comment}|{LineCont} } {Separator}*[\[] { /* array */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; /* Clipper does not like while[] at all */ GenError( ERR_SYNTAX, yytext, NULL ); } {Separator}*[\:\=\|\$\%\*\,\/\]\)\}\^] { /* there is an operator after "case" */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; yylval.string = strdup( "WHILE" ); unput( yytext[ yyleng-1 ] ); return IDENTIFIER; } {Separator}*("+="|"-="|"->") { /* operators */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; yylval.string = strdup( "WHILE" ); unput( yytext[ yyleng-1 ] ); unput( yytext[ yyleng-2 ] ); @@ -590,7 +619,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} } {Separator}*. { /* identifiers and literals */ yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; if( _iState == LOOKUP || _iState == DO ) { /* it is first item in the line or after DO */ unput( yytext[ yyleng-1 ] ); @@ -611,14 +640,14 @@ Separator {SpaceTab}|{Comment}|{LineCont} {Separator}*\n { /* at the end of line */ yy_lex_count_lf(); --iLine; - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; unput( '\n' ); yylval.string = strdup( "WITH" ); return IDENTIFIER; } {Separator}*"with" { yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; yyless( yyleng-4 ); if( _iState == DO ) { /* DO with */ @@ -639,7 +668,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} } {Separator}*. { yy_lex_count_lf(); - BEGIN 0; + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; unput( yytext[ yyleng-1 ] ); if( _iState == WHILE || _iState == DO || _iState == IDENTIFIER ) { /* DO WITH */ @@ -764,7 +793,7 @@ Separator {SpaceTab}|{Comment}|{LineCont} yyleng = iIdentifierLength; yytext[yyleng] = 0; - /* printf( "\nIdentifier = %s Length = %i IndexSets = %i\n", strupr( strdup( yytext ) ), iIdentifierLength, iIndexSets ); */ + /*printf( "\nINDEX BEGIN Identifier = %s Length = %i IndexSets = %i\n", strupr( strdup( yytext ) ), iIdentifierLength, iIndexSets );*/ } {