General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
LIDO - Reference ManualComputationsComputations are associated with rules or with symbols. Each computation (that is not overridden) is executed exactly once for every instance of its context in a particular tree. A computation may yield a value denoted as an attribute which may be used by other computations. Computations may also be specified as depending on one another without passing a value in order to specify dependences on side-effects of computations. (see Dependent Expressions).
SyntaxComputations ::= [ 'COMPUTE' Computation ] Computation ::= Computation Computation | | Attribute '=' Expression Terminator | Expression Terminator | Attribute '+=' Expression Terminator Terminator ::= ';' | 'BOTTOMUP' ';'
There are three forms of computations: attribute computations denoted
as an assignment to an attribute, plain computations
that are simple expressions, and accumulating computations which
are a special variant of attribute computations, distinguished by the
Attribute Computations and Plain ComputationsThe following example shows a sequence of two attribute computations and two plain computations: ExamplesCOMPUTE Expr.postType = boolType; Stmt[1].code = PTGWhile (Expr.code, Stmt[2].code); printf ("while loop in line %d\n", LINE); printf ("value = %d\n", Expr.val) BOTTOMUP; END; A computation is executed by evaluating its expression. It depends on every attribute that occurs in the expression regardless whether the attribute is used for the evaluation. We say those attributes are the preconditions of the computation. The attribute on the left-hand side of an attribute computation represents the postcondition of that computation. Plain computations do not establish a postcondition for any other computation. The evaluator is generated such that the computations are executed in an order that obeys these dependencies for any tree of the tree grammar. If both a symbol computation and a rule computation define the same attribute of a symbol, the rule computation will be executed in that context, overriding the symbol computation.
An expression may occur in value context, where it must yield
a value, or it may occur in
If the left-hand side attribute of an attribute computation
has a type different from
A plain computation is in
Computations may be specified to be executed
Note: A
Note: Due to the parser's lookahead, one token beyond the last token
of the context of the
Restrictions
If the attribute in an attribute computation has a non- Multiple symbol computations that define the same attribute are forbidden. There must be exactly one attribute computation for each synthesized attribute of the left-hand side nonterminal and for each inherited attribute of each nonterminal occurrence on the right-hand side in the production of a rule context, or such a computation is inherited in the rule context. (For accumulating computations a different rule applies.) There may not be any cyclic dependencies between computations for any tree of the tree grammar.
Contexts that may belong to subtrees which are built by
computations (see Computed Subtrees) may not have
computations that are marked
LIGA may fail to allocate
Accumulating Computations
There are situations where a
A computation is marked to be accumulating by the RULE: Program ::= Statements COMPUTE Program.AnalysisDone += DoThis ( ); END; .... RULE: Program ::= Statements COMPUTE Program.AnalysisDone += DoThat ( ) <- Statements.checked; END;Two accumulating computations contribute both to the attribute Program.AnalysisDone , such that it represents the state when
the calls DoThis ( ) and DoThat ( ) are executed after the
pre-condition Statements.checked has been reached.
The two accumulating computations above have the same effect as if there
was a single computation, as in
RULE: Program ::= Statements COMPUTE Program.AnalysisDone = ORDER (DoThis ( ), DoThat ( )) <- Statements.checked; END;The order in which DoThis ( ) and DoThat ( ) are executed
is arbitrarily decided by the Liga system.
Accumulating computations may be formulated in rule context
or in the context of
Only The set of accumulating computations of an attribute is combined into a single computation, containing all dependences and function calls of the contributing accumulating computations, as shown above.
Accumulating computations may be inherited from
SYMBOL Program INHERITS AddOn COMPUTE SYNT. AnalysisDone += AllWaysDo ( ); END; CLASS SYMBOL AddOn COMPUTE SYNT. AnalysisDone += AndAlsoDo (); END;Then all four computations for Program.AnalysisDone
(two in the RULE context above, one in the TREE symbol context Program , and one
inherited from the CLASS symbol AddOn )
will be combined into one. It characterizes the state after execution of the
four function calls and the computation of Statements.checked .
RestrictionsIf an attribute has an accumulating computation, it is called an accumulating attribute, and may not have or inherit non-accumulating computations.
An accumulating attribute must have type
Let
Let
|