Questions tagged [ambiguous-grammar]

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.

121 questions
0
votes
1 answer

is this grammar ambiguous

I want to convert this grammar to an unambiguous grammar: S -> if E then S | if E then S else S | a E -> b I found a solution which is more complicated than my solution but I'm not sure if my solution is correct: S -> if E then T else S |…
ayyoob imani
  • 639
  • 7
  • 16
0
votes
1 answer

Is a context-free grammar that can be transformed into a LR parsing table unambiguous?

I know that in general it is undecidable whether a context-free grammar is unambiguous. However, this does not imply that this cannot be decided for a subset of context-free grammars. A grammar is used to transform an input text into a parse tree.…
0
votes
1 answer

XText Dangling Else - The Other Option

So I've been using X-Text and playing with Syntactic Predicates. The classic example is the dangling else problem, where the solution given is to greedily parse the else statement, i.e. don't terminate the inner expression, like so: IfStatement: …
alexp82539
  • 77
  • 1
  • 5
0
votes
1 answer

How to show the following grammar is ambiguous?

I have the following grammar defined: S -> A|B, A -> aAb | ab, B -> aBb | epsilon; After working for some time, I still couldn't find a string to construct a distinctive parse tree to show that this grammar is ambiguous. Like: aaabbb,abab,etc. It…
0
votes
1 answer

Tcpdump BPF syntax ambiguity

Observe these lines of BPF filters in tcpdump/libpcap syntax: 1: not host x or host y 2: not (host x or host y) 3: not (host x or y) 4: not host x or y 5: (not host x) or host y 6: (not host x) or y It is my opinion that host z matches all of the…
Cheatah
  • 1,825
  • 2
  • 13
  • 21
0
votes
1 answer

Semantics-directed parser combinators

I tried this import scala.util.parsing.combinator._ def name = ident ^^ {case ident => if (ident.contains("a")) ident.toUpperCase else ident println(parseAll(name, "aa")) // parsed: AA println(parseAll(name, "bb")) with output [1.3] parsed:…
0
votes
1 answer

Resolving ambiguity of the grammar

I have a grammar rules like that; S -> S and S S -> S or S S -> (S) S -> true | false -- and , or , ( , ) , true ,false are terminals -- I can find out that this grammar is ambiguous, but how can I modify this grammar to solve the ambiguity?
ccca
  • 75
  • 2
  • 11
0
votes
1 answer

I am getting a left recursion error in my antlr parser grammar

I am getting the error [fatal] rule statement has non-LL(*) decision due to recursive rule invocations reachable from alts 6,7. Resolve by left-factoring or using syntactic predicates or using backtrack=true option. I don't know exactly…
0
votes
1 answer

How to solve this ambiguous grammar?

I am creating a compiler and I am using lex and bison. This is a part of my grammar : math : math binop math | VAR | INT | GREEK | "(" math ")" | math comp math | "-" math | math math | "\\sqrt" "{" math…
0
votes
0 answers

XText: ambiguous grammar with identifiers

I am having a problem with an ambiguous Xtext grammar, but I just cannot find the correct solution. Program: (statements+=Statement)+ Statement: (AssignmentStatement | ResetStatement); ResetStatement returns Statement: 'RESET'…
0
votes
1 answer

Xtext Grammar Ambiguities (Backtracking is not working)

I am trying to use Xtext to design a simple language for operations on sets of numbers. Here are some examples of strings in the language: {2,1+6} (A set of numbers 2 and 7) {1+3, 3+5} + {2..5} (A union of sets {4, 8} and {2, 3, 4, 5}) I am using…
Evgenii.Balai
  • 939
  • 13
  • 30
0
votes
2 answers

Context Free Grammar BNF

need help with a non-extended BNF grammar: Σ = {a,b,c} L = {ω ɛ Σ^* | such that all a's (if any) comes before all c's(if any)} For example, the strings aba, cbc, and abacbc are in the language, but string abcabc is not. This is what i have so far…
Jon Abraham
  • 851
  • 3
  • 14
  • 27
0
votes
1 answer

Irony Reduce-Reduce Problems

I have been trying to figure out this same issue for almost 2 weeks now. At first it was shift-reduce errors now its reduce-reduce problems. I have tried doing it so many ways and now I have came to the point where I just need help. I've coded many…
0
votes
1 answer

Helping on how to solve ambiguous grammar

Show that the following grammar is ambiguous. (To show that a grammar is ambiguous, you must demonstrate that it can generate two parse trees for the same string.) ` `person::= woman|man woman::= willma|betty|empty …
0
votes
0 answers

Removing hidden ambiguity in grammar using left factoring

I am trying to reduce the grammar to LL(1) for a hypothetical language we created. I have removed most of the left factoring issues in the grammar, using the general rule of introducing new non-terminal characters for the same. For…
viv1
  • 99
  • 2
  • 10
1 2 3
8 9