Merge remote-tracking branch 'origin/main'

This commit is contained in:
i22011 2024-05-02 16:10:47 +02:00
commit 56c32fe9d3
27 changed files with 837 additions and 37 deletions

99
.gitignore vendored
View File

@ -1,38 +1,77 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
.idea/artifacts
.idea/compiler.xml
.idea/libraries/
*.iws
.idea/jarRepositories.xml
.idea/modules.xml
.idea/*.iml
.idea/modules
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
# CMake
cmake-build-*/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
### VS Code ###
.vscode/
# File-based project format
*.iws
### Mac OS ###
.DS_Store
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

13
.idea/compiler.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="JavaCompiler" />
</profile>
</annotationProcessing>
</component>
</project>

20
.idea/jarRepositories.xml Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

View File

@ -1,5 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ANTLRGenerationPreferences">
<option name="perGrammarGenerationSettings">
<list>
<PerGrammarGenerationSettings>
<option name="fileName" value="$PROJECT_DIR$/src/main/java/parser/SimpleJava.g4" />
<option name="autoGen" value="true" />
<option name="outputDir" value="C:\Users\ARB00075\Documents\DH\Compilerbau\NichtHaskell2.0\src\main\java\parser\out" />
<option name="libDir" value="" />
<option name="encoding" value="" />
<option name="pkg" value="" />
<option name="language" value="" />
<option name="generateVisitor" value="true" />
</PerGrammarGenerationSettings>
</list>
</option>
</component>
<component name="ANTLRNewGenerationPreferences">
<option name="perGrammarGenerationSettings">
<list>
<PerGrammarGenerationSettings>
<option name="fileName" value="$PROJECT_DIR$/src/main/java/parser/SimpleJava.g4" />
<option name="autoGen" value="true" />
<option name="outputDir" value="C:\Users\Johannes Ehlert\Documents\Git\JavaCompiler\src\main\java" />
<option name="libDir" value="" />
<option name="encoding" value="" />
<option name="pkg" value="parser.generated" />
<option name="language" value="" />
<option name="generateVisitor" value="true" />
</PerGrammarGenerationSettings>
</list>
</option>
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">

BIN
antlr-4.12.0-complete.jar Normal file

Binary file not shown.

View File

@ -0,0 +1,5 @@
package ast;
public enum AccessModifier {
Public,Private
}

View File

@ -0,0 +1,7 @@
package ast;
public abstract class ClassDeclaration {
public AccessModifier accessModifier;
}

View File

@ -0,0 +1,13 @@
package ast;
public class Identifier {
private String name;
public Identifier(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
}

View File

@ -0,0 +1,7 @@
package ast;
public interface Type {
}

View File

@ -1,7 +0,0 @@
package org.example;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

View File

@ -0,0 +1,20 @@
package parser;
import parser.generated.SimpleJavaBaseVisitor;
import parser.generated.SimpleJavaParser;
public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitProgram(SimpleJavaParser.ProgramContext ctx) {
ProgramNode program = new ProgramNode();
for (SimpleJavaParser.ClassDeclarationContext classDeclCtx : ctx.classDeclaration()) {
program.addClass((ClassDeclarationNode) visit(classDeclCtx));
}
return program;
}
@Override
public ASTNode visitClassDeclaration(SimpleJavaParser.ClassDeclarationContext ctx) {
return new ClassDeclarationNode(ctx.IDENTIFIER().getText());
}
}

View File

@ -0,0 +1,8 @@
package parser;
import java.util.ArrayList;
import java.util.List;
public abstract class ASTNode { }

View File

@ -0,0 +1,11 @@
package parser;
import parser.ASTNode;
public class ClassDeclarationNode extends ASTNode {
public String identifier;
public ClassDeclarationNode(String identifier) {
this.identifier = identifier;
}
}

View File

