Questions tagged [lemon]

Lemon is a parser generator, maintained as part of the SQLite project, that generates an LALR(1) parser in the C programming language from an input context-free grammar. Do not use this tag for questions about the COIN-OR Lemon Graph library (use [lemon-graph-library]) nor for questions about the R ggplot2 add-on lemon (use [ggplot2]).

Lemon) is a public-domain parser generator, maintained as part of the SQLite project, that generates an LALR(1) parser in the C programming language from an input context-free grammar. Please do not use this tag for questions about the COIN-OR Lemon Graph library (use ) nor for questions about the R ggplot2 add-on lemon (use ).

Lemon grammars are described in BNF (similar to Yacc or Bison grammars, although the syntax is not compatible). It differs from Yacc in that tokens and their associated semantic value are passed to a Lemon parser one at a time in individual function calls. (Yacc parsers call the lexical analyser to get the token; semantic values are passed in globals.)

Although packages for Lemon do exist, it is trivial to build, since it consists of a single stand-alone source file and a template file used to create the generated parser, both found in the SQLite source tree. Lemon documentation can be found in the SQLite documentation directory.

77 questions
17
votes
2 answers

Lemon power or not?

For grammar parser, I used to "play" with Bison which have its pros/cons. Last week, I noticed on SqLite site that the engine is done with another grammar parser: Lemon Sounds great after reading the thin documentation. Do you have some feedback…
Stef
  • 3,691
  • 6
  • 43
  • 58
6
votes
1 answer

Solving parsing conflicts in a tiny Lemon grammar

I'm trying to learn basics of the Lemon parser generator, but I stuck quickly. Here's a tiny grammar: %right PLUS_PLUS. %left DOT. program ::= expr. member_expr ::= expr DOT IDENTIFIER. lhs_expr ::= member_expr. expr ::= lhs_expr. expr ::=…
Dmitry Frank
  • 10,417
  • 10
  • 64
  • 114
5
votes
2 answers

lemon parser parsing 0 token

I'm having a problem using (reentrant) Flex + Lemon for parsing. I'm using a simple grammar and lexer here. When I run it, I'll put in a number followed by an EOF token (Ctrl-D). The printout will read: 89 found int of . AST=0. Where the first…
semisight
  • 914
  • 1
  • 8
  • 15
5
votes
3 answers

"Expected token" using lemon parser generator

Is there a known way to generate an "Expected token" list when a syntax error happens ? I'm using Lemon as parser generator.
Maël Nison
  • 7,055
  • 7
  • 46
  • 77
5
votes
1 answer

Troubles with lemon grammar (precedence?)

I'm having trouble with a simple grammar I have created to support function calls. I am using the lemon-based PHP_ParserGenerator by Greg. This is the relevant part of the grammar: program ::= expr(A). { $this->result = A;…
Dennis Haarbrink
  • 3,738
  • 1
  • 27
  • 54
4
votes
2 answers

Recovering error tokens in parsing (Lemon)

I'm using Lemon as a parser generator, its error handling is the same as yacc's and bison's if you don't know Lemon. Lemon has an option to define the error token in a set of rules in order to catch parsing errors. The default behavior of the…
Sadly Not
  • 234
  • 2
  • 15
4
votes
2 answers

LALR(1) empty list of parameters for functions

I have a simple LALR(1) grammar, but I'm encountering a problem. start ::= spec. spec ::= MOD STRING top_stmt. spec ::= top_stmt. top_stmt ::= stmt. top_stmt ::= conditional. stmt ::= expr. stmt ::= assignment. conditional ::= IF stmt_list. expr ::=…
Flavius
  • 13,566
  • 13
  • 80
  • 126
4
votes
1 answer

Representing statement-terminating newlines in a grammar?

A lot of programming languages have statements terminated by line-endings. Usually, though, line endings are allowed in the middle of a statement if the parser can't make sense of the line; for example, a = 3 + 4 ...will be parsed in Ruby and…
Ricky Stewart
  • 1,102
  • 1
  • 8
  • 18
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
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

Lemon parser as Xcode build rule

When using lemon parser in Xcode integrated as 'Yacc source file using Script', warnings generated by lemon don't show up in the Xcode warning section.
catlan
  • 25,100
  • 8
  • 67
  • 78
3
votes
2 answers

How to use GNU readline with flex-lexer?

I think that using the GNU Readline library for a command-line prompt is good and I want that functionality for my shell that I'm working on. Now readline works for me (my environment is CLion, CMake, Ubuntu, BSD, C, flex-lexer and lemon-parser) but…
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
3
votes
1 answer

Is there a good working tutorial on re2c + lemon?

I've tried a couple. And there is only a couple of tutorials in Google for re2c+lemon. Currently for all examples I get similar bunch of errors like: In file included from main.cpp:2:0: parser.y:44:5: error: ‘yygotominor’ was not declared in this…
Sergey
  • 19,487
  • 13
  • 44
  • 68
3
votes
1 answer

Generate the LR parse table from the Lemon Parser Generator

I'm trying to generate the parser table using the lemon parser generator, but the .out file generated when I run lemon grammar.y only contains the states of the automaton. Is there a way to also get the goto table for non-terminals, not only the…
Paul
  • 20,883
  • 7
  • 57
  • 74
3
votes
1 answer

Bison/YACC vs. Lemon vs. standard input

I'm trying to convert a calculator from Bison to Lemon. I ran into an unexpected problem involving standard input where the two programs behave quite differently. The Bison version prints the result immediately after pressing [Enter]. With…
Sammy Mitchell
  • 398
  • 3
  • 8
1
2 3 4 5 6