Generic Interpreter 1.3
Protected API

gi
Class Grammar.Semantics

java.lang.Object
  extended by gi.Grammar.Semantics
Enclosing class:
Grammar

protected static class Grammar.Semantics
extends Object

This class implements Semantics embedded in productions and evaluated when interpreting.

Version:
1.3
Author:
© 1999-2009 Craig A. Rich <carich@csupomona.edu>

Constructor Summary
protected Grammar.Semantics()
          Constructs Semantics.
 
Method Summary
protected  void f(Grammar.ParseTree t, int l)
          Evaluates attributes in a ParseTree when interpreting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Grammar.Semantics

protected Grammar.Semantics()

Constructs Semantics.

Method Detail

f

protected void f(Grammar.ParseTree t,
                 int l)
          throws Lexicon.Exception

Evaluates attributes in a ParseTree when interpreting. The semantic function f is invoked when a production containing this Semantics is applied to the ParseTree. t provides the context in which attribute evaluation occurs. t.root and t.child are the left and right side of the production in which this Semantics is embedded.

User-defined semantics are implemented by extending the class Semantics and overriding this method. The f method provided does nothing.

During top-down LL(1) parsing, the ParseTree is constructed from the top down by leftmost derivation. This is a depth-first left-to-right traversal, in which embedded Semantics are evaluated when first visited. Evaluation should not depend on attribute values produced by Semantics below or to the right of this Semantics. In other words, LL parsing supports evaluation of L-attributed semantic specifications.

During bottom-up LR(0), SLR(1) or LR(1) parsing, the ParseTree is constructed from the bottom up by reverse rightmost derivation. Embedded Semantics are evaluated after all subtrees rooted in the phrase to be reduced have been visited.

Parameters:
t - the ParseTree in which attribute evaluation occurs.
l - the index in t.child at which the Semantics being evaluated occurs. Introduced in version 1.1.
Throws:
Lexicon.Exception - only if overridden to do so.
Since:
1.1, renames evaluate in version 1.0.

 

© 1999-2009 Craig A. Rich <carich@csupomona.edu>