antr gen package expilcitly added and some printlines in main
This commit is contained in:
parent
80917ec222
commit
dbcf40ea84
1
Source/.idea/libraries/asm_9_7.xml
generated
1
Source/.idea/libraries/asm_9_7.xml
generated
@ -2,6 +2,7 @@
|
|||||||
<library name="asm-9.7">
|
<library name="asm-9.7">
|
||||||
<CLASSES>
|
<CLASSES>
|
||||||
<root url="jar://$PROJECT_DIR$/../Lib/asm-9.7.jar!/" />
|
<root url="jar://$PROJECT_DIR$/../Lib/asm-9.7.jar!/" />
|
||||||
|
<root url="jar://$PROJECT_DIR$/../../../antlr-4.13.1-complete.jar!/" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES />
|
<SOURCES />
|
||||||
|
2
Source/.idea/misc.xml
generated
2
Source/.idea/misc.xml
generated
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -2,7 +2,17 @@ import abstractSyntaxTree.Class.FieldDecl;
|
|||||||
import abstractSyntaxTree.Class.MethodDecl;
|
import abstractSyntaxTree.Class.MethodDecl;
|
||||||
import abstractSyntaxTree.Class.RefType;
|
import abstractSyntaxTree.Class.RefType;
|
||||||
import abstractSyntaxTree.Program;
|
import abstractSyntaxTree.Program;
|
||||||
|
import gen.DecafLexer;
|
||||||
|
import gen.DecafParser;
|
||||||
|
import org.antlr.v4.runtime.CharStream;
|
||||||
|
import org.antlr.v4.runtime.CharStreams;
|
||||||
|
import org.antlr.v4.runtime.CommonTokenStream;
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
|
import org.antlr.v4.runtime.tree.ParseTree;
|
||||||
|
|
||||||
|
import java.io.CharArrayReader;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -11,6 +21,36 @@ public class Compiler {
|
|||||||
public static void main(String[] args) throws Exception{
|
public static void main(String[] args) throws Exception{
|
||||||
|
|
||||||
// get file
|
// get file
|
||||||
|
// String filePath = "EmptyClass.java";
|
||||||
|
// String content = new String(Files.readAllBytes(Paths.get(filePath)));
|
||||||
|
// CharArrayReader charStream = new CharArrayReader(content.toCharArray());
|
||||||
|
|
||||||
|
CharStream codeCharStream = CharStreams.fromString("class Example { }");
|
||||||
|
DecafLexer lexer = new DecafLexer(codeCharStream);
|
||||||
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||||
|
|
||||||
|
System.out.println("--- print tokens ---");
|
||||||
|
tokens.fill();
|
||||||
|
|
||||||
|
List<Token> tokenList = tokens.getTokens();
|
||||||
|
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
for (Token token : tokenList) {
|
||||||
|
stringBuilder.append(token.toString()).append(" ");
|
||||||
|
}
|
||||||
|
String readableTokens = stringBuilder.toString().trim();
|
||||||
|
|
||||||
|
System.out.println(readableTokens);
|
||||||
|
|
||||||
|
|
||||||
|
DecafParser parser = new DecafParser(tokens);
|
||||||
|
|
||||||
|
ParseTree tree = parser.program();
|
||||||
|
|
||||||
|
System.out.println("--- print tree ---");
|
||||||
|
System.out.println(tree);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Program abstractSyntaxTree = new Program(new ArrayList<>());
|
Program abstractSyntaxTree = new Program(new ArrayList<>());
|
||||||
List<FieldDecl> emptyFieldDecl = new ArrayList<>();
|
List<FieldDecl> emptyFieldDecl = new ArrayList<>();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/Users/dh10krj/OneDrive - Durr Group/Dokumente/S4/Compilerbau/projekt/NichtHaskell/Source/Decaf.g4 by ANTLR 4.13.1
|
package gen;// Generated from C:/Users/dh10krj/OneDrive - Durr Group/Dokumente/S4/Compilerbau/projekt/NichtHaskell/Source/Decaf.g4 by ANTLR 4.13.1
|
||||||
|
|
||||||
import org.antlr.v4.runtime.ParserRuleContext;
|
import org.antlr.v4.runtime.ParserRuleContext;
|
||||||
import org.antlr.v4.runtime.tree.ErrorNode;
|
import org.antlr.v4.runtime.tree.ErrorNode;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/Users/dh10krj/OneDrive - Durr Group/Dokumente/S4/Compilerbau/projekt/NichtHaskell/Source/Decaf.g4 by ANTLR 4.13.1
|
package gen;// Generated from C:/Users/dh10krj/OneDrive - Durr Group/Dokumente/S4/Compilerbau/projekt/NichtHaskell/Source/Decaf.g4 by ANTLR 4.13.1
|
||||||
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/Users/dh10krj/OneDrive - Durr Group/Dokumente/S4/Compilerbau/projekt/NichtHaskell/Source/Decaf.g4 by ANTLR 4.13.1
|
package gen;// Generated from C:/Users/dh10krj/OneDrive - Durr Group/Dokumente/S4/Compilerbau/projekt/NichtHaskell/Source/Decaf.g4 by ANTLR 4.13.1
|
||||||
import org.antlr.v4.runtime.Lexer;
|
import org.antlr.v4.runtime.Lexer;
|
||||||
import org.antlr.v4.runtime.CharStream;
|
import org.antlr.v4.runtime.CharStream;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/Users/dh10krj/OneDrive - Durr Group/Dokumente/S4/Compilerbau/projekt/NichtHaskell/Source/Decaf.g4 by ANTLR 4.13.1
|
package gen;// Generated from C:/Users/dh10krj/OneDrive - Durr Group/Dokumente/S4/Compilerbau/projekt/NichtHaskell/Source/Decaf.g4 by ANTLR 4.13.1
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/Users/dh10krj/OneDrive - Durr Group/Dokumente/S4/Compilerbau/projekt/NichtHaskell/Source/Decaf.g4 by ANTLR 4.13.1
|
package gen;// Generated from C:/Users/dh10krj/OneDrive - Durr Group/Dokumente/S4/Compilerbau/projekt/NichtHaskell/Source/Decaf.g4 by ANTLR 4.13.1
|
||||||
import org.antlr.v4.runtime.atn.*;
|
import org.antlr.v4.runtime.atn.*;
|
||||||
import org.antlr.v4.runtime.dfa.DFA;
|
import org.antlr.v4.runtime.dfa.DFA;
|
||||||
import org.antlr.v4.runtime.*;
|
import org.antlr.v4.runtime.*;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/Users/dh10krj/OneDrive - Durr Group/Dokumente/S4/Compilerbau/projekt/NichtHaskell/Source/Decaf.g4 by ANTLR 4.13.1
|
package gen;// Generated from C:/Users/dh10krj/OneDrive - Durr Group/Dokumente/S4/Compilerbau/projekt/NichtHaskell/Source/Decaf.g4 by ANTLR 4.13.1
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user