company logo

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

Notes:

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.

Attributes
    Functions