Questions tagged [glr]

GLR parser ("Generalized Left-to-right Rightmost derivation parser") is an extension of an LR parser algorithm to handle nondeterministic and ambiguous grammars.

The GLR algorithm works in a manner similar to the LR parser algorithm, except that, given a particular grammar, a GLR parser will process all possible interpretations of a given input in a breadth-first search. On the front-end, a GLR parser generator converts an input grammar into parser tables, in a manner similar to an LR generator. However, where LR parse tables allow for only one state transition (given a state and an input token), GLR parse tables allow for multiple transitions. In effect, GLR allows for shift/reduce and reduce/reduce conflicts.

When a conflicting transition is encountered, the parse stack is forked into two or more parallel parse stacks, where the state corresponding to each possible transition is at the top. Then, the next input token is read and used to determine the next transition(s) for each of the "top" states – and further forking can occur. If any given top state and input token do not result in at least one transition, then that "path" through the parse tables is invalid and can be discarded.

A crucial optimization allows sharing of common prefixes and suffixes of these stacks, which constrains the overall search space and memory usage required to parse input text. The complex structures that arise from this improvement make the search graph a directed acyclic graph (with additional restrictions on the "depths" of various nodes), rather than a tree.

32 questions
24
votes
4 answers

GLR parsing algorithm resources

I am writing a GLR parser generator and would like some advice on resources relating to this algorithm both on the internet and of the dead-tree variety (books for those unfamiliar with the geek-speak). I know Bison can generate GLR parsers, and…
ljs
  • 37,275
  • 36
  • 106
  • 124
13
votes
2 answers

How to implement a graph-structured stack?

Ok, so I would like to make a GLR parser generator. I know there exist such programs better than what I will probably make, but I am doing this for fun/learning so that's not important. I have been reading about GLR parsing and I think I have a…
Emil
  • 131
  • 4
8
votes
3 answers

Who is faster: PEG or GLR?

I'm trying to create some kind of lint tool for the C/AL programming language. So basically I need to perform syntax and lexical analysis against the source code. I've planned to write parser from the scratch, but then discovered that there are a…
shytikov
  • 9,155
  • 8
  • 56
  • 103
6
votes
3 answers

C++ GLR parsers with Bison

I'm using Bison to generate a parser. I've got one shift/reduce conflict where I really need Bison to use GLR rather than LALR to deal with it. But I've passed the %glr-parser directive and the source file still states that it's a LALR parser. I…
Puppy
  • 144,682
  • 38
  • 256
  • 465
6
votes
2 answers

why is `int test {}` a function definition in C language BNF

I'm interested in the famous The syntax of C in Backus-Naur Form and studied for a while, what confuse me is that some syntax looks wrong to me but is considered right according to the BNF. For example, int test {}, what's this? I think this is a…
user2269707
5
votes
2 answers

Bison, C++ GLR parsing: how to force shift\reduce conflict?

How can I force the shift\reduce conflict to be resolved by the GLR method? Suppose I want the parser to resolve the conflict between the right shift operator and two closing angle brackets of template arguments for itself. I make the lexer pass the…
slavasav
  • 71
  • 1
  • 7
4
votes
2 answers

Why does this very simple grammar cause GLR parsers to choke?

I've tried several different parser generators (Bison, DParser, etc.) that claim to be able to generate GLR parsers i.e., ones that can handle ambiguous grammars. Here is a very simple ambiguous grammar of the type I'm talking about: START: A |…
user3268289
  • 175
  • 1
  • 9
4
votes
1 answer

Ambiguous non-terminal in GLR

When GLR parser reduces some text to the same non-terminal in two ore more ways it merges parse subtrees. Rekers uses 'symbol nodes' for this. I this not each non-terminal could cause a merge. Knowing in advance what non-terminals never merge will…
4
votes
1 answer

How to solve LR(1) grammar ambiguity between ternary expressions (a ? b : c) and "maybe" expressions (a?)?

I have created a grammar, a stripped-down version of which is reproduced below: (0) exp1: ternary; (1) exp1: exp2; (2) ternary: exp2 "?" exp1 ":" exp1; (3) exp2: exp2 "+" exp3; (4) exp2: exp3; (5) exp3: maybe; (6) exp3: "1"; (7) maybe: exp3 "?"; I…
user541686
  • 205,094
  • 128
  • 528
  • 886
4
votes
2 answers

How to enforce associativity rules in a GLR parser?

I'm writing a GLR for fun (again, because I understood a few things since my last try). The parser is working now and I am implementing disambiguation rules. I am handling precedence in a way that seems to work. Now I'm a bit at loss regarding…
djfm
  • 2,317
  • 1
  • 18
  • 34
3
votes
4 answers

Implementing "*?" (lazy "*") regexp pattern in combinatorial GLR parsers

I have implemented combinatorial GLR parsers. Among them there are: char(·) parser which consumes specified character or range of characters. many(·) combinator which repeats specified parser from zero to infinite times. Example:…
Lavir the Whiolet
  • 1,006
  • 9
  • 18
2
votes
3 answers

Bison: GLR-parsing of valid expression fails without error message

I'm working on a GLR-parser in GNU bison and I have the following problem: the language I'm trying to parse allows boolean expressions including relations (<,>,<=,...) and boolean composition (and, or, not). Now the problem is that the language also…
Algoman
  • 1,905
  • 16
  • 16
2
votes
1 answer

GLR parser with error recovery: too much alternatives when there are errors in input

Preamble I have written GLR-parser with error recovery. When it encounters an error it splits into following alternatives: Insert the expected element into input (may be the user just missed it) and proceed as usual. Replace the erroneous element…
Lavir the Whiolet
  • 1,006
  • 9
  • 18
2
votes
2 answers

in Bison, how can I specity left associativity for a non-terminal?

I have the following Bison grammar snippet: binary_op: BINARY_OP { ... } | '|' %prec BINARY_OP { ... …
nielsbot
  • 15,922
  • 4
  • 48
  • 73
2
votes
1 answer

using bison++ to create glr parser

I’ve recently been developing a parser with flex/bison bison pair. I was having trouble getting the parser to fit into my application the way I wanted. This included problems with making the parser reentrant and thread safe as well as fitting it…
Dominic Birmingham
  • 325
  • 1
  • 3
  • 11
1
2 3