|
libsnobol4 1.0.2
High-performance SNOBOL4-style pattern matching library
|
Recursive descent parser for SNOBOL pattern syntax. More...


Go to the source code of this file.
Classes | |
| struct | parser_error_t |
Macros | |
| #define | SNOBOL_PARSER_ERROR_MAX 256 |
Typedefs | |
| typedef struct snobol_parser | snobol_parser_t |
Enumerations | |
| enum | { SNOBOL_PARSER_MAX_DEPTH = 96 } |
| enum | { SNOBOL_PARSER_MAX_AST_DEPTH = 1000 } |
Functions | |
| snobol_parser_t * | snobol_parser_create (void) |
| ast_node_t * | snobol_parser_parse (snobol_parser_t *parser, snobol_lexer_t *lexer) |
| bool | snobol_parser_has_error (snobol_parser_t *parser) |
| const char * | snobol_parser_get_error (snobol_parser_t *parser) |
| void | snobol_parser_get_error_location (snobol_parser_t *parser, size_t *line, size_t *column) |
| void | snobol_parser_clear_error (snobol_parser_t *parser) |
| void | snobol_parser_destroy (snobol_parser_t *parser) |
Recursive descent parser for SNOBOL pattern syntax.
Consumes tokens from lexer and produces AST. Opaque handle pattern - implementation details hidden from callers.
Definition in file parser.h.
| #define SNOBOL_PARSER_ERROR_MAX 256 |
| typedef struct snobol_parser snobol_parser_t |
| anonymous enum |
Maximum structural nesting depth of a parsed pattern.
Each parenthesised group, label prefix, capture and function-call argument consumes one recursive-descent level. The parser rejects patterns that exceed this budget with a parse error instead of letting repeated '(' or a chain of nested calls exhaust the C stack.
The cap is sized against the most expensive production, not the cheapest: a table-update level costs about 3.5 KiB in a Debug build (ARBNO about 2.1 KiB, EVAL about 2.8 KiB, a group about 1.3 KiB), so 96 levels stay below 336 KiB and fit the smallest default thread stack (512 KiB on macOS) with room for the caller's frames above the parse entry. Do not raise it without re-measuring the largest production; a level count is only a safe proxy for stack use when it is calibrated this way.
Builder-composed ASTs (snobol_pattern_build_compile) bypass the parser and are not subject to this limit.
| Enumerator | |
|---|---|
| SNOBOL_PARSER_MAX_DEPTH | |
| anonymous enum |
Maximum height of the AST the parser hands to the compiler.
Flat alternation branches and match-naming operators extend the tree without recursing the descent, so they get a larger budget than SNOBOL_PARSER_MAX_DEPTH. It still bounds the recursive walkers (emit_node_c/emit_alt_c, ast_max_reg_c, snobol_ast_free). Those are cheaper per level than the descent: a 1000-branch alternation compiles inside a 128 KiB thread stack in a Release build and needs about 384 KiB in a Debug build, which still fits the 512 KiB target with margin.
| Enumerator | |
|---|---|
| SNOBOL_PARSER_MAX_AST_DEPTH | |
| void snobol_parser_clear_error | ( | snobol_parser_t * | parser | ) |
Clear parser error state (for reuse)
| parser | Parser instance |
| snobol_parser_t * snobol_parser_create | ( | void | ) |
Create a new parser
| void snobol_parser_destroy | ( | snobol_parser_t * | parser | ) |
Destroy parser and free resources
| parser | Parser to destroy (NULL is safe) |
| const char * snobol_parser_get_error | ( | snobol_parser_t * | parser | ) |
Get parser error message
| parser | Parser instance |
| void snobol_parser_get_error_location | ( | snobol_parser_t * | parser, |
| size_t * | line, | ||
| size_t * | column ) |
Get error location
| parser | Parser instance |
| line | Output: line number (1-based) |
| column | Output: column number (1-based) |
| bool snobol_parser_has_error | ( | snobol_parser_t * | parser | ) |
Check if parser has an error
| parser | Parser instance |
| ast_node_t * snobol_parser_parse | ( | snobol_parser_t * | parser, |
| snobol_lexer_t * | lexer ) |
Parse a complete pattern from tokens
| parser | Parser instance |
| lexer | Lexer instance (must be created with same source) |