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

Boolean algebra grammar example for librdesc. More...

#include "../../include/cfg.h"
#include "../../include/bnf_dsl.h"

Go to the source code of this file.

Macros

#define PREFIX_TK(tk)   TK_ ## tk
 add TK_ prefix in TK macro
 
#define PREFIX_NT(nt)   NT_ ## nt
 add NT_ prefix in NT macro
 
#define BALG_TK_COUNT   14
 total count of terminal symbols
 
#define BALG_NT_COUNT   17
 Total count of non-terminal symbols defined in enum balg_nt. Determines the size of the first dimension of the grammar table.
 
#define BALG_NT_VARIANT_COUNT   6
 Maximum number of production variants (alternatives) for a single non-terminal and +1 for end-of-construct sentinel. Used to dimension the static array (2nd dimension).
 
#define BALG_NT_BODY_LENGTH   5
 Maximum number of symbols in a production body (Right-Hand Side) and +1 for end-of-body sentinel. Used to dimension the static array (3rd dimension).
 

Enumerations

enum  balg_tk {
  TK_NOTOKEN , 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)
 
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
}
 non-terminal Symbols
 

Variables

const char balg_tks [BALG_TK_COUNT]
 token character mapping (for exblex)
 
const char *const balg_tk_names [BALG_TK_COUNT]
 names of tokens that used in BNF
 
const char *const balg_tk_names_escaped [BALG_TK_COUNT]
 names of tokens that can be used in dotlang graph (special chars are escaped)
 
const char *const balg_nt_names [BALG_NT_COUNT]
 non-terminal names (for debugging/printing CST)
 

Detailed Description

Boolean algebra grammar example for librdesc.

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

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

Language features:

Variable Documentation

◆ balg_nt_names

const char* const balg_nt_names[BALG_NT_COUNT]
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",
}

non-terminal names (for debugging/printing CST)

◆ balg_tk_names

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

names of tokens that used in BNF

◆ balg_tk_names_escaped

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

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

◆ balg_tks

const char balg_tks[BALG_TK_COUNT]
Initial value:
= {
'\0',
'1', '0', 'w',
'|', '&', '!',
'(', ')', '{', '}',
'=', ',', ';',
}

token character mapping (for exblex)