@ -0,0 +1,27 @@
package parser;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import parser.generated.SimpleJavaLexer;
import parser.generated.SimpleJavaParser;
public class Main {
public static void main(String[] args) throws Exception {
// Assuming args[0] contains the path to the input file
CharStream codeCharStream = CharStreams.fromString("class Test { }");
SimpleJavaLexer lexer = new SimpleJavaLexer(codeCharStream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SimpleJavaParser parser = new SimpleJavaParser(tokens);
ParseTree tree = parser.program(); // parse the input
ASTBuilder builder = new ASTBuilder();
ProgramNode ast = (ProgramNode) builder.visit(tree); // build the AST
// Optionally print or process the AST
System.out.println("Parsed " + ast.classes.size() + " classes.");
System.out.println(ast.classes.get(0).identifier);
}
}

View File

@ -0,0 +1,15 @@
package parser;
import parser.ASTNode;
import parser.ClassDeclarationNode;
import java.util.ArrayList;
import java.util.List;
public class ProgramNode extends ASTNode {
public List<ClassDeclarationNode> classes = new ArrayList<>();
public void addClass(ClassDeclarationNode classNode) {
classes.add(classNode);
}
}

View File

@ -0,0 +1,9 @@
grammar SimpleJava;
program : classDeclaration+;
classDeclaration : 'class' IDENTIFIER '{' '}';
IDENTIFIER : [a-zA-Z][a-zA-Z0-9_]*;
WS : [ \t\r\n]+ -> skip;

View File

@ -0,0 +1 @@
class Test { }

View File

@ -0,0 +1,23 @@
token literal names:
null
'class'
'{'
'}'
null
null
token symbolic names:
null
null
null
null
IDENTIFIER
WS
rule names:
program
classDeclaration
atn:
[4, 1, 5, 15, 2, 0, 7, 0, 2, 1, 7, 1, 1, 0, 4, 0, 6, 8, 0, 11, 0, 12, 0, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 2, 0, 2, 0, 0, 13, 0, 5, 1, 0, 0, 0, 2, 9, 1, 0, 0, 0, 4, 6, 3, 2, 1, 0, 5, 4, 1, 0, 0, 0, 6, 7, 1, 0, 0, 0, 7, 5, 1, 0, 0, 0, 7, 8, 1, 0, 0, 0, 8, 1, 1, 0, 0, 0, 9, 10, 5, 1, 0, 0, 10, 11, 5, 4, 0, 0, 11, 12, 5, 2, 0, 0, 12, 13, 5, 3, 0, 0, 13, 3, 1, 0, 0, 0, 1, 7]

View File

@ -0,0 +1,8 @@
T__0=1
T__1=2
T__2=3
IDENTIFIER=4
WS=5
'class'=1
'{'=2
'}'=3

View File

@ -0,0 +1,64 @@
// Generated from C:/Users/Johannes Ehlert/Documents/Git/JavaCompiler/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
/**
* This class provides an empty implementation of {@link SimpleJavaListener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
@SuppressWarnings("CheckReturnValue")
public class SimpleJavaBaseListener implements SimpleJavaListener {
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterProgram(SimpleJavaParser.ProgramContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitProgram(SimpleJavaParser.ProgramContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterClassDeclaration(SimpleJavaParser.ClassDeclarationContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitClassDeclaration(SimpleJavaParser.ClassDeclarationContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitTerminal(TerminalNode node) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitErrorNode(ErrorNode node) { }
}

View File

@ -0,0 +1,29 @@
// Generated from C:/Users/Johannes Ehlert/Documents/Git/JavaCompiler/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
/**
* This class provides an empty implementation of {@link SimpleJavaVisitor},
* which can be extended to create a visitor which only needs to handle a subset
* of the available methods.
*
* @param <T> The return type of the visit operation. Use {@link Void} for
* operations with no return type.
*/
@SuppressWarnings("CheckReturnValue")
public class SimpleJavaBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements SimpleJavaVisitor<T> {
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitProgram(SimpleJavaParser.ProgramContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitClassDeclaration(SimpleJavaParser.ClassDeclarationContext ctx) { return visitChildren(ctx); }
}

View File

@ -0,0 +1,32 @@
token literal names:
null
'class'
'{'
'}'
null
null
token symbolic names:
null
null
null
null
IDENTIFIER
WS
rule names:
T__0
T__1
T__2
IDENTIFIER
WS
channel names:
DEFAULT_TOKEN_CHANNEL
HIDDEN
mode names:
DEFAULT_MODE
atn:
[4, 0, 5, 35, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 5, 3, 24, 8, 3, 10, 3, 12, 3, 27, 9, 3, 1, 4, 4, 4, 30, 8, 4, 11, 4, 12, 4, 31, 1, 4, 1, 4, 0, 0, 5, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 1, 0, 3, 2, 0, 65, 90, 97, 122, 4, 0, 48, 57, 65, 90, 95, 95, 97, 122, 3, 0, 9, 10, 13, 13, 32, 32, 36, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 1, 11, 1, 0, 0, 0, 3, 17, 1, 0, 0, 0, 5, 19, 1, 0, 0, 0, 7, 21, 1, 0, 0, 0, 9, 29, 1, 0, 0, 0, 11, 12, 5, 99, 0, 0, 12, 13, 5, 108, 0, 0, 13, 14, 5, 97, 0, 0, 14, 15, 5, 115, 0, 0, 15, 16, 5, 115, 0, 0, 16, 2, 1, 0, 0, 0, 17, 18, 5, 123, 0, 0, 18, 4, 1, 0, 0, 0, 19, 20, 5, 125, 0, 0, 20, 6, 1, 0, 0, 0, 21, 25, 7, 0, 0, 0, 22, 24, 7, 1, 0, 0, 23, 22, 1, 0, 0, 0, 24, 27, 1, 0, 0, 0, 25, 23, 1, 0, 0, 0, 25, 26, 1, 0, 0, 0, 26, 8, 1, 0, 0, 0, 27, 25, 1, 0, 0, 0, 28, 30, 7, 2, 0, 0, 29, 28, 1, 0, 0, 0, 30, 31, 1, 0, 0, 0, 31, 29, 1, 0, 0, 0, 31, 32, 1, 0, 0, 0, 32, 33, 1, 0, 0, 0, 33, 34, 6, 4, 0, 0, 34, 10, 1, 0, 0, 0, 3, 0, 25, 31, 1, 6, 0, 0]

View File

@ -0,0 +1,140 @@
// Generated from C:/Users/Johannes Ehlert/Documents/Git/JavaCompiler/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue", "this-escape"})
public class SimpleJavaLexer extends Lexer {
static { RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, IDENTIFIER=4, WS=5;
public static String[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
};
public static String[] modeNames = {
"DEFAULT_MODE"
};
private static String[] makeRuleNames() {
return new String[] {
"T__0", "T__1", "T__2", "IDENTIFIER", "WS"
};
}
public static final String[] ruleNames = makeRuleNames();
private static String[] makeLiteralNames() {
return new String[] {
null, "'class'", "'{'", "'}'"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
return new String[] {
null, null, null, null, "IDENTIFIER", "WS"
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
public SimpleJavaLexer(CharStream input) {
super(input);
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@Override
public String getGrammarFileName() { return "SimpleJava.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public String[] getChannelNames() { return channelNames; }
@Override
public String[] getModeNames() { return modeNames; }
@Override
public ATN getATN() { return _ATN; }
public static final String _serializedATN =
"\u0004\u0000\u0005#\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+
"\u0007\u0001\u0002\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004"+
"\u0007\u0004\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000"+
"\u0001\u0000\u0001\u0001\u0001\u0001\u0001\u0002\u0001\u0002\u0001\u0003"+
"\u0001\u0003\u0005\u0003\u0018\b\u0003\n\u0003\f\u0003\u001b\t\u0003\u0001"+
"\u0004\u0004\u0004\u001e\b\u0004\u000b\u0004\f\u0004\u001f\u0001\u0004"+
"\u0001\u0004\u0000\u0000\u0005\u0001\u0001\u0003\u0002\u0005\u0003\u0007"+
"\u0004\t\u0005\u0001\u0000\u0003\u0002\u0000AZaz\u0004\u000009AZ__az\u0003"+
"\u0000\t\n\r\r $\u0000\u0001\u0001\u0000\u0000\u0000\u0000\u0003\u0001"+
"\u0000\u0000\u0000\u0000\u0005\u0001\u0000\u0000\u0000\u0000\u0007\u0001"+
"\u0000\u0000\u0000\u0000\t\u0001\u0000\u0000\u0000\u0001\u000b\u0001\u0000"+
"\u0000\u0000\u0003\u0011\u0001\u0000\u0000\u0000\u0005\u0013\u0001\u0000"+
"\u0000\u0000\u0007\u0015\u0001\u0000\u0000\u0000\t\u001d\u0001\u0000\u0000"+
"\u0000\u000b\f\u0005c\u0000\u0000\f\r\u0005l\u0000\u0000\r\u000e\u0005"+
"a\u0000\u0000\u000e\u000f\u0005s\u0000\u0000\u000f\u0010\u0005s\u0000"+
"\u0000\u0010\u0002\u0001\u0000\u0000\u0000\u0011\u0012\u0005{\u0000\u0000"+
"\u0012\u0004\u0001\u0000\u0000\u0000\u0013\u0014\u0005}\u0000\u0000\u0014"+
"\u0006\u0001\u0000\u0000\u0000\u0015\u0019\u0007\u0000\u0000\u0000\u0016"+
"\u0018\u0007\u0001\u0000\u0000\u0017\u0016\u0001\u0000\u0000\u0000\u0018"+
"\u001b\u0001\u0000\u0000\u0000\u0019\u0017\u0001\u0000\u0000\u0000\u0019"+
"\u001a\u0001\u0000\u0000\u0000\u001a\b\u0001\u0000\u0000\u0000\u001b\u0019"+
"\u0001\u0000\u0000\u0000\u001c\u001e\u0007\u0002\u0000\u0000\u001d\u001c"+
"\u0001\u0000\u0000\u0000\u001e\u001f\u0001\u0000\u0000\u0000\u001f\u001d"+
"\u0001\u0000\u0000\u0000\u001f \u0001\u0000\u0000\u0000 !\u0001\u0000"+
"\u0000\u0000!\"\u0006\u0004\u0000\u0000\"\n\u0001\u0000\u0000\u0000\u0003"+
"\u0000\u0019\u001f\u0001\u0006\u0000\u0000";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -0,0 +1,8 @@
T__0=1
T__1=2
T__2=3
IDENTIFIER=4
WS=5
'class'=1
'{'=2
'}'=3

View File

@ -0,0 +1,30 @@
// Generated from C:/Users/Johannes Ehlert/Documents/Git/JavaCompiler/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated;
import org.antlr.v4.runtime.tree.ParseTreeListener;
/**
* This interface defines a complete listener for a parse tree produced by
* {@link SimpleJavaParser}.
*/
public interface SimpleJavaListener extends ParseTreeListener {
/**
* Enter a parse tree produced by {@link SimpleJavaParser#program}.
* @param ctx the parse tree
*/
void enterProgram(SimpleJavaParser.ProgramContext ctx);
/**
* Exit a parse tree produced by {@link SimpleJavaParser#program}.
* @param ctx the parse tree
*/
void exitProgram(SimpleJavaParser.ProgramContext ctx);
/**
* Enter a parse tree produced by {@link SimpleJavaParser#classDeclaration}.
* @param ctx the parse tree
*/
void enterClassDeclaration(SimpleJavaParser.ClassDeclarationContext ctx);
/**
* Exit a parse tree produced by {@link SimpleJavaParser#classDeclaration}.
* @param ctx the parse tree
*/
void exitClassDeclaration(SimpleJavaParser.ClassDeclarationContext ctx);
}

View File

@ -0,0 +1,221 @@
// Generated from C:/Users/Johannes Ehlert/Documents/Git/JavaCompiler/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"})
public class SimpleJavaParser extends Parser {
static { RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, IDENTIFIER=4, WS=5;
public static final int
RULE_program = 0, RULE_classDeclaration = 1;
private static String[] makeRuleNames() {
return new String[] {
"program", "classDeclaration"
};
}
public static final String[] ruleNames = makeRuleNames();
private static String[] makeLiteralNames() {
return new String[] {
null, "'class'", "'{'", "'}'"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
return new String[] {
null, null, null, null, "IDENTIFIER", "WS"
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public String getGrammarFileName() { return "SimpleJava.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public SimpleJavaParser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@SuppressWarnings("CheckReturnValue")
public static class ProgramContext extends ParserRuleContext {
public List<ClassDeclarationContext> classDeclaration() {
return getRuleContexts(ClassDeclarationContext.class);
}
public ClassDeclarationContext classDeclaration(int i) {
return getRuleContext(ClassDeclarationContext.class,i);
}
public ProgramContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_program; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof SimpleJavaListener ) ((SimpleJavaListener)listener).enterProgram(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof SimpleJavaListener ) ((SimpleJavaListener)listener).exitProgram(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof SimpleJavaVisitor ) return ((SimpleJavaVisitor<? extends T>)visitor).visitProgram(this);
else return visitor.visitChildren(this);
}
}
public final ProgramContext program() throws RecognitionException {
ProgramContext _localctx = new ProgramContext(_ctx, getState());
enterRule(_localctx, 0, RULE_program);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(5);
_errHandler.sync(this);
_la = _input.LA(1);
do {
{
{
setState(4);
classDeclaration();
}
}
setState(7);
_errHandler.sync(this);
_la = _input.LA(1);
} while ( _la==T__0 );
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class ClassDeclarationContext extends ParserRuleContext {
public TerminalNode IDENTIFIER() { return getToken(SimpleJavaParser.IDENTIFIER, 0); }
public ClassDeclarationContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_classDeclaration; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof SimpleJavaListener ) ((SimpleJavaListener)listener).enterClassDeclaration(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof SimpleJavaListener ) ((SimpleJavaListener)listener).exitClassDeclaration(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof SimpleJavaVisitor ) return ((SimpleJavaVisitor<? extends T>)visitor).visitClassDeclaration(this);
else return visitor.visitChildren(this);
}
}
public final ClassDeclarationContext classDeclaration() throws RecognitionException {
ClassDeclarationContext _localctx = new ClassDeclarationContext(_ctx, getState());
enterRule(_localctx, 2, RULE_classDeclaration);
try {
enterOuterAlt(_localctx, 1);
{
setState(9);
match(T__0);
setState(10);
match(IDENTIFIER);
setState(11);
match(T__1);
setState(12);
match(T__2);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static final String _serializedATN =
"\u0004\u0001\u0005\u000f\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001"+
"\u0001\u0000\u0004\u0000\u0006\b\u0000\u000b\u0000\f\u0000\u0007\u0001"+
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0000"+
"\u0000\u0002\u0000\u0002\u0000\u0000\r\u0000\u0005\u0001\u0000\u0000\u0000"+
"\u0002\t\u0001\u0000\u0000\u0000\u0004\u0006\u0003\u0002\u0001\u0000\u0005"+
"\u0004\u0001\u0000\u0000\u0000\u0006\u0007\u0001\u0000\u0000\u0000\u0007"+
"\u0005\u0001\u0000\u0000\u0000\u0007\b\u0001\u0000\u0000\u0000\b\u0001"+
"\u0001\u0000\u0000\u0000\t\n\u0005\u0001\u0000\u0000\n\u000b\u0005\u0004"+
"\u0000\u0000\u000b\f\u0005\u0002\u0000\u0000\f\r\u0005\u0003\u0000\u0000"+
"\r\u0003\u0001\u0000\u0000\u0000\u0001\u0007";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -0,0 +1,25 @@
// Generated from C:/Users/Johannes Ehlert/Documents/Git/JavaCompiler/src/main/java/parser/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
/**
* This interface defines a complete generic visitor for a parse tree produced
* by {@link SimpleJavaParser}.
*
* @param <T> The return type of the visit operation. Use {@link Void} for
* operations with no return type.
*/
public interface SimpleJavaVisitor<T> extends ParseTreeVisitor<T> {
/**
* Visit a parse tree produced by {@link SimpleJavaParser#program}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitProgram(SimpleJavaParser.ProgramContext ctx);
/**
* Visit a parse tree produced by {@link SimpleJavaParser#classDeclaration}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitClassDeclaration(SimpleJavaParser.ClassDeclarationContext ctx);
}