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

Kevin "MiNdCRY" Erath mindcry2000 at gmx.de
Tue Sep 10 04:06:42 PDT 2002


ah thanks,

this seem to work, man why i didn't think about this :-) thanks!!
but still, it would be even better if i just could use it like name_a
without doing a predicate bevor it..
is this possible ? is there another solution or way to hide it ?

if not, i can live with this solution though :-)
Kevin


>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/





 

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



More information about the antlr-interest mailing list