Added implementation for a visitor

This commit is contained in:
Marvin Kaiser
2019-10-28 16:13:37 +01:00
parent 0a9d702198
commit bc4cc334bd
48 changed files with 740 additions and 790 deletions

View File

@@ -1,4 +1,3 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//target/generated-sources/antlr4=UTF-8
encoding/<project>=UTF-8

View File

@@ -9,6 +9,8 @@
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<antlr4.visitor>true</antlr4.visitor>
<antlr4.listener>false</antlr4.listener>
</properties>
<dependencies>
<dependency>

View File

@@ -0,0 +1,227 @@
package de.hsrm.compiler.Klang;
import org.antlr.v4.runtime.misc.NotNull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class EvalVisitor extends KlangBaseVisitor<Value> {
// used to compare floating point numbers
public static final double SMALL_VALUE = 0.00000000001;
// store variables (there's only one global scope!)
private Map<String, Value> memory = new HashMap<String, Value>();
// assignment/id overrides
@Override
public Value visitAssignment(KlangParser.AssignmentContext ctx) {
String id = ctx.ID().getText();
Value value = this.visit(ctx.expr());
return memory.put(id, value);
}
@Override
public Value visitIdAtom(KlangParser.IdAtomContext ctx) {
String id = ctx.getText();
Value value = memory.get(id);
if(value == null) {
throw new RuntimeException("no such variable: " + id);
}
return value;
}
// atom overrides
@Override
public Value visitStringAtom(KlangParser.StringAtomContext ctx) {
String str = ctx.getText();
// strip quotes
str = str.substring(1, str.length() - 1).replace("\"\"", "\"");
return new Value(str);
}
@Override
public Value visitNumberAtom(KlangParser.NumberAtomContext ctx) {
return new Value(Double.valueOf(ctx.getText()));
}
@Override
public Value visitBooleanAtom(KlangParser.BooleanAtomContext ctx) {
return new Value(Boolean.valueOf(ctx.getText()));
}
@Override
public Value visitNilAtom(KlangParser.NilAtomContext ctx) {
return new Value(null);
}
// expr overrides
@Override
public Value visitParExpr(KlangParser.ParExprContext ctx) {
return this.visit(ctx.expr());
}
@Override
public Value visitPowExpr(KlangParser.PowExprContext ctx) {
Value left = this.visit(ctx.expr(0));
Value right = this.visit(ctx.expr(1));
return new Value(Math.pow(left.asDouble(), right.asDouble()));
}
@Override
public Value visitUnaryMinusExpr(KlangParser.UnaryMinusExprContext ctx) {
Value value = this.visit(ctx.expr());
return new Value(-value.asDouble());
}
@Override
public Value visitNotExpr(KlangParser.NotExprContext ctx) {
Value value = this.visit(ctx.expr());
return new Value(!value.asBoolean());
}
@Override
public Value visitMultiplicationExpr(@NotNull KlangParser.MultiplicationExprContext ctx) {
Value left = this.visit(ctx.expr(0));
Value right = this.visit(ctx.expr(1));
switch (ctx.op.getType()) {
case KlangParser.MULT:
return new Value(left.asDouble() * right.asDouble());
case KlangParser.DIV:
return new Value(left.asDouble() / right.asDouble());
case KlangParser.MOD:
return new Value(left.asDouble() % right.asDouble());
default:
throw new RuntimeException("unknown operator: " + KlangParser.tokenNames[ctx.op.getType()]);
}
}
@Override
public Value visitAdditiveExpr(@NotNull KlangParser.AdditiveExprContext ctx) {
Value left = this.visit(ctx.expr(0));
Value right = this.visit(ctx.expr(1));
switch (ctx.op.getType()) {
case KlangParser.PLUS:
return left.isDouble() && right.isDouble() ?
new Value(left.asDouble() + right.asDouble()) :
new Value(left.asString() + right.asString());
case KlangParser.MINUS:
return new Value(left.asDouble() - right.asDouble());
default:
throw new RuntimeException("unknown operator: " + KlangParser.tokenNames[ctx.op.getType()]);
}
}
@Override
public Value visitRelationalExpr(@NotNull KlangParser.RelationalExprContext ctx) {
Value left = this.visit(ctx.expr(0));
Value right = this.visit(ctx.expr(1));
switch (ctx.op.getType()) {
case KlangParser.LT:
return new Value(left.asDouble() < right.asDouble());
case KlangParser.LTEQ:
return new Value(left.asDouble() <= right.asDouble());
case KlangParser.GT:
return new Value(left.asDouble() > right.asDouble());
case KlangParser.GTEQ:
return new Value(left.asDouble() >= right.asDouble());
default:
throw new RuntimeException("unknown operator: " + KlangParser.tokenNames[ctx.op.getType()]);
}
}
@Override
public Value visitEqualityExpr(@NotNull KlangParser.EqualityExprContext ctx) {
Value left = this.visit(ctx.expr(0));
Value right = this.visit(ctx.expr(1));
switch (ctx.op.getType()) {
case KlangParser.EQ:
return left.isDouble() && right.isDouble() ?
new Value(Math.abs(left.asDouble() - right.asDouble()) < SMALL_VALUE) :
new Value(left.equals(right));
case KlangParser.NEQ:
return left.isDouble() && right.isDouble() ?
new Value(Math.abs(left.asDouble() - right.asDouble()) >= SMALL_VALUE) :
new Value(!left.equals(right));
default:
throw new RuntimeException("unknown operator: " + KlangParser.tokenNames[ctx.op.getType()]);
}
}
@Override
public Value visitAndExpr(KlangParser.AndExprContext ctx) {
Value left = this.visit(ctx.expr(0));
Value right = this.visit(ctx.expr(1));
return new Value(left.asBoolean() && right.asBoolean());
}
@Override
public Value visitOrExpr(KlangParser.OrExprContext ctx) {
Value left = this.visit(ctx.expr(0));
Value right = this.visit(ctx.expr(1));
return new Value(left.asBoolean() || right.asBoolean());
}
// log override
@Override
public Value visitLog(KlangParser.LogContext ctx) {
Value value = this.visit(ctx.expr());
System.out.println(value);
return value;
}
// if override
@Override
public Value visitIf_stat(KlangParser.If_statContext ctx) {
List<KlangParser.Condition_blockContext> conditions = ctx.condition_block();
boolean evaluatedBlock = false;
for(KlangParser.Condition_blockContext condition : conditions) {
Value evaluated = this.visit(condition.expr());
if(evaluated.asBoolean()) {
evaluatedBlock = true;
// evaluate this block whose expr==true
this.visit(condition.stat_block());
break;
}
}
if(!evaluatedBlock && ctx.stat_block() != null) {
// evaluate the else-stat_block (if present == not null)
this.visit(ctx.stat_block());
}
return Value.VOID;
}
// while override
@Override
public Value visitWhile_stat(KlangParser.While_statContext ctx) {
Value value = this.visit(ctx.expr());
while(value.asBoolean()) {
// evaluate the code block
this.visit(ctx.stat_block());
// evaluate the expression
value = this.visit(ctx.expr());
}
return Value.VOID;
}
}

View File

@@ -19,6 +19,7 @@ public class Klang {
KlangParser parser = new KlangParser(tokens);
ParseTree tree = parser.parse(); // begin parsing at init rule
System.out.println(tree.toStringTree(parser)); // print LISP-style tree
EvalVisitor visitor = new EvalVisitor();
visitor.visit(tree);
}
}

View File

@@ -0,0 +1,59 @@
package de.hsrm.compiler.Klang;
public class Value {
public static Value VOID = new Value(new Object());
final Object value;
public Value(Object value) {
this.value = value;
}
public Boolean asBoolean() {
return (Boolean)value;
}
public Double asDouble() {
return (Double)value;
}
public String asString() {
return String.valueOf(value);
}
public boolean isDouble() {
return value instanceof Double;
}
@Override
public int hashCode() {
if(value == null) {
return 0;
}
return this.value.hashCode();
}
@Override
public boolean equals(Object o) {
if(value == o) {
return true;
}
if(value == null || o == null || o.getClass() != value.getClass()) {
return false;
}
Value that = (Value)o;
return this.value.equals(that.value);
}
@Override
public String toString() {
return String.valueOf(value);
}
}

Binary file not shown.

View File

@@ -1,340 +0,0 @@
// Generated from de/hsrm/compiler/Klang/Klang.g4 by ANTLR 4.5
package de.hsrm.compiler.Klang;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
/**
* This class provides an empty implementation of {@link KlangListener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
public class KlangBaseListener implements KlangListener {
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterParse(KlangParser.ParseContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitParse(KlangParser.ParseContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterBlock(KlangParser.BlockContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitBlock(KlangParser.BlockContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterStat(KlangParser.StatContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitStat(KlangParser.StatContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterAssignment(KlangParser.AssignmentContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitAssignment(KlangParser.AssignmentContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterIf_stat(KlangParser.If_statContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitIf_stat(KlangParser.If_statContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterCondition_block(KlangParser.Condition_blockContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitCondition_block(KlangParser.Condition_blockContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterStat_block(KlangParser.Stat_blockContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitStat_block(KlangParser.Stat_blockContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterWhile_stat(KlangParser.While_statContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitWhile_stat(KlangParser.While_statContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterLog(KlangParser.LogContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitLog(KlangParser.LogContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterNotExpr(KlangParser.NotExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitNotExpr(KlangParser.NotExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterUnaryMinusExpr(KlangParser.UnaryMinusExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitUnaryMinusExpr(KlangParser.UnaryMinusExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterMultiplicationExpr(KlangParser.MultiplicationExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitMultiplicationExpr(KlangParser.MultiplicationExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterAtomExpr(KlangParser.AtomExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitAtomExpr(KlangParser.AtomExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterOrExpr(KlangParser.OrExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitOrExpr(KlangParser.OrExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterAdditiveExpr(KlangParser.AdditiveExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitAdditiveExpr(KlangParser.AdditiveExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterPowExpr(KlangParser.PowExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitPowExpr(KlangParser.PowExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterRelationalExpr(KlangParser.RelationalExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitRelationalExpr(KlangParser.RelationalExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterEqualityExpr(KlangParser.EqualityExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitEqualityExpr(KlangParser.EqualityExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterAndExpr(KlangParser.AndExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitAndExpr(KlangParser.AndExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterParExpr(KlangParser.ParExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitParExpr(KlangParser.ParExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterNumberAtom(KlangParser.NumberAtomContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitNumberAtom(KlangParser.NumberAtomContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterBooleanAtom(KlangParser.BooleanAtomContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitBooleanAtom(KlangParser.BooleanAtomContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterIdAtom(KlangParser.IdAtomContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitIdAtom(KlangParser.IdAtomContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterStringAtom(KlangParser.StringAtomContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitStringAtom(KlangParser.StringAtomContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterNilAtom(KlangParser.NilAtomContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitNilAtom(KlangParser.NilAtomContext 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,190 @@
// Generated from de/hsrm/compiler/Klang/Klang.g4 by ANTLR 4.5
package de.hsrm.compiler.Klang;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
/**
* This class provides an empty implementation of {@link KlangVisitor},
* 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.
*/
public class KlangBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements KlangVisitor<T> {
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitParse(KlangParser.ParseContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitBlock(KlangParser.BlockContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitStat(KlangParser.StatContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitAssignment(KlangParser.AssignmentContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitIf_stat(KlangParser.If_statContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitCondition_block(KlangParser.Condition_blockContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitStat_block(KlangParser.Stat_blockContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitWhile_stat(KlangParser.While_statContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitLog(KlangParser.LogContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitNotExpr(KlangParser.NotExprContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitUnaryMinusExpr(KlangParser.UnaryMinusExprContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitMultiplicationExpr(KlangParser.MultiplicationExprContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitAtomExpr(KlangParser.AtomExprContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitOrExpr(KlangParser.OrExprContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitAdditiveExpr(KlangParser.AdditiveExprContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitPowExpr(KlangParser.PowExprContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitRelationalExpr(KlangParser.RelationalExprContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitEqualityExpr(KlangParser.EqualityExprContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitAndExpr(KlangParser.AndExprContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitParExpr(KlangParser.ParExprContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitNumberAtom(KlangParser.NumberAtomContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitBooleanAtom(KlangParser.BooleanAtomContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitIdAtom(KlangParser.IdAtomContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitStringAtom(KlangParser.StringAtomContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitNilAtom(KlangParser.NilAtomContext ctx) { return visitChildren(ctx); }
}

View File

@@ -1,293 +0,0 @@
// Generated from de/hsrm/compiler/Klang/Klang.g4 by ANTLR 4.5
package de.hsrm.compiler.Klang;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.ParseTreeListener;
/**
* This interface defines a complete listener for a parse tree produced by
* {@link KlangParser}.
*/
public interface KlangListener extends ParseTreeListener {
/**
* Enter a parse tree produced by {@link KlangParser#parse}.
* @param ctx the parse tree
*/
void enterParse(KlangParser.ParseContext ctx);
/**
* Exit a parse tree produced by {@link KlangParser#parse}.
* @param ctx the parse tree
*/
void exitParse(KlangParser.ParseContext ctx);
/**
* Enter a parse tree produced by {@link KlangParser#block}.
* @param ctx the parse tree
*/
void enterBlock(KlangParser.BlockContext ctx);
/**
* Exit a parse tree produced by {@link KlangParser#block}.
* @param ctx the parse tree
*/
void exitBlock(KlangParser.BlockContext ctx);
/**
* Enter a parse tree produced by {@link KlangParser#stat}.
* @param ctx the parse tree
*/
void enterStat(KlangParser.StatContext ctx);
/**
* Exit a parse tree produced by {@link KlangParser#stat}.
* @param ctx the parse tree
*/
void exitStat(KlangParser.StatContext ctx);
/**
* Enter a parse tree produced by {@link KlangParser#assignment}.
* @param ctx the parse tree
*/
void enterAssignment(KlangParser.AssignmentContext ctx);
/**
* Exit a parse tree produced by {@link KlangParser#assignment}.
* @param ctx the parse tree
*/
void exitAssignment(KlangParser.AssignmentContext ctx);
/**
* Enter a parse tree produced by {@link KlangParser#if_stat}.
* @param ctx the parse tree
*/
void enterIf_stat(KlangParser.If_statContext ctx);
/**
* Exit a parse tree produced by {@link KlangParser#if_stat}.
* @param ctx the parse tree
*/
void exitIf_stat(KlangParser.If_statContext ctx);
/**
* Enter a parse tree produced by {@link KlangParser#condition_block}.
* @param ctx the parse tree
*/
void enterCondition_block(KlangParser.Condition_blockContext ctx);
/**
* Exit a parse tree produced by {@link KlangParser#condition_block}.
* @param ctx the parse tree
*/
void exitCondition_block(KlangParser.Condition_blockContext ctx);
/**
* Enter a parse tree produced by {@link KlangParser#stat_block}.
* @param ctx the parse tree
*/
void enterStat_block(KlangParser.Stat_blockContext ctx);
/**
* Exit a parse tree produced by {@link KlangParser#stat_block}.
* @param ctx the parse tree
*/
void exitStat_block(KlangParser.Stat_blockContext ctx);
/**
* Enter a parse tree produced by {@link KlangParser#while_stat}.
* @param ctx the parse tree
*/
void enterWhile_stat(KlangParser.While_statContext ctx);
/**
* Exit a parse tree produced by {@link KlangParser#while_stat}.
* @param ctx the parse tree
*/
void exitWhile_stat(KlangParser.While_statContext ctx);
/**
* Enter a parse tree produced by {@link KlangParser#log}.
* @param ctx the parse tree
*/
void enterLog(KlangParser.LogContext ctx);
/**
* Exit a parse tree produced by {@link KlangParser#log}.
* @param ctx the parse tree
*/
void exitLog(KlangParser.LogContext ctx);
/**
* Enter a parse tree produced by the {@code notExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void enterNotExpr(KlangParser.NotExprContext ctx);
/**
* Exit a parse tree produced by the {@code notExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void exitNotExpr(KlangParser.NotExprContext ctx);
/**
* Enter a parse tree produced by the {@code unaryMinusExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void enterUnaryMinusExpr(KlangParser.UnaryMinusExprContext ctx);
/**
* Exit a parse tree produced by the {@code unaryMinusExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void exitUnaryMinusExpr(KlangParser.UnaryMinusExprContext ctx);
/**
* Enter a parse tree produced by the {@code multiplicationExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void enterMultiplicationExpr(KlangParser.MultiplicationExprContext ctx);
/**
* Exit a parse tree produced by the {@code multiplicationExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void exitMultiplicationExpr(KlangParser.MultiplicationExprContext ctx);
/**
* Enter a parse tree produced by the {@code atomExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void enterAtomExpr(KlangParser.AtomExprContext ctx);
/**
* Exit a parse tree produced by the {@code atomExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void exitAtomExpr(KlangParser.AtomExprContext ctx);
/**
* Enter a parse tree produced by the {@code orExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void enterOrExpr(KlangParser.OrExprContext ctx);
/**
* Exit a parse tree produced by the {@code orExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void exitOrExpr(KlangParser.OrExprContext ctx);
/**
* Enter a parse tree produced by the {@code additiveExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void enterAdditiveExpr(KlangParser.AdditiveExprContext ctx);
/**
* Exit a parse tree produced by the {@code additiveExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void exitAdditiveExpr(KlangParser.AdditiveExprContext ctx);
/**
* Enter a parse tree produced by the {@code powExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void enterPowExpr(KlangParser.PowExprContext ctx);
/**
* Exit a parse tree produced by the {@code powExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void exitPowExpr(KlangParser.PowExprContext ctx);
/**
* Enter a parse tree produced by the {@code relationalExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void enterRelationalExpr(KlangParser.RelationalExprContext ctx);
/**
* Exit a parse tree produced by the {@code relationalExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void exitRelationalExpr(KlangParser.RelationalExprContext ctx);
/**
* Enter a parse tree produced by the {@code equalityExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void enterEqualityExpr(KlangParser.EqualityExprContext ctx);
/**
* Exit a parse tree produced by the {@code equalityExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void exitEqualityExpr(KlangParser.EqualityExprContext ctx);
/**
* Enter a parse tree produced by the {@code andExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void enterAndExpr(KlangParser.AndExprContext ctx);
/**
* Exit a parse tree produced by the {@code andExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
*/
void exitAndExpr(KlangParser.AndExprContext ctx);
/**
* Enter a parse tree produced by the {@code parExpr}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
*/
void enterParExpr(KlangParser.ParExprContext ctx);
/**
* Exit a parse tree produced by the {@code parExpr}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
*/
void exitParExpr(KlangParser.ParExprContext ctx);
/**
* Enter a parse tree produced by the {@code numberAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
*/
void enterNumberAtom(KlangParser.NumberAtomContext ctx);
/**
* Exit a parse tree produced by the {@code numberAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
*/
void exitNumberAtom(KlangParser.NumberAtomContext ctx);
/**
* Enter a parse tree produced by the {@code booleanAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
*/
void enterBooleanAtom(KlangParser.BooleanAtomContext ctx);
/**
* Exit a parse tree produced by the {@code booleanAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
*/
void exitBooleanAtom(KlangParser.BooleanAtomContext ctx);
/**
* Enter a parse tree produced by the {@code idAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
*/
void enterIdAtom(KlangParser.IdAtomContext ctx);
/**
* Exit a parse tree produced by the {@code idAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
*/
void exitIdAtom(KlangParser.IdAtomContext ctx);
/**
* Enter a parse tree produced by the {@code stringAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
*/
void enterStringAtom(KlangParser.StringAtomContext ctx);
/**
* Exit a parse tree produced by the {@code stringAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
*/
void exitStringAtom(KlangParser.StringAtomContext ctx);
/**
* Enter a parse tree produced by the {@code nilAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
*/
void enterNilAtom(KlangParser.NilAtomContext ctx);
/**
* Exit a parse tree produced by the {@code nilAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
*/
void exitNilAtom(KlangParser.NilAtomContext ctx);
}

View File

@@ -102,12 +102,9 @@ public class KlangParser extends Parser {
}
@Override public int getRuleIndex() { return RULE_parse; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterParse(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitParse(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitParse(this);
else return visitor.visitChildren(this);
}
}
@@ -146,12 +143,9 @@ public class KlangParser extends Parser {
}
@Override public int getRuleIndex() { return RULE_block; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterBlock(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitBlock(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitBlock(this);
else return visitor.visitChildren(this);
}
}
@@ -209,12 +203,9 @@ public class KlangParser extends Parser {
}
@Override public int getRuleIndex() { return RULE_stat; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterStat(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitStat(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitStat(this);
else return visitor.visitChildren(this);
}
}
@@ -287,12 +278,9 @@ public class KlangParser extends Parser {
}
@Override public int getRuleIndex() { return RULE_assignment; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterAssignment(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitAssignment(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitAssignment(this);
else return visitor.visitChildren(this);
}
}
@@ -346,12 +334,9 @@ public class KlangParser extends Parser {
}
@Override public int getRuleIndex() { return RULE_if_stat; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterIf_stat(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitIf_stat(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitIf_stat(this);
else return visitor.visitChildren(this);
}
}
@@ -422,12 +407,9 @@ public class KlangParser extends Parser {
}
@Override public int getRuleIndex() { return RULE_condition_block; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterCondition_block(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitCondition_block(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitCondition_block(this);
else return visitor.visitChildren(this);
}
}
@@ -468,12 +450,9 @@ public class KlangParser extends Parser {
}
@Override public int getRuleIndex() { return RULE_stat_block; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterStat_block(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitStat_block(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitStat_block(this);
else return visitor.visitChildren(this);
}
}
@@ -533,12 +512,9 @@ public class KlangParser extends Parser {
}
@Override public int getRuleIndex() { return RULE_while_stat; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterWhile_stat(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitWhile_stat(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitWhile_stat(this);
else return visitor.visitChildren(this);
}
}
@@ -578,12 +554,9 @@ public class KlangParser extends Parser {
}
@Override public int getRuleIndex() { return RULE_log; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterLog(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitLog(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitLog(this);
else return visitor.visitChildren(this);
}
}
@@ -630,12 +603,9 @@ public class KlangParser extends Parser {
}
public NotExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterNotExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitNotExpr(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitNotExpr(this);
else return visitor.visitChildren(this);
}
}
public static class UnaryMinusExprContext extends ExprContext {
@@ -645,12 +615,9 @@ public class KlangParser extends Parser {
}
public UnaryMinusExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterUnaryMinusExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitUnaryMinusExpr(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitUnaryMinusExpr(this);
else return visitor.visitChildren(this);
}
}
public static class MultiplicationExprContext extends ExprContext {
@@ -666,12 +633,9 @@ public class KlangParser extends Parser {
public TerminalNode MOD() { return getToken(KlangParser.MOD, 0); }
public MultiplicationExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterMultiplicationExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitMultiplicationExpr(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitMultiplicationExpr(this);
else return visitor.visitChildren(this);
}
}
public static class AtomExprContext extends ExprContext {
@@ -680,12 +644,9 @@ public class KlangParser extends Parser {
}
public AtomExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterAtomExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitAtomExpr(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitAtomExpr(this);
else return visitor.visitChildren(this);
}
}
public static class OrExprContext extends ExprContext {
@@ -698,12 +659,9 @@ public class KlangParser extends Parser {
public TerminalNode OR() { return getToken(KlangParser.OR, 0); }
public OrExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterOrExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitOrExpr(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitOrExpr(this);
else return visitor.visitChildren(this);
}
}
public static class AdditiveExprContext extends ExprContext {
@@ -718,12 +676,9 @@ public class KlangParser extends Parser {
public TerminalNode MINUS() { return getToken(KlangParser.MINUS, 0); }
public AdditiveExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterAdditiveExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitAdditiveExpr(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitAdditiveExpr(this);
else return visitor.visitChildren(this);
}
}
public static class PowExprContext extends ExprContext {
@@ -736,12 +691,9 @@ public class KlangParser extends Parser {
public TerminalNode POW() { return getToken(KlangParser.POW, 0); }
public PowExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterPowExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitPowExpr(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitPowExpr(this);
else return visitor.visitChildren(this);
}
}
public static class RelationalExprContext extends ExprContext {
@@ -758,12 +710,9 @@ public class KlangParser extends Parser {
public TerminalNode GT() { return getToken(KlangParser.GT, 0); }
public RelationalExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterRelationalExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitRelationalExpr(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitRelationalExpr(this);
else return visitor.visitChildren(this);
}
}
public static class EqualityExprContext extends ExprContext {
@@ -778,12 +727,9 @@ public class KlangParser extends Parser {
public TerminalNode NEQ() { return getToken(KlangParser.NEQ, 0); }
public EqualityExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterEqualityExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitEqualityExpr(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitEqualityExpr(this);
else return visitor.visitChildren(this);
}
}
public static class AndExprContext extends ExprContext {
@@ -796,12 +742,9 @@ public class KlangParser extends Parser {
public TerminalNode AND() { return getToken(KlangParser.AND, 0); }
public AndExprContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterAndExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitAndExpr(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitAndExpr(this);
else return visitor.visitChildren(this);
}
}
@@ -1023,12 +966,9 @@ public class KlangParser extends Parser {
public TerminalNode CPAR() { return getToken(KlangParser.CPAR, 0); }
public ParExprContext(AtomContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterParExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitParExpr(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitParExpr(this);
else return visitor.visitChildren(this);
}
}
public static class BooleanAtomContext extends AtomContext {
@@ -1036,48 +976,36 @@ public class KlangParser extends Parser {
public TerminalNode FALSE() { return getToken(KlangParser.FALSE, 0); }
public BooleanAtomContext(AtomContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterBooleanAtom(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitBooleanAtom(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitBooleanAtom(this);
else return visitor.visitChildren(this);
}
}
public static class IdAtomContext extends AtomContext {
public TerminalNode ID() { return getToken(KlangParser.ID, 0); }
public IdAtomContext(AtomContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterIdAtom(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitIdAtom(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitIdAtom(this);
else return visitor.visitChildren(this);
}
}
public static class StringAtomContext extends AtomContext {
public TerminalNode STRING() { return getToken(KlangParser.STRING, 0); }
public StringAtomContext(AtomContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterStringAtom(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitStringAtom(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitStringAtom(this);
else return visitor.visitChildren(this);
}
}
public static class NilAtomContext extends AtomContext {
public TerminalNode NIL() { return getToken(KlangParser.NIL, 0); }
public NilAtomContext(AtomContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterNilAtom(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitNilAtom(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitNilAtom(this);
else return visitor.visitChildren(this);
}
}
public static class NumberAtomContext extends AtomContext {
@@ -1085,12 +1013,9 @@ public class KlangParser extends Parser {
public TerminalNode FLOAT() { return getToken(KlangParser.FLOAT, 0); }
public NumberAtomContext(AtomContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).enterNumberAtom(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof KlangListener ) ((KlangListener)listener).exitNumberAtom(this);
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof KlangVisitor ) return ((KlangVisitor<? extends T>)visitor).visitNumberAtom(this);
else return visitor.visitChildren(this);
}
}

View File

@@ -0,0 +1,180 @@
// Generated from de/hsrm/compiler/Klang/Klang.g4 by ANTLR 4.5
package de.hsrm.compiler.Klang;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
/**
* This interface defines a complete generic visitor for a parse tree produced
* by {@link KlangParser}.
*
* @param <T> The return type of the visit operation. Use {@link Void} for
* operations with no return type.
*/
public interface KlangVisitor<T> extends ParseTreeVisitor<T> {
/**
* Visit a parse tree produced by {@link KlangParser#parse}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitParse(KlangParser.ParseContext ctx);
/**
* Visit a parse tree produced by {@link KlangParser#block}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitBlock(KlangParser.BlockContext ctx);
/**
* Visit a parse tree produced by {@link KlangParser#stat}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitStat(KlangParser.StatContext ctx);
/**
* Visit a parse tree produced by {@link KlangParser#assignment}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitAssignment(KlangParser.AssignmentContext ctx);
/**
* Visit a parse tree produced by {@link KlangParser#if_stat}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitIf_stat(KlangParser.If_statContext ctx);
/**
* Visit a parse tree produced by {@link KlangParser#condition_block}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitCondition_block(KlangParser.Condition_blockContext ctx);
/**
* Visit a parse tree produced by {@link KlangParser#stat_block}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitStat_block(KlangParser.Stat_blockContext ctx);
/**
* Visit a parse tree produced by {@link KlangParser#while_stat}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitWhile_stat(KlangParser.While_statContext ctx);
/**
* Visit a parse tree produced by {@link KlangParser#log}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitLog(KlangParser.LogContext ctx);
/**
* Visit a parse tree produced by the {@code notExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitNotExpr(KlangParser.NotExprContext ctx);
/**
* Visit a parse tree produced by the {@code unaryMinusExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitUnaryMinusExpr(KlangParser.UnaryMinusExprContext ctx);
/**
* Visit a parse tree produced by the {@code multiplicationExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitMultiplicationExpr(KlangParser.MultiplicationExprContext ctx);
/**
* Visit a parse tree produced by the {@code atomExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitAtomExpr(KlangParser.AtomExprContext ctx);
/**
* Visit a parse tree produced by the {@code orExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitOrExpr(KlangParser.OrExprContext ctx);
/**
* Visit a parse tree produced by the {@code additiveExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitAdditiveExpr(KlangParser.AdditiveExprContext ctx);
/**
* Visit a parse tree produced by the {@code powExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitPowExpr(KlangParser.PowExprContext ctx);
/**
* Visit a parse tree produced by the {@code relationalExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitRelationalExpr(KlangParser.RelationalExprContext ctx);
/**
* Visit a parse tree produced by the {@code equalityExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitEqualityExpr(KlangParser.EqualityExprContext ctx);
/**
* Visit a parse tree produced by the {@code andExpr}
* labeled alternative in {@link KlangParser#expr}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitAndExpr(KlangParser.AndExprContext ctx);
/**
* Visit a parse tree produced by the {@code parExpr}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitParExpr(KlangParser.ParExprContext ctx);
/**
* Visit a parse tree produced by the {@code numberAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitNumberAtom(KlangParser.NumberAtomContext ctx);
/**
* Visit a parse tree produced by the {@code booleanAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitBooleanAtom(KlangParser.BooleanAtomContext ctx);
/**
* Visit a parse tree produced by the {@code idAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitIdAtom(KlangParser.IdAtomContext ctx);
/**
* Visit a parse tree produced by the {@code stringAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitStringAtom(KlangParser.StringAtomContext ctx);
/**
* Visit a parse tree produced by the {@code nilAtom}
* labeled alternative in {@link KlangParser#atom}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitNilAtom(KlangParser.NilAtomContext ctx);
}

Binary file not shown.

View File

@@ -1,5 +1,5 @@
/home/marvin/Documents/university/compiler/antlr_test/klang/klang/src/main/java/de/hsrm/compiler/Klang/Klang.java
/home/marvin/Documents/university/compiler/antlr_test/klang/klang/target/generated-sources/antlr4/de/hsrm/compiler/Klang/KlangParser.java
/home/marvin/Documents/university/compiler/antlr_test/klang/klang/target/generated-sources/antlr4/de/hsrm/compiler/Klang/KlangBaseListener.java
/home/marvin/Documents/university/compiler/antlr_test/klang/klang/target/generated-sources/antlr4/de/hsrm/compiler/Klang/KlangLexer.java
/home/marvin/Documents/university/compiler/antlr_test/klang/klang/target/generated-sources/antlr4/de/hsrm/compiler/Klang/KlangListener.java
/home/marvin/Documents/university/compiler/klang/target/generated-sources/antlr4/de/hsrm/compiler/Klang/KlangLexer.java
/home/marvin/Documents/university/compiler/klang/target/generated-sources/antlr4/de/hsrm/compiler/Klang/KlangBaseVisitor.java
/home/marvin/Documents/university/compiler/klang/target/generated-sources/antlr4/de/hsrm/compiler/Klang/KlangParser.java
/home/marvin/Documents/university/compiler/klang/src/main/java/de/hsrm/compiler/Klang/Klang.java
/home/marvin/Documents/university/compiler/klang/target/generated-sources/antlr4/de/hsrm/compiler/Klang/KlangVisitor.java