Added file loading and displaying of images in tabs

This commit is contained in:
2017-06-09 15:49:26 +02:00
parent a991a23339
commit 3958c68fd0
24 changed files with 590 additions and 177 deletions
+67 -60
View File
@@ -1,101 +1,108 @@
package com.imegumii;
import java.io.*;
import java.nio.Buffer;
/**
* Created by kenny on 8-6-2017.
*/
public class FileParser {
public static DFA<String> readDFA(String filename)
public static Importable read(String filename)
{
File f = new File("input/" + filename + ".dot");
File f = new File("input/" + filename);
Character[] chars = {'a', 'b'};
DFA<String> dfa = new DFA<String>(chars);
Importable imp = null;
try (BufferedReader br = new BufferedReader(new FileReader(f))) {
String line;
while ((line = br.readLine()) != null) {
if(line.startsWith("B")) {
String[] states = line.substring(1,line.length()).split(",");
for(String s : states) { dfa.defineAsStartState(s); }
}
else if(line.startsWith("E")) {
String[] states = line.substring(1,line.length()).split(",");
for(String s : states) { dfa.defineAsEndState(s); }
}
String type = br.readLine();
else {
String[] trans = line.split(">");
dfa.addTransition(new Transition<String>(trans[0], trans[1].toCharArray()[0], trans[2]));
}
switch (type)
{
case "DFA":
imp = readDFA(br);
break;
case "NDFA":
imp = readNDFA(br);
break;
case "REGEX":
imp = readRegex(br);
break;
default:
break;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return imp;
}
public static DFA<String> readDFA(BufferedReader br) throws IOException {
Character[] chars = {'a', 'b'};
DFA<String> dfa = new DFA<String>(chars);
String line;
while ((line = br.readLine()) != null) {
if(line.startsWith("B")) {
String[] states = line.substring(1,line.length()).split(",");
for(String s : states) { dfa.defineAsStartState(s); }
}
else if(line.startsWith("E")) {
String[] states = line.substring(1,line.length()).split(",");
for(String s : states) { dfa.defineAsEndState(s); }
}
else {
String[] trans = line.split(">");
dfa.addTransition(new Transition<String>(trans[0], trans[1].toCharArray()[0], trans[2]));
}
}
return dfa;
}
public static NDFA<String> readNDFA(String filename)
{
File f = new File("input/" + filename + ".dot");
public static NDFA<String> readNDFA(BufferedReader br) throws IOException {
Character[] chars = {'a', 'b'};
NDFA<String> ndfa = new NDFA<String>(chars);
Character[] chars = {'a', 'b'};
NDFA<String> ndfa = new NDFA<String>(chars);
String line;
while ((line = br.readLine()) != null) {
if(line.startsWith("B")) {
String[] states = line.substring(1,line.length()).split(",");
for(String s : states) { ndfa.defineAsStartState(s); }
}
try (BufferedReader br = new BufferedReader(new FileReader(f))) {
String line;
while ((line = br.readLine()) != null) {
if(line.startsWith("B")) {
String[] states = line.substring(1,line.length()).split(",");
for(String s : states) { ndfa.defineAsStartState(s); }
}
else if(line.startsWith("E")) {
String[] states = line.substring(1,line.length()).split(",");
for(String s : states) { ndfa.defineAsEndState(s); }
}
else if(line.startsWith("E")) {
String[] states = line.substring(1,line.length()).split(",");
for(String s : states) { ndfa.defineAsEndState(s); }
}
else {
String[] trans = line.split(">");
else {
String[] trans = line.split(">");
if(trans[1].equals("$")) {
ndfa.addTransition(new Transition<String>(trans[0], Transition.EPSILON, trans[2]));
}
else
ndfa.addTransition(new Transition<String>(trans[0], trans[1].toCharArray()[0], trans[2]));
if(trans[1].equals("$")) {
ndfa.addTransition(new Transition<String>(trans[0], Transition.EPSILON, trans[2]));
}
else
ndfa.addTransition(new Transition<String>(trans[0], trans[1].toCharArray()[0], trans[2]));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return ndfa;
}
public static RegExp readRegex(String filename)
{
File f = new File("input/" + filename + ".dot");
BufferedReader br = null;
public static RegExp readRegex(BufferedReader br) throws IOException {
String line = "Error";
try {
br = new BufferedReader(new FileReader(f));
line = br.readLine();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
line = br.readLine();
RegExp regex = new RegExp("a"); //RegExp.parse(line);
RegExp regex = new RegExp("a").of(new RegExp("b").ster()); //RegExp.parse(line);
return regex;
}