Use this tag in the cases where a parser cannot resolve an ambiguous grammar. For example, when a compiler cannot determine the right choice because an identifier can signify multiple different things.
Questions tagged [ambiguous-grammar]
121 questions
2
votes
2 answers
How can I show that this grammar is ambiguous?
I want to prove that this grammar is ambiguous, but I'm not sure how I am supposed to do that. Do I have to use parse trees?
S -> if E then S | if E then S else S | begin S L | print E
L -> end | ; S L
E -> i

name
- 419
- 3
- 14
2
votes
1 answer
Shift/reduce conflict in Happy grammar
I've got the following (heavily stripped down) Happy grammar
%token
'{' { Langle }
'}' { Rangle }
'..' { DotDot }
'::' { ColonColon }
'@' { At }
mut { Mut }
ident { Ident }
%%
pattern
: binding_mode ident at_pat…

Alec
- 31,829
- 7
- 67
- 114
2
votes
1 answer
make menhir find all alternatives?
I would like to change the behavior of menhir's output in follwoing way:
I want it to look up all grammatical alternatives if it finds any, and put them in a list and get me back this ambigouus interpretation. It shall not reduce conflicts, just…

Prodiction
- 187
- 12
2
votes
1 answer
PEGJS predicate grammar
I need to create a grammar with the help of predicate. The below grammar fails for the given case.
startRule = a:namespace DOT b:id OPEN_BRACE CLOSE_BRACE {return {"namespace": a, "name": b}}
namespace = id (DOT id)*
DOT = '.';
OPEN_BRACE =…

djadmin
- 1,742
- 3
- 19
- 27
2
votes
1 answer
Ambiguous Grammars (BNF NOTATION)
Given this grammar:
::= | ;
::= If then
::= true | false
::= | s1 | s2
How do I prove that it is ambiguous?

Jade
- 335
- 1
- 2
- 12
1
vote
0 answers
How to remove ambiguity of this grammar using lark
I have build a grammar for propositional formulas, however I have found that it is ambiguous, i.e., there is more than one derivation tree for my input formulas.
This is the smallest ambiguous grammar I have found
_PL_grammar = (
r"""
…

djimenez
- 41
- 3
1
vote
1 answer
How does the latest ANTLR4 resolve the "dangling else" ambiguity?
I am using antlr 'org.antlr:antlr4:4.9.2' and come across the "dangling else" ambiguity problem; see the following grammar IfStat.g4.
// file: IfStat.g4
grammar IfStat;
stat : 'if' expr 'then' stat
| 'if' expr 'then' stat 'else' stat
|…

hengxin
- 1,867
- 2
- 21
- 42
1
vote
1 answer
Ambiguity in grammar not reported by ANTLR
Can anyone help me understand what makes ANTLR not report an issue with the ambiguity in this grammar?
https://github.com/NASA-SW-VnV/fret/blob/master/fret-electron/support/NuSMVParser/NuSMV.g4#L61-L78
The rules in simpleExpr and ltlExpr are…

Ivan Perez
- 582
- 2
- 17
1
vote
2 answers
Parser/Grammar: 2x parenthesis in nested rules
Despite my limited knowledge about compiling/parsing I dared to build a small recursive-descent parser for OData $filter expressions. The parser only needs to check the expression for correctness and output a corresponding condition in SQL. As input…

AndreasS
- 315
- 3
- 12
1
vote
2 answers
Show that the grammar. S->aS|aSbS|Ɛ is ambiguous and find the unambiguous grammar
I have this question:
Show that the grammar. S->aS|aSbS|Ɛ is ambiguous and find the unambiguous grammar.
I tried learning from the internet whatever I could about ambiguous grammars but most of those try on the same old examples and I feel that they…

Vaibhav Chopra
- 87
- 1
- 8
1
vote
1 answer
Is this context free grammar ambiguous?
I would like to know if the following context-free grammar is ambiguous or not.
S -> 0S | A | 0
A -> 1A | 1
I am fairly convinced that it is unambiguous but I was told that it was ambiguous instead. Could someone please help me?
Thank you.

dumb asz
- 13
- 3
1
vote
0 answers
Is the following grammar is ambiguous and if it is What's the unambiguous grammar of the following
E-->I/E+E/E-E/E*E/E/E
I-->a/b/Ia/Ib/I0/I1
I know how to remove ambiguity for the productions of E but the presence of I is making me confuse to solve the ambiguity

Praveen Kumar
- 11
- 1
1
vote
0 answers
How to convert ambiguous grammar to unambiguous grammar
I've got a grammar which I believe is ambiguous. I don't know how to eliminate the ambiguity and convert it to an unambiguous grammar.
expr ::= num | lvalue | incrop expr | expr incrop | expr binop expr | (expr)
lvalue ::= $expr
incrop ::= ++…

pooria
- 343
- 2
- 14
1
vote
1 answer
How to solve ambiguity in with keywords as identifiers in grammar kit
I've been trying to write the graphql language grammar for grammarkit and I've found myself really stuck on an ambiguity issue for quite some time now. Keywords in graphql (such as: type, implements, scalar ) can also be names of types or fields.…

Jeff
- 13
- 2
1
vote
1 answer
LL1 grammar for arithmetic expressions and assignments
I would like to design an LL1 grammar for arithmetic equations and variable assignments. I began with this grammar:
I have a nonambiguous grammar for arithmetic expressions:
E → T E’
E’ → | + E
T → id T’
T’ → | * T
However, I'm not sure how to…

maddie
- 1,854
- 4
- 30
- 66