[antlr-interest] Grammar for End of Line.

Joan Pujol joanpujol at gmail.com
Thu Aug 26 07:47:16 PDT 2004


You can solve the lexer indeterminism this way (You have to declare
ENDLINE toke in tokens sections:

STREXPR         :       ('X' NEWLINE)=>'X' {$setType(ENDLINE);}
			        |('a'..'z' | 'A'..'Z')+;


About the grammar It's recursive!

> recordexpr      :       ((assignexpr)COMMA)+ ;
> 
> assignexpr      :       aexpr (ASSIGN^ assignexpr)+ ;
> 
> aexpr           :       parenargs (aexpr)+ ;
> 
> parenargs       :       LPAREN
>                         (
>                           assignexpr

assignexpr-> aexpr -> parenargs -> (CONSUME LPAREN)
then another time assignexpr --> CONSUME LPAREN and another assignexpr....
and...


Cheers,



On Thu, 26 Aug 2004 05:01:39 -0000, din_wins <din_wins at yahoo.com> wrote:
> The grammar for which i need to write requires for checking end of
> the line and end of the record. i need to check for X or x
> respectively.
> 
> How I need to go about in writing the gramar for the above. I am here
> with producing my grammar file also. When I write rule for checking X
> then i am getting lots of errors.
> 
> Request any immediate help in this regard.
> 
> ======================================================================
> 
> options {
>         language = "CSharp";
> }
> class BMSParser1 extends Parser;
> 
> options
>         {
> 
>                 buildAST = true;
>         }
> 
> file            :       (line (NEWLINE line)* EOF!) ;
> 
> line            :       (lineexpr)+ ;
> 
> lineexpr        :       (recordexpr ENDLINE)+ ;
> 
> recordexpr      :       ((assignexpr)COMMA)+ ;
> 
> assignexpr      :       aexpr (ASSIGN^ assignexpr)+ ;
> 
> aexpr           :       parenargs (aexpr)+ ;
> 
> parenargs       :       LPAREN
>                         (
>                           assignexpr
>                            (
>                              COMMA!
>                               assignexpr
>                            )*
>                         )
>                         RPAREN
>                 ;
> 
> class BMSLexer1 extends Lexer;
> 
> ENDLINE         :       'X';
> 
> LPAREN          :       '(';
> 
> RPAREN          :       ')';
> 
> ASSIGN          :       '=';
> 
> COMMA           :       ',';
> 
> WS              :       (' '
>                 |       '\t'
>                 |       )
>                         { _ttype = Token.SKIP; }
>                 ;
> STREXPR         :       ('a'..'z' | 'A'..'Z')+ ;
> 
> DIGIT           :       ('0'..'9')+ ;
> 
> NEWLINE         :       ('\r''\n')=> '\r''\n' //DOS
>                 | '\r'                  //MAC
>                 | '\n'                  //UNIX
>                 { newline(); }
>                 ;
> 
> 
> Yahoo! Groups Links
> 
> 
> 
> 
> 


-- 
Joan Jesús Pujol Espinar


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list