This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
112 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"Hello World |
15 changes: 14 additions & 1 deletion
15
src/main/java/com/auberer/compilerdesignlectureproject/CompilerDesignLectureProject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
package com.auberer.compilerdesignlectureproject; | ||
|
||
import com.auberer.compilerdesignlectureproject.lexer.Lexer; | ||
|
||
public class CompilerDesignLectureProject { | ||
static String basePath = System.getProperty("user.dir"); | ||
static String testfile = new String(basePath + "/test.txt"); | ||
static String emptyfile = new String(basePath + "/empty.txt"); | ||
static String invalidFile = new String(basePath + "/invalid.txt"); | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Hello World!"); | ||
try { | ||
Lexer lexer = new Lexer(testfile); | ||
lexer.start(); | ||
} | ||
catch (Exception ex){ | ||
ex.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/com/auberer/compilerdesignlectureproject/lexer/LexerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,51 @@ | ||
package com.auberer.compilerdesignlectureproject.lexer; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class LexerTest { | ||
|
||
static String basePath = System.getProperty("user.dir"); | ||
static String testfile = new String(basePath + "/test.txt"); | ||
static String emptyfile = new String(basePath + "/empty.txt"); | ||
static String invalidFile = new String(basePath + "/invalid.txt"); | ||
|
||
@Test | ||
@DisplayName("Test for End of file") | ||
public void isEOF() throws IOException { | ||
Lexer lexer = new Lexer(emptyfile); | ||
lexer.start(); | ||
|
||
assertEquals(lexer.getTokens().size(), 1); | ||
assertEquals(lexer.getTokens().get(0).getType(), TokenType.TOK_EOF); | ||
} | ||
|
||
@Test | ||
@DisplayName("Test for invalid token") | ||
public void isInvalid() throws IOException { | ||
Lexer lexer = new Lexer(invalidFile); | ||
lexer.start(); | ||
|
||
assertEquals(lexer.getTokens().get(0).getType(), TokenType.TOK_INVALID); | ||
} | ||
|
||
@Test | ||
@DisplayName("Test for valid file") | ||
public void isValid() throws IOException{ | ||
Lexer lexer = new Lexer(testfile); | ||
lexer.start(); | ||
|
||
assertEquals(lexer.getTokens().size(), 8); | ||
|
||
TokenType[] expected = {TokenType.TOK_KEYWORD, TokenType.TOK_IDENTIFIER, TokenType.TOK_INTEGER, TokenType.TOK_STRING, TokenType.TOK_KEYWORD, TokenType.TOK_IDENTIFIER, TokenType.TOK_DOUBLE, TokenType.TOK_EOF}; | ||
|
||
for(int i = 0; i < lexer.getTokens().size(); i++){ | ||
assertEquals(lexer.getTokens().get(i).getType(), expected[i]); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
Irgendwas | ||
int a 10 | ||
"hello world" double ddd | ||
22,5 |