librdesc
Loading...
Searching...
No Matches
Macros | Enumerations | Variables
boolean_algebra.h File Reference

Boolean algebra grammar example for librdesc. More...

#include "../../include/grammar.h"
#include "../../include/rule_macros.h"
Include dependency graph for boolean_algebra.h:

Go to the source code of this file.

Macros

#define BALG_PRODUCTION_COUNT   17
 Total count of nonterminal symbols defined in enum balg_nt. Determines the size of the first dimension of the grammar table.
 
#define BALG_MAX_ALTERNATIVE_COUNT   5
 Maximum number of alternatives for a single production and +1 for end of production sentinel. Used to dimension the static array (2nd dimension).
 
#define BALG_MAX_ALTERNATIVE_SIZE   4
 Maximum number of symbols in an alternative (Right-Hand Side) and +1 for end-of-body sentinel. Used to dimension the static array (3rd dimension).
 

Enumerations

enum  balg_tk {
  TK_TRUE , TK_FALSE , TK_IDENT , TK_PIPE ,
  TK_AMP , TK_EXCL , TK_LPAREN , TK_RPAREN ,
  TK_LCURLY , TK_RCURLY , TK_EQ , TK_COMMA ,
  TK_SEMI
}
 Terminal symbols (tokens). More...
 
enum  balg_nt {
  NT_BIT , NT_IDENT , NT_CALL , NT_CALL_OPTPARAMS ,
  NT_EXPR , NT_EXPR_REST , NT_TERM , NT_TERM_REST ,
  NT_FACTOR , NT_ATOM , NT_STMT , NT_STMTS ,
  NT_ASGN , NT_IDENT_LS , NT_IDENT_LS_REST , NT_EXPR_LS ,
  NT_EXPR_LS_REST
}
 Nonterminal symbols.
 

Variables

const char *const balg_tk_names []
 Names of tokens that are used in BNF.
 
const char *const balg_tk_names_escaped []
 Names of tokens that can be used in dotlang graph (special chars are escaped).
 
const char *const balg_nt_names []
 Nonterminal names (for debugging/printing CST).
 
static const struct rdesc_grammar_symbol balg [BALG_PRODUCTION_COUNT][BALG_MAX_ALTERNATIVE_COUNT+1][BALG_MAX_ALTERNATIVE_SIZE+1]
 Sample grammar.
 

Detailed Description

Boolean algebra grammar example for librdesc.

This file defines a sample grammar for a simple Boolean Algebra language. It serves two main purposes:

  1. To demonstrate how to use the rule macros (rule_macros.h) to define grammars.
  2. To act as a stress-test for the parser's backtracking engine by introducing intentional ambiguities.

Language features:

Enumeration Type Documentation

◆ balg_tk

enum balg_tk

Terminal symbols (tokens).

Warning
Token id 0 is reserved in rdesc. Tokens cannot start from 0.

Variable Documentation

◆ balg

Sample grammar.

Note
Productions must be in the same order as listed in the nonterminal enum definition. rrr(X, ...) macro expands into two consecutive production rules, NT_X and NT_X_REST.
By default, TK(X)/NT(X) expand to TK_X/NT_X. You must use TK(X)/NT(X) instead of TK(TK_X)/NT(NT_X). See Name Mapping for Identifiers for overriding default behavior and details.
Warning
+1 is required in and 2nd dimensions of 3D grammar array to account for sentinels.

◆ balg_nt_names

const char* const balg_nt_names[]
Initial value:
= {
"bit", "ident", "call",
"call_optparams",
"expr", "expr_rest",
"term", "term_rest",
"factor", "atom",
"stmt", "stmts", "asgn",
"ident_ls", "ident_ls_rest",
"expr_ls", "expr_ls_rest",
}

Nonterminal names (for debugging/printing CST).

◆ balg_tk_names

const char* const balg_tk_names[]
Initial value:
= {
"1", "0", "@ident",
"|", "&", "!",
"(", ")", "{", "}",
"=", ",", ";",
}

Names of tokens that are used in BNF.

◆ balg_tk_names_escaped

const char* const balg_tk_names_escaped[]
Initial value:
= {
"1", "0", "@ident",
"\\|", "&", "!",
"(", ")", "\\{", "\\}",
"=", ",", ";",
}

Names of tokens that can be used in dotlang graph (special chars are escaped).