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
3
votes
3 answers

what is an ambiguous context free grammar?

I'm not really very clear on the concept of ambiguity in context free grammars. If anybody could help me out and explain the concept or provide a good resource I'd greatly appreciate it.
3
votes
1 answer

ANTLR4 grammar no viable alternative at input

I am working on a project and I have to create a parser for the following grammar: grammar T; I am trying to read this piece of code: theory oo begin builtins: asymmetric-encryption functions: f/1 // f/1 used for function in protocol /* Channel…
3
votes
1 answer

Why does the compiler fail to find the right type?

I have a method and a class with the same name. In a case, the compiler understands that I am using the class name, but not in another case: using System; using DTO; namespace DTO { public class Foo { public string Bar { get; set;…
Boiethios
  • 38,438
  • 19
  • 134
  • 183
3
votes
2 answers

Pretty printing ambiguous grammar

I have implemented parser combinators, that can parse grammars that may contain ambiguity. An error is given when the grammar is ambiguous, but going in the other direction is proving to be more difficult. The question is how to pretty print an…
3
votes
1 answer

Ambiguous grammar and Right Most Derivative

Ambiguous grammar is defined as, "An ambiguous grammar is a context-free grammar for which there exists a string that can have more than one leftmost derivation or parse tree." My doubt is, 1) If the grammar has more than one Right Most…
3
votes
1 answer

How does Swift disambiguate Type Arguments in Expression Contexts?

Take a look at the following two expressions: baz(Foo(0)) baz(Foo < Bar, Bar > (0)) Without knowing what, baz, Foo and Bar are (baz can be a type or a method, Foo and Bar can be types or variables), there is no way of disambiguating…
Clashsoft
  • 11,553
  • 5
  • 40
  • 79
3
votes
1 answer

Resolving LALR Ambiguities

I've recently wrapped my head around LALR enough to write an LALR generator, and I'm trying to construct a java- or c#-style grammar for it (the beginnings of which are specified here). I know it's extra effort to write the parser generator, like…
Josh Wyant
  • 1,177
  • 1
  • 8
  • 13
3
votes
1 answer

One-Character parenthesis matching

Given the grammar rule (BNF, | means or): x := a | x x | x + x | x + "x" | "x" + x | "x" + "x" , with + left-associative (a+a+a means (a+a)+a), concatenation left-associative (aaa means (aa)a, not a(aa)), and + lazily eating operands (aa+aa…
Carucel
  • 435
  • 5
  • 11
3
votes
2 answers

How do I make Marpa's sequence rules greedy?

I am working on a Marpa::R2 grammar that groups items in a text. Each group can only contain items of a certain kind, but is not explicitly delimited. This causes problems, because x...x (where . represents an item that can be part of a group) can…
amon
  • 57,091
  • 2
  • 89
  • 149
3
votes
1 answer

Simple ambiguous grammar with reduce-reduce conflict

The following simple grammar to parse a logical expression results in a reduce/reduce conflict: %token AND OR %token NUMBER VARIABLE %% logical_expr : logical_expr AND logical_term | logical_expr OR logical_term | logical_term …
2
votes
3 answers

How to generate all possible parsings of an ambiguous grammar

I've looked at quite a few grammar parsers, but none of them seem to be able to generate all parsings of an ambiguous grammar. (I've also checked these questions, which don't provide any helpful solutions to my problem.) How can I go about…
Pro Q
  • 4,391
  • 4
  • 43
  • 92
2
votes
1 answer

Bison reduce/reduce conflict between lambda expression and parenthesized identifier

I'm attempting to write my own programming language at the moment, and I have the following simplified grammar: ... %% prog: stmtlist | %empty; block: "{" stmtlist "}"; stmtlist: stmtlist ";" stmt | stmt; decllist: decllist "," decl |…
jinscoe123
  • 1,467
  • 14
  • 24
2
votes
2 answers

How to check if this grammar is ambiguous or not?

I´m having trouble to see if this grammar it´s ambiguous or not. How can I check if it is ambiguous? G = ({S,A,B}, {0,1}, P, S} P: S → 0B | 1A A → 0 | 0S | 1AA B → 1 | 1S | 0BB
Suri
  • 23
  • 1
  • 3
2
votes
1 answer

How can I make this grammar unambiguous?

I'm trying to write a parser for a simple language: parser = Lark(""" ?start: arithmetic_expr | boolean_expr // relational operation ?rel_op : arithmetic_expr ("<" | ">" | "==" | "!=") arithmetic_expr // boolean expression …
Ushyme
  • 140
  • 1
  • 8
2
votes
1 answer

CFG: Why is this grammar ambiguous?

The grammar is as follows. S -> SS' | a | b S' -> a | b The way I understand it, derivations from this grammar will be like SS'S'S'S'... (0 or more S'), where each S or S' will generate a or b. Can someone provide an example that shows this grammar…
1
2
3
8 9