[antlr-interest] Need help with simple grammar

Johannes Luber jaluber at gmx.de
Sun Apr 22 13:57:46 PDT 2007


Florian Weimer wrote:
> * Johannes Luber:
> 
>> Florian Weimer wrote:
>>  > By the way, is there an easy way to accept any non-empty,
>>> non-whitespace string for FILE, including "get", "put", etc.?
>>>
>> Your wish is my command :D
>>
>> <http://www.antlr.org/wiki/display/ANTLR3/Quick+Starter+on+Parser+Grammars+-+No+Past+Experience+Required>
> 
> Thanks, but I don't think it's that easy.  For instance, the grammar
> does not parse "get data from data".

Oh, I thought you didn't want only to parse "file" at the end. As it is,
 the grammar disallows keywords as filenames. If you want to allow
really everything, you have to apply the following steps:

1. Create a rule

ID : ('a'..'z'|'A'..'Z'|'.'}+;

Add additional characters at your leisure.

2. Change FILE to

FILE : ID;

3. Exchange all token rules with normal grammar rules like:

GET : {input.LT(1).getText().equals("get")}? ID;

Best regards,
Johannes Luber


More information about the antlr-interest mailing list