|
librdesc
|
Macros for context-free grammar definitions. More...
#include <stddef.h>Go to the source code of this file.
Macros | |
| #define | PREFIX_TK(tk) tk |
| Name mapping for token identifiers. | |
| #define | PREFIX_NT(nt) nt |
| #define | POSTFIX_NT_REST(nt) nt ## _REST |
| Name mapping for non-terminal list to rest types. | |
| #define | EOB -1 |
| #define | EOC -2 |
| #define | SEOB { .ty = CFG_SENTINEL, .id = EOB } |
| Sentinel struct for the end of a rule's body (EOB) | |
| #define | SEOC { { .ty = CFG_SENTINEL, .id = EOC } } |
| Sentinel struct for the end of a construct's variants (EOC) | |
| #define | TK(tk) { .ty = CFG_TOKEN, .id = PREFIX_TK(tk) } |
| Macro to create a terminal (token) production symbol. | |
| #define | NT(nt) { .ty = CFG_NONTERMINAL, .id = PREFIX_NT(nt) } |
| Macro to create a non-terminal production symbol. | |
| #define | EPSILON SEOB |
| Macro to create an epsilon production symbol. | |
| #define | r(...) { { __VA_ARGS__ SEOB }, SEOC } |
| Macro to define a grammar rule. Adds end-of-body and construct sentinels to grammar rules. | |
| #define | rrr(head, listelem, delim) |
| Macro to define a pair of rules for a right-recursive list. | |
| #define | ropt(...) { { __VA_ARGS__, SEOB }, { SEOB }, SEOC } |
| Macro to define an optional grammar rule (epsilon production). | |
| #define | alt SEOB, }, { |
| Macro for syntactic sugar to separate non-terminal alternatives. | |
Macros for context-free grammar definitions.
Provides macros (r, rrr, ropt) to define these production rules in a readable way.
You may define PREFIX_TK and PREFIX_NT macros before including this file to automatically add prefixes in grammar definitions.
| #define alt SEOB, }, { |
Macro for syntactic sugar to separate non-terminal alternatives.
Expands to the end-of-body sentinel and new variant syntax.
| #define EOB -1 |
integer representing EOB (end-of-body)
| #define EOC -2 |
integer representing EOC (end-of-construct)
| #define PREFIX_NT | ( | nt | ) | nt |
| #define PREFIX_TK | ( | tk | ) | tk |
Name mapping for token identifiers.
This macro determines how a raw token name passed to TK(...) is expanded into a C identifier (typically an enum member).
TK(IDENT) expands to IDENT.#define PREFIX_TK(x) MY_TK_ ## x). Macro to define an optional grammar rule (epsilon production).
This is a shortcut for a rule with two variants:
__VA_ARGS__| #define rrr | ( | head, | |
| listelem, | |||
| delim | |||
| ) |
Macro to define a pair of rules for a right-recursive list.
This is the standard pattern for lists and operator precedence. It automatically defines the rule for 'head' and 'head_REST'.
For example, rrr(EXPR_LS, NT(EXPR), TK(COMMA)) defines:
<expr_ls> ::= <expr> <expr_ls_rest><expr_ls_rest> ::= "," <expr_ls> | E| head | The base non-terminal. |
| listelem | The non-terminal for the list element. |
| delim | The token used as a separator. |
| #define SEOB { .ty = CFG_SENTINEL, .id = EOB } |
Sentinel struct for the end of a rule's body (EOB)
Usage with DSL is not recommended, use EPSILON instead.
| #define SEOC { { .ty = CFG_SENTINEL, .id = EOC } } |
Sentinel struct for the end of a construct's variants (EOC)
Not recommended, use r and ropt instead.