Lemon is a
parser generator, maintained as part of the
SQLite
SQLite (, ) is a database engine written in the C programming language. It is not a standalone app; rather, it is a library that software developers embed in their apps. As such, it belongs to the family of embedded databases. It is the most ...
project, that generates a ''look-ahead LR parser'' (
LALR parser) in the programming language
C from an input
context-free grammar
In formal language theory, a context-free grammar (CFG) is a formal grammar whose production rules are of the form
:A\ \to\ \alpha
with A a ''single'' nonterminal symbol, and \alpha a string of terminals and/or nonterminals (\alpha can be empt ...
. The generator is quite simple, implemented in one C source file with another file used as a template for output.
Lexical analysis is performed externally.
Lemon is similar to the programs
Bison
Bison are large bovines in the genus ''Bison'' (Greek: "wild ox" (bison)) within the tribe Bovini. Two extant and numerous extinct species are recognised.
Of the two surviving species, the American bison, ''B. bison'', found only in North Ame ...
and
Yacc
Yacc (Yet Another Compiler-Compiler) is a computer program for the Unix operating system developed by Stephen C. Johnson. It is a Look Ahead Left-to-Right Rightmost Derivation (LALR) parser generator, generating a LALR parser (the part of a com ...
, but is incompatible with both. The grammar input format is different, to help prevent common coding errors. Other distinctive features include a
reentrant
Reentrant or re-entrant can refer to:
*Re-entrant (landform), the low ground formed between two hill spurs.
*Reentrancy (computing) in computer programming
*Reentrant mutex in computer science
*Reentry (neural circuitry) in neuroscience
*Salients ...
,
thread-safe Thread safety is a computer programming concept applicable to multi-threaded code. Thread-safe code only manipulates shared data structures in a manner that ensures that all threads behave properly and fulfill their design specifications without uni ...
output
parser, and the concept of ''non-terminal destructors'' that try to make it easier to avoid
memory leaks.
SQLite uses Lemon with a hand-coded tokenizer to parse
SQL strings.
Lemon, together with
re2c
re2c is a free and open-source lexer generator for C, C++, Go, and Rust. It compiles declarative regular expression specifications to deterministic finite automata. Originally written by Peter Bumbulis and described in his paper, re2c was put ...
and a re2c wrapper named Perplex, are used in
BRL-CAD
BRL-CAD is a constructive solid geometry (CSG) solid modeling computer-aided design (CAD) system. It includes an interactive geometry editor, ray tracing support for graphics rendering and geometric analysis, computer network distributed frameb ...
as platform-agnostic and easily compilable alternatives to Flex and Bison. This combination is also used with STEPcode.
OpenFOAM expression evaluation uses a combination of
ragel and a version of lemon that has been minimally modified to ease C++ integration without affecting C integration.
[
] The parser grammars are augmented with
m4 macros.
Notes
References
*
*
External links
* {{Official website
Calculator with Lemon and Lex in C++ Example Lemon, bundled with Re2c and PerplexLemon Grove: Lemon along with sibling projects, forks and assets
Parser generators
Public-domain software with source code