General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
LIDO -- Computations in TreesTree StructureThe central data structure of a specified language processor is a tree. It usually represents the abstract structure of the particular input text and is built by actions of the scanner and parser. The trees a language processor operates on are specified by a context-free grammar, the tree grammar. It is part of the specification in LIDO. Figure 1 shows a tree grammar for simple expressions that consist of numbers and binary operators.
RULE: Root ::= Expr END; RULE: Expr ::= Expr Opr Expr END; RULE: Expr ::= Number END; RULE: Opr ::= '+' END; RULE: Opr ::= '*' END;Figure 1: Expression Tree Grammar
Figure 2 shows an example for a tree specified by this grammar, which
may represent the input expression
Root | | Expr | -----------|----------- | | | Expr Opr Expr | | | - - ------------ | | | Expr Opr Expr | | | - - - Number + Number * Number Figure 2: An Expression Tree
A tree node together with its immediate descendent nodes represents the
application of a production, called a rule context. In Figure 2, there are
for example two instances of the rule context for the second rule of the
grammar. The two productions for
If we consider a node of a tree, then it connects two adjacent contexts,
an upper context and a lower context. For example the upper context
of an
Two kinds of terminals are distinguished: Literal terminals like
When designing a tree grammar one often needs to specify
that a certain kind of nodes has an arbitrary number of subtrees.
For example a block may consist of a sequence of definitions
and statements. That can be expressed using RULE: BLOCK ::= '{' Sequence '}' END; RULE: Sequence LISTOF Definition | Statement END;Here, a Sequence node is specified to have an arbitrary number
(including zero) of subtrees rooted by nodes of type Definition
or Statement .
The
The above RULE: Sequence ::= S END; RULE: S :: = S Definition END; RULE: S :: = S Statement END; RULE: S :: = END;This is also one of the forms of productions that could be specified in the concrete grammar for the parser. Several other forms, for example right recursive productions, would match to the LISTOF rule as well.
|