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
0
votes
0 answers
Resolving a reduce/reduce conflict in a parser for lambda calculus
I've been trying for the past couple of days write a menhir (yacc) grammar for this seemingly simple language with some syntax sugar, but can't figure out to do so without ambiguities.
The relevant constructs from the language are:
Application is…

aradarbel10
- 435
- 3
- 10
0
votes
1 answer
ANTLR: Why is this grammar rule for a tuples not LL(1)?
I have the following grammar rules defined to cover tuples of the form: (a), (a,), (a,b), (a,b,) and so on. However, antlr3 gives the warning:
"Decision can match input such as "COMMA" using multiple alternatives: 1, 2
I believe this means that my…

ogr
- 3
- 2
0
votes
1 answer
Unordered result because of an ambiguous grammar using Flex and Bison
I'm trying to create a section for variable declaration (a bit similar to HTML) using Flex and Bison, my grammar is correct (no lexical or syntax errors), but the displayed result isn't ordered.
example.txt:
< a AS INT…

lili
- 1
- 1
0
votes
1 answer
How to create an object in a form like this: ifstream in();
Im beginner in c++. I have seen several times when object created like:
class_name object_name();
and after that you can refer to object_name as an object of the class.
How can i do this in my class? Should I override the constructor? And how to do…

KLGR
- 31
- 5
0
votes
0 answers
How to correctly transform the following grammar to fall into LL(1)
Recently I'm trying to write a compiler for a modified subset of OCaml, through the official documentation I've written a similar grammar given below as what they do to the expressions:(since its a slightly modified version so there will be some…

Dylech30th
- 157
- 2
- 10
0
votes
0 answers
Bison Difficult Dangling Else Removal
I am trying to get rid of dangling else in my grammar. Terminals are capital-letter words. I have:
statement:
expression_statement (not important now )
| compound_statement (not important now )
| selection_statement
|…

Riomare
- 65
- 1
- 10
0
votes
1 answer
Difficulty fixing dangling else problem without assoc in Bison
I have tried to follow the advice on fixing dangling else problem for an assignments grammar but I can't quite get it. I still have the a single shift/reduce conflict. I can't use assoc or left nor right for the Bison file.
I have tried to exhaust…

Carl Dent
- 3
- 1
0
votes
1 answer
How should a unary operator be applied in an expression grammar?
I have a grammar that I've implemented in C#. My question relates to evaluating expressions. A cutdown version of the grammar just relating to expressions is. Note that the grammar also supports logical operations (using AND and OR, rather than &&…

Mark Roworth
- 409
- 2
- 15
0
votes
1 answer
Cannot get LL(1) form of grammar for recursive descent parser
I have grammar:
S -> bU | ad | d
U -> Ufab | VSc | bS
V -> fad | f | Ua
To contruct recursive descent parser I need LL(1) form.
Best I got is:
S -> bU | ad | d
U -> fY | bSX
Y -> adScX | ScX
X -> fabX | aScX | ε
Removed left recursions and done…

jvinkovic
- 35
- 3
- 7
0
votes
1 answer
Bison compiler: remove conflicts
I'm developing a compiler for a C-like language using Bison and Flex. The compiler, at the moment, is able to recognize a language with declaration, assignment and print statements and arithmetic and logic expressions (using only int variables). It…

forzalupi1912
- 63
- 1
- 4
0
votes
1 answer
Syntax Error in Lex and Yacc caused by scanner or parser
I am pretty new in Lex and Yacc. I try to learn about grammar rules and semantic actions. I was trying to write a parser that basically does assignments, function declarations, function calls and print statements. The problem is that after I give an…

Yagimutsu
- 57
- 7
0
votes
0 answers
LALR parser being slower than recursive descent parser
Recently I wrote a (highly optimized) LALR(1) parser (that could handle ambiguous grammars) and supplied it a very ambiguous grammar. After that, I wrote a recursive descent parser for the same grammar, but with all the ambiguity taken out. I've…

xilpex
- 3,097
- 2
- 14
- 45
0
votes
1 answer
Ambiguity in Grammars
I'm learning about ambiguity in grammars and I need a little help to understand better. Here is a grammar:
::= if then
::= if then else
::= a
Using a parse tree or left-most derivation, how can I show that this…

SarahCaw
- 11
- 2
0
votes
2 answers
Can a BNF grammar that does not follow operator associativity and precedence rules be considered as an unambiguous grammar?
Consider this BNF grammar:
= =
= A|B|C
= + | * |()|
This grammar is not ambiguous, since only one parse tree can be drawn for a statement.However, this clearly does not follow operator…

Bora Kurucu
- 21
- 1
- 5
0
votes
1 answer
why is this a ambiguous grammar?
I have the following excercise:
Demostrate this grammar is ambiguous:
S-> bA | aB
A-> a | aS | bAA
B-> b | bS | aBB
By the theory that I've read a grammar can be ambiguous if:
1) A string W ∈ L(G), generates two differents trees
2) Makes 2 or more…

k1k4ss0
- 139
- 4