[antlr-interest] Check for end of token stream when parser finishes.

shibinck shibinck at gmail.com
Mon Jun 29 17:28:18 PDT 2009


Hi,You shouldn't redefine EOF. It's a predefined token for end of stream. I
guess this is what you want
grammar test;
test     : exp+ EOF;
exp    : ONE ('+' ONE)* ';';
ONE    : '1';
-shibin


On Tue, Jun 30, 2009 at 5:46 AM, Gyanit Singh <gyanit at gmail.com> wrote:

> The problem still remains.
> ----------------------
> grammar test;
> test     : (exp EOF)+;
> exp    : ONE ('+' ONE)* ;
> ONE    : '1';
> EOF   : ';'
> -----------------------
>
> Now I am looking for list of expression seperated by a semicolon. The
> problem is checking whether parser have matched the whole token stream or
> not.
>
> Now "1+1;11+1;" will match "1+1;" and ignores last "11+1;". The application
> requires me of raising an exception whenever there are tokens remaining (as
> it is more likely input error).
>
> -gyanit
>
>
> Hi,You could use the EOF token to match the whole input
>> test: exp EOF;
>> -shibin
>>
>>
>> On Tue, Jun 30, 2009 at 5:29 AM, Gyanit Singh <gyanit at gmail.com> wrote:
>>
>>> Hi all,
>>>
>>> I have a simple grammar
>>> ----------------------
>>> grammar test;
>>> test     : exp;
>>> exp    : ONE ('+' ONE)* ;
>>> ONE    : '1';
>>> -----------------------
>>>
>>> if you try to parse "1+11" the parser matches test and expr to "1+1" and
>>> ignores the last "1". Is there a way to throw an exception when this
>>> happens.
>>>
>>> More abstractly, when the rule is kleene closure (or plus) and it ends
>>> leading to the end of the main rule (for the above example rule "test") and
>>> still there are tokens remaining then how to throw and exception instead of
>>> partial match. In other words, after the parsing is done how to check
>>> whether the token stream has ended or not?
>>>
>>> thanks,
>>> gyanit.
>>>
>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>>> Unsubscribe:
>>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090630/a27e4154/attachment.html 


More information about the antlr-interest mailing list