public class Simulator
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected FSA |
automa |
protected int |
pointer_state |
protected int |
pointer_string |
Modifier and Type | Method and Description |
---|---|
protected Transition |
backtracking(java.util.Vector<Continuation> continuation,
java.util.Vector<Continuation> visited)
Select a transition in the continuation that is not visited, save it in the visited continuation and restore the state of the continuation.
|
void |
changeAutoma(FSA automa)
Change the automaton to simulate
|
protected boolean |
checkContinuation(Transition tr,
int symbol)
If a transition was selected in the continuation (tr not null), then perform the step by updating the state of the simulator
|
protected static int |
contains(int n,
int[] a)
check if n is contained in a
|
protected static int |
contains(int n,
java.util.Vector v)
Check if n is contained in the vector v
|
protected Continuation |
createContinuation()
Freeze the actual state of the simulator in a continuation
|
protected boolean |
isValid(Transition tr,
int symbol)
Check if the transition can be performed
|
protected void |
restoreStateContinuation(Continuation c)
restore the state of the simulator freezed in the continuation c
|
boolean |
run(int[] s)
At every iteration:
first check if the string is consumed, then if we are in a final state and the side conditions are verified then the string is accepted,
else backtracking if possible, otherwise return false
if the string is not consumed yet:
if there is a continuation then performs the step stored
else if there are possible steps then performs one and store the others in the continuation
if no possible step are allowed, then performs backtracking or if the continuation is empty return false
|
protected boolean |
sideConditions()
A method to be extended in case of additional conditions of acceptance
|
protected boolean |
step(int symbol,
java.util.Vector<Continuation> continuation,
java.util.Vector<Continuation> visited)
Select all the possible transition that can be executed in this configuration, then perform the first transition and store all the other in the continuation.
|
protected void |
updateState(Transition tr,
int symbol)
Update the state of the simulator by performing the transition tr
|
protected int pointer_state
protected int pointer_string
protected FSA automa
public Simulator(FSA automa)
automa
- The automaton to simulatepublic void changeAutoma(FSA automa)
automa
- public boolean run(int[] s)
s
- the string to be recognizedprotected boolean checkContinuation(Transition tr, int symbol)
tr
- transition to performsymbol
- the symbol in inputprotected Transition backtracking(java.util.Vector<Continuation> continuation, java.util.Vector<Continuation> visited)
continuation
- vector of continuation to be visitedvisited
- vector of visited continuationprotected void restoreStateContinuation(Continuation c)
c
- the continuation to be restoredprotected boolean sideConditions()
protected void updateState(Transition tr, int symbol)
tr
- the transition to be performedsymbol
- the symbol in inputprotected boolean isValid(Transition tr, int symbol)
tr
- transition to be performedsymbol
- symbol in inputprotected boolean step(int symbol, java.util.Vector<Continuation> continuation, java.util.Vector<Continuation> visited)
symbol
- the symbol in inputcontinuation
- the vector of continuation to be performedvisited
- the vector of visited continuationprotected Continuation createContinuation()
protected static int contains(int n, int[] a)
n
- integer to searcha
- array of integerprotected static int contains(int n, java.util.Vector v)
n
- the integer to be searchedv
- a vector of integer