[antlr-interest] Quaestion about adding logic checks into the parsers grammer..

John Allen Green greenj at ix.netcom.com
Wed Sep 11 03:56:51 PDT 2002


Oops, thought of another way, which might be more what you are looking for,
since you mentioned syntactic predicates. Leave the semantic checks within
name_a and name_b, and then add syntactic predicates within name:

name
    :    (name_a)=> name_a
    |    (name_b)=> name_b
    ;


John


--On 10/09/2002 11:23 AM +0200 Kevin "MiNdCRY" Erath wrote:

> Hi,
> 
> after using flex/bison for months (if not years), i thought it's time to
> get used to a more modern lexer/parser :-)
> actually i am playing around with antlr to see what is possible and what
> not..
> 
> actually i try to figure out how i can add my own checks to the grammer, a
> pretty silly example (to help you understand what i want to try):
> 
> the lexer returns me a ID which is defined like ('a'..'z'|'A'..'Z')
> 
> now in the parser i want to have something simular to:
> 
> name
>     :    name_a // got a ID beginning with a
>     |    name_b // got a ID beginning with b
>     ;
> 
> name_b
>     :    /*only match if ID begins with b*/ ID
>     ;
> 
> name_a
>     :    /*only match if ID begins with a*/ ID
>     ;
> 
> for sure in this case it could be done in the lexer, and it's just a dang
> silly example...
> 
> i tryed to do:
> name_a
>     :    {LA(1)==ID && LT(1).get()->getText()=="a"}? ID
>     ;
> 
> or:
> 
> name_a
>     :    ({LA(1)==ID && LT(1).get()->getText()=="a"}?)=> ID
>     |    IGNORE_ME_TOKEN
>     ;
> 
> and:
> 
> name_a
>     :    i:ID {i->getText()=="a"}?
>     ;
> 
> but it seems that they all only help for semantical checks, how can i do
> such checks for the Syntax ?
> i want to use this with a Symbol Table, if a ID has been already used i
> want to use different rules etc...
> 
> thanks for your help,
> Kevin
> 
> "¨¨°º©o.,MiNdCRY,.o©º°¨¨"
> ------------------------------------------
>   www.game-designer.net
> ------------------------------------------
> 
> 
> 
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 
> 
> 
>  



 

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



More information about the antlr-interest mailing list