General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Tree ParsingSummary of the Specification LanguageThe phrase structure of the specification language is described by the following ambiguous grammar:
Source: (Include / Declaration / Rule)+ . Declaration: (Nonterm // ',') ':' Type ';' . Nonterm: Identifier . Type: Identifier . Rule: Nonterm '::=' Node (':' / '::') Action ['COST' Integer] ';' / Nonterm '::=' Nonterm ':' Action ['COST' Integer] ';' / Nonterm '::=' Fragment ':' Action ['COST' Integer] ';' . Action: Identifier . Node: Terminal / Terminal '(' Nonterm [',' Nonterm] ')' / Terminal '(' (Type // ',') ')' / Terminal '(' Nonterm [',' Nonterm] ',' (Type // ',') ')' . Terminal: Identifier . Fragment: Terminal '(' Child [',' Child] ')' . Child: Nonterm / Fragment . Declarations and rules are the main components of a specification. Includes are simply names of files that are needed to define the identifiers representing types and actions.
An
An DeclarationsEach nonterminal symbol must be declared, stating the type of the value associated with it:
Declaration: (Nonterm // ',') ':' Type ';' . Nonterm: Identifier . Type: Identifier .
Types are always represented by identifiers.
If the type is a C basic type, no further declaration is necessary.
Other types must be defined by a
Here is a set of declarations that is appropriate for the examples given earlier in this document:
IntLit: int; IntReg, FltReg: reg; "mydefs.h"
Because RulesAs discussed earlier, there are three kinds of rules: node rules (see Rules Describing Tree Nodes), chain rules (see Chain Rules), and fragment rules (see Rules Describing Tree Fragments):
Rule: Nonterm '::=' Node (':' / '::') Action ['COST' Integer] ';' / Nonterm '::=' Nonterm ':' Action ['COST' Integer] ';' / Nonterm '::=' Fragment ':' Action ['COST' Integer] ';' . Action: Identifier .
Each rule has an associated
action and an optional
cost (which defaults to 1 if not specified).
The action is defined by an identifier, which must be defined in the
file described by one of the A node rule describes a single, possibly decorated, node of the tree being parsed (see Rules Describing Tree Nodes):
Node: Terminal / Terminal '(' Nonterm [',' Nonterm] ')' / Terminal '(' (Type // ',') ')' / Terminal '(' Nonterm [',' Nonterm] ',' (Type // ',') ')' . Terminal: Identifier .
Each
The A fragment rule describes a fragment consisting of two or more adjacent nodes:
Fragment: Terminal '(' Child [',' Child] ')' . Child: Nonterm / Fragment . Nodes participating in fragments may not be decorated. There is no limit on the size of a fragment.
|