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
0
votes
2 answers

How can I avoid using a global variable?

Is it ever ok to use a global variable? I am using a global variable and I understand that is not ideal. It looks like this int result2 = 0; void setresult2(int a) { result2 = a; } I'm using the variable in my lemon grammar for my custom…
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
0
votes
1 answer

Parsing a conditional with lemon

I want to parse the following script str="HELLO" if [ $str = "HELLO" ]; then echo FOO fi The first line str="HELLO" I can parse and the variable gets saved for usage. It's possible to run the script str="HELLO" echo $str and get the output…
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
0
votes
2 answers

Is the bug in the grammar or in the code?

I'm not sure if this grammar is correct for a shell command language that should also be able to execute single-quotes and double-quotes. It seems that non-trivial commands work e.g. ls -al | sort | wc -l but the simple one does not work with…
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
0
votes
2 answers

build error using flex-lexer and cmake

i'm learning cmake and flex-lexer but i get a build problem with error code 2 according to the error message from make: $ make /usr/bin/cmake -H/home/dac/ClionProjects/openshell -B/home/dac/ClionProjects/openshell --check-build-system…
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
0
votes
1 answer

build error using CMake

I get a build error when trying to build a flex and lemon project with CMake. Can you help me find what is wrong? $ make /usr/bin/cmake -H/home/dac/ClionProjects/openshell -B/home/dac/ClionProjects/openshell --check-build-system…
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
0
votes
1 answer

lemon + re2c not getting correct rule resolution

This is my lemon parser grammar %nonassoc IMPLICATION. %nonassoc PERIOD. %nonassoc NEWLINE. %nonassoc END. %nonassoc STRING. program ::= in END. in ::= . in ::= in rule NEWLINE. in ::= in rule. rule ::= STRING(A) IMPLICATION STRING(B) PERIOD.…
Pdksock
  • 1,042
  • 2
  • 13
  • 26
0
votes
1 answer

Why does lemon not execute terminals immediately?

I am moving a small threaded interpreter using flex and yacc to re2c and lemon. Everything is working but literals. Why does the action associated with literals fail to run as it does with yacc? I expect "1.0 end" but get "0.0…
LogicG8
  • 1,767
  • 16
  • 26
0
votes
1 answer

Parser expression for comma-separated function call parameters

Im writing a parser than can parse expressions like myfunc1(), myfunc2(param1) and myfunc3(param1, param2) (with an unknown amount of parameters). Now I'm trying to get my parse expressions right. I'm using the Lemon Parser Generator. Here is what…
chiborg
  • 26,978
  • 14
  • 97
  • 115
0
votes
1 answer

Using midaction rules in Lemon to interpret "let" expression

I'm trying to write a "toy" interpreter using Flex + Lemon that supports a very basic "let" syntax where a variable X is temporarily bound to an expression. For example, "letx 3 + 4 in x + 8" should evaluate to 15. In essence, what I'd "like" the…
0
votes
2 answers

Parser reducing too early

I've got a grammar that basically looks like : start ::= groups. groups ::= groups group. groups ::= group. group(A) ::= IDENTIFIER identparams CURLY_OPEN assignments CURLY_CLOSE SEMICOLON. group(A) ::= IDENTIFIER CURLY_OPEN assignments CURLY_CLOSE…
Igmar Palsenberg
  • 637
  • 4
  • 10
0
votes
1 answer

How do I get a Lemon parser to terminate itself on a newline?

Following this old tutorial, I am trying to get a lemon parser to automatically terminate parsing on an EOL token. The relevant part of the parser looks like this: start ::= in . in ::= . in ::= in commandList EOL . { printf("start ::=…
theory
  • 9,178
  • 10
  • 59
  • 129
0
votes
1 answer

Precedence conflict with postfix/infix operators

Here is a grammar wrote for the lemon parser generator : %left PostDecrementation. %right PreDecrementation. program ::= expression. expression ::= Terminal. expression ::= unaryoperation. unaryoperation ::= Decrementation expression.…
Maël Nison
  • 7,055
  • 7
  • 46
  • 77
0
votes
2 answers

How do I capture the line number of a syntax error in generated parser

All of the tokens I pass to Lemon are structures that have line number information attached. Look at the syntax_error definition below %name SinkParser %token_prefix SINKPARSER_TOKEN_ %token_type {SinkParserNode*} %extra_argument {…
doug65536
  • 6,562
  • 3
  • 43
  • 53
0
votes
1 answer

Shift/reduce conflict with expression call

When I'm trying to compile this simple parser using Lemon, I get a conflict but I can't see which rule is wrong. The conflict disappear if I remove the binaryexpression or the callexpression. %left Add. program ::= expression. expression ::=…
Maël Nison
  • 7,055
  • 7
  • 46
  • 77
-1
votes
3 answers

Debugging parser generated code

I have generated a parser code using Lemon Parser. I am not able to debug the generated code. Control shows some other source code than the currently executing statement. Breakpoints are displaced. I tried on gdb and Visual C++. Both have the same…
Bharadwaj
  • 1,071
  • 2
  • 8
  • 8