Skip to content
Snippets Groups Projects
Commit 68ae5539 authored by Ronny Böttger's avatar Ronny Böttger
Browse files

fixed Bank

parent 82f7b913
No related branches found
No related tags found
No related merge requests found
Showing
with 63 additions and 47 deletions
aspect Analysis { aspect Analysis {
/*
public void StateMachine.printSomeAnalysis() { public void StateMachine.printSomeAnalysis() {
Set<Set<State>> sccs = this.SCC(); Set<Set<State>> sccs = this.SCC();
System.out.print("SCCs found: "); System.out.print("SCCs found: ");
...@@ -17,5 +17,5 @@ aspect Analysis { ...@@ -17,5 +17,5 @@ aspect Analysis {
this.getInitial().minDistTo(finalState) + " step(s)"); this.getInitial().minDistTo(finalState) + " step(s)");
} }
} }
*/
} }
aspect Analysis { aspect Analysis {
/** Compute all states reachable from the current state */ /** Compute all states reachable from the current state */
/*
syn Set<State> State.reachable() circular [new HashSet<State>()] { syn Set<State> State.reachable() circular [new HashSet<State>()] {
Set<State> result = new HashSet<>(); Set<State> result = new HashSet<>();
result.addAll(successors()); result.addAll(successors());
...@@ -9,8 +10,10 @@ aspect Analysis { ...@@ -9,8 +10,10 @@ aspect Analysis {
} }
return result; return result;
} }
*/
/** Compute the minimum number of transitions to the other state, ignoring states with empty labels */ /** Compute the minimum number of transitions to the other state, ignoring states with empty labels */
/*
syn int State.minDistTo(State other) circular [-1] { syn int State.minDistTo(State other) circular [-1] {
if (this == other) { if (this == other) {
return 0; return 0;
...@@ -25,12 +28,13 @@ aspect Analysis { ...@@ -25,12 +28,13 @@ aspect Analysis {
} }
return result; return result;
} }
*/
/** A transition is an epsilon transition if the label is empty */ /** A transition is an epsilon transition if the label is empty */
syn boolean Transition.isEpsilon() = getLabel().isEmpty(); //syn boolean Transition.isEpsilon() = getLabel().isEmpty();
/** Collect all epsilon transitions */ /** Collect all epsilon transitions */
coll Set<Transition> StateMachine.epsilonTransitions() [new HashSet<>()]; //coll Set<Transition> StateMachine.epsilonTransitions() [new HashSet<>()];
Transition contributes this when isEpsilon() to StateMachine.epsilonTransitions(); //Transition contributes this when isEpsilon() to StateMachine.epsilonTransitions();
} }
...@@ -8,8 +8,8 @@ import java.util.*; ...@@ -8,8 +8,8 @@ import java.util.*;
%embed {: %embed {:
// this code is inlined in the generated parser class // this code is inlined in the generated parser class
State initial; //State initial;
List<State> finals = new ArrayList<>(); //List<State> finals = new ArrayList<>();
:}; :};
%goal goal; %goal goal;
......
...@@ -35,12 +35,5 @@ Identifier = [:jletter:][:jletterdigit:]* ...@@ -35,12 +35,5 @@ Identifier = [:jletter:][:jletterdigit:]*
{WhiteSpace} { } {WhiteSpace} { }
// token definitions // token definitions
"initial" { return sym(Terminals.INITIAL); }
"final" { return sym(Terminals.FINAL); }
"state" { return sym(Terminals.STATE); }
"trans" { return sym(Terminals.TRANS); }
{Identifier} { return sym(Terminals.NAME); } {Identifier} { return sym(Terminals.NAME); }
";" { return sym(Terminals.SEMI); }
":" { return sym(Terminals.COLON); }
"->" { return sym(Terminals.ARROW); }
<<EOF>> { return sym(Terminals.EOF); } <<EOF>> { return sym(Terminals.EOF); }
...@@ -3,6 +3,7 @@ aspect ConnectedComponents { ...@@ -3,6 +3,7 @@ aspect ConnectedComponents {
/** /**
* Kosaraju's algorithm * Kosaraju's algorithm
*/ */
/*
syn Set<Set<State>> StateMachine.SCC() { syn Set<Set<State>> StateMachine.SCC() {
Map<State, Set> visited = new HashMap<>(); Map<State, Set> visited = new HashMap<>();
LinkedList<State> locked = new LinkedList<>(); LinkedList<State> locked = new LinkedList<>();
...@@ -33,5 +34,5 @@ aspect ConnectedComponents { ...@@ -33,5 +34,5 @@ aspect ConnectedComponents {
if (visited.get(t.getFrom()) == null) if (visited.get(t.getFrom()) == null)
t.getFrom().assign(visited, root); t.getFrom().assign(visited, root);
} }
*/
} }
aspect NameAnalysis { aspect NameAnalysis {
/** resolve a state using its name */ /** resolve a state using its name */
/*
syn State StateMachine.resolveState(String id) { syn State StateMachine.resolveState(String id) {
for (State s : states()) { for (State s : states()) {
if (s.getLabel().equals(id)) { if (s.getLabel().equals(id)) {
...@@ -9,8 +10,10 @@ aspect NameAnalysis { ...@@ -9,8 +10,10 @@ aspect NameAnalysis {
} }
return null; return null;
} }
*/
/** resolve a transition using its name */ /** resolve a transition using its name */
/*
syn Transition StateMachine.resolveTransition(String id) { syn Transition StateMachine.resolveTransition(String id) {
for (Transition t : transitions()) { for (Transition t : transitions()) {
if (t.getLabel().equals(id)) { if (t.getLabel().equals(id)) {
...@@ -19,11 +22,12 @@ aspect NameAnalysis { ...@@ -19,11 +22,12 @@ aspect NameAnalysis {
} }
return null; return null;
} }
*/
// required interface implementation for name analysis in parser // required interface implementation for name analysis in parser
eq StateMachine.globallyResolveStateByToken(String id) = resolveState(id); //eq StateMachine.globallyResolveStateByToken(String id) = resolveState(id);
eq Element.globallyResolveStateByToken(String id) = containingStateMachine().resolveState(id); //eq Element.globallyResolveStateByToken(String id) = containingStateMachine().resolveState(id);
eq StateMachine.globallyResolveTransitionByToken(String id) = resolveTransition(id); //eq StateMachine.globallyResolveTransitionByToken(String id) = resolveTransition(id);
eq Element.globallyResolveTransitionByToken(String id) = containingStateMachine().resolveTransition(id); //eq Element.globallyResolveTransitionByToken(String id) = containingStateMachine().resolveTransition(id);
} }
...@@ -5,22 +5,23 @@ aspect Navigation { ...@@ -5,22 +5,23 @@ aspect Navigation {
// ====================================================== // ======================================================
/** Check, whether an this element is a state */ /** Check, whether an this element is a state */
syn boolean Element.isState() = false; //syn boolean Element.isState() = false;
eq State.isState() = true; //eq State.isState() = true;
/** View this element as a state */ /** View this element as a state */
syn State Element.asState() = null; //syn State Element.asState() = null;
eq State.asState() = this; //eq State.asState() = this;
/** Check, whether an this element is a transition */ /** Check, whether an this element is a transition */
syn boolean Element.isTransition() = false; //syn boolean Element.isTransition() = false;
eq Transition.isTransition() = true; //eq Transition.isTransition() = true;
/** View this element as a transition */ /** View this element as a transition */
syn Transition Element.asTransition() = null; //syn Transition Element.asTransition() = null;
eq Transition.asTransition() = this; //eq Transition.asTransition() = this;
/** Get all states */ /** Get all states */
/*
syn List<State> StateMachine.states() { syn List<State> StateMachine.states() {
List<State> states = new ArrayList<>(); List<State> states = new ArrayList<>();
for (Element element: getElementList()) { for (Element element: getElementList()) {
...@@ -30,8 +31,10 @@ aspect Navigation { ...@@ -30,8 +31,10 @@ aspect Navigation {
} }
return states; return states;
} }
*/
/** Get all transitions */ /** Get all transitions */
/*
syn List<Transition> StateMachine.transitions() { syn List<Transition> StateMachine.transitions() {
List<Transition> transitions = new ArrayList<>(); List<Transition> transitions = new ArrayList<>();
for (Element element: getElementList()) { for (Element element: getElementList()) {
...@@ -41,18 +44,19 @@ aspect Navigation { ...@@ -41,18 +44,19 @@ aspect Navigation {
} }
return transitions; return transitions;
} }
*/
/** Get the state machine the element is contained in */ /** Get the state machine the element is contained in */
inh StateMachine Element.containingStateMachine(); //inh StateMachine Element.containingStateMachine();
eq StateMachine.getElement().containingStateMachine() = this; //eq StateMachine.getElement().containingStateMachine() = this;
/** Determine whether the State is final */ /** Determine whether the State is final */
syn boolean State.isInitial() = containingStateMachine().getInitial().equals(this); //syn boolean State.isInitial() = containingStateMachine().getInitial().equals(this);
/** Determine whether the State is final */ /** Determine whether the State is final */
syn boolean State.isFinal() = containingStateMachine().getFinalList().contains(this); //syn boolean State.isFinal() = containingStateMachine().getFinalList().contains(this);
/** Get all successor states */ /** Get all successor states */
syn Collection<State> State.successors() = getOutgoingList().stream().map(Transition::getTo).collect(Collectors.toList()); //syn Collection<State> State.successors() = getOutgoingList().stream().map(Transition::getTo).collect(Collectors.toList());
} }
aspect Printing { aspect Printing {
/** Return a textual representation of the state machine */ /** Return a textual representation of the state machine */
/*
syn String StateMachine.prettyPrint() { syn String StateMachine.prettyPrint() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
states().forEach(s -> sb.append(s.prettyPrint())); states().forEach(s -> sb.append(s.prettyPrint()));
transitions().forEach(t -> sb.append(t.prettyPrint())); transitions().forEach(t -> sb.append(t.prettyPrint()));
return sb.toString(); return sb.toString();
} }
*/
/** Return a textual representation of the state machine */ /** Return a textual representation of the state machine */
syn String Element.prettyPrint(); //syn String Element.prettyPrint();
eq State.prettyPrint() = (isInitial() ? "initial " : "") + (isFinal() ? "final " : "") + "state " + getLabel() + ";\n"; //eq State.prettyPrint() = (isInitial() ? "initial " : "") + (isFinal() ? "final " : "") + "state " + getLabel() + ";\n";
eq Transition.prettyPrint() = "trans " + getFrom().getLabel() + " -> " + getTo().getLabel() + (isEpsilon() ? "" : " : " + getLabel()) + ";\n"; //eq Transition.prettyPrint() = "trans " + getFrom().getLabel() + " -> " + getTo().getLabel() + (isEpsilon() ? "" : " : " + getLabel()) + ";\n";
} }
aspect StateMachinetoDotG { aspect StateMachinetoDotG {
/*
syn String StateMachine.toDot() { syn String StateMachine.toDot() {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
b.append("strict digraph cycles {\n"); b.append("strict digraph cycles {\n");
...@@ -15,4 +16,5 @@ aspect StateMachinetoDotG { ...@@ -15,4 +16,5 @@ aspect StateMachinetoDotG {
b.append("}\n"); b.append("}\n");
return b.toString(); return b.toString();
} }
*/
} }
aspect Transformation { aspect Transformation {
/** remove transformations with empty labels */ /** remove transformations with empty labels */
/*
public void StateMachine.removeEpsilonTransition(Transition t) { public void StateMachine.removeEpsilonTransition(Transition t) {
if (t.isEpsilon()) { if (t.isEpsilon()) {
State oldFrom = t.getFrom(); State oldFrom = t.getFrom();
...@@ -29,4 +30,5 @@ aspect Transformation { ...@@ -29,4 +30,5 @@ aspect Transformation {
System.err.println("Won't remove non-epsilon transition " + t.getLabel()); System.err.println("Won't remove non-epsilon transition " + t.getLabel());
} }
} }
*/
} }
...@@ -28,7 +28,7 @@ aspect JastAddAPIExtension { ...@@ -28,7 +28,7 @@ aspect JastAddAPIExtension {
} }
throw new RuntimeException("unable to remove child, because it was not contained in its parent!"); throw new RuntimeException("unable to remove child, because it was not contained in its parent!");
} }
/*
public String Element.customID() { public String Element.customID() {
return getLabel(); return getLabel();
} }
...@@ -36,4 +36,5 @@ aspect JastAddAPIExtension { ...@@ -36,4 +36,5 @@ aspect JastAddAPIExtension {
public String Element.toString() { public String Element.toString() {
return getLabel(); return getLabel();
} }
*/
} }
...@@ -2,9 +2,9 @@ package de.tudresden.inf.st.statemachine; ...@@ -2,9 +2,9 @@ package de.tudresden.inf.st.statemachine;
import beaver.Parser; import beaver.Parser;
import de.tudresden.inf.st.jastadd.dumpAst.ast.Dumper; import de.tudresden.inf.st.jastadd.dumpAst.ast.Dumper;
import de.tudresden.inf.st.statemachine.jastadd.model.State; //import de.tudresden.inf.st.statemachine.jastadd.model.State;
import de.tudresden.inf.st.statemachine.jastadd.model.StateMachine; //import de.tudresden.inf.st.statemachine.jastadd.model.StateMachine;
import de.tudresden.inf.st.statemachine.jastadd.model.Transition; //import de.tudresden.inf.st.statemachine.jastadd.model.Transition;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Paths; import java.nio.file.Paths;
...@@ -16,6 +16,7 @@ public class Main { ...@@ -16,6 +16,7 @@ public class Main {
public static Object DrAST_root_node; public static Object DrAST_root_node;
public static void main(String[] args) throws IOException, Parser.Exception { public static void main(String[] args) throws IOException, Parser.Exception {
/*
StateMachine stateMachine; StateMachine stateMachine;
if (args.length == 0) { if (args.length == 0) {
stateMachine = createExample(); stateMachine = createExample();
...@@ -45,8 +46,10 @@ public class Main { ...@@ -45,8 +46,10 @@ public class Main {
System.out.println(stateMachine.toDot()); System.out.println(stateMachine.toDot());
Dumper.read(stateMachine).dumpAsPNG(Paths.get("02-transformed.png")); Dumper.read(stateMachine).dumpAsPNG(Paths.get("02-transformed.png"));
DrAST_root_node = stateMachine; DrAST_root_node = stateMachine;
*/
} }
/*
private static void printHeading(String s) { private static void printHeading(String s) {
System.out.println(); System.out.println();
System.out.println("========================================"); System.out.println("========================================");
...@@ -95,5 +98,5 @@ public class Main { ...@@ -95,5 +98,5 @@ public class Main {
stateMachine.getInitial().minDistTo(finalState) + " step(s)"); stateMachine.getInitial().minDistTo(finalState) + " step(s)");
} }
} }
*/
} }
package de.tudresden.inf.st.statemachine; package de.tudresden.inf.st.statemachine;
import beaver.Parser; import beaver.Parser;
import de.tudresden.inf.st.statemachine.jastadd.model.StateMachine; import de.tudresden.inf.st.statemachine.jastadd.model.Bank;
import de.tudresden.inf.st.statemachine.jastadd.parser.StateMachineParser; import de.tudresden.inf.st.statemachine.jastadd.parser.BankParser;
import de.tudresden.inf.st.statemachine.jastadd.scanner.StateMachineScanner; import de.tudresden.inf.st.statemachine.jastadd.scanner.BankScanner;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
...@@ -16,11 +16,11 @@ import java.nio.file.Path; ...@@ -16,11 +16,11 @@ import java.nio.file.Path;
* @author rschoene - Initial contribution * @author rschoene - Initial contribution
*/ */
public class ParserUtils { public class ParserUtils {
static StateMachine load(Path path) throws IOException, Parser.Exception { static Bank load(Path path) throws IOException, Parser.Exception {
Reader reader = Files.newBufferedReader(path); Reader reader = Files.newBufferedReader(path);
StateMachineScanner scanner = new StateMachineScanner(reader); BankScanner scanner = new BankScanner(reader);
StateMachineParser parser = new StateMachineParser(); BankParser parser = new BankParser();
StateMachine result = (StateMachine) parser.parse(scanner); Bank result = (Bank) parser.parse(scanner);
reader.close(); reader.close();
return result; return result;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment