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
1
vote
1 answer
Shift/reduce conflicts using Sablecc
I'm supposed to write a .grammar file for MiniPython using Sablecc. I'm getting these shift/reduce conflicts:
shift/reduce conflict in state [stack: TIf PTpower *] on TMult in {
[ PMltp = * TMult PTopower Mltp ] (shift)
[ PMlpt = * ]…

hussar
- 13
- 3
1
vote
1 answer
BNF grammar associativity
I'm trying to understand how left and right associative grammars work and I need a little help. So I decided to come up an example and ask for some clarification.
Basically, I want to create a grammar for two logical operations: and + implication. I…

Sreten Jocić
- 165
- 1
- 14
1
vote
1 answer
Fully left-factor the following grammar so that it is suitable for use in a top-down compiler
Here S is the non-terminal start symbol; A,
B, C are non-terminal symbols; x, y, are terminal symbols
S → A B A C | A C A B
A → A x | A y
B → B x x | B y y
C → x y | y x
Having watched videos I understand simple examples for eliminating left…

James
- 13
- 3
1
vote
1 answer
Why is this grammar ambiguous?
I'm using Antlr4. Here is my grammar:
assign : id '=' expr ;
id : 'A' | 'B' | 'C' ;
expr : expr '+' term
| expr '-' term
| term ;
term : term '*' factor
| term '/' factor
| factor ;
factor : expr '**' factor
…

Andromeda
- 49
- 1
- 12
1
vote
0 answers
Grammar for expressions. Four levels of precedence. LL(1)
I need to know how to make a grammar for expressions to create a parser and ast. I have four levels of precedence:
1. ** !
2. * / % &
3. + - ^ |
4. <= >= < >
I have made this:
Exps -> RExp4
RExp4 -> OpEq Exps | RExp3
RExp3 -> OpAd Exps |…

Aion
- 11
- 3
1
vote
2 answers
If the grammar is ambiguous then there exists exactly one handle for each sentential form.?
there can be two productions from which we can do the reduction. After giving precedence and associations as required there will be one handle only.so is this statement true??

siddharth
- 579
- 1
- 8
- 18
1
vote
1 answer
Why is layout around optional parts of a production causing ambiguity?
In Rascal, why is it that when there is layout at the position of an optional part of a production, this causes ambiguity? E.g. "{ }" is ambiguous as Start1, while it parses fine as Start2 from the following grammar, which I would have expected to…

Olav Trauschke
- 126
- 8
1
vote
1 answer
Resolve ambiguity from grammar for C initialization list
I cannot seem to resolve the ambiguity contained in the following rule:
InitializerList_a →,[Initializer][InitializerList_a]
It is causing a shift/reduce conflict in my parser (I'm using Bison). The following is its closure:
InitializerList_a →…

Jarri Abidi
- 58
- 6
1
vote
1 answer
Chomsky languages: how to recognize them?
I have a problem with the recognition of languages. Given a certain language, for example ancb2n, n > 0, how do I determine quickly what type belongs according Chomsky?
My idea was to determine the grammar that generates it and then up to the…

Balboa
- 59
- 6
1
vote
1 answer
ContextFreeGrammar ambiguity
given a CFG: S--> aS | Sa | b I can not find any string that can be made from two different pars trees.
the middle state has left recursion but without eliminating that is there any string that shows the CFG ambiguity ? can anyone help plz.

Amir-Mousavi
- 4,273
- 12
- 70
- 123
1
vote
0 answers
Converting ambiguous to unambigous grammar for arithmetic expressions
I'm attempting to come up with a non-ambiguous grammar for arithmetic expressions to make an Earley parser faster but I seem to be having trouble.
This is the given ambiguous grammar
S -> E | S,S
E -> E+E | E-E | E*E | (E) | -E | V
V -> a | b |…

user2104113
- 11
- 1
0
votes
2 answers
Make this Expression Grammar unambiguous for LL(1)
How can we make this Expression grammar unambiguous for LL(1) parsing?
The grammar is very similar to expressions used in most C like languages.
Note: Strings in <> are non-terminals, while those in Upper Case are terminals.
--> …

Ashhar Akhlaque
- 51
- 5
0
votes
1 answer
The same instance of a sub-formula in the Xtext grammar
I have an Xtext grammar for a CNL sentence and in some its variants I would require the user to write the same parts in the sentence:
Formula:
'It' 'should' 'be' e1=Expr 'and' 'again' e2=Expr;
where Expr is a recursive expression like a boolean…

SeregASM
- 75
- 12
0
votes
1 answer
Conflict in ambiguous grammar due to ordered declaration of optional blocks
I need help defining some rules for a grammar in cups. The rules in question belong to the declaration block, which consists of the declaration of 0 or more constants, 0 or more type records, and 0 or more variables. An example of code to parser:
x:…

Eml0c
- 1
- 4
0
votes
1 answer
ANTLR4 Ambiguity parsing SQL BETWEEN followed by an AND
I am trying to parse this expression (based on SQLite): 0 BETWEEN 0 AND 2 AND 1 < 9.
Here is the relevant portion:
expression
: term #termExpression
| left=expression '<' right=expression #lessThanExpression
| value=expression NOT?…

Travis Parks
- 8,435
- 12
- 52
- 85