xrel.matcher
Class PatternMatching

java.lang.Object
  |
  +--xrel.matcher.PatternMatching
All Implemented Interfaces:
SymElementKind

public class PatternMatching
extends java.lang.Object
implements SymElementKind

Starts the main algorithm for the pattern matching.

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

Author:
Fabrizio Bisi

Field Summary
static int matchingClause
          A return value: it says what clause it matches.
 
Fields inherited from interface xrel.parser.SymElementKind
LABEL, PATTERN, S_LABELS, S_PATTERNS, S_TYPES, S_VALUES, S_VARIABLES, TYPE, UNDEFINED, VALUE, VARIABLE
 
Constructor Summary
PatternMatching()
           
 
Method Summary
static void buildAutomata(SymTable st)
          Builds the automaton for every pattern in the symbol table.
static void completeAutomata(SymTable st)
          Final phase to build automata.
static void dumpAutomata(SymTable st, java.io.PrintStream out)
          Writes the internal structure of the automata associated to the patterns of the symbol table.
static void eps_elim_Automata(SymTable st)
          Removes the null transitions in all the automata associated to the patterns of the symbol table.
static boolean matchWith(SimpleNode value, boolean debug)
          The main method of this class.
static void rem_useless_Automata(SymTable st)
          Removes the useless states from all the automata associated to the patterns of the symbol table.
static void setSymbolTable(SymTable st)
          Assigns the symbol table.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

matchingClause

public static int matchingClause
A return value: it says what clause it matches.
Constructor Detail

PatternMatching

public PatternMatching()
Method Detail

matchWith

public static boolean matchWith(SimpleNode value,
                                boolean debug)
The main method of this class.
Parameters:
value - the value to check. The patterns are passed throughout the symbol table.
Returns:
the result (if either it matches or not)

dumpAutomata

public static void dumpAutomata(SymTable st,
                                java.io.PrintStream out)

Writes the internal structure of the automata associated to the patterns of the symbol table.

It simply calls the method dump on the tree automata associated to each pattern.

Parameters:
st - the symbol table
out - the place where to print out
See Also:
xrel.matcher.TreeAutomaton#dump(PrintStream out)

buildAutomata

public static void buildAutomata(SymTable st)

Builds the automaton for every pattern in the symbol table.

For each pattern it first calls the method build() and then it computes the epsilon closures calling the method compute_closures().

N.B.: to build all the automata do the followings:

  1. First call buildAutomata()
  2. Then call eps_elim_Automata()
  3. Finally call rem_useless_Automata()
These phases are separated for debug purpouses only.

Parameters:
st - the symbol table.
See Also:
xrel.matcher.TreeAutomaton#build(SymElement el), xrel.matcher.TreeAutomaton#compute_closures()

eps_elim_Automata

public static void eps_elim_Automata(SymTable st)

Removes the null transitions in all the automata associated to the patterns of the symbol table. It simply calls the method epsilon_elimination() on each single automaton.

N.B.: to build all the automata do the followings:

  1. First call buildAutomata()
  2. Then call eps_elim_Automata()
  3. Finally call rem_useless_Automata()
These phases are separated for debug purpouses only.

Parameters:
st - the symbol table
See Also:
xrel.matcher.TreeAutomaton#epsilon_elimination()

rem_useless_Automata

public static void rem_useless_Automata(SymTable st)

Removes the useless states from all the automata associated to the patterns of the symbol table. It simply calls the method remove_useless_states() on each single automaton.

N.B.: to build all the automata do the followings:

  1. First call buildAutomata()
  2. Then call eps_elim_Automata()
  3. Finally call rem_useless_Automata()
These phases are separated for debug purpouses only.

Parameters:
st - the symbol table
See Also:
xrel.matcher.TreeAutomaton#remove_useless_states()

completeAutomata

public static void completeAutomata(SymTable st)

Final phase to build automata.

It simply calls the method setStateTransitions on each automaton.

Parameters:
st - the symbol table
out - the place where to print out
See Also:
xrel.matcher.TreeAutomaton#dump(PrintStream out)

setSymbolTable

public static void setSymbolTable(SymTable st)
Assigns the symbol table. Call this function before to call the main method.
Parameters:
st - the symbol table pointer.