Home · Docs · Primer · Examples · Prefixing · Syntax · Rules · Parser · Tree · Actions · Debug
Support

HAPY RULE SYNTAX

Hapy rules are valid C++ expressions that use Hapy objects. The result of an expression is usually assigned to an existing Rule object so that it can be references in this and other expressions (see Primer for more information on that).

The table below shows how general parsing or grammar concepts can be expressed using Hapy rules. For each concept, a Hapy C++ expression, a typical EBNF equivalent, and a parsing tree node structure are provided. For each node, the ASCII drawing shows a rule identifier and immediate node children (if any). Tree node interface is documented elsewhere.

Concept Hapy BNF Pree node with kids
equivalence: R is A R = A; R = A.
R
|
A
concatenation: A is followed by B is followed by C is followed by ... Z R = A >> B >> C >> ... Z; R = A B C ... Z.
     R     
     |     
+-+-+-...-+
| | |     |
A B C     Z
alternation: A or B or C or ... Z R = A | B | C | ... Z; R = A.
R = B | C | ... Z.
R      R     R         R
|  OR  |  OR |  OR ... |
A      B     C         Z
negation: A but not B and not C and not ... Z R = A - B - C - ... Z; R = A - B - C - ... Z.
R
|
A
kleene star: zero or more As R = *A; R = A*.
     R           R
     |           |
+-+-+-...-+  OR  -
| | |     |       
A A A     A       
repetition: one or more As R = +A; R = A+.
     R      
     |     
+-+-+-...-+
| | |     |
A A A     A
option: A or nothing R = !A; R = [A].
R      R
|  OR  |
A      -
terminal: a literal constant R = "string"; or
R = 'char'
R = "string". or
R = 'char'.
R
|
-

SourceForge Home