BNFNode - BNF tree node
A BNF tree node proies the data for symbol in an BNF expression. BNF tree nodes form a hierarchy from top BNF symbol down to terminal symbols. In order to analyze BNF trees, the class provides several iteration and check functions. Moreover, BNF tree nodes may return the position and content of the symbol in the expression.
BNF tree nodes do not support reference counters for copy nodes. Hence, the data, that is shared between copy nodes will not automatically released when destructing the node. Hence, release() has to be called explicitly in order to release BNFNode data.
// BNF definition
operation := operand [ right_side(*) ]
right_side := operator operand
operand := number | '(' operation ')'
operator := '+' | '-' | '*' | '/'
std_symbols ::= class(BNFStandardSymbols)
number ::= ref(std_integer)
// Expression: 5+12*(3+7)-1
// BNF tree
operation: 5+12*(3+7)-1
operand: 5
std_integer: 5
right_side: +12
operator: +
operand: 12
std_integer: 12
right_side: *(3+7)-1
operator: *
operand: (3+7)
(: (
operation: 3+7
operand: 3
std_integer: 3
right_side: +7
operator: +
operand: 7
std_integer: 7
): )
right_side: -1
operator: -
operand: 1
std_integer: 1
The example below shows the definition for the arithmetical expressions with integer numbers. terminal symbols are defined in BNFStandardSymbols BNF. There, symbol std_integer is referenced as number.
- BNFNode - Constructor
- assign - Assign an BNFNode to nother BNFNode
- column - Current start column number
- count - Get number of sub nodes
- get - Locate BNF tree node
- hasParent - Does parser has got a parent
- isSymbol - Is current symbol same as symbol passed
- isValid - Check whether BNF tree node is valid
- length - Value length
- line - Line number for BNF node
- parent - Get parent BNF node
- print - Print BNF tree
- release - Release bnf node hierarchy
- symbol - Get symbol name for BNF node
- toSymbol - Convert BNF node
- tryGet - Try to locate BNF node
- value - Get symbol value for BNF node
- ~BNFNode - Destructor