From 00774e4ae67802e49495a5304b435c454d5be82a Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Tue, 18 May 1999 08:57:39 +0000 Subject: [PATCH] May 18 1999 Ron Pinkas added support for [] String Delimiters. Please note {String} definition needed to be removed. Seem to only be used in will probably be resolved by the Pre Processor any way. Also found and corrected tranctuation of string literals. In the last 3 weeks someone changed the following to have yytext + 1 and yyleng - 2. I reverted it back to yytext and yyleng - 1 respectivly. [^']*' { 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; } Removed from bld32exe.bat refrences to -mh and -F (invalid options). Also removed refrences to HBTOOLS.LIB (non existed). --- harbour/.cvspass | 1 + harbour/source/compiler/harbour.l | 108 ++++++++++++++++++++++++++--- harbour/tests/working/bld32exe.bat | 8 +-- 3 files changed, 103 insertions(+), 14 deletions(-) diff --git a/harbour/.cvspass b/harbour/.cvspass index c6c8feba88..e890e03bd7 100644 --- a/harbour/.cvspass +++ b/harbour/.cvspass @@ -1 +1,2 @@ :pserver:alinares@harbour.joca.es:/home/devel/cvsroot A,cd: 0^dh, +:pserver:rpinkas@harbour.joca.es:/home/devel/cvsroot A:y=,d diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index 31e7e154cb..1cbfe74f1a 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -61,6 +61,10 @@ long lNumber = 0; #define OPERATOR -1 int _iState = LOOKUP; +/* Support for Array Index */ +int iIndexSets = 0; +int i_INDEX_STATE = 0; + void yy_lex_count_lf( void ) { char * pTmp = yytext; @@ -78,8 +82,12 @@ InvalidNumber [0-9]+\. Number ([0-9]+)|([0-9]*\.[0-9]+) HexNumber 0x[0-9A-F]+ Identifier (([a-zA-Z])|([_a-zA-Z][_a-zA-Z0-9]+)) -String (\"(([^\"]*)|([\!]*))\")|(\'(([^\']*)|([\!]*))\') + +/* TODO check if String definition can be removed - Ron Pinkas added support for [] String Delimiters see STRING1, STRING2 and STRING3*/ +/*String (\"(([^\"]*)|([\!]*))\")|(\'(([^\']*)|([\!]*))\')*/ + PseudoFunc {Identifier}"("+.*")"+ +Array {Identifier}[ \t]*(\[[^\]]*\])+ Comment1 "/*"([^\*]|[\*][^\/])*"*/" Comment2 [\/][\/].* @@ -88,8 +96,9 @@ LineCont (;.*\n) Separator {SpaceTab}|{Comment}|{LineCont} %x COMMENT3 DEFINE DEFINE_PARAMS DEFINE_EXPR -%x IFDEF IFNDEF STRING1 STRING2 +%x IFDEF IFNDEF STRING1 STRING2 STRING3 %x NEXT_ BREAK_ CASE_ DO_ WHILE_ WITH_ END_ +%s INDEX %% @@ -100,17 +109,38 @@ Separator {SpaceTab}|{Comment}|{LineCont} ' BEGIN STRING1; \" 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; -[^']*' { BEGIN 0; yylval.string = strdup( yytext + 1 ); - yylval.string[ yyleng - 2 ] = 0; return LITERAL; } -[^\"]*\" { BEGIN 0; yylval.string = strdup( yytext + 1 ); - yylval.string[ yyleng - 2 ] = 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; } +[^\]]*\] { BEGIN 0; yylval.string = strdup( yytext ); + yylval.string[ yyleng - 1 ] = 0; return LITERAL; } + +\n { yyerror( "Unterminated Array Index" ); exit(1); } + +\[ { return yytext[ 0 ] ; } + +\] { + iIndexSets-- ; + if( iIndexSets == 0 ) + { + /* printf( "\nIndex End\n" ); */ + + /* No longer in this state. */ + i_INDEX_STATE = 0; + BEGIN 0; + } + return yytext[ 0 ]; + } "/*" BEGIN COMMENT3; -"*"["*"]*"/" BEGIN 0; +"*"["*"]*"/" { if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; } [^"*/"\n]* ; "*" ; [\/\"]+ ; @@ -122,12 +152,12 @@ Separator {SpaceTab}|{Comment}|{LineCont} {SpaceTab} ; {Identifier} LastDef( pDefs )->szValue = strdup( yytext ); BEGIN 0; {PseudoFunc} LastDef( pDefs )->szValue = strdup( yytext ); BEGIN 0; -{String} LastDef( pDefs )->szValue = strdup( yytext ); BEGIN 0; + -?{Number} LastDef( pDefs )->szValue = strdup( yytext ); BEGIN 0; {HexNumber} LastDef( pDefs )->szValue = strdup( yytext ); BEGIN 0; "/*".*"*/" ; {Number}{SpaceTab}*[\(] yyerror( "Syntax error in #define" ); -{String}{SpaceTab}*[\(] yyerror( "Syntax error in #define" ); + {Identifier}{SpaceTab}*[\(] Define( yytext ); BEGIN DEFINE_PARAMS; {SpaceTab} ; {Identifier} DefineKey( yytext ); @@ -650,7 +680,65 @@ Separator {SpaceTab}|{Comment}|{LineCont} } } -{String} yylval.string = strdup( yytext + 1 ); yylval.string[ yyleng - 2 ] = 0; return LITERAL; +{Array} { BEGIN INDEX; + { + int i = 0, iIdentifierLength = 0; + char chr; + + /* Other states will know to resume this state. */ + i_INDEX_STATE = 1; + + while( i < yyleng ) + { + chr = *( yytext + i++ ); + if( chr == '[' ) + { + if( iIdentifierLength ) + { + iIndexSets++; + } + else + { + iIdentifierLength = i - 1; + iIndexSets++; + } + } + } + + yyless( iIdentifierLength ); + + /* Remove optional white space between Identifier and Index */ + while( yytext[ iIdentifierLength - 1] < 48 ) + iIdentifierLength--; + + yyleng = iIdentifierLength; + yytext[yyleng] = 0; + /* printf( "\nIdentifier = %s Length = %i IndexSets = %i\n", strupr( strdup( yytext ) ), iIdentifierLength, iIndexSets ); */ + } + + { + PDEFINE pDef = FindDef( yytext ); + char * szText; int c; + + if( pDef ) + { + c = strlen( pDef->szValue ) - 1; + szText = pDef->szValue; + while( c >= 0 ) + unput( szText[ c-- ] ); + } + else + { + if( _iRestrictSymbolLength && strlen( yytext ) > 10 ) + { + yytext[ 10 ] = 0; + yyleng = 10; + } + yylval.string = strupr( strdup( yytext ) ); + return IDENTIFIER; + } + } + } {LineCont} ++iLine; diff --git a/harbour/tests/working/bld32exe.bat b/harbour/tests/working/bld32exe.bat index 3864ff4733..cc7d586909 100644 --- a/harbour/tests/working/bld32exe.bat +++ b/harbour/tests/working/bld32exe.bat @@ -3,15 +3,15 @@ IF A%1 == A GOTO :SINTAX IF A%2 == A GOTO :NOOUTPUT -echo -mh -O2 -Fm -e%2.exe -I..\..\include ..\..\source\vm\hvm.c %1.c > b32.bc -echo ..\..\libs\b32\harbour.lib ..\..\libs\b32\hbtools.lib ..\..\libs\b32\terminal.lib >> b32.bc +echo -O2 -e%2.exe -I..\..\include ..\..\source\vm\hvm.c %1.c > b32.bc +echo ..\..\libs\b32\harbour.lib ..\..\libs\b32\terminal.lib >> b32.bc bcc32 @b32.bc del b32.bc GOTO :END :NOOUTPUT -echo -mh -O2 -Fm -e%1.exe -I..\..\include ..\..\source\vm\hvm.c %1.c > b32.bc -echo ..\..\libs\b32\harbour.lib ..\..\libs\b32\hbtools.lib ..\..\libs\b32\terminal.lib >> b32.bc +echo -O2 -e%1.exe -I..\..\include ..\..\source\vm\hvm.c %1.c > b32.bc +echo ..\..\libs\b32\harbour.lib ..\..\libs\b32\terminal.lib >> b32.bc bcc32 @b32.bc del b32.bc GOTO :END