From de42b22c12f78729841f5e8836e88e91c238b65b Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Mon, 15 May 2000 17:16:10 +0000 Subject: [PATCH] 20000515-10:15 GMT-8 Ron Pinkas * source/compiler/harbour.l + Added states DECLARE & OPTIONAL_ * Modified rules for "declare" and "optiona" to use states, and support abbreviations. * Modified rules for "declare" to support backdated syntax DECLARE aVar[...] --- harbour/ChangeLog | 9 ++- harbour/source/compiler/harbour.l | 126 ++++++++++++++++++++---------- 2 files changed, 92 insertions(+), 43 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 35bb5f6707..2b3d93075d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,8 +1,15 @@ +20000515-10:15 GMT-8 Ron Pinkas + + * source/compiler/harbour.l + + Added states DECLARE & OPTIONAL_ + * Modified rules for "declare" and "optiona" to use states, and support abbreviations. + * Modified rules for "declare" to support backdated syntax DECLARE aVar[...] + 20000515-17:15 GMT+1 Ryszard Glab *source/rtl/gtcrs/gtcrs.c *fixed initialization of curses library - + 20000514-22:25 GMT-8 Ron Pinkas * source/compiler/harbour.l diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index ed10f890b2..539678c0ee 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -113,6 +113,7 @@ Separator {SpaceTab} %x FOR_ FUNCTION_ IIF_ IF_ IN_ INIT_ LOCAL_ LOOP_ %x MEMVAR_ PARAM_ PRIVATE_ PUBLIC_ STATIC_ RETURN_ RECOVER_ %x INVALIDNUM_ OTHERWISE_ PROCEDURE_ +%x DECLARE_ OPTIONAL_ %s INDEX %% @@ -351,53 +352,94 @@ Separator {SpaceTab} /* ************************************************************************ */ %} -"declare"{Separator}+"with"{Separator}+[^ .] { unput( yytext[ yyleng-1 ] ); - unput( ' ' ); - unput( 'h' ); - unput( 't' ); - unput( 'i' ); - unput( 'w' ); - if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; - yylval.string = hb_strdup( "declare" ); - hb_comp_iState = IDENTIFIER; - return IDENTIFIER; - } +"decl"("are"|"ar"|"a")? { BEGIN DECLARE_; + yylval.string = hb_strupr( hb_strdup( yytext ) ); + } -"declare"{Separator}+"to"{Separator}+[^ .] { unput( yytext[ yyleng-1 ] ); - unput( ' ' ); - unput( 'o' ); - unput( 't' ); - if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; - yylval.string = hb_strdup( "declare" ); - hb_comp_iState = IDENTIFIER; - return IDENTIFIER; - } +{Separator}+({Identifier}|{MacroVar}){Separator}*"[" { if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; -"declare"{Separator}+[_a-zA-Z\&] { unput( yytext[ yyleng-1 ] ); BEGIN 0; return DECLARE; } + unput( '[' ); + yyleng--; -"optional"{Separator}+"with"{Separator}+[^ .] { unput( yytext[ yyleng-1 ] ); - unput( ' ' ); - unput( 'h' ); - unput( 't' ); - unput( 'i' ); - unput( 'w' ); - if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; - yylval.string = hb_strdup( "OPTIONAL" ); - hb_comp_iState = IDENTIFIER; - return IDENTIFIER; - } + /* Remove possible white space between the Identifier and the Index. */ + while( yytext[ yyleng - 1 ] < 48 ) + yyleng--; -"optional"{Separator}+"to"{Separator}+[^ .] { unput( yytext[ yyleng-1 ] ); - unput( ' ' ); - unput( 'o' ); - unput( 't' ); - if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; - yylval.string = hb_strdup( "OPTIONAL" ); - hb_comp_iState = IDENTIFIER; - return IDENTIFIER; - } + /* Pushback the Identifier */ + while( yytext[ yyleng - 1 ] > 32 ) + unput( yytext[ --yyleng ] ); + //printf( "\nPushing: %c\n", yytext[ --yyleng ] ); -"optional"{Separator}+[_a-zA-Z\&] { unput( yytext[ yyleng-1 ] ); BEGIN 0; return OPTIONAL; } + + yytext[ yyleng ] = 0; + + if( hb_comp_iState == LOOKUP ) + { /* it is first item in the line */ + hb_xfree( (void *) yylval.string ); + hb_comp_iState = PRIVATE; + return PRIVATE; + } + else + { /* there is another item in line already */ + hb_comp_iState = IDENTIFIER; + return IDENTIFIER; + } + } + +{Separator}+[_a-zA-Z\&] { /* an Identifier after DECLARE */ + unput( yytext[ yyleng-1 ] ); + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; + + if( hb_comp_iState == LOOKUP ) + { /* it is first item in the line */ + hb_xfree( (void *) yylval.string ); + hb_comp_iState = DECLARE; + return DECLARE; + } + else + { /* there is another item in line already */ + hb_comp_iState = IDENTIFIER; + return IDENTIFIER; + } + } +{Separator}*[^a-zA-Z] { /* any character (not identifier) after DECLARE */ + unput( yytext[ yyleng-1 ] ); + + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; + hb_comp_iState = IDENTIFIER; + + return IDENTIFIER; + } + +"opti"("onal"|"ona"|"on"|"o")? { BEGIN OPTIONAL_; + yylval.string = hb_strupr( hb_strdup( yytext ) ); + } +{Separator}+[_a-zA-Z\&] { /* an Identifier after OPTIONAL */ + unput( yytext[ yyleng-1 ] ); + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; + + if( hb_comp_iState == LOOKUP ) + { /* it is first item in the line */ + hb_xfree( (void *) yylval.string ); + hb_comp_iState = OPTIONAL; + return OPTIONAL; + } + else + { /* there is another item in line already */ + hb_comp_iState = IDENTIFIER; + return IDENTIFIER; + } + } +{Separator}*[^a-zA-Z] { /* any character (not identifier) after OPTIONAL */ + unput( yytext[ yyleng-1 ] ); + if( i_INDEX_STATE ) BEGIN INDEX; else BEGIN 0; + hb_comp_iState = IDENTIFIER; + return IDENTIFIER; + } + +%{ +/* ************************************************************************ */ +%} "do" BEGIN DO_; {Separator}+"case" { /* DO CASE statement */