Optional parser rules skips if the value not matched

13 views
Skip to first unread message

ayyanar ayns

unread,
Apr 28, 2018, 10:16:34 AM4/28/18
to antlr-discussion
 I have expresion like below 

expression
: query (logical query)*
;


logical
: 'and'
| 'or'
| 'OR'
| 'AND'
| '&&'
| '||'
;

Note: I have validated the query rules its working file.. for validating logical if i give invalid it doesn't throws exception .. it was skipping 
can you any one help me ?

For example:

input is [abc and] it throws the exception as missing value of query valid behavious
if the input is [abc and1 ] it doesn't thows exception, its skips and printing only the value of abc 


here the abc is the value of query rules 

Mike Lischke

unread,
Apr 28, 2018, 10:20:53 AM4/28/18
to antlr-di...@googlegroups.com
Sounds like the parser is skipping the unknown input. Does your top level rule end with EOF?

ayyanar ayns

unread,
Apr 28, 2018, 10:22:24 AM4/28/18
to antlr-discussion
does your top level rule end with EOF? what does it mean ? Sorry bro am just new to Antlr

Mike Lischke

unread,
Apr 28, 2018, 12:13:29 PM4/28/18
to azrdev via antlr-discussion
>
> does your top level rule end with EOF? what does it mean ? Sorry bro am just new to Antlr

Assume you have a rule like "query“ which calls (among others) your expression rule. And this is the rule you call when you parse input (which makes it the top level rule). In order to tell the parser to consume all input for a successful parse run you should tell it to take everything into account that is available (by telling it to match until it sees the EOF token):

query: rule1 rule2 expression rule3 EOF;


Mike
--
www.soft-gems.net

ayyanar ayns

unread,
Apr 28, 2018, 12:32:36 PM4/28/18
to antlr-di...@googlegroups.com
ya i have EOF in the my top level rul



Mike
--
www.soft-gems.net

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussion+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Thanking you,
Ayyanar M

David Whitten

unread,
Apr 28, 2018, 12:43:54 PM4/28/18
to antlr-di...@googlegroups.com
So I'm confused what the problem is.
you said that a rule is complete when it has 
query (logical query)*

but you fed it
[abc and]
which translates to
query logical

which does not finish the (logical query) part
so you should create a exception/error because
it only partially filled out your requirement.
I expect there isn't a rule for 
query logical (query logical)*
which is supposed to match an error of a missing query
so you can print out an error message about the missing query,
so ANTLR is creating an exception to handle what you didn't do yourself.

Dave Whitten

On Sat, Apr 28, 2018 at 12:32 PM, ayyanar ayns <ayyan...@gmail.com> wrote:
ya i have EOF in the my top level rul
Reply all
Reply to author
Forward
0 new messages