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
3
votes
1 answer

Flex and Lemon Parser

I'm trying to learn flex and lemon, in order to parse a (moderately) complex file format. So far, I have my grammar and lex file and I believe it is correctly parsing an example file. Right now, I want to pass the token text scanned with flex to…
zync
  • 463
  • 3
  • 17
3
votes
2 answers

How to handle same symbol used for two things lemon parser

I'm developing a domain specific language. Part of the language is exactly like C expression parsing semantics such as precidence and symbols. I'm using the Lemon parser. I ran into an issue of the same token being used for two different things, and…
doug65536
  • 6,562
  • 3
  • 43
  • 53
2
votes
1 answer

Ambiguous grammar with Lemon Parser Generator

So basically I want to parsed structure CSS code in PHP, using a lexer/parser generated by the PEAR packages PHP_LexerGenerator and PHP_ParserGenerator. My goal is to parse files like this: selector, selector2 { prop: value; prop2 /*comment…
xrstf
  • 1,162
  • 1
  • 9
  • 12
2
votes
1 answer

Bison passing back resulting AST

In lemon I was able to use the third parameter of the parsing function to pass back the result to the caller when the starting symbol was reduced. How would I do the same in bison? Is it enough to assign that value to $$ within the starting symbol's…
Flavius
  • 13,566
  • 13
  • 80
  • 126
2
votes
1 answer

Is the lemon parser LALR(1) or SLR(1)?

I'm reading the PHP portation of the lemon parser: for ($i = 0; $i < $this->nstate; $i++) { /* Loop over all states */ $stp = $this->sorted[$i]->data; for ($cfp = $stp->cfp; $cfp; $cfp = $cfp->next) { /* Loop over all…
yoyo
  • 1,113
  • 2
  • 17
  • 25
2
votes
2 answers

Fixing Lemon parsing confilcts

I'm writing up a small parser which parses constraints, using Flex and Lemon. Lemon is reporting a couple of parsing conflicts I haven't been able to get rid of. Are there any particular tricks for getting rid of parsing conflicts in a context free…
Null Set
  • 5,374
  • 24
  • 37
2
votes
1 answer

Lemon takes lempar.c and outputs garbage at end of file

I'm using the LEMON Parser Generator and for some reason it's outputting a bunch of garbage at the end of the outputted file, rather than replacing the %%s from lempar.c with the generated code. I've copied lemon.c and lempar.c directly from the…
PaulBGD
  • 2,018
  • 5
  • 22
  • 30
2
votes
1 answer

Use lemon parser(LALR) generate a calulator, how to get param from expressions

I want to get param from a input. For example: Input:12+10. After running my calculator. I want to get 12 and 10. I know, I have to use the fourth param in Parse(pParser, hTokenID, sTokenData, pArg);, but how?…
tac
  • 31
  • 3
2
votes
1 answer

How to use lemon to handle a expression with variables

I want to implement such a program: it reads some expressions which includes some variables. These variables will be set later, and the program should calculate the final result(like sql prepared statement). For example, the expression maybe like…
akawhy
  • 1,558
  • 1
  • 11
  • 18
2
votes
1 answer

Using Lemon parser with custom token values

I am porting an old grammar to lemon and I have all the terminal symbols already defined in a header file; I would like to use them with those values instead of the ones generated in parser.h by lemon: is that possible? Overwriting parser.h is…
skarux
  • 131
  • 2
  • 7
2
votes
1 answer

Segmentation fault from Lemon-generated parser in C++

I am trying to figure out the Lemon parser generator, so I wrote a little test to help myself fully understand. The files generate without a problem and the compiler does not complain, but when I try to run it I get a Segmentation Fault. What am I…
Michele De Pascalis
  • 932
  • 2
  • 9
  • 26
2
votes
1 answer

JSON parsing using Lemon (and Core Foundation)

I'm trying to write a simple JSON parser using Lemon and Apple Core Foundation. Here's the code so far: %include { #import #import "state.h" // struct ParserState { CFTypeRef result; }; #import "tuple.h" // struct…
Matteo Pacini
  • 21,796
  • 7
  • 67
  • 74
2
votes
1 answer

"Partial parsing" with lemon

I have an SQL grammar built using the lemon parser generator. The normal entry point to parsing a command is a statement (like SELECT ...), so the statement is my %start non-terminal in the grammar. So far everything works fine. Now I want to do a…
lucas clemente
  • 6,255
  • 8
  • 41
  • 61
2
votes
1 answer

Generating a JavaScript SQL parser for SQLite3 (with Lemon? ANTLR3?)

For the last couple of weeks i've been diving into the pretty world of parsing SQL statements into something managable, only to find out that i'll probably need a full lexer/parser to properly handle all the allowed tokens/formats to do the same…
SchizoDuckie
  • 9,353
  • 6
  • 33
  • 40
2
votes
2 answers

use variables in Lemon parser?

I want to allow mathematical variables in my Lemon parser-driven app. For example, if the user enters x^2+y, I want to then be able to evaluate this for 100000 different pairs of values of x and y, hopefully without having to reparse each time. …
William Jockusch
  • 26,513
  • 49
  • 182
  • 323