xrel.analyzer
Class Translate

java.lang.Object
  |
  +--xrel.analyzer.Translate
All Implemented Interfaces:
SpecialNames, SymElementKind, XRelParserTreeConstants

public class Translate
extends java.lang.Object
implements XRelParserTreeConstants, SymElementKind, SpecialNames

Provides several transform operations to the symbol table.

In details:

To know more see the descriptions of the methods.

N.B.: This is a static class so you will never need to allocate an object of this class.

Author:
Fabrizio Bisi

Fields inherited from interface xrel.parser.XRelParserTreeConstants
JJTAS, JJTCASE, JJTCOMMA, JJTEMPTY, JJTEXPORTTP, JJTIDENTIFIER, JJTIMPORTST, jjtNodeName, JJTOPERATOR, JJTPAR, JJTPROGRAM, JJTSTATEMENTLIST, JJTSTRING, JJTSTRINGLITERAL, JJTSWITCHCASE, JJTTAG, JJTTYPEDECL, JJTVOID
 
Fields inherited from interface xrel.parser.SymElementKind
EXPRESSION, LABEL, PATTERN, S_EXPRESSIONS, S_LABELS, S_PATTERNS, S_TYPES, S_VARIABLES, TYPE, UNDEFINED, VARIABLE
 
Fields inherited from interface xrel.parser.SpecialNames
AnyTagName, AnyTypeName, AutomatonPrefix, EmptyPatternName, ExportTypeName, ExpressionPrefix, PatternPrefix, SpecialPrefix, StringName, StringPatternName, StringTypeName, StrLiteralPrefix, StrLiteralSuffix, StrUnquotedPrefix, StrUnquotedSuffix
 
Constructor Summary
Translate()
           
 
Method Summary
static void addPredefined(SymTable st)
          Adds the predefined type "Any" to the symbol table.
static void desugar(SymTable st)
          Performs a few simplifications to all the elements in the symbol table: types, patterns, variable types and expressions.
static SimpleNode desugarElement(SymTable st, SimpleNode node)
          Removes the operators "+" and "?"
static void diagnosticChecks(SymTable st, int phase)
          Perform diagnostic checks on the elements inside the symbol table.
static void normalization(SymTable st)
          Internalizes all the patterns of the program, that is it transformes them in an internal format so that they can be easily transformed in automata.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Translate

public Translate()
Method Detail

addPredefined

public static void addPredefined(SymTable st)

Adds the predefined type "Any" to the symbol table. Remember that Any is defined as in the following:

 typedef Any = (~[Any] | String)*;

Parameters:
st - the symbol table

desugar

public static void desugar(SymTable st)

Performs a few simplifications to all the elements in the symbol table: types, patterns, variable types and expressions.

Specifically it performs the following transformations:

N.B.:

  1. The initial symbol "#" of pseudo-labels grants that it's impossibile to have name conflicts with normal labels, as XML tag names never begin with this symbol (labels in XRel follow the same syntactic conventions as XML names)
  2. This function transforms the original syntax tree so that it's impossible to have a correspondance with tokens
  3. In the transformation of P+ P and its subtree is copied instead of referenced twice. This is to have the parent pointer correctly set in both the instances.

Parameters:
st - the symbol table

desugarElement

public static SimpleNode desugarElement(SymTable st,
                                        SimpleNode node)
Removes the operators "+" and "?" and replaces ground types (String and string literals) with pseudo-labels.

The names chosen for pseudo-labels are #String[] for String and #".." for string literals. Note that initial symbol grants that it's impossibile to have name conflicts with normal labels, as XML tag names never begin with "#" symbol (labels in XRel follow the same syntactic conventions as XML names).

Operators are removed in the following way:

N.B.:

  1. This function transforms the original syntax tree so that it's impossible to have a correspondance with tokens
  2. In the transformation of P+ P and its subtree is copied instead of referenced twice. This is to have the parent pointer correctly set in both the instances.

Parameters:
st - the symbol table
node - the root node of the subtree to change

normalization

public static void normalization(SymTable st)

Internalizes all the patterns of the program, that is it transformes them in an internal format so that they can be easily transformed in automata.

In details it makes the following changes to the patterns:

  1. it expands the type names at top-level, i.e. it replaces type names with theirs related type expressions
  2. it creates new (sub)patterns to group the tag contents

The resulting patterns have the following syntax:

   P ::= P as x     variable binder
         l[X]       label
         ()         empty pattern
         P,P        concatenation
         P|P        choice
         P*         repetition
where x,.. ranges over variable names and X,.. ranges over pattern references. Substantially there are no more type names (because they've been expanded) and each tag content corresponds to a specifical pattern. These are exactly the changes this function does.

N.B.:

Parameters:
st - the symbol table

diagnosticChecks

public static void diagnosticChecks(SymTable st,
                                    int phase)
Perform diagnostic checks on the elements inside the symbol table.

The phase parameter can be one of the following:

0
called after desugaring
1
called after normalization

Parameters:
st - the simbol table
phase - the phase after which is called