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

Unambigous grammar to ambiguous

I don't know if it is the right site to ask this. But we're studying about ambiguities of grammar. Including left most derivation and right most derivation. My practice problem is this: E -> E * E | E + E | N N -> 0N | 1N | Output: 0110 + 110 *…
Yodism
  • 227
  • 1
  • 5
  • 17
0
votes
1 answer

Parsing Cool Language with antlr, cant print the desired out put

I'm a writing a parser/lexer for COOL ( classroom object-oriented language ). u can see the grammar in the following link: ( LAST PAGE OF THE MANUAL ) http://theory.stanford.edu/~aiken/software/cool/cool-manual.pdf I am using ANTLR to write this…
0
votes
1 answer

Ambiguity in Context free Grammar

Question Show that the context-free grammar "S->SbS|ScS|a" is ambiguous by giving two parse trees for the string abaca. I don't get how the string is ambiguous ? I was reading a book on compilers and self learning so i was doing this question in…
user1010101
  • 2,062
  • 7
  • 47
  • 76
0
votes
1 answer

Find each of the following languages? (grammar)

I want to, for each of the following languages on Τ={a, b, c}, construct the corresponding regular expression and regular grammar: All strings containing exactly three a’s. All strings containing at most three b’s. How can I do this?
0
votes
1 answer

Show the following grammar is ambiguous

I'm trying to identify a sentence that can produce more than one derivation tree. Also provide two different trees from the sentence = = + | = a | b | c p.s i have a hard time figuring out the sentences
0
votes
1 answer

Rule not recognized

I've written a grammar which should allow me to define variables and arrays. Everything worked fine until I split up the variables into local and global variables. Now my parser doesn't recognize the arrays anymore (it says it would be a variable…
Raven
  • 2,951
  • 2
  • 26
  • 42
0
votes
1 answer

context free grammar ambiguous?

For the following context free grammar: S --> (S) | SS | A A --> a | A,A | E (E is the empty string) The formal definition is: G=(V,T,P,S) V={A,S} T={E;a; ( ; ) ; , } S=S P: S --> (S) S --> SS S --> A A -->a A -->A,A A --> E (E is…
user2880113
  • 345
  • 1
  • 5
  • 13
0
votes
1 answer

LALR grammar ambiguous

I have made a grammar for boolean and arithmetic expressions. I want to handle arithmetic expressions like: (1+5)+(-3) I'm done with that work: I can handle all the expressions I want. My problem is that a boolean expression can be something…
Jorge Silva
  • 225
  • 1
  • 3
  • 10
0
votes
1 answer

How do I make this simple grammar unambiguous?

Here is the ambiguous grammar for a simple DDC compiler in BNF form: ::= | ::= | ::= | ::= 0 | 1 | 2 | 3 | 4 | 5 |…
amorimluc
  • 1,661
  • 5
  • 22
  • 32
-1
votes
1 answer

Failed Predicate Exception

Can anyone give me some examples of Failed Predicate exception in ANTLR. and some examples that will clearly explain :- input mismatch VS failed predicate VS no viable alt exceptions in ANTLR. thanks in advance.
-1
votes
1 answer

Unambiguous grammar for expressions with let and addition

What is an unambiguous grammar equivalent to to the following ambiguous grammar for a language of expressions with let and addition? E ⇒ let id = E in E E ⇒ E + E E ⇒ num The ambiguity should be solved so that: addition is left associative addition…
Romildo
  • 545
  • 9
  • 20
-1
votes
1 answer

Compilers: change ambiguous grammar

I have a little problem with this exercise. Given this grammar: S -> aX | X X -> aXb | b | eps a) shows that it is ambiguous with a string b) say what language captures the grammar c) change the grammar and build a descendant parser Solution by…
Federico
  • 143
  • 1
  • 1
  • 10
-1
votes
1 answer

Confused at transferring an ambiguous grammar to an unambiguous one

An ambiguous grammar is given and I am asked to rewrite the grammar to make it unambiguous. In fact, I don't know why the given grammar is ambiguous, let alone rewriting it to an unambiguous one. The given grammar is S -> SS | a | b , and I have…
-2
votes
3 answers

Can you explicitly use a constructor overload?

If I have 2 constructor overloads calculations(double vector, double angle); calculations(double horizontalVector, double verticalVector); How can I ensure the compiler specifically uses one of the overloads that I choose (as each of them do…
-2
votes
1 answer

Find a s-grammar (simple grammar)

find a simple grammar (a.k.a s-grammar) for the following language: L={(ab)2mb :m>=0} [i did this but it is wrong] S-> aASBB|b A-> a B->b
Fulla
  • 79
  • 7
1 2 3
8
9