Initial commit
This commit is contained in:
7
ÜB-Praxis-Scanner für Namen-Leer/.classpath
Normal file
7
ÜB-Praxis-Scanner für Namen-Leer/.classpath
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry excluding="**/*.cup|**/*.lex" kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
8
ÜB-Praxis-Scanner für Namen-Leer/.idea/.gitignore
generated
vendored
Normal file
8
ÜB-Praxis-Scanner für Namen-Leer/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
10
ÜB-Praxis-Scanner für Namen-Leer/.idea/libraries/lib.xml
generated
Normal file
10
ÜB-Praxis-Scanner für Namen-Leer/.idea/libraries/lib.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<component name="libraryTable">
|
||||
<library name="lib">
|
||||
<CLASSES>
|
||||
<root url="file://$PROJECT_DIR$/lib" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
<jarDirectory url="file://$PROJECT_DIR$/lib" recursive="false" />
|
||||
</library>
|
||||
</component>
|
||||
6
ÜB-Praxis-Scanner für Namen-Leer/.idea/misc.xml
generated
Normal file
6
ÜB-Praxis-Scanner für Namen-Leer/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8.0_181" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
ÜB-Praxis-Scanner für Namen-Leer/.idea/modules.xml
generated
Normal file
8
ÜB-Praxis-Scanner für Namen-Leer/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/ÜB-Praxis-Scanner für Namen-Leer.iml" filepath="$PROJECT_DIR$/ÜB-Praxis-Scanner für Namen-Leer.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
18
ÜB-Praxis-Scanner für Namen-Leer/.project
Normal file
18
ÜB-Praxis-Scanner für Namen-Leer/.project
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ÜB-Praxis-Scanner für Namen-Leer</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>pi.eclipse.cle.CupLexNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
@@ -0,0 +1,5 @@
|
||||
//src/de/dhbw/compiler/JFlexASScanner/JFlexASScanner.lex/lex-code-method=0
|
||||
//src/de/dhbw/compiler/JFlexASScanner/JFlexASScanner.lex/lex-comply-jlex=false
|
||||
//src/de/dhbw/compiler/JFlexASScanner/JFlexASScanner.lex/lex-output=src
|
||||
//src/de/dhbw/compiler/JFlexASScanner/JFlexASScanner.lex/lex-skip-min=false
|
||||
eclipse.preferences.version=1
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
ÜB-Praxis-Scanner für Namen-Leer/lib/hamcrest-all-1.3.jar
Normal file
BIN
ÜB-Praxis-Scanner für Namen-Leer/lib/hamcrest-all-1.3.jar
Normal file
Binary file not shown.
BIN
ÜB-Praxis-Scanner für Namen-Leer/lib/jflex-1.6.1.jar
Normal file
BIN
ÜB-Praxis-Scanner für Namen-Leer/lib/jflex-1.6.1.jar
Normal file
Binary file not shown.
12
ÜB-Praxis-Scanner für Namen-Leer/lib/jflexant.xml
Normal file
12
ÜB-Praxis-Scanner für Namen-Leer/lib/jflexant.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="JFlex" default="scanner" basedir=".">
|
||||
<description>
|
||||
Generate Scanner from lex-files
|
||||
</description>
|
||||
|
||||
<taskdef classname="jflex.anttask.JFlexTask" name="jflex" classpath="jflex-1.6.1.jar"/>
|
||||
|
||||
<target name="scanner">
|
||||
<jflex file="../src/de/dhbw/compiler/JFlexASScanner/JFlexASScanner.lex" />
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,117 @@
|
||||
/* **********************************************
|
||||
* Duale Hochschule Baden-Württemberg Karlsruhe
|
||||
* Prof. Dr. Jörn Eisenbiegler
|
||||
*
|
||||
* Vorlesung Übersetzerbau
|
||||
* Praxis AS-Scanner tabellengesteuert 1
|
||||
*
|
||||
* **********************************************
|
||||
*/
|
||||
|
||||
package de.dhbw.compiler.namenscanner;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
import de.dhbw.compiler.namenscanner.Token;
|
||||
|
||||
public class NamenScanner {
|
||||
|
||||
private final int ignore = -2;
|
||||
|
||||
private Reader in = null;
|
||||
private StringBuffer text = new StringBuffer();
|
||||
|
||||
private enum NamenState { WS, P, PE, PET, PETR, PETRA, PETE, PETER, A, AN, ANN, ANNA, EOF};
|
||||
|
||||
private NamenState state = NamenState.WS;
|
||||
private int tokentype = Token.INVALID;
|
||||
|
||||
|
||||
public NamenScanner(Reader input) {
|
||||
this.in = input;
|
||||
}
|
||||
|
||||
private Token step(int c, NamenState newState, boolean create, int newTokenType) {
|
||||
Token res = null;
|
||||
if (create) {
|
||||
res = new Token(tokentype, text.toString());
|
||||
text = new StringBuffer();
|
||||
}
|
||||
if (c!=ignore) {
|
||||
text.append((char)c);
|
||||
}
|
||||
state = newState;
|
||||
tokentype = newTokenType;
|
||||
return res;
|
||||
}
|
||||
|
||||
public Token nextToken() throws Exception {
|
||||
Token token = null;
|
||||
while (token == null) {
|
||||
char c = nextCharacter();
|
||||
|
||||
// peter
|
||||
switch (state) {
|
||||
case WS:
|
||||
switch (c) {
|
||||
case (char) -1: token = step(ignore, NamenState.EOF, false, Token.EOF); break;
|
||||
case ' ': case '\t': case '\n': case '\r': token = step(ignore, NamenState.WS, false, Token.INVALID); break;
|
||||
case 'p': token = step(c, NamenState.P, false, Token.INVALID); break;
|
||||
case 'a': token = step(c, NamenState.A, false, Token.INVALID); break;
|
||||
default:
|
||||
if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) {
|
||||
token = step(c, NamenState.WS, false, Token.INVALID);
|
||||
} else {
|
||||
throw new Exception("Unexpected character: " + c + " (" + (int) c + ")");
|
||||
} break;
|
||||
} break;
|
||||
case P:
|
||||
switch (c) {
|
||||
case (char) -1: token = step(ignore, NamenState.EOF, false, Token.EOF); break;
|
||||
case ' ': case '\t': case '\n': case '\r': token = step(ignore, NamenState.WS, false, Token.INVALID); break;
|
||||
case '': token = step(c, NamenState.P, false, Token.INVALID); break;
|
||||
case 'A': token = step(c, NamenState.A, false, Token.INVALID); break;
|
||||
default:
|
||||
if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) {
|
||||
token = step(c, NamenState.WS, false, Token.INVALID);
|
||||
} else {
|
||||
throw new Exception("Unexpected character: " + c + " (" + (int) c + ")");
|
||||
} break;
|
||||
} break;
|
||||
case PE:
|
||||
break;
|
||||
case PET:
|
||||
break;
|
||||
case PETR:
|
||||
break;
|
||||
case PETRA:
|
||||
break;
|
||||
case PETE:
|
||||
break;
|
||||
case PETER:
|
||||
break;
|
||||
case A:
|
||||
break;
|
||||
case AN:
|
||||
break;
|
||||
case ANN:
|
||||
break;
|
||||
case ANNA:
|
||||
break;
|
||||
case EOF:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
private char nextCharacter() {
|
||||
try {
|
||||
return (char) in.read();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/* **********************************************
|
||||
* Duale Hochschule Baden-Württemberg Karlsruhe
|
||||
* Prof. Dr. Jörn Eisenbiegler
|
||||
*
|
||||
* Vorlesung Übersetzerbau
|
||||
* Praxis AS-Scanner mit JFlex 1
|
||||
*
|
||||
* **********************************************
|
||||
*/
|
||||
|
||||
package de.dhbw.compiler.namenscanner;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
|
||||
public class NamenScannerMain {
|
||||
|
||||
private static final String TEST = "anna peter petra";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
NamenScanner scanner = new NamenScanner(new StringReader(TEST));
|
||||
|
||||
Token mytoken = scanner.nextToken();
|
||||
|
||||
while (mytoken.getType()!=Token.EOF) {
|
||||
System.out.println(mytoken);
|
||||
mytoken = scanner.nextToken();
|
||||
}
|
||||
|
||||
System.out.println(mytoken);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
/* **********************************************
|
||||
* Duale Hochschule Baden-Württemberg Karlsruhe
|
||||
* Prof. Dr. Jörn Eisenbiegler
|
||||
*
|
||||
* Vorlesung Übersetzerbau
|
||||
* Praxis AS-Scanner mit JFlex
|
||||
* - Testfälle Aufgabe 1
|
||||
*
|
||||
* **********************************************
|
||||
*/
|
||||
|
||||
package de.dhbw.compiler.namenscanner;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestNamenScanner1 extends TokenStreamTest {
|
||||
|
||||
@Test
|
||||
public void tokenPeter() throws Exception {
|
||||
testTokenList("peter", new Token(Token.PETER, "peter"));
|
||||
testTokenList(" peter ", new Token(Token.PETER, "peter"));
|
||||
testTokenList(" peter peter ", new Token(Token.PETER, "peter"),
|
||||
new Token(Token.PETER, "peter"));
|
||||
testTokenList(" peterpeter ", new Token(Token.PETER, "peter"),
|
||||
new Token(Token.PETER, "peter"));
|
||||
testTokenList("peterpeter", new Token(Token.PETER, "peter"),
|
||||
new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tokenPetra() throws Exception {
|
||||
testTokenList("petra", new Token(Token.PETRA, "petra"));
|
||||
testTokenList(" petra ", new Token(Token.PETRA, "petra"));
|
||||
testTokenList(" petra petra ", new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.PETRA, "petra"));
|
||||
testTokenList(" petrapetra ", new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.PETRA, "petra"));
|
||||
testTokenList("petrapetra", new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.PETRA, "petra"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tokenAnna() throws Exception {
|
||||
testTokenList("anna", new Token(Token.ANNA, "anna"));
|
||||
testTokenList(" anna ", new Token(Token.ANNA, "anna"));
|
||||
testTokenList(" anna anna ", new Token(Token.ANNA, "anna"),
|
||||
new Token(Token.ANNA, "anna"));
|
||||
testTokenList(" annaanna ", new Token(Token.ANNA, "anna"),
|
||||
new Token(Token.ANNA, "anna"));
|
||||
testTokenList("annaanna", new Token(Token.ANNA, "anna"),
|
||||
new Token(Token.ANNA, "anna"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tokenPeterPetraAnna() throws Exception {
|
||||
testTokenList("peter petra anna", new Token(Token.PETER, "peter"),
|
||||
new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.ANNA, "anna"));
|
||||
testTokenList(" peter petra anna ", new Token(Token.PETER, "peter"),
|
||||
new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.ANNA, "anna"));
|
||||
testTokenList("peterpetraanna", new Token(Token.PETER, "peter"),
|
||||
new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.ANNA, "anna"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tokenAnnaPetraPeter() throws Exception {
|
||||
testTokenList("anna petra peter",
|
||||
new Token(Token.ANNA, "anna"),
|
||||
new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.PETER, "peter"));
|
||||
testTokenList(" anna petra peter ",
|
||||
new Token(Token.ANNA, "anna"),
|
||||
new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.PETER, "peter"));
|
||||
testTokenList("annapetrapeter",
|
||||
new Token(Token.ANNA, "anna"),
|
||||
new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tokenPetraAnnaPeter() throws Exception {
|
||||
testTokenList("petra anna peter",
|
||||
new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.ANNA, "anna"),
|
||||
new Token(Token.PETER, "peter"));
|
||||
testTokenList(" petra anna peter ",
|
||||
new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.ANNA, "anna"),
|
||||
new Token(Token.PETER, "peter"));
|
||||
testTokenList("petraannapeter",
|
||||
new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.ANNA, "anna"),
|
||||
new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tokenViele() throws Exception {
|
||||
testTokenList("petra anna peterannapeterpetra petra annaanna peter",
|
||||
new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.ANNA, "anna"),
|
||||
new Token(Token.PETER, "peter"),
|
||||
new Token(Token.ANNA, "anna"),
|
||||
new Token(Token.PETER, "peter"),
|
||||
new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.PETRA, "petra"),
|
||||
new Token(Token.ANNA, "anna"),
|
||||
new Token(Token.ANNA, "anna"),
|
||||
new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenX() throws Exception {
|
||||
testTokenList("x", new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenWSx() throws Exception {
|
||||
testTokenList(" x", new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenP() throws Exception {
|
||||
testTokenList("p", new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenPe() throws Exception {
|
||||
testTokenList("pe", new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenPet() throws Exception {
|
||||
testTokenList("pet", new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenPetr() throws Exception {
|
||||
testTokenList("petr", new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenPete() throws Exception {
|
||||
testTokenList("pete", new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenA() throws Exception {
|
||||
testTokenList("a", new Token(Token.ANNA, "anna"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenAn() throws Exception {
|
||||
testTokenList("an", new Token(Token.ANNA, "anna"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenAnn() throws Exception {
|
||||
testTokenList("ann", new Token(Token.ANNA, "anna"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenPx() throws Exception {
|
||||
testTokenList("px", new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenPex() throws Exception {
|
||||
testTokenList("pex", new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenPetx() throws Exception {
|
||||
testTokenList("petx", new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenPetrx() throws Exception {
|
||||
testTokenList("petrx", new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenPetrax() throws Exception {
|
||||
testTokenList("petrax", new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenPetex() throws Exception {
|
||||
testTokenList("petex", new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenPeterx() throws Exception {
|
||||
testTokenList("peterx", new Token(Token.PETER, "peter"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenAx() throws Exception {
|
||||
testTokenList("ax", new Token(Token.ANNA, "anna"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenAnx() throws Exception {
|
||||
testTokenList("anx", new Token(Token.ANNA, "anna"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenAnnx() throws Exception {
|
||||
testTokenList("annx", new Token(Token.ANNA, "anna"));
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void tokenAnnax() throws Exception {
|
||||
testTokenList("annx", new Token(Token.ANNA, "anna"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/* **********************************************
|
||||
* Duale Hochschule Baden-Württemberg Karlsruhe
|
||||
* Prof. Dr. Jörn Eisenbiegler
|
||||
*
|
||||
* Vorlesung Übersetzerbau
|
||||
* Praxis AS-Scanner mit JFlex
|
||||
* - Testsuite
|
||||
*
|
||||
* **********************************************
|
||||
*/
|
||||
|
||||
package de.dhbw.compiler.namenscanner;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ TestNamenScanner1.class })
|
||||
public class TestsAll {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/* **********************************************
|
||||
* Duale Hochschule Baden-Württemberg Karlsruhe
|
||||
* Prof. Dr. Jörn Eisenbiegler
|
||||
*
|
||||
* Vorlesung Übersetzerbau
|
||||
* Praxis AS-Scanner mit JFlex
|
||||
* - Token-Definition
|
||||
*
|
||||
* **********************************************
|
||||
*/
|
||||
|
||||
package de.dhbw.compiler.namenscanner;
|
||||
|
||||
public class Token {
|
||||
|
||||
public static final int EOF = 0;
|
||||
public static final int INVALID = -1;
|
||||
public static final int PETER = 1;
|
||||
public static final int PETRA = 2;
|
||||
public static final int ANNA = 3;
|
||||
|
||||
private int type;
|
||||
private String text;
|
||||
|
||||
public Token(int type, String text) {
|
||||
this.type = type;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "(" + getTypeName(type) + "," + text + ")";
|
||||
}
|
||||
|
||||
public static String getTypeName(int tokenType) {
|
||||
switch (tokenType) {
|
||||
case EOF: return "EOF";
|
||||
case INVALID: return "INVALID";
|
||||
case PETER: return "peter";
|
||||
case PETRA: return "petra";
|
||||
case ANNA: return "anna";
|
||||
default: return "Unknown token type!";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/* **********************************************
|
||||
* Duale Hochschule Baden-Württemberg Karlsruhe
|
||||
* Prof. Dr. Jörn Eisenbiegler
|
||||
*
|
||||
* Vorlesung Übersetzerbau
|
||||
* Praxis AS-Scanner mit JFlex
|
||||
* - Testfall-Utility
|
||||
*
|
||||
* **********************************************
|
||||
*/
|
||||
|
||||
package de.dhbw.compiler.namenscanner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
import de.dhbw.compiler.namenscanner.NamenScanner;
|
||||
import de.dhbw.compiler.namenscanner.Token;
|
||||
|
||||
public abstract class TokenStreamTest {
|
||||
|
||||
protected void testTokenList(String in, Token... TokenList) throws Exception {
|
||||
NamenScanner scanner = new NamenScanner(new StringReader(in));
|
||||
Token myToken;
|
||||
|
||||
for (Token expected : TokenList) {
|
||||
myToken = scanner.nextToken();
|
||||
assertEquals("Expect Token "+expected.toString()+". Error in type.",
|
||||
expected.getType(), myToken.getType());
|
||||
assertEquals("Expect Token "+expected.toString()+". Error in text.",
|
||||
expected.getText(), myToken.getText());
|
||||
}
|
||||
|
||||
myToken = scanner.nextToken();
|
||||
assertEquals("Expected End of File (EOF), read " + myToken.toString() + ".", Token.EOF, myToken.getType());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<output url="file://$MODULE_DIR$/bin" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="jdk" jdkName="1.8.0_181" jdkType="JavaSDK" />
|
||||
<orderEntry type="library" exported="" name="lib" level="project" />
|
||||
<orderEntry type="module-library" exported="">
|
||||
<library name="junit4">
|
||||
<CLASSES>
|
||||
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.12.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
||||
Reference in New Issue
Block a user