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
1
vote
0 answers

Parsing conflict in Lemon grammar

I am writing a parser for LaTeX mathematical formulas to convert them into MathML. So I wrote this grammar for Lemon. %token BEGIN_GROUP END_GROUP MATH_SHIFT ALIGNMENT_TAB. %token END_OF_LINE PARAMETER SUPERSCRIPT SUBSCRIPT. %token SPACE LETTER…
1
vote
1 answer

Fixing ambiguities on a Lemon parser grammar

I'm having what appears to be an ambiguous grammar. It seems like there are some problems under FileText since there is no conflict when I run only the top part (above FileText). Can anyone help me to spot where my issue is? I believe my tree looks…
Pete Darrow
  • 455
  • 5
  • 20
1
vote
1 answer

SR conflict in a grammar - how to resolve it? (Lemon/yacc)

I have put together a grammar in Lemon (which is similar to YACC) but it is producing an S/R conflict. I am not used to LALR parsing and don't understand what the problem is, nor how to resolve it. The grammar is: %right EQUALS. %right RIGHT_ASSIGN…
1
vote
2 answers

How do I fix this parsing conflict?

I have a small grammar written in lemon that is causing a parsing conflict. This is the part of the grammar that is causing the conflict: selection_statement ::= KWD_IF LPAREN expression RPAREN statement. selection_statement ::= KWD_IF LPAREN…
joe
  • 463
  • 4
  • 17
1
vote
1 answer

Lemon parser token value with void * type

I was trying to use void* type for my lemon parser but I got some weird problem. Initially I used a custom token type, a struct to hold the values of token, then I switched to void* because my token value types vary. Here is some of my parser…
Arif Balik
  • 115
  • 1
  • 9
1
vote
1 answer

Lemon Parser REPL

I'm trying to build a Smalltalk REPL based on LanguageKit, which uses a lemon gramma. Currently the parser only supports parsing complete class definitions, but not statements outside of the method syntax. For example this gets parsed: methodName…
catlan
  • 25,100
  • 8
  • 67
  • 78
1
vote
1 answer

How to disallow blanks between tokens?

In bash, there must be no spaces around = in the assigment. x=10 bash's yylex() just returns the whole thing x=10 as an ASSIGNMENT_WORD token. Then do the processing. http://git.savannah.gnu.org/cgit/bash.git/tree/parse.y#n723 But is it better…
user1424739
  • 11,937
  • 17
  • 63
  • 152
1
vote
1 answer

lemon parser reduce error

I'm attempting to write a grammar to parse numbers in English sentences, and I can successfully parse up to 999. Once I add in the logic to support the thousands place, I get a reduce parsing conflict, and I'm having a hard time understanding what's…
JesseBuesking
  • 6,496
  • 4
  • 44
  • 89
1
vote
2 answers

How can I remove the function call ambiguity from a Lemon grammar?

I have the following lemon grammar (simplified from the real grammar): %right ASSIGN . %nonassoc FN_CALL . program ::= expression . expression ::= expression ASSIGN expression . expression ::= function_call . [FN_CALL] expression ::= IDENTIFIER…
Topoli
  • 11
  • 1
1
vote
1 answer

Lemon Parser-Generator: Are nonterminals not evaluated?

I try to learn parsers. Because my C skills are pretty low, I googled a PHP Lemon to learn sth about Parser Generators. Anyway, the code here should be readable for normal lemon friends, too. As always when handling parsing questions, I start with…
erikbstack
  • 12,878
  • 21
  • 81
  • 115
1
vote
2 answers

How to overcome shift-reduce conflict in LALR grammar

I am trying to parse positive and negative decimals. number(N) ::= pnumber(N1). number(N) ::= nnumber(N1). number(N) ::= pnumber(N1) DOT pnumber(N2). number(N) ::= nnumber(N1) DOT pnumber(N2). pnumber(N) ::= NUMBER(N1). nnumber(N) ::= MINUS…
Pdksock
  • 1,042
  • 2
  • 13
  • 26
1
vote
1 answer

Getting lemon parser conflict

I am trying to write a simple parser using lemon, for a javascript-like language. I am unable to resolve a conflict error, and I suspect it is a unsolvable problem. The conflict is between the grammar for: {x = 10;} and {x:10}; The first is a…
1
vote
2 answers

Lemon Parser skips things (Or my misunderstanding)

Updated with more info I'm having a problem parsing a simple array of elements with Lemon. Can someone enlighten me?? I'm trying to parse this string "[0 0 612 792][100 200]" with mygrammar definition and the parser always skips the first array…
1
vote
2 answers

Why unknown variable "mystring"?

I'm trying to debug why my variable mystring is not known when I think it should be according to an earlier question Is the bug in the grammar or in the code? (gdb) run The program being debugged has been started already. Start it from the…
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
1
vote
1 answer

Custom deallocation function for tokens destructor in Lemon

I want Lemon to parse a simple C-like expression, supporting integer and string comparison over a predefined set of variables with known names. Let's assume it supports only string comparison, for simplicity. So, the following string is a good…
firegurafiku
  • 3,017
  • 1
  • 28
  • 37