LALR parsers (lookahead LR) are a family of parsers that are often used in parser generators. They provide a balance between the expressivity of LR(1) parsers and the size of LR(0) parsers.
Questions tagged [lalr]
176 questions
0
votes
2 answers
Parsing a CFG with alternatives
I have a fairly simple language represented as a CFG.
S → A z
A → A y A
| A x A
| A w
| v
Since there's left-recursion, a recursive descent parser isn't going to cut it. However, I also need to find every possible interpretation: given v x v…

Draconis
- 3,209
- 1
- 19
- 31
0
votes
1 answer
Shift/reduce conflict in yacc grammar
I've written a grammar that as rules as follows:
A : B '?'
| B
| A '+' A
;
B : "a"
| "c" A "t" A
;
And this gives me a shift/reduce conflict on
A : B . '?' (96)
A : B . (98)
I've tried multiple ways to change the grammar but I seem…

Frank Wright
- 83
- 3
- 8
0
votes
0 answers
LALR construction from recursive grammar
Suppose I've to parse a list of one and unique terminal token x.
I might be wrong but I thing I've two way:
One declaring a recursive non terminal this way : A -> xA
One other declaring a recursive non terminal that way : A -> Ax
That should…

Lewis Anesa
- 102
- 3
- 12
0
votes
1 answer
Cannot resolve the following reduce-reduce error (LALR parses)
I am currently implementing the part of the Decaf (programming language) grammar. Here is the relevant snippet of bison code:
type:
INT
| ID
| type LS RS
;
local_var_decl:
type ID SEMICOLON
;
name:
THIS
| ID
| name DOT ID
|…

oneturkmen
- 1,288
- 1
- 11
- 27
0
votes
1 answer
Lemon Parser: This rule can not be reduced
I'm attempting to write a grammar to parse templating language say jinja2 (or twig at your choose), and I can't successfully parse switch-case statement.
Let me show desired syntax:
{% switch username %}
{% case "Jim" %}
I want to say:
…

serghei
- 3,069
- 2
- 30
- 48
0
votes
0 answers
Bison : shift-reduce conflicts even though %left %right directive
I know that most of the shift/reduce conflicts can be solved by using %left or %right directives. But even with that, I am getting conflicts. Following is a block of my grammar:
expression: variable '=' expression
| expression…

Chaitanya Patel
- 390
- 1
- 4
- 15
0
votes
1 answer
Parsing with parenthesis and different types of expressions
I'm currently using happy to parse a language, but I don't think the parser is relevant, except to say it's an LALR parser. Here's a small excerpt from the grammar:
ArithExpr -> ArithExpr + ArithExpr
ArithExpr -> ( ArithExpr )
ArithExpr ->…

Clinton
- 22,361
- 15
- 67
- 163
0
votes
1 answer
how to give action for every rule bison
I am trying to make a small compiler using flex and bison but i was not getting how to give action for every rule
my grammar is like:
%union{
std::string *s;
};
%start program
%type expr
%token KEYWORD
%token …

Jeevansai Jinne
- 147
- 2
- 4
- 12
0
votes
1 answer
Bison/EBNF parse list with at least two elements
I am currently trying to parse a comma seperated list with at least two elements using bison.
I know how to parse a list using this:
list : list "," element
| element
but how can I make sure that the list has at least two elements?

Exagon
- 4,798
- 6
- 25
- 53
0
votes
1 answer
Shift/reduce LALR(1) conflict due to parentheses
I'm currently writing a Visual Basic-like LALR(1) grammar, and face this particular shift/reduce conflict which I have no idea how to solve it properly.
The problematic parts of the grammar are (Please see EDIT 1 and EDIT 2 for…

Sam Tatasurya
- 223
- 2
- 15
0
votes
1 answer
Should I be using parser generators for anything else but a language?
While trying to get my feet wet with lexical analysers and parser generators, I realized that most resources in the Internet (Tutorials, Forums, StackOverflow) only talk about languages. Is it because tools like Flex and Bison are only suitable for…

exilit
- 1,156
- 11
- 23
0
votes
1 answer
Template class using Gold Parser and the Klimstra engine
I'm using Klimstra's VB.NET template from the "Create skeleton program" of the GOLD parser but the resulting template has methods with the overrides keyword and inherits from TemplateParser..
Am I supposed to create the TemplateParser class or is…

Weeber
- 11
- 1
0
votes
1 answer
How yacc knows for look ahead
How could yacc knows to shift * but not to reduce T to E in line 10
STACK INPUT BUFFER ACTION
$ num1+num2*num3$ shift
$num1 +num2*num3$ reduc
$F +num2*num3$ reduc
$T +num2*num3$ reduc
$E …

vinay negi
- 38
- 1
- 7
0
votes
1 answer
Effect of yacc operator associativity declaration on expressions that have just a few tokens
When you have a grammar like this one:
B: 'a' A 'a'
| 'b' A 'b'
A: 'a' 'a'
| 'a'
The %right 'a' declaration causes aa.a not to be accepted because a shift happens instead of a reduce at '.',
and %left 'a' doesn't accept neither aa.aa nor…

user2373145
- 332
- 2
- 14
0
votes
0 answers
Using bison rule inside another rule
Let's assume I have grammar like this:
expr : expr '-' expr { $$ = $1 - $3; }
| "Function" '(' expr ',' expr ')' { $$ = ($3 - $5) * 2; }
| NUMBER { $$ = $1; };
How can use rule
expr : expr '-' expr { $$ = $1 - $3; }
inside
expr :…

Milos Ljumovic
- 403
- 4
- 16