Rule
public struct Rule<Param>
Represents a rule of the grammar.
A rule is similar to a rule in a context-free grammar, and has the form
L => R1 ... Rn
where L is the left-hand side of the rule, and R1 ... Rn is the right-hand side of the rule.
Unlike the rules of a context-free grammar though, each of the symbols L, R1, …, Rn carries an input and an output parameter with them.
The property eval (in tandem with the property initialEnv) is responsible for computing these parameters along the stages of the parsing process.
Furthermore, the symbol L does not have to be a nonterminal, but can also be a terminal symbol. In this case, the invocation of this rule during parsing spawns a separate
parsing process with a grammar identical with the current grammar, except that L is now treated as a nonterminal symbol. This enables a form of scannerless parsing.
Seealso
GrammarSeealso
EvalFunc-
The left-hand side
Lof a rule of the formL => R1 ... Rn.Declaration
Swift
public let lhs: Symbol -
The right-hand side
[R1 ... Rn]of a rule of the formL => R1 ... RnDeclaration
Swift
public let rhs: [Symbol] -
The evaluation function responsible for this rule.
Declaration
Swift
public let eval: EvalFunc<Param> -
Creates a rule.
Declaration
Parameters
lhsThe left-hand side
Lof the rule.rhsThe right-hand side
R1 ... Rnof the rule.initialEnvThe initial environment of the rule.
evalThe evaluation function of the rule.
Rule Structure Reference