src/libnetdata/eval/re2c_lemon/README.md
This directory contains a parser implementation for Netdata's expression evaluator using re2c for lexical analysis and Lemon for syntax parsing.
The re2c/Lemon-based parser is designed to be more efficient and maintainable compared to the handwritten recursive descent parser in the parent directory. It achieves full compatibility with the original parser while providing better performance, especially for complex expressions with nested operations.
re2c is a lexer generator that translates regular expressions into deterministic finite automata (DFA) and produces efficient C code. The lexer implemented in lexer.re tokenizes the input string according to the expression language grammar, handling:
Lemon is a parser generator similar to YACC/Bison but with a different parsing technique and better thread safety. The grammar in parser.y defines the expression language syntax, operator precedence, and associativity rules.
This parser implementation can be selected by defining USE_RE2C_LEMON_PARSER in eval-internal.h. When enabled, the function parse_expression_with_re2c_lemon() is used instead of the original recursive descent parser.
Parser Generator Approach: Using specialized tools (re2c and Lemon) for lexical analysis and parsing rather than handwritten code.
Full Compatibility: Maintains 100% compatibility with the original parser, ensuring all test cases pass with identical results.
Proper Operator Precedence: Handles operator precedence correctly, especially for complex cases like nested ternary operators.
Flexible Variable Names: Supports the same variable naming rules as the original parser, including braced variables with spaces.
Special Literal Handling: Properly processes special literals like NaN and Infinity in various capitalizations.
Case-Insensitive Keywords: Handles logical operators (AND, OR, NOT) case-insensitively, just like the original parser.
Reduced Memory Leaks: Carefully manages memory allocations to prevent leaks, especially in error conditions.
If you need to modify the lexer or parser definitions, you can rebuild the generated files using:
make -C src/libnetdata/eval/re2c_lemon
This requires re2c and lemon to be installed on your system.
EVAL_NODE structure.?:) is properly implemented as right-associative.$var) and braced syntax (${complex var}).mallocz, freez, etc.).