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

John Allen Green greenj at ix.netcom.com
Wed Sep 11 04:12:38 PDT 2002


You might search the Antlr archives for requests for "hoisting". It's
probably what you have in mind, and no, Antlr doesn't do it (yet).
Actually, I think Terence recently added some hoisting support to the
lexer, so we can keep our fingers crossed for future versions for the
parser.

John




--On 10/09/2002 1:06 PM +0200 Kevin "MiNdCRY" Erath wrote:

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



 

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



More information about the antlr-interest mailing list