arithmetic.g4 question

76 views
Skip to first unread message

Willy Andrianarisoa

unread,
Jun 12, 2024, 3:10:45 AM6/12/24
to antlr-discussion
I try to implement formula builder project , i start as a scratch the arithmetic.g4 grammar available in antlr4 github (https://github.com/antlr/grammars-v4/blob/master/arithmetic/arithmetic.g4)
I start to test it , with some inputs,
When i try to analyze (with ANTLR input below
10 < 10G
it didn"treport any error ! 
Is this correct (10G is a bad input i suppose)?
I'm a little bit stucked with it. I t

I put in attachments ,  the grammar and the parsetree result
Thanks for any help
Will
arithmetic.g4
parseTree.png

Michael Rachow

unread,
Jul 17, 2024, 9:14:38 AM7/17/24
to antlr-discussion
Hi,

maybe extraneous input at the end is finally not shown.

You might try
10G>10
possibly with -token to see more.

Regards,
Michael

Willy Andrianarisoa

unread,
Jul 18, 2024, 6:42:16 AM7/18/24
to antlr-discussion

Hi,
Let me check and il will be back to you.
Thanks
Regards
Willy

Ken Domino

unread,
Jul 19, 2024, 7:25:22 AM7/19/24
to antlr-discussion
Antlr has no syntax to declare a start rule, so it could be any parser rule. But, that can lead to confusing behavior. '10 < 10G' is illegal input with rule "file_". But, if you try parsing '10 < 10G' from rule "expression", the parse will succeed and not produce an error. Why? This is because "expression" is not an EOF-terminated rule. Instead, the parser backs up to the point of a valid expression, does not output any error, and succeeds. This is by design. Unfortunately, it was also a source of unchecked errors in several important programming language grammars in grammars-v4. Consequently, EOF was added to every start rule. https://github.com/antlr/grammars-v4/pull/2675. --Ken

Michael Rachow

unread,
Jul 19, 2024, 3:54:31 PM7/19/24
to antlr-discussion
Thanks Ken,
learned something.
Regards,
Michael
Reply all
Reply to author
Forward
0 new messages