Questions tagged [lalr]

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.

176 questions
4
votes
2 answers

LALR(1) parser generator for scala

I know that it's possible to use, for example, bison-generated Java files in scala project, but is there any native "grammar to scala" LALR(1) generators?
John Rivers
  • 1,307
  • 10
  • 20
4
votes
3 answers

LR(k) or LALR(k) parser generator with features similar to ANTLR

I'm currently in the process of writing a parser for some language. I've been given a grammar for this language, but this grammar has some left recursions and non-LL(*) constructs, so ANTLR doesn't do very well, even with backtracking. Because…
Jost
  • 5,948
  • 8
  • 42
  • 72
4
votes
1 answer

Why is this grammar conflicts?

It is compiled with Lemon, which is a LALR(1) parser generator : program ::= statement. statement ::= ifstatement Newline. statement ::= returnstatement Newline. ifstatement ::= If Number A statement B. ifstatement ::= If Number A statement B…
Maël Nison
  • 7,055
  • 7
  • 46
  • 77
3
votes
1 answer

Ambiguity in Bison grammar

I've got a problem in my Bison grammar. I've got a pair of shift/reduces which are fine, and six reduce/reduces. The issue is that I don't understand how the reduce/reduce conflicts come about, since the parser should know which to choose from…
Puppy
  • 144,682
  • 38
  • 256
  • 465
3
votes
2 answers

Simple Grammar for Lemon LALR Parser

I've been stuck with this since a while now. I want to parse something as simple as: LIKES: word1 word2 .. wordN HATES: word1 word2 .. wordN I am using Lemon+Flex. At the moment my Grammar looks something like this : %left LIKES MOODS FROM HATES…
crozzfire
  • 186
  • 1
  • 1
  • 13
3
votes
1 answer

How to understand LALR Shift/Reduce Algorithm

I'm trying to read Compiler Construction by Niklaus Wirth. On page 23 he starts to describe how LALR would parse the expression x*(y+z) given the following grammar: E = T | E "+" T. expression T = F | T "*" F. term F = id | "(" E ")".…
ktr
  • 696
  • 9
  • 15
3
votes
1 answer

General language parser as a finite state machine

I've written very low performance descent recursion parser for general language (open source, for EBNF grammars). And I want to fix its performance by rewriting parser. I read about lexical analysis, LL, LR, LALR parsers and modifications like…
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
0 answers

LR(k) parse table construction: Is it possible to calculate the lookahead sets on demand?

I've began to read about LR(k) parse table construction, and all texts explaining the algorithm for k > 0 suggest that the lookaheads should be calculated for every symbol before generating the item sets, then when all item sets are generated, the…
Thiago Padilha
  • 4,590
  • 5
  • 44
  • 69
3
votes
1 answer

Resolving a shift/reduce conflict in an LALR parser

I've been using PLY to build up a parser for my language, however I've got a shift/reduce conflict that's causing me some trouble. My language has generic types with a syntax ala C++ templates. So right now I have rules like: expression :…
Alex Gaynor
  • 14,353
  • 9
  • 63
  • 113
3
votes
2 answers

Left Recursion in Grammar Results in Conflicts

Throughout a Bison grammar I am using right recursion, and I have read that left recursion is better because it doesn't have to build the whole stack first. However, when I try to switch to left recursion on any of them, I always end up with a lot…
Kyle Brandt
  • 26,938
  • 37
  • 124
  • 165
3
votes
1 answer

Error recovery in an LALR(1) grammar

I'm using some parser and lexer generating tools (similar to Lex and Bison, but for C#) to generate programs that parse strings into abstract syntax trees that can later be evaluated. I wanted to do error recovery (i.e. report in the produced…
Jesus is Lord
  • 14,971
  • 11
  • 66
  • 97
3
votes
1 answer

How can I resolve a reduce reduce conflict:

The following (simplified) Bison grammar produces a reduce reduce conflict: expr : '(' expr ')' | ID | fn ; arg_list : ID | arg_list ID ; fn : '(' ')' fnbody | '(' arg_list ')' fnbody …
Aaron Yodaiken
  • 19,163
  • 32
  • 103
  • 184
2
votes
2 answers

How to resolve a shift-reduce conflict in unambiguous grammar

I'm trying to parse a simple grammar using an LALR(1) parser generator (Bison, but the problem is not specific to that tool), and I'm hitting a shift-reduce conflict. The docs and other sources I've found about fixing these tend to say one or more…
Geoff Romer
  • 2,358
  • 1
  • 18
  • 19
2
votes
1 answer

How to avoid a shift reduce conflict in a LALR grammar for parsing nested lists?

I would like to create a LALR grammar to parse nested lists, but I get always a shift/reduce conflict. I have the list1 which is a list of type1 items and list2: ::= | ; ::= A | B | ; And I have a…
ceving
  • 21,900
  • 13
  • 104
  • 178
1 2
3
11 12