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
1 answer
How can I convert this ambiguous grammar to non-ambiguous grammar?
S -> ABCD
A -> ae | af | ag | ah
B -> b | ε
C -> hcd | bcd | cd
D -> e | f | g | h
I've already tried left factorization on 2 and 4 but I'm stuck with | in many of my productions.
0
votes
2 answers
keywords and identifiers conflict writing lexer? (scala libs)
I've tried fastparse, parboiled2 and scala-combinators.
They all have this problem when defining a LEXER:
LET_KEYWORD ::= "let"
IDENTIFIER ::= "[a-zA-Z]+".r
When I run them against input "leto" they produce [LET_KEYWORD,IDENTIFIER(o)].
I'd expect…

caeus
- 3,084
- 1
- 22
- 36
0
votes
2 answers
Converting ambiguous language to unambiguous
I've been given a homework task to convert the following grammar to unambiguous.
A --> B
A --> ε
B --> B @ B
B --> STRING
B --> DOUBLE(STRING)
where A and B are non-terminals and STRING and DOUBLE are non-terminals.
I can derive that it is…

Neri Villa
- 35
- 6
0
votes
1 answer
Bison how to describe optional syntax in grammar without shift-reduce conflicts?
I have a file that is described with a grammar. It has a section that can consist of one or two kinds of contents, and it can be in arbitrary order:
...
type_a_thing
type_b_thing
type_b_thing
type_a_thing
....
Or…

waszil
- 390
- 2
- 5
- 15
0
votes
0 answers
How to remove ambiguity in following grammar?
S -> Sa | SbSa | ε
I found a similar question but i don't understand : http://automatasteps.blogspot.co.id/2007/08/unambiguous-grammar.html
How do i change this to the unambiguous one?
My string is bbaaa

Ricky
- 21
- 1
- 3
0
votes
1 answer
If then else ambiguity in CUP
I am constructing a grammar in CUP, and I have ran into a roadblock on defining IF-THEN-ELSE statements.
My code looked like this:
start with statements;
/* Top level statements */
statements ::= statement | statement SEPARATOR statements…

Jsevillamol
- 2,425
- 2
- 23
- 46
0
votes
1 answer
(Programming language) How to judge whether this grammar is ambiguous
S -> ()
| (S)
| SS
Is this grammar ambiguous?
and How do i judge whether this grammar is ambiguous?
I learned to draw a Parse tree. But I do not know how to draw it.

황인서
- 1
0
votes
0 answers
Parser Stack Overflow LL(1)
I am studying compiler design and I am trying to implement an LL(1) parser by hand. I already finished the lexical scanner and it works great. However, I'm quite new to elimination of left recursiveness and left factoring. I created a parse() method…
0
votes
1 answer
How can semantic predicates use early information from listeners with ANTLR 4?
I have a parser based on ANTLR 4 and using listeners, not visitors. It already recognizes and stores the declaration of functions, variables and so on.
I'm trying to resolve some grammar ambiguities with semantic predicates, for instance to separate…

RedGlyph
- 11,309
- 6
- 37
- 49
0
votes
1 answer
Shift/Reduce IF-ELSE conflict in my grammar
I'm trying to write a small parser. Unfortunately I get a "shift-reduce conflict". Grammars are not my strong point, and I only need to get this one small thingy done. Here's the reduced grammar that produces the error:
stmts_opt -> stmts
;
stmts…

AbdelKh
- 499
- 7
- 19
0
votes
1 answer
Follow set example doesn't follow any rules?
S → asg
S → if C then S E
C → bool
E → else S
E → λ
all the lower case and the λ are terminal symbols
I need help deriving the follow set of this grammar. I normally do not have trouble with these problems and I know the rules, but when I…

WJosh Vetter
- 37
- 6
0
votes
1 answer
How to show that a grammar with Bitwise operator is ambiguous using the expression a>>b^c
I am trying to solve this question but I really don't know how to get started. I would appreciate some help.
The bitwise operators for a language are shown in the table below alongside the grammar. The operators and the grammar rules are in order of…
0
votes
1 answer
Correctness of a grammar for propositional logic
I am trying to write a grammar for propositional logic for the purpose of creating a LL parser (lexical analysis).
I tried the following grammar:
F = F and F
F = F or F
F = F => F
F = F <=> F
F = not F
F = (F)
D = a
but I discovered that it is…

halm helmi
- 11
- 4
0
votes
1 answer
Verilog `PATHPULSE$` Syntax
In reading the Verilog specification, I noticed a peculiar syntactical construct involving specifying path pulses. Specifically, statements in the form
PATHPULSE$in_port$out_port = ...;
According to the spec, in_port and out_port can either be…

Drew McGowen
- 11,471
- 1
- 31
- 57
0
votes
1 answer
Removing ambiguity from grammar
Ambiguous grammar:
E -> UV | EBE | V | [E]
V -> a | b
U -> < | >
B -> ? | ! | @
Some information:
Order of precedence: ? < ! < @, with unary operators (<,>) being the highest
Binary operators ?, !, @ are right associative.
My attempt:
E -> UV | EBT…

uohzxela
- 613
- 4
- 14
- 28