[antlr-interest] VB If elseif end if?
Anakreon
anakreonmejdi at yahoo.gr
Wed Apr 28 05:49:40 PDT 2004
ronald.petty at milliman.com wrote:
>
> I have in my Parser the rule
>
> //don't forget s1:s2:s3 etc for "If x Then s1:s2..." and for general use
> statement
> : {System.out.println("Entered Statement:Declaration");}
> (declaration)=>declaration
> {System.out.println("Leaving Statement:Declaration");}
> | {System.out.println("Entered Statement:Expr");}
> expr
> {System.out.println("Leaving Statement:Expr");}
> | {System.out.println("Entered Statement:IF");}
> IF expr THEN (statement)* (ELSEIF expr THEN
> (statement)*)* (ELSE (statement)*)? (END IF)?
> {System.out.println("Leaving Statement:IF");}
> ;
>
> And for newlines in the lexer
>
> NL
> :
> ( ("\r\n") => "\r\n"
> | '\r'
> | '\n'
> )+
> { newline(); _ttype = Token.SKIP; }
> ;
>
> If I have the input
>
> if x then y
> if x then y
>
> The result is valid according to my grammar. However instead of two "if
> then" statements I have one "if" with another shoved in the tail end of
> the statement.
>
> (hope this is good syntax)
>
> statement
> if (start of statement input)
> x = expr (for now just an identifier)
> then (next part of the expression
> y = statement (which is an expr, just an identifier)
> now sense we are looping in the statement (statement)*
> the next if x then y is starting there instead of a top level statement.
>
> This is because in VB the newline after y means your done. However I
> eat all newlines in the lexer. What are the possible ways around this?
>
> Thanks for the pointers.
> Ron
New lines are significant in VB.
For this reason the lexer I implemented eats new lines if the last token given
was '_' or a new line.The last token which the lexer served to the parser is
stored in a variable.
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