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

Kevin "MiNdCRY" Erath mindcry2000 at gmx.de
Tue Sep 10 02:23:46 PDT 2002


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/ 



More information about the antlr-interest mailing list