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
1
vote
1 answer

Is there a type of parser generator that handles all deterministic context-free grammars?

I need a way of generating parsers for all deterministic context-free grammars. I know that every deterministic context-free grammar can be parsed by some LR(k) parser. The problem is that I need to generate parsers for grammars of unknown k. So, to…
1
vote
1 answer

How to get 'expected token' in bison/yacc GLR-parser?

How to get 'expected token' in bison/yacc GLR-parser? Hi, In the project i am doing, there'er a few ambiguous gramar. So i am trying to use %glr-parser to solve the shift/reduce confilicts. When i was using non-GLR parser, i can use the…
user789265
  • 23
  • 4
1
vote
1 answer

Faulty bison reduction using %glr-parser and %merge rules

Currently I'm trying to build a parser for VHDL which has some of the problems C++-Parsers have to face. The context-free grammar of VHDL produces a parse forest rather than a single parse tree because of it's ambiguity regarding function calls and…
forflo
  • 33
  • 3
1
vote
0 answers

Is there a complete test for GLR parser?

Is there a complete series tests to test if a GLR parser is correctly written? I'am writing a GLR parser, so I want to find some tests for my code. I can't figured out a complete test suit by my self because of some missing conditions perhaps. I've…
qdwang
  • 425
  • 1
  • 4
  • 13
1
vote
1 answer

What is the right way to convert EBNF to BNF when using GLR parser?

EBNF like this Goal = Stmt Stmt = "if" "expr" "then" Stmt ("else" Stmt)? Stmt = "S" Should I Convert this to Goal = Stmt X = "else" Stmt Stmt = "if" "expr" "then" Stmt | "if" "expr" "then" Stmt X Stmt = "S" Or Goal = Stmt Stmt = "if" "expr"…
qdwang
  • 425
  • 1
  • 4
  • 13
1
vote
1 answer

Errors when compiling GLR parsers from Happy - 'parse error on input ‘case’'

I have tried multiple example grammars and get the same error when I try to compile the generated files. For example I have followed exactly the solution to this question - GLR_Lib.hs: Could not find module 'System' where the grammar file is…
user7533
  • 15
  • 2
1
vote
0 answers

Start symbols in Happy with GLR mode

Suppose I define a happy grammar %name pf f %tokentype { AB } %error { parseError } %token a { A } b { B } %% f : a g a {} | b {} g : b b {} { data AB = A | B deriving (Eq,Ord,Show) parseError _ = error " bad " } If I compile…
Jonathan Gallagher
  • 2,115
  • 2
  • 17
  • 31
1
vote
0 answers

DParser: Unresolved Ambiguity

I have a large grammar written for DParser format and using the Python binding. When I parse a code using this grammar, I get the following exception but with different symbols depending on what code I pass to it. But the ambiguous symbols are…
Amal
  • 243
  • 1
  • 3
  • 8
1
vote
1 answer

Nondeterministic, unamigious Grammar?

According to wikipedias GLR description, they "handle nondeterministic and ambiguous grammars." I can visualize an ambiguous grammar, like the dangling else problem, but what's a nondeterministic CF grammar which isn't ambiguous?
Stefan K.
  • 7,701
  • 6
  • 52
  • 64
0
votes
1 answer

C Bison GLR const stack item

I started writing a simple LR(1) parser with Bison. When processing lists I used a simple implementation of a vector, for example when parsing a list of expressions: tuple-expression-list: expression[first] ',' expression[second] { …
Lars M.
  • 179
  • 10
0
votes
2 answers

Bison: distinguish variables by type / YYERROR in GLR-parsers

I'm working on a parser, using GNU bison, and I'm facing an interesting problem. My actual problem is a bit different and less interesting in general, so I will state it a bit differently, so that an answer would be more useful in general. I need to…
Algoman
  • 1,905
  • 16
  • 16
0
votes
3 answers

Bison C++ GLR parser using variants

I am currently creating a parser using bison, which uses the variant feature heavily, since my grammar is not LALR(1) I want to use the GLR option. When I try to do so I get the following error: error: '"glr.cc"' does not support '%define…
Exagon
  • 4,798
  • 6
  • 25
  • 53
0
votes
1 answer

Bison parser with operator tokens in variable name

I am new to bison, and have the misfortune of needing to write a parser for a language that may have what would otherwise be an operator within a variable name. For example, depending on context, the expression FOO = BAR-BAZ could be interpreted…
0
votes
2 answers

Additional syntax error message on GLR parser when syntax is ambiguous

I am using Bison 2.7 to write a GLR parser and also turn on %error-verbose option. When I ran the parser, it gave me "syntax is ambiguous" error. Is there a way that Bison can give me more details on where/how the syntax is ambiguous?
chenwj
  • 1,989
  • 2
  • 16
  • 30
0
votes
1 answer

GLR_Lib.hs: Could not find module 'System'

I am trying to generate a GLR parser from happy, but I am getting errors once the files are generated. Here is an example, ABC.y , so it's clear what I am trying: { module Main where } %name ps1 s1 %tokentype { ABC } %error { parseError } %token a…
Jonathan Gallagher
  • 2,115
  • 2
  • 17
  • 31