Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
968189a100 | ||
|
d6b4b41d3c | ||
|
ae22e8ab82 | ||
|
30596e0c52 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/src/main/java/de/dhbw/horb/antlr/
|
||||
.idea
|
10
.idea/.gitignore
generated
vendored
Normal file
10
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# GitHub Copilot persisted chat sessions
|
||||
/copilot/chatSessions
|
13
.idea/compiler.xml
generated
Normal file
13
.idea/compiler.xml
generated
Normal 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="decaf" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
BIN
.idea/copilot/chatSessions/00000000000.xd
generated
Normal file
BIN
.idea/copilot/chatSessions/00000000000.xd
generated
Normal file
Binary file not shown.
BIN
.idea/copilot/chatSessions/blobs/version
generated
Normal file
BIN
.idea/copilot/chatSessions/blobs/version
generated
Normal file
Binary file not shown.
47
.idea/copilot/chatSessions/xd.lck
generated
Normal file
47
.idea/copilot/chatSessions/xd.lck
generated
Normal file
@ -0,0 +1,47 @@
|
||||
Private property of Exodus: 41264@Simon-Lenovo-Ubuntu
|
||||
|
||||
jetbrains.exodus.io.LockingManager.lock(LockingManager.kt:88)
|
||||
jetbrains.exodus.io.LockingManager.lock(LockingManager.kt:39)
|
||||
jetbrains.exodus.io.FileDataWriter.lock(FileDataWriter.kt:70)
|
||||
jetbrains.exodus.log.Log.tryLock(Log.kt:804)
|
||||
jetbrains.exodus.log.Log.<init>(Log.kt:117)
|
||||
jetbrains.exodus.env.Environments.newLogInstance(Environments.kt:117)
|
||||
jetbrains.exodus.env.Environments.newLogInstance(Environments.kt:81)
|
||||
jetbrains.exodus.env.Environments.newLogInstance(Environments.kt:77)
|
||||
jetbrains.exodus.env.Environments$newInstance$4.invoke(Environments.kt:46)
|
||||
jetbrains.exodus.env.Environments$newInstance$4.invoke(Environments.kt:46)
|
||||
jetbrains.exodus.env.Environments.prepare(Environments.kt:120)
|
||||
jetbrains.exodus.env.Environments.newInstance(Environments.kt:46)
|
||||
kotlinx.dnq.store.container.EntityStoreHelperKt.createTransientEntityStore(EntityStoreHelper.kt:40)
|
||||
kotlinx.dnq.store.container.EntityStoreHelperKt.createTransientEntityStore(EntityStoreHelper.kt:31)
|
||||
kotlinx.dnq.store.container.EntityStoreHelperKt.createTransientEntityStore$default(EntityStoreHelper.kt:30)
|
||||
com.github.copilot.chat.session.persistence.xodus.XdChatSessionPersistenceService.initStore(XdChatSessionPersistenceService.kt:115)
|
||||
com.github.copilot.chat.session.persistence.xodus.XdChatSessionPersistenceService.<init>(XdChatSessionPersistenceService.kt:22)
|
||||
com.github.copilot.chat.session.persistence.xodus.XdChatSessionPersistenceService.<init>(XdChatSessionPersistenceService.kt:15)
|
||||
com.github.copilot.chat.session.persistence.ChatSessionPersistenceServiceKt.ChatSessionPersistenceService(ChatSessionPersistenceService.kt:43)
|
||||
com.github.copilot.chat.session.persistence.ChatSessionPersistenceServiceKt.chatSessionsPersistenceService(ChatSessionPersistenceService.kt:53)
|
||||
com.github.copilot.chat.session.ChatSessionManager.<init>(ChatSessionManager.kt:45)
|
||||
com.github.copilot.chat.session.ChatSessionManager.<init>(ChatSessionManager.kt:25)
|
||||
com.github.copilot.chat.window.CopilotChatToolWindow.onCopilotReady(CopilotChatToolWindow.kt:133)
|
||||
com.github.copilot.chat.window.CopilotChatToolWindow.access$onCopilotReady(CopilotChatToolWindow.kt:40)
|
||||
com.github.copilot.chat.window.CopilotChatToolWindow$initCopilotStatusListener$1.invoke(CopilotChatToolWindow.kt:118)
|
||||
com.github.copilot.chat.window.CopilotChatToolWindow$initCopilotStatusListener$1.invoke(CopilotChatToolWindow.kt:115)
|
||||
com.github.copilot.status.CopilotAuthStatusKt.subscribeToCopilotAuthStatus$lambda$0(CopilotAuthStatus.kt:44)
|
||||
com.intellij.util.messages.impl.MessageBusImplKt.invokeMethod(MessageBusImpl.kt:700)
|
||||
com.intellij.util.messages.impl.MessageBusImplKt.invokeListener(MessageBusImpl.kt:664)
|
||||
com.intellij.util.messages.impl.MessageBusImplKt.deliverMessage(MessageBusImpl.kt:423)
|
||||
com.intellij.util.messages.impl.MessageBusImplKt.pumpWaiting(MessageBusImpl.kt:402)
|
||||
com.intellij.util.messages.impl.MessageBusImplKt.access$pumpWaiting(MessageBusImpl.kt:1)
|
||||
com.intellij.util.messages.impl.MessagePublisher.invoke(MessageBusImpl.kt:461)
|
||||
jdk.proxy6/jdk.proxy6.$Proxy166.onCopilotStatus(Unknown Source)
|
||||
com.github.copilot.status.CopilotStatusService.notifyApplication(CopilotStatusService.java:76)
|
||||
com.github.copilot.status.CopilotStatusService.notifyApplication(CopilotStatusService.java:64)
|
||||
com.github.copilot.github.GitHubAuthStartupActivity.handleAuthNotifications(GitHubAuthStartupActivity.java:54)
|
||||
com.github.copilot.github.GitHubAuthStartupActivity.execute(GitHubAuthStartupActivity.java:35)
|
||||
com.intellij.ide.startup.impl.StartupManagerImplKt$launchActivity$1.invokeSuspend(StartupManagerImpl.kt:482)
|
||||
kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
|
||||
kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
|
||||
kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
|
||||
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
|
||||
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
|
||||
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
|
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
20
.idea/jarRepositories.xml
generated
Normal file
20
.idea/jarRepositories.xml
generated
Normal 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>
|
28
.idea/misc.xml
generated
Normal file
28
.idea/misc.xml
generated
Normal file
@ -0,0 +1,28 @@
|
||||
<?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/antlr4/de/dhbw/horb/Decaf.g4" />
|
||||
<option name="autoGen" value="true" />
|
||||
<option name="outputDir" value="$PROJECT_DIR$/src/main/java" />
|
||||
<option name="libDir" value="$PROJECT_DIR$/src/main/antlr4/de/dhbw/horb" />
|
||||
<option name="encoding" value="" />
|
||||
<option name="pkg" value="de.dhbw.horb.antlr" />
|
||||
<option name="language" value="" />
|
||||
<option name="generateVisitor" value="true" />
|
||||
</PerGrammarGenerationSettings>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK" />
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
20
pom.xml
20
pom.xml
@ -12,8 +12,8 @@
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>19</maven.compiler.source>
|
||||
<maven.compiler.target>19</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -32,22 +32,6 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin> <!-- ANTLR parser generation -->
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
<version>4.11.1</version>
|
||||
<configuration>
|
||||
<visitor>true</visitor>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>antlr</id>
|
||||
<goals>
|
||||
<goal>antlr4</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
|
@ -1,43 +1,29 @@
|
||||
package de.dhbw.horb;
|
||||
|
||||
|
||||
import de.dhbw.horb.antlr.DecafParser;
|
||||
import de.dhbw.horb.ast.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ASTGenerator {
|
||||
|
||||
public static Program generateAST(DecafParser.ProgramContext parseTree){
|
||||
List<Variable> variables = new ArrayList<>();
|
||||
for(DecafParser.VarContext varCtx : parseTree.var()){
|
||||
variables.add(generateVariable(varCtx));
|
||||
}
|
||||
List<Function> funcs = new ArrayList<>();
|
||||
for(DecafParser.FuncContext fctx : parseTree.func()){
|
||||
funcs.add(generateFunc(fctx));
|
||||
}
|
||||
public static Program generateAST(DecafParser.ProgramContext parseTree) {
|
||||
List<Variable> variables = parseTree.var().stream().map(var -> new Variable(var.id().getText(), Type.mapType(var.type().getText()))).toList();
|
||||
List<Function> funcs = parseTree.func().stream().map(ASTGenerator::generateFunc).toList();
|
||||
return new Program(variables, funcs);
|
||||
}
|
||||
|
||||
public static Variable generateVariable(DecafParser.VarContext ctx) {
|
||||
return new Variable(ctx.id().getText(), getType(ctx.type()));
|
||||
}
|
||||
|
||||
public static Variable generateVariable(DecafParser.ParamContext ctx) {
|
||||
return new Variable(ctx.id().getText(), getType(ctx.type()));
|
||||
}
|
||||
|
||||
public static Function generateFunc(DecafParser.FuncContext ctx) {
|
||||
throw new RuntimeException("TODO");
|
||||
}
|
||||
|
||||
public static Type getType(DecafParser.TypeContext ctx){
|
||||
if(ctx.INT() != null)
|
||||
return Type.INT;
|
||||
if(ctx.BOOL() != null)
|
||||
return Type.BOOL;
|
||||
if(ctx.VOID() != null)
|
||||
return Type.VOID;
|
||||
throw new RuntimeException();
|
||||
Type t = Type.mapType(ctx.type().getText());
|
||||
String id = ctx.id().getText();
|
||||
List<Variable> params = Optional.ofNullable(ctx.params())
|
||||
.map(p -> p.param().stream().map(param -> new Variable(param.getText(), Type.mapType(param.type().getText()))).collect(Collectors.toList()))
|
||||
.orElseGet(ArrayList::new);
|
||||
Block block = new BlockGenerator().visit(ctx.block());
|
||||
return new Function(t, id, params, block);
|
||||
}
|
||||
}
|
||||
|
21
src/main/java/de/dhbw/horb/BlockGenerator.java
Normal file
21
src/main/java/de/dhbw/horb/BlockGenerator.java
Normal file
@ -0,0 +1,21 @@
|
||||
package de.dhbw.horb;
|
||||
|
||||
import de.dhbw.horb.antlr.DecafBaseVisitor;
|
||||
import de.dhbw.horb.antlr.DecafParser;
|
||||
import de.dhbw.horb.ast.Block;
|
||||
import de.dhbw.horb.ast.Statement;
|
||||
import de.dhbw.horb.ast.Type;
|
||||
import de.dhbw.horb.ast.Variable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockGenerator extends DecafBaseVisitor<Block> {
|
||||
|
||||
@Override
|
||||
public Block visitBlock(DecafParser.BlockContext ctx) {
|
||||
List<Variable> vars = ctx.var().stream().map(var -> new Variable(var.id().getText(), Type.mapType(var.type().getText()))).toList();
|
||||
List<Statement> stmts = ctx.stmt().stream().map(stmt -> new StatementGenerator().visit(stmt)).toList();
|
||||
return new Block(vars, stmts);
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
package de.dhbw.horb;
|
||||
|
||||
import de.dhbw.horb.ast.*;
|
||||
import de.dhbw.horb.antlr.DecafLexer;
|
||||
import de.dhbw.horb.antlr.DecafParser;
|
||||
import de.dhbw.horb.ast.Program;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Decaf language Compiler
|
||||
*/
|
||||
|
@ -1,7 +1,13 @@
|
||||
package de.dhbw.horb;
|
||||
|
||||
import de.dhbw.horb.antlr.DecafParser;
|
||||
import de.dhbw.horb.antlr.DecafBaseVisitor;
|
||||
import de.dhbw.horb.ast.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
|
||||
@Override
|
||||
public Expression visitBinaryOperation(DecafParser.BinaryOperationContext ctx) {
|
||||
@ -10,7 +16,7 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
|
||||
|
||||
@Override
|
||||
public Expression visitFunCallExpression(DecafParser.FunCallExpressionContext ctx) {
|
||||
throw new RuntimeException("TODO");
|
||||
return new FunctionCall(ctx.funcCall().id().getText(), Optional.of(ctx.funcCall().args()).map(arg -> arg.expr().stream().map(this::visit).toList()).orElseGet(ArrayList::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -30,25 +36,28 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
|
||||
return generateLocation(ctx.loc());
|
||||
}
|
||||
|
||||
public static Expression generateConstant(DecafParser.LiteralContext ctx){
|
||||
if(ctx.number() != null)
|
||||
public static Expression generateConstant(DecafParser.LiteralContext ctx) {
|
||||
if (ctx.number() != null)
|
||||
return new IntConstant(Integer.valueOf(ctx.number().getText()));
|
||||
if(ctx.boolean_() != null)
|
||||
if (ctx.boolean_() != null)
|
||||
return new BoolConstant(Boolean.valueOf(ctx.boolean_().getText()));
|
||||
throw new RuntimeException();
|
||||
}
|
||||
public static Operator generateOperator(DecafParser.BinaryOpContext ctx){
|
||||
if(ctx.ADD() != null)return Operator.ADD;
|
||||
if(ctx.SUB() != null)return Operator.SUB;
|
||||
if(ctx.MUL() != null)return Operator.MUL;
|
||||
|
||||
public static Operator generateOperator(DecafParser.BinaryOpContext ctx) {
|
||||
if (ctx.ADD() != null) return Operator.ADD;
|
||||
if (ctx.SUB() != null) return Operator.SUB;
|
||||
if (ctx.MUL() != null) return Operator.MUL;
|
||||
throw new RuntimeException();
|
||||
}
|
||||
public static Binary generateBinary(DecafParser.BinaryOperationContext ctx){
|
||||
|
||||
public static Binary generateBinary(DecafParser.BinaryOperationContext ctx) {
|
||||
ExpressionGenerator eGen = new ExpressionGenerator();
|
||||
return new Binary(eGen.visit(ctx.expr().get(0)) // left side
|
||||
, generateOperator(ctx.binaryOp()) //operator
|
||||
, eGen.visit(ctx.expr().get(1))); //right side
|
||||
}
|
||||
|
||||
public static Location generateLocation(DecafParser.LocContext loc) {
|
||||
return new Location(loc.id().getText());
|
||||
}
|
||||
|
@ -1,44 +1,49 @@
|
||||
package de.dhbw.horb;
|
||||
|
||||
import de.dhbw.horb.antlr.DecafBaseVisitor;
|
||||
import de.dhbw.horb.antlr.DecafParser;
|
||||
import de.dhbw.horb.ast.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
|
||||
public class StatementGenerator extends DecafBaseVisitor<Statement> {
|
||||
@Override
|
||||
public Statement visitAssign(DecafParser.AssignContext ctx) {
|
||||
throw new RuntimeException("TODO");
|
||||
return new Assignment(new Location(ctx.loc().getText()), new ExpressionGenerator().visit(ctx.expr()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement visitIf(DecafParser.IfContext ctx) {
|
||||
throw new RuntimeException("TODO");
|
||||
Block elseBlock = new Block(Collections.emptyList(), Collections.emptyList());
|
||||
if (ctx.block().size() > 1)
|
||||
elseBlock = new BlockGenerator().visit(ctx.block(1));
|
||||
return new IfElse(new ExpressionGenerator().visit(ctx.expr()), new BlockGenerator().visit(ctx.block(0)), elseBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement visitWhile(DecafParser.WhileContext ctx) {
|
||||
throw new RuntimeException("TODO");
|
||||
return new While(new ExpressionGenerator().visit(ctx.expr()), new BlockGenerator().visit(ctx.block()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement visitReturn(DecafParser.ReturnContext ctx) {
|
||||
throw new RuntimeException("TODO");
|
||||
return new Return(new ExpressionGenerator().visit(ctx.expr()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement visitReturnVoid(DecafParser.ReturnVoidContext ctx) {
|
||||
throw new RuntimeException("TODO");
|
||||
return new ReturnVoid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement visitBreak(DecafParser.BreakContext ctx) {
|
||||
throw new RuntimeException("TODO");
|
||||
return new Break();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement visitContinue(DecafParser.ContinueContext ctx) {
|
||||
throw new RuntimeException("TODO");
|
||||
return new Continue();
|
||||
}
|
||||
|
||||
}
|
||||
|
78
src/main/java/de/dhbw/horb/antlr/Decaf.interp
Normal file
78
src/main/java/de/dhbw/horb/antlr/Decaf.interp
Normal file
@ -0,0 +1,78 @@
|
||||
token literal names:
|
||||
null
|
||||
';'
|
||||
'def'
|
||||
'('
|
||||
')'
|
||||
','
|
||||
'{'
|
||||
'}'
|
||||
'='
|
||||
'if'
|
||||
'else'
|
||||
'while'
|
||||
'return'
|
||||
'break'
|
||||
'continue'
|
||||
'true'
|
||||
'false'
|
||||
'-'
|
||||
'+'
|
||||
'*'
|
||||
'int'
|
||||
'bool'
|
||||
'void'
|
||||
null
|
||||
null
|
||||
null
|
||||
|
||||
token symbolic names:
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
SUB
|
||||
ADD
|
||||
MUL
|
||||
INT
|
||||
BOOL
|
||||
VOID
|
||||
IDENTIFIER
|
||||
Number
|
||||
WS
|
||||
|
||||
rule names:
|
||||
program
|
||||
var
|
||||
type
|
||||
func
|
||||
params
|
||||
param
|
||||
block
|
||||
stmt
|
||||
expr
|
||||
binaryOp
|
||||
loc
|
||||
funcCall
|
||||
args
|
||||
literal
|
||||
boolean
|
||||
number
|
||||
id
|
||||
|
||||
|
||||
atn:
|
||||
[4, 1, 25, 167, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 1, 0, 1, 0, 5, 0, 37, 8, 0, 10, 0, 12, 0, 40, 9, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 3, 3, 53, 8, 3, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 5, 4, 61, 8, 4, 10, 4, 12, 4, 64, 9, 4, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 5, 6, 71, 8, 6, 10, 6, 12, 6, 74, 9, 6, 1, 6, 5, 6, 77, 8, 6, 10, 6, 12, 6, 80, 9, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 3, 7, 99, 8, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 3, 7, 117, 8, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 3, 8, 127, 8, 8, 1, 8, 1, 8, 1, 8, 1, 8, 5, 8, 133, 8, 8, 10, 8, 12, 8, 136, 9, 8, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 3, 11, 145, 8, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 5, 12, 152, 8, 12, 10, 12, 12, 12, 155, 9, 12, 1, 13, 1, 13, 3, 13, 159, 8, 13, 1, 14, 1, 14, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 0, 1, 16, 17, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 0, 3, 1, 0, 20, 22, 1, 0, 17, 19, 1, 0, 15, 16, 170, 0, 38, 1, 0, 0, 0, 2, 41, 1, 0, 0, 0, 4, 45, 1, 0, 0, 0, 6, 47, 1, 0, 0, 0, 8, 57, 1, 0, 0, 0, 10, 65, 1, 0, 0, 0, 12, 68, 1, 0, 0, 0, 14, 116, 1, 0, 0, 0, 16, 126, 1, 0, 0, 0, 18, 137, 1, 0, 0, 0, 20, 139, 1, 0, 0, 0, 22, 141, 1, 0, 0, 0, 24, 148, 1, 0, 0, 0, 26, 158, 1, 0, 0, 0, 28, 160, 1, 0, 0, 0, 30, 162, 1, 0, 0, 0, 32, 164, 1, 0, 0, 0, 34, 37, 3, 2, 1, 0, 35, 37, 3, 6, 3, 0, 36, 34, 1, 0, 0, 0, 36, 35, 1, 0, 0, 0, 37, 40, 1, 0, 0, 0, 38, 36, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 1, 1, 0, 0, 0, 40, 38, 1, 0, 0, 0, 41, 42, 3, 4, 2, 0, 42, 43, 3, 32, 16, 0, 43, 44, 5, 1, 0, 0, 44, 3, 1, 0, 0, 0, 45, 46, 7, 0, 0, 0, 46, 5, 1, 0, 0, 0, 47, 48, 5, 2, 0, 0, 48, 49, 3, 4, 2, 0, 49, 50, 3, 32, 16, 0, 50, 52, 5, 3, 0, 0, 51, 53, 3, 8, 4, 0, 52, 51, 1, 0, 0, 0, 52, 53, 1, 0, 0, 0, 53, 54, 1, 0, 0, 0, 54, 55, 5, 4, 0, 0, 55, 56, 3, 12, 6, 0, 56, 7, 1, 0, 0, 0, 57, 62, 3, 10, 5, 0, 58, 59, 5, 5, 0, 0, 59, 61, 3, 10, 5, 0, 60, 58, 1, 0, 0, 0, 61, 64, 1, 0, 0, 0, 62, 60, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 9, 1, 0, 0, 0, 64, 62, 1, 0, 0, 0, 65, 66, 3, 4, 2, 0, 66, 67, 3, 32, 16, 0, 67, 11, 1, 0, 0, 0, 68, 72, 5, 6, 0, 0, 69, 71, 3, 2, 1, 0, 70, 69, 1, 0, 0, 0, 71, 74, 1, 0, 0, 0, 72, 70, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 78, 1, 0, 0, 0, 74, 72, 1, 0, 0, 0, 75, 77, 3, 14, 7, 0, 76, 75, 1, 0, 0, 0, 77, 80, 1, 0, 0, 0, 78, 76, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, 81, 1, 0, 0, 0, 80, 78, 1, 0, 0, 0, 81, 82, 5, 7, 0, 0, 82, 13, 1, 0, 0, 0, 83, 84, 3, 20, 10, 0, 84, 85, 5, 8, 0, 0, 85, 86, 3, 16, 8, 0, 86, 87, 5, 1, 0, 0, 87, 117, 1, 0, 0, 0, 88, 89, 3, 22, 11, 0, 89, 90, 5, 1, 0, 0, 90, 117, 1, 0, 0, 0, 91, 92, 5, 9, 0, 0, 92, 93, 5, 3, 0, 0, 93, 94, 3, 16, 8, 0, 94, 95, 5, 4, 0, 0, 95, 98, 3, 12, 6, 0, 96, 97, 5, 10, 0, 0, 97, 99, 3, 12, 6, 0, 98, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 117, 1, 0, 0, 0, 100, 101, 5, 11, 0, 0, 101, 102, 5, 3, 0, 0, 102, 103, 3, 16, 8, 0, 103, 104, 5, 4, 0, 0, 104, 105, 3, 12, 6, 0, 105, 117, 1, 0, 0, 0, 106, 107, 5, 12, 0, 0, 107, 108, 3, 16, 8, 0, 108, 109, 5, 1, 0, 0, 109, 117, 1, 0, 0, 0, 110, 111, 5, 12, 0, 0, 111, 117, 5, 1, 0, 0, 112, 113, 5, 13, 0, 0, 113, 117, 5, 1, 0, 0, 114, 115, 5, 14, 0, 0, 115, 117, 5, 1, 0, 0, 116, 83, 1, 0, 0, 0, 116, 88, 1, 0, 0, 0, 116, 91, 1, 0, 0, 0, 116, 100, 1, 0, 0, 0, 116, 106, 1, 0, 0, 0, 116, 110, 1, 0, 0, 0, 116, 112, 1, 0, 0, 0, 116, 114, 1, 0, 0, 0, 117, 15, 1, 0, 0, 0, 118, 119, 6, 8, -1, 0, 119, 127, 3, 26, 13, 0, 120, 121, 5, 3, 0, 0, 121, 122, 3, 16, 8, 0, 122, 123, 5, 4, 0, 0, 123, 127, 1, 0, 0, 0, 124, 127, 3, 22, 11, 0, 125, 127, 3, 20, 10, 0, 126, 118, 1, 0, 0, 0, 126, 120, 1, 0, 0, 0, 126, 124, 1, 0, 0, 0, 126, 125, 1, 0, 0, 0, 127, 134, 1, 0, 0, 0, 128, 129, 10, 5, 0, 0, 129, 130, 3, 18, 9, 0, 130, 131, 3, 16, 8, 6, 131, 133, 1, 0, 0, 0, 132, 128, 1, 0, 0, 0, 133, 136, 1, 0, 0, 0, 134, 132, 1, 0, 0, 0, 134, 135, 1, 0, 0, 0, 135, 17, 1, 0, 0, 0, 136, 134, 1, 0, 0, 0, 137, 138, 7, 1, 0, 0, 138, 19, 1, 0, 0, 0, 139, 140, 3, 32, 16, 0, 140, 21, 1, 0, 0, 0, 141, 142, 3, 32, 16, 0, 142, 144, 5, 3, 0, 0, 143, 145, 3, 24, 12, 0, 144, 143, 1, 0, 0, 0, 144, 145, 1, 0, 0, 0, 145, 146, 1, 0, 0, 0, 146, 147, 5, 4, 0, 0, 147, 23, 1, 0, 0, 0, 148, 153, 3, 16, 8, 0, 149, 150, 5, 5, 0, 0, 150, 152, 3, 16, 8, 0, 151, 149, 1, 0, 0, 0, 152, 155, 1, 0, 0, 0, 153, 151, 1, 0, 0, 0, 153, 154, 1, 0, 0, 0, 154, 25, 1, 0, 0, 0, 155, 153, 1, 0, 0, 0, 156, 159, 3, 30, 15, 0, 157, 159, 3, 28, 14, 0, 158, 156, 1, 0, 0, 0, 158, 157, 1, 0, 0, 0, 159, 27, 1, 0, 0, 0, 160, 161, 7, 2, 0, 0, 161, 29, 1, 0, 0, 0, 162, 163, 5, 24, 0, 0, 163, 31, 1, 0, 0, 0, 164, 165, 5, 23, 0, 0, 165, 33, 1, 0, 0, 0, 13, 36, 38, 52, 62, 72, 78, 98, 116, 126, 134, 144, 153, 158]
|
47
src/main/java/de/dhbw/horb/antlr/Decaf.tokens
Normal file
47
src/main/java/de/dhbw/horb/antlr/Decaf.tokens
Normal file
@ -0,0 +1,47 @@
|
||||
T__0=1
|
||||
T__1=2
|
||||
T__2=3
|
||||
T__3=4
|
||||
T__4=5
|
||||
T__5=6
|
||||
T__6=7
|
||||
T__7=8
|
||||
T__8=9
|
||||
T__9=10
|
||||
T__10=11
|
||||
T__11=12
|
||||
T__12=13
|
||||
T__13=14
|
||||
T__14=15
|
||||
T__15=16
|
||||
SUB=17
|
||||
ADD=18
|
||||
MUL=19
|
||||
INT=20
|
||||
BOOL=21
|
||||
VOID=22
|
||||
IDENTIFIER=23
|
||||
Number=24
|
||||
WS=25
|
||||
';'=1
|
||||
'def'=2
|
||||
'('=3
|
||||
')'=4
|
||||
','=5
|
||||
'{'=6
|
||||
'}'=7
|
||||
'='=8
|
||||
'if'=9
|
||||
'else'=10
|
||||
'while'=11
|
||||
'return'=12
|
||||
'break'=13
|
||||
'continue'=14
|
||||
'true'=15
|
||||
'false'=16
|
||||
'-'=17
|
||||
'+'=18
|
||||
'*'=19
|
||||
'int'=20
|
||||
'bool'=21
|
||||
'void'=22
|
376
src/main/java/de/dhbw/horb/antlr/DecafBaseListener.java
Normal file
376
src/main/java/de/dhbw/horb/antlr/DecafBaseListener.java
Normal file
@ -0,0 +1,376 @@
|
||||
// Generated from /home/simon/dev/AntlrAssignment3Template/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
|
||||
package de.dhbw.horb.antlr;
|
||||
|
||||
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 DecafListener},
|
||||
* which can be extended to create a listener which only needs to handle a subset
|
||||
* of the available methods.
|
||||
*/
|
||||
@SuppressWarnings("CheckReturnValue")
|
||||
public class DecafBaseListener implements DecafListener {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterProgram(DecafParser.ProgramContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitProgram(DecafParser.ProgramContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterVar(DecafParser.VarContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitVar(DecafParser.VarContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterType(DecafParser.TypeContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitType(DecafParser.TypeContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterFunc(DecafParser.FuncContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitFunc(DecafParser.FuncContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterParams(DecafParser.ParamsContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitParams(DecafParser.ParamsContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterParam(DecafParser.ParamContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitParam(DecafParser.ParamContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterBlock(DecafParser.BlockContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitBlock(DecafParser.BlockContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterAssign(DecafParser.AssignContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitAssign(DecafParser.AssignContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterFunctionCall(DecafParser.FunctionCallContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitFunctionCall(DecafParser.FunctionCallContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterIf(DecafParser.IfContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitIf(DecafParser.IfContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterWhile(DecafParser.WhileContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitWhile(DecafParser.WhileContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterReturn(DecafParser.ReturnContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitReturn(DecafParser.ReturnContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterReturnVoid(DecafParser.ReturnVoidContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitReturnVoid(DecafParser.ReturnVoidContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterBreak(DecafParser.BreakContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitBreak(DecafParser.BreakContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterContinue(DecafParser.ContinueContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitContinue(DecafParser.ContinueContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterExpression(DecafParser.ExpressionContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitExpression(DecafParser.ExpressionContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterFunCallExpression(DecafParser.FunCallExpressionContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitFunCallExpression(DecafParser.FunCallExpressionContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterConstant(DecafParser.ConstantContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitConstant(DecafParser.ConstantContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterBinaryOperation(DecafParser.BinaryOperationContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitBinaryOperation(DecafParser.BinaryOperationContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterLocation(DecafParser.LocationContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitLocation(DecafParser.LocationContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterBinaryOp(DecafParser.BinaryOpContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitBinaryOp(DecafParser.BinaryOpContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterLoc(DecafParser.LocContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitLoc(DecafParser.LocContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterFuncCall(DecafParser.FuncCallContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitFuncCall(DecafParser.FuncCallContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterArgs(DecafParser.ArgsContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitArgs(DecafParser.ArgsContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterLiteral(DecafParser.LiteralContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitLiteral(DecafParser.LiteralContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterBoolean(DecafParser.BooleanContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitBoolean(DecafParser.BooleanContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterNumber(DecafParser.NumberContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitNumber(DecafParser.NumberContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterId(DecafParser.IdContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitId(DecafParser.IdContext 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) { }
|
||||
}
|
211
src/main/java/de/dhbw/horb/antlr/DecafBaseVisitor.java
Normal file
211
src/main/java/de/dhbw/horb/antlr/DecafBaseVisitor.java
Normal file
@ -0,0 +1,211 @@
|
||||
// Generated from /home/simon/dev/AntlrAssignment3Template/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
|
||||
package de.dhbw.horb.antlr;
|
||||
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
||||
|
||||
/**
|
||||
* This class provides an empty implementation of {@link DecafVisitor},
|
||||
* 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 DecafBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements DecafVisitor<T> {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitProgram(DecafParser.ProgramContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitVar(DecafParser.VarContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitType(DecafParser.TypeContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitFunc(DecafParser.FuncContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitParams(DecafParser.ParamsContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitParam(DecafParser.ParamContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitBlock(DecafParser.BlockContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitAssign(DecafParser.AssignContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitFunctionCall(DecafParser.FunctionCallContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitIf(DecafParser.IfContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitWhile(DecafParser.WhileContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitReturn(DecafParser.ReturnContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitReturnVoid(DecafParser.ReturnVoidContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitBreak(DecafParser.BreakContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitContinue(DecafParser.ContinueContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitExpression(DecafParser.ExpressionContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitFunCallExpression(DecafParser.FunCallExpressionContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitConstant(DecafParser.ConstantContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitBinaryOperation(DecafParser.BinaryOperationContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitLocation(DecafParser.LocationContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitBinaryOp(DecafParser.BinaryOpContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitLoc(DecafParser.LocContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitFuncCall(DecafParser.FuncCallContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitArgs(DecafParser.ArgsContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitLiteral(DecafParser.LiteralContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitBoolean(DecafParser.BooleanContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitNumber(DecafParser.NumberContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitId(DecafParser.IdContext ctx) { return visitChildren(ctx); }
|
||||
}
|
92
src/main/java/de/dhbw/horb/antlr/DecafLexer.interp
Normal file
92
src/main/java/de/dhbw/horb/antlr/DecafLexer.interp
Normal file
@ -0,0 +1,92 @@
|
||||
token literal names:
|
||||
null
|
||||
';'
|
||||
'def'
|
||||
'('
|
||||
')'
|
||||
','
|
||||
'{'
|
||||
'}'
|
||||
'='
|
||||
'if'
|
||||
'else'
|
||||
'while'
|
||||
'return'
|
||||
'break'
|
||||
'continue'
|
||||
'true'
|
||||
'false'
|
||||
'-'
|
||||
'+'
|
||||
'*'
|
||||
'int'
|
||||
'bool'
|
||||
'void'
|
||||
null
|
||||
null
|
||||
null
|
||||
|
||||
token symbolic names:
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
SUB
|
||||
ADD
|
||||
MUL
|
||||
INT
|
||||
BOOL
|
||||
VOID
|
||||
IDENTIFIER
|
||||
Number
|
||||
WS
|
||||
|
||||
rule names:
|
||||
T__0
|
||||
T__1
|
||||
T__2
|
||||
T__3
|
||||
T__4
|
||||
T__5
|
||||
T__6
|
||||
T__7
|
||||
T__8
|
||||
T__9
|
||||
T__10
|
||||
T__11
|
||||
T__12
|
||||
T__13
|
||||
T__14
|
||||
T__15
|
||||
SUB
|
||||
ADD
|
||||
MUL
|
||||
INT
|
||||
BOOL
|
||||
VOID
|
||||
IDENTIFIER
|
||||
Number
|
||||
WS
|
||||
|
||||
channel names:
|
||||
DEFAULT_TOKEN_CHANNEL
|
||||
HIDDEN
|
||||
|
||||
mode names:
|
||||
DEFAULT_MODE
|
||||
|
||||
atn:
|
||||
[4, 0, 25, 150, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 1, 21, 1, 21, 1, 21, 1, 22, 4, 22, 138, 8, 22, 11, 22, 12, 22, 139, 1, 23, 4, 23, 143, 8, 23, 11, 23, 12, 23, 144, 1, 24, 1, 24, 1, 24, 1, 24, 0, 0, 25, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 1, 0, 3, 2, 0, 65, 90, 97, 122, 1, 0, 48, 57, 3, 0, 9, 10, 13, 13, 32, 32, 151, 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, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 1, 51, 1, 0, 0, 0, 3, 53, 1, 0, 0, 0, 5, 57, 1, 0, 0, 0, 7, 59, 1, 0, 0, 0, 9, 61, 1, 0, 0, 0, 11, 63, 1, 0, 0, 0, 13, 65, 1, 0, 0, 0, 15, 67, 1, 0, 0, 0, 17, 69, 1, 0, 0, 0, 19, 72, 1, 0, 0, 0, 21, 77, 1, 0, 0, 0, 23, 83, 1, 0, 0, 0, 25, 90, 1, 0, 0, 0, 27, 96, 1, 0, 0, 0, 29, 105, 1, 0, 0, 0, 31, 110, 1, 0, 0, 0, 33, 116, 1, 0, 0, 0, 35, 118, 1, 0, 0, 0, 37, 120, 1, 0, 0, 0, 39, 122, 1, 0, 0, 0, 41, 126, 1, 0, 0, 0, 43, 131, 1, 0, 0, 0, 45, 137, 1, 0, 0, 0, 47, 142, 1, 0, 0, 0, 49, 146, 1, 0, 0, 0, 51, 52, 5, 59, 0, 0, 52, 2, 1, 0, 0, 0, 53, 54, 5, 100, 0, 0, 54, 55, 5, 101, 0, 0, 55, 56, 5, 102, 0, 0, 56, 4, 1, 0, 0, 0, 57, 58, 5, 40, 0, 0, 58, 6, 1, 0, 0, 0, 59, 60, 5, 41, 0, 0, 60, 8, 1, 0, 0, 0, 61, 62, 5, 44, 0, 0, 62, 10, 1, 0, 0, 0, 63, 64, 5, 123, 0, 0, 64, 12, 1, 0, 0, 0, 65, 66, 5, 125, 0, 0, 66, 14, 1, 0, 0, 0, 67, 68, 5, 61, 0, 0, 68, 16, 1, 0, 0, 0, 69, 70, 5, 105, 0, 0, 70, 71, 5, 102, 0, 0, 71, 18, 1, 0, 0, 0, 72, 73, 5, 101, 0, 0, 73, 74, 5, 108, 0, 0, 74, 75, 5, 115, 0, 0, 75, 76, 5, 101, 0, 0, 76, 20, 1, 0, 0, 0, 77, 78, 5, 119, 0, 0, 78, 79, 5, 104, 0, 0, 79, 80, 5, 105, 0, 0, 80, 81, 5, 108, 0, 0, 81, 82, 5, 101, 0, 0, 82, 22, 1, 0, 0, 0, 83, 84, 5, 114, 0, 0, 84, 85, 5, 101, 0, 0, 85, 86, 5, 116, 0, 0, 86, 87, 5, 117, 0, 0, 87, 88, 5, 114, 0, 0, 88, 89, 5, 110, 0, 0, 89, 24, 1, 0, 0, 0, 90, 91, 5, 98, 0, 0, 91, 92, 5, 114, 0, 0, 92, 93, 5, 101, 0, 0, 93, 94, 5, 97, 0, 0, 94, 95, 5, 107, 0, 0, 95, 26, 1, 0, 0, 0, 96, 97, 5, 99, 0, 0, 97, 98, 5, 111, 0, 0, 98, 99, 5, 110, 0, 0, 99, 100, 5, 116, 0, 0, 100, 101, 5, 105, 0, 0, 101, 102, 5, 110, 0, 0, 102, 103, 5, 117, 0, 0, 103, 104, 5, 101, 0, 0, 104, 28, 1, 0, 0, 0, 105, 106, 5, 116, 0, 0, 106, 107, 5, 114, 0, 0, 107, 108, 5, 117, 0, 0, 108, 109, 5, 101, 0, 0, 109, 30, 1, 0, 0, 0, 110, 111, 5, 102, 0, 0, 111, 112, 5, 97, 0, 0, 112, 113, 5, 108, 0, 0, 113, 114, 5, 115, 0, 0, 114, 115, 5, 101, 0, 0, 115, 32, 1, 0, 0, 0, 116, 117, 5, 45, 0, 0, 117, 34, 1, 0, 0, 0, 118, 119, 5, 43, 0, 0, 119, 36, 1, 0, 0, 0, 120, 121, 5, 42, 0, 0, 121, 38, 1, 0, 0, 0, 122, 123, 5, 105, 0, 0, 123, 124, 5, 110, 0, 0, 124, 125, 5, 116, 0, 0, 125, 40, 1, 0, 0, 0, 126, 127, 5, 98, 0, 0, 127, 128, 5, 111, 0, 0, 128, 129, 5, 111, 0, 0, 129, 130, 5, 108, 0, 0, 130, 42, 1, 0, 0, 0, 131, 132, 5, 118, 0, 0, 132, 133, 5, 111, 0, 0, 133, 134, 5, 105, 0, 0, 134, 135, 5, 100, 0, 0, 135, 44, 1, 0, 0, 0, 136, 138, 7, 0, 0, 0, 137, 136, 1, 0, 0, 0, 138, 139, 1, 0, 0, 0, 139, 137, 1, 0, 0, 0, 139, 140, 1, 0, 0, 0, 140, 46, 1, 0, 0, 0, 141, 143, 7, 1, 0, 0, 142, 141, 1, 0, 0, 0, 143, 144, 1, 0, 0, 0, 144, 142, 1, 0, 0, 0, 144, 145, 1, 0, 0, 0, 145, 48, 1, 0, 0, 0, 146, 147, 7, 2, 0, 0, 147, 148, 1, 0, 0, 0, 148, 149, 6, 24, 0, 0, 149, 50, 1, 0, 0, 0, 3, 0, 139, 144, 1, 6, 0, 0]
|
210
src/main/java/de/dhbw/horb/antlr/DecafLexer.java
Normal file
210
src/main/java/de/dhbw/horb/antlr/DecafLexer.java
Normal file
@ -0,0 +1,210 @@
|
||||
// Generated from /home/simon/dev/AntlrAssignment3Template/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
|
||||
package de.dhbw.horb.antlr;
|
||||
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 DecafLexer 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, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9,
|
||||
T__9=10, T__10=11, T__11=12, T__12=13, T__13=14, T__14=15, T__15=16, SUB=17,
|
||||
ADD=18, MUL=19, INT=20, BOOL=21, VOID=22, IDENTIFIER=23, Number=24, WS=25;
|
||||
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", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8",
|
||||
"T__9", "T__10", "T__11", "T__12", "T__13", "T__14", "T__15", "SUB",
|
||||
"ADD", "MUL", "INT", "BOOL", "VOID", "IDENTIFIER", "Number", "WS"
|
||||
};
|
||||
}
|
||||
public static final String[] ruleNames = makeRuleNames();
|
||||
|
||||
private static String[] makeLiteralNames() {
|
||||
return new String[] {
|
||||
null, "';'", "'def'", "'('", "')'", "','", "'{'", "'}'", "'='", "'if'",
|
||||
"'else'", "'while'", "'return'", "'break'", "'continue'", "'true'", "'false'",
|
||||
"'-'", "'+'", "'*'", "'int'", "'bool'", "'void'"
|
||||
};
|
||||
}
|
||||
private static final String[] _LITERAL_NAMES = makeLiteralNames();
|
||||
private static String[] makeSymbolicNames() {
|
||||
return new String[] {
|
||||
null, null, null, null, null, null, null, null, null, null, null, null,
|
||||
null, null, null, null, null, "SUB", "ADD", "MUL", "INT", "BOOL", "VOID",
|
||||
"IDENTIFIER", "Number", "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 DecafLexer(CharStream input) {
|
||||
super(input);
|
||||
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGrammarFileName() { return "Decaf.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\u0019\u0096\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002"+
|
||||
"\u0001\u0007\u0001\u0002\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002"+
|
||||
"\u0004\u0007\u0004\u0002\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002"+
|
||||
"\u0007\u0007\u0007\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002"+
|
||||
"\u000b\u0007\u000b\u0002\f\u0007\f\u0002\r\u0007\r\u0002\u000e\u0007\u000e"+
|
||||
"\u0002\u000f\u0007\u000f\u0002\u0010\u0007\u0010\u0002\u0011\u0007\u0011"+
|
||||
"\u0002\u0012\u0007\u0012\u0002\u0013\u0007\u0013\u0002\u0014\u0007\u0014"+
|
||||
"\u0002\u0015\u0007\u0015\u0002\u0016\u0007\u0016\u0002\u0017\u0007\u0017"+
|
||||
"\u0002\u0018\u0007\u0018\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001"+
|
||||
"\u0001\u0001\u0001\u0001\u0001\u0002\u0001\u0002\u0001\u0003\u0001\u0003"+
|
||||
"\u0001\u0004\u0001\u0004\u0001\u0005\u0001\u0005\u0001\u0006\u0001\u0006"+
|
||||
"\u0001\u0007\u0001\u0007\u0001\b\u0001\b\u0001\b\u0001\t\u0001\t\u0001"+
|
||||
"\t\u0001\t\u0001\t\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001"+
|
||||
"\u000b\u0001\u000b\u0001\u000b\u0001\u000b\u0001\u000b\u0001\u000b\u0001"+
|
||||
"\u000b\u0001\f\u0001\f\u0001\f\u0001\f\u0001\f\u0001\f\u0001\r\u0001\r"+
|
||||
"\u0001\r\u0001\r\u0001\r\u0001\r\u0001\r\u0001\r\u0001\r\u0001\u000e\u0001"+
|
||||
"\u000e\u0001\u000e\u0001\u000e\u0001\u000e\u0001\u000f\u0001\u000f\u0001"+
|
||||
"\u000f\u0001\u000f\u0001\u000f\u0001\u000f\u0001\u0010\u0001\u0010\u0001"+
|
||||
"\u0011\u0001\u0011\u0001\u0012\u0001\u0012\u0001\u0013\u0001\u0013\u0001"+
|
||||
"\u0013\u0001\u0013\u0001\u0014\u0001\u0014\u0001\u0014\u0001\u0014\u0001"+
|
||||
"\u0014\u0001\u0015\u0001\u0015\u0001\u0015\u0001\u0015\u0001\u0015\u0001"+
|
||||
"\u0016\u0004\u0016\u008a\b\u0016\u000b\u0016\f\u0016\u008b\u0001\u0017"+
|
||||
"\u0004\u0017\u008f\b\u0017\u000b\u0017\f\u0017\u0090\u0001\u0018\u0001"+
|
||||
"\u0018\u0001\u0018\u0001\u0018\u0000\u0000\u0019\u0001\u0001\u0003\u0002"+
|
||||
"\u0005\u0003\u0007\u0004\t\u0005\u000b\u0006\r\u0007\u000f\b\u0011\t\u0013"+
|
||||
"\n\u0015\u000b\u0017\f\u0019\r\u001b\u000e\u001d\u000f\u001f\u0010!\u0011"+
|
||||
"#\u0012%\u0013\'\u0014)\u0015+\u0016-\u0017/\u00181\u0019\u0001\u0000"+
|
||||
"\u0003\u0002\u0000AZaz\u0001\u000009\u0003\u0000\t\n\r\r \u0097\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\u0000\u000b\u0001\u0000\u0000\u0000\u0000\r"+
|
||||
"\u0001\u0000\u0000\u0000\u0000\u000f\u0001\u0000\u0000\u0000\u0000\u0011"+
|
||||
"\u0001\u0000\u0000\u0000\u0000\u0013\u0001\u0000\u0000\u0000\u0000\u0015"+
|
||||
"\u0001\u0000\u0000\u0000\u0000\u0017\u0001\u0000\u0000\u0000\u0000\u0019"+
|
||||
"\u0001\u0000\u0000\u0000\u0000\u001b\u0001\u0000\u0000\u0000\u0000\u001d"+
|
||||
"\u0001\u0000\u0000\u0000\u0000\u001f\u0001\u0000\u0000\u0000\u0000!\u0001"+
|
||||
"\u0000\u0000\u0000\u0000#\u0001\u0000\u0000\u0000\u0000%\u0001\u0000\u0000"+
|
||||
"\u0000\u0000\'\u0001\u0000\u0000\u0000\u0000)\u0001\u0000\u0000\u0000"+
|
||||
"\u0000+\u0001\u0000\u0000\u0000\u0000-\u0001\u0000\u0000\u0000\u0000/"+
|
||||
"\u0001\u0000\u0000\u0000\u00001\u0001\u0000\u0000\u0000\u00013\u0001\u0000"+
|
||||
"\u0000\u0000\u00035\u0001\u0000\u0000\u0000\u00059\u0001\u0000\u0000\u0000"+
|
||||
"\u0007;\u0001\u0000\u0000\u0000\t=\u0001\u0000\u0000\u0000\u000b?\u0001"+
|
||||
"\u0000\u0000\u0000\rA\u0001\u0000\u0000\u0000\u000fC\u0001\u0000\u0000"+
|
||||
"\u0000\u0011E\u0001\u0000\u0000\u0000\u0013H\u0001\u0000\u0000\u0000\u0015"+
|
||||
"M\u0001\u0000\u0000\u0000\u0017S\u0001\u0000\u0000\u0000\u0019Z\u0001"+
|
||||
"\u0000\u0000\u0000\u001b`\u0001\u0000\u0000\u0000\u001di\u0001\u0000\u0000"+
|
||||
"\u0000\u001fn\u0001\u0000\u0000\u0000!t\u0001\u0000\u0000\u0000#v\u0001"+
|
||||
"\u0000\u0000\u0000%x\u0001\u0000\u0000\u0000\'z\u0001\u0000\u0000\u0000"+
|
||||
")~\u0001\u0000\u0000\u0000+\u0083\u0001\u0000\u0000\u0000-\u0089\u0001"+
|
||||
"\u0000\u0000\u0000/\u008e\u0001\u0000\u0000\u00001\u0092\u0001\u0000\u0000"+
|
||||
"\u000034\u0005;\u0000\u00004\u0002\u0001\u0000\u0000\u000056\u0005d\u0000"+
|
||||
"\u000067\u0005e\u0000\u000078\u0005f\u0000\u00008\u0004\u0001\u0000\u0000"+
|
||||
"\u00009:\u0005(\u0000\u0000:\u0006\u0001\u0000\u0000\u0000;<\u0005)\u0000"+
|
||||
"\u0000<\b\u0001\u0000\u0000\u0000=>\u0005,\u0000\u0000>\n\u0001\u0000"+
|
||||
"\u0000\u0000?@\u0005{\u0000\u0000@\f\u0001\u0000\u0000\u0000AB\u0005}"+
|
||||
"\u0000\u0000B\u000e\u0001\u0000\u0000\u0000CD\u0005=\u0000\u0000D\u0010"+
|
||||
"\u0001\u0000\u0000\u0000EF\u0005i\u0000\u0000FG\u0005f\u0000\u0000G\u0012"+
|
||||
"\u0001\u0000\u0000\u0000HI\u0005e\u0000\u0000IJ\u0005l\u0000\u0000JK\u0005"+
|
||||
"s\u0000\u0000KL\u0005e\u0000\u0000L\u0014\u0001\u0000\u0000\u0000MN\u0005"+
|
||||
"w\u0000\u0000NO\u0005h\u0000\u0000OP\u0005i\u0000\u0000PQ\u0005l\u0000"+
|
||||
"\u0000QR\u0005e\u0000\u0000R\u0016\u0001\u0000\u0000\u0000ST\u0005r\u0000"+
|
||||
"\u0000TU\u0005e\u0000\u0000UV\u0005t\u0000\u0000VW\u0005u\u0000\u0000"+
|
||||
"WX\u0005r\u0000\u0000XY\u0005n\u0000\u0000Y\u0018\u0001\u0000\u0000\u0000"+
|
||||
"Z[\u0005b\u0000\u0000[\\\u0005r\u0000\u0000\\]\u0005e\u0000\u0000]^\u0005"+
|
||||
"a\u0000\u0000^_\u0005k\u0000\u0000_\u001a\u0001\u0000\u0000\u0000`a\u0005"+
|
||||
"c\u0000\u0000ab\u0005o\u0000\u0000bc\u0005n\u0000\u0000cd\u0005t\u0000"+
|
||||
"\u0000de\u0005i\u0000\u0000ef\u0005n\u0000\u0000fg\u0005u\u0000\u0000"+
|
||||
"gh\u0005e\u0000\u0000h\u001c\u0001\u0000\u0000\u0000ij\u0005t\u0000\u0000"+
|
||||
"jk\u0005r\u0000\u0000kl\u0005u\u0000\u0000lm\u0005e\u0000\u0000m\u001e"+
|
||||
"\u0001\u0000\u0000\u0000no\u0005f\u0000\u0000op\u0005a\u0000\u0000pq\u0005"+
|
||||
"l\u0000\u0000qr\u0005s\u0000\u0000rs\u0005e\u0000\u0000s \u0001\u0000"+
|
||||
"\u0000\u0000tu\u0005-\u0000\u0000u\"\u0001\u0000\u0000\u0000vw\u0005+"+
|
||||
"\u0000\u0000w$\u0001\u0000\u0000\u0000xy\u0005*\u0000\u0000y&\u0001\u0000"+
|
||||
"\u0000\u0000z{\u0005i\u0000\u0000{|\u0005n\u0000\u0000|}\u0005t\u0000"+
|
||||
"\u0000}(\u0001\u0000\u0000\u0000~\u007f\u0005b\u0000\u0000\u007f\u0080"+
|
||||
"\u0005o\u0000\u0000\u0080\u0081\u0005o\u0000\u0000\u0081\u0082\u0005l"+
|
||||
"\u0000\u0000\u0082*\u0001\u0000\u0000\u0000\u0083\u0084\u0005v\u0000\u0000"+
|
||||
"\u0084\u0085\u0005o\u0000\u0000\u0085\u0086\u0005i\u0000\u0000\u0086\u0087"+
|
||||
"\u0005d\u0000\u0000\u0087,\u0001\u0000\u0000\u0000\u0088\u008a\u0007\u0000"+
|
||||
"\u0000\u0000\u0089\u0088\u0001\u0000\u0000\u0000\u008a\u008b\u0001\u0000"+
|
||||
"\u0000\u0000\u008b\u0089\u0001\u0000\u0000\u0000\u008b\u008c\u0001\u0000"+
|
||||
"\u0000\u0000\u008c.\u0001\u0000\u0000\u0000\u008d\u008f\u0007\u0001\u0000"+
|
||||
"\u0000\u008e\u008d\u0001\u0000\u0000\u0000\u008f\u0090\u0001\u0000\u0000"+
|
||||
"\u0000\u0090\u008e\u0001\u0000\u0000\u0000\u0090\u0091\u0001\u0000\u0000"+
|
||||
"\u0000\u00910\u0001\u0000\u0000\u0000\u0092\u0093\u0007\u0002\u0000\u0000"+
|
||||
"\u0093\u0094\u0001\u0000\u0000\u0000\u0094\u0095\u0006\u0018\u0000\u0000"+
|
||||
"\u00952\u0001\u0000\u0000\u0000\u0003\u0000\u008b\u0090\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);
|
||||
}
|
||||
}
|
||||
}
|
47
src/main/java/de/dhbw/horb/antlr/DecafLexer.tokens
Normal file
47
src/main/java/de/dhbw/horb/antlr/DecafLexer.tokens
Normal file
@ -0,0 +1,47 @@
|
||||
T__0=1
|
||||
T__1=2
|
||||
T__2=3
|
||||
T__3=4
|
||||
T__4=5
|
||||
T__5=6
|
||||
T__6=7
|
||||
T__7=8
|
||||
T__8=9
|
||||
T__9=10
|
||||
T__10=11
|
||||
T__11=12
|
||||
T__12=13
|
||||
T__13=14
|
||||
T__14=15
|
||||
T__15=16
|
||||
SUB=17
|
||||
ADD=18
|
||||
MUL=19
|
||||
INT=20
|
||||
BOOL=21
|
||||
VOID=22
|
||||
IDENTIFIER=23
|
||||
Number=24
|
||||
WS=25
|
||||
';'=1
|
||||
'def'=2
|
||||
'('=3
|
||||
')'=4
|
||||
','=5
|
||||
'{'=6
|
||||
'}'=7
|
||||
'='=8
|
||||
'if'=9
|
||||
'else'=10
|
||||
'while'=11
|
||||
'return'=12
|
||||
'break'=13
|
||||
'continue'=14
|
||||
'true'=15
|
||||
'false'=16
|
||||
'-'=17
|
||||
'+'=18
|
||||
'*'=19
|
||||
'int'=20
|
||||
'bool'=21
|
||||
'void'=22
|
316
src/main/java/de/dhbw/horb/antlr/DecafListener.java
Normal file
316
src/main/java/de/dhbw/horb/antlr/DecafListener.java
Normal file
@ -0,0 +1,316 @@
|
||||
// Generated from /home/simon/dev/AntlrAssignment3Template/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
|
||||
package de.dhbw.horb.antlr;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||
|
||||
/**
|
||||
* This interface defines a complete listener for a parse tree produced by
|
||||
* {@link DecafParser}.
|
||||
*/
|
||||
public interface DecafListener extends ParseTreeListener {
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#program}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterProgram(DecafParser.ProgramContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#program}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitProgram(DecafParser.ProgramContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#var}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterVar(DecafParser.VarContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#var}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitVar(DecafParser.VarContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#type}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterType(DecafParser.TypeContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#type}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitType(DecafParser.TypeContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#func}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterFunc(DecafParser.FuncContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#func}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitFunc(DecafParser.FuncContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#params}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterParams(DecafParser.ParamsContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#params}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitParams(DecafParser.ParamsContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#param}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterParam(DecafParser.ParamContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#param}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitParam(DecafParser.ParamContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#block}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterBlock(DecafParser.BlockContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#block}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitBlock(DecafParser.BlockContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code Assign}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterAssign(DecafParser.AssignContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by the {@code Assign}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitAssign(DecafParser.AssignContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code FunctionCall}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterFunctionCall(DecafParser.FunctionCallContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by the {@code FunctionCall}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitFunctionCall(DecafParser.FunctionCallContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code If}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterIf(DecafParser.IfContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by the {@code If}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitIf(DecafParser.IfContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code While}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterWhile(DecafParser.WhileContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by the {@code While}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitWhile(DecafParser.WhileContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code Return}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterReturn(DecafParser.ReturnContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by the {@code Return}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitReturn(DecafParser.ReturnContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code ReturnVoid}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterReturnVoid(DecafParser.ReturnVoidContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by the {@code ReturnVoid}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitReturnVoid(DecafParser.ReturnVoidContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code Break}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterBreak(DecafParser.BreakContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by the {@code Break}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitBreak(DecafParser.BreakContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code Continue}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterContinue(DecafParser.ContinueContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by the {@code Continue}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitContinue(DecafParser.ContinueContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code Expression}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterExpression(DecafParser.ExpressionContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by the {@code Expression}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitExpression(DecafParser.ExpressionContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code FunCallExpression}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterFunCallExpression(DecafParser.FunCallExpressionContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by the {@code FunCallExpression}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitFunCallExpression(DecafParser.FunCallExpressionContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code Constant}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterConstant(DecafParser.ConstantContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by the {@code Constant}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitConstant(DecafParser.ConstantContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code BinaryOperation}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterBinaryOperation(DecafParser.BinaryOperationContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by the {@code BinaryOperation}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitBinaryOperation(DecafParser.BinaryOperationContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by the {@code Location}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterLocation(DecafParser.LocationContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by the {@code Location}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitLocation(DecafParser.LocationContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#binaryOp}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterBinaryOp(DecafParser.BinaryOpContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#binaryOp}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitBinaryOp(DecafParser.BinaryOpContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#loc}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterLoc(DecafParser.LocContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#loc}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitLoc(DecafParser.LocContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#funcCall}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterFuncCall(DecafParser.FuncCallContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#funcCall}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitFuncCall(DecafParser.FuncCallContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#args}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterArgs(DecafParser.ArgsContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#args}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitArgs(DecafParser.ArgsContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#literal}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterLiteral(DecafParser.LiteralContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#literal}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitLiteral(DecafParser.LiteralContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#boolean}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterBoolean(DecafParser.BooleanContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#boolean}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitBoolean(DecafParser.BooleanContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#number}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterNumber(DecafParser.NumberContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#number}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitNumber(DecafParser.NumberContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link DecafParser#id}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterId(DecafParser.IdContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link DecafParser#id}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitId(DecafParser.IdContext ctx);
|
||||
}
|
1639
src/main/java/de/dhbw/horb/antlr/DecafParser.java
Normal file
1639
src/main/java/de/dhbw/horb/antlr/DecafParser.java
Normal file
File diff suppressed because it is too large
Load Diff
194
src/main/java/de/dhbw/horb/antlr/DecafVisitor.java
Normal file
194
src/main/java/de/dhbw/horb/antlr/DecafVisitor.java
Normal file
@ -0,0 +1,194 @@
|
||||
// Generated from /home/simon/dev/AntlrAssignment3Template/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
|
||||
package de.dhbw.horb.antlr;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
||||
|
||||
/**
|
||||
* This interface defines a complete generic visitor for a parse tree produced
|
||||
* by {@link DecafParser}.
|
||||
*
|
||||
* @param <T> The return type of the visit operation. Use {@link Void} for
|
||||
* operations with no return type.
|
||||
*/
|
||||
public interface DecafVisitor<T> extends ParseTreeVisitor<T> {
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#program}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitProgram(DecafParser.ProgramContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#var}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitVar(DecafParser.VarContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#type}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitType(DecafParser.TypeContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#func}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitFunc(DecafParser.FuncContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#params}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitParams(DecafParser.ParamsContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#param}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitParam(DecafParser.ParamContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#block}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitBlock(DecafParser.BlockContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Assign}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitAssign(DecafParser.AssignContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code FunctionCall}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitFunctionCall(DecafParser.FunctionCallContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code If}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitIf(DecafParser.IfContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code While}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitWhile(DecafParser.WhileContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Return}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitReturn(DecafParser.ReturnContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code ReturnVoid}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitReturnVoid(DecafParser.ReturnVoidContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Break}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitBreak(DecafParser.BreakContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Continue}
|
||||
* labeled alternative in {@link DecafParser#stmt}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitContinue(DecafParser.ContinueContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Expression}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitExpression(DecafParser.ExpressionContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code FunCallExpression}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitFunCallExpression(DecafParser.FunCallExpressionContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Constant}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitConstant(DecafParser.ConstantContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code BinaryOperation}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitBinaryOperation(DecafParser.BinaryOperationContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Location}
|
||||
* labeled alternative in {@link DecafParser#expr}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitLocation(DecafParser.LocationContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#binaryOp}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitBinaryOp(DecafParser.BinaryOpContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#loc}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitLoc(DecafParser.LocContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#funcCall}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitFuncCall(DecafParser.FuncCallContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#args}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitArgs(DecafParser.ArgsContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#literal}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitLiteral(DecafParser.LiteralContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#boolean}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitBoolean(DecafParser.BooleanContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#number}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitNumber(DecafParser.NumberContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DecafParser#id}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitId(DecafParser.IdContext ctx);
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package de.dhbw.horb.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record Assignment(Location loc, Expression value) implements Statement {
|
||||
}
|
||||
|
@ -1,8 +1,4 @@
|
||||
package de.dhbw.horb.ast;
|
||||
|
||||
import de.dhbw.horb.ExpressionGenerator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record Binary(Expression left, Operator op, Expression right) implements Expression{
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.dhbw.horb.ast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public record Block(List<Variable> vars, List<Statement> stmts) implements Node {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.dhbw.horb.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record BoolConstant(Boolean value) implements Expression {
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
package de.dhbw.horb.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record Break() implements Statement {
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
package de.dhbw.horb.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record Continue() implements Statement {
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.dhbw.horb.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record IfElse(Expression cond, Block ifBlock, Block elseBlock) implements Statement {
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.dhbw.horb.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record IntConstant(Integer value) implements Expression {
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
package de.dhbw.horb.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record Location(String name) implements Expression {
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
package de.dhbw.horb.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Node {
|
||||
}
|
||||
|
@ -1,7 +1,4 @@
|
||||
package de.dhbw.horb.ast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public record Return(Expression ret) implements Statement {
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
package de.dhbw.horb.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record ReturnVoid() implements Statement {
|
||||
}
|
||||
|
@ -3,5 +3,14 @@ package de.dhbw.horb.ast;
|
||||
public enum Type {
|
||||
INT,
|
||||
BOOL,
|
||||
VOID
|
||||
VOID;
|
||||
|
||||
public static Type mapType(String type){
|
||||
return switch (type) {
|
||||
case "int" -> Type.INT;
|
||||
case "bool" -> Type.BOOL;
|
||||
case "void" -> Type.VOID;
|
||||
default -> throw new RuntimeException("Unknown type: " + type);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
package de.dhbw.horb.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record Variable(String name, Type type) implements Node{
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
package de.dhbw.horb.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record While(Expression cond, Block block) implements Statement {
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbw.horb;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import de.dhbw.horb.ast.Program;
|
||||
@ -8,14 +9,12 @@ import org.junit.Test;
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class CompilerTest
|
||||
{
|
||||
public class CompilerTest {
|
||||
/**
|
||||
* Rigorous Test :-)
|
||||
*/
|
||||
@Test
|
||||
public void generateASTTest()
|
||||
{
|
||||
public void generateASTTest() {
|
||||
String inputString = "def int add(int x, int y)\n" +
|
||||
"{\n" +
|
||||
"return x + y;\n" +
|
||||
@ -27,6 +26,6 @@ public class CompilerTest
|
||||
"return add(a, 2);\n" +
|
||||
"}";
|
||||
Program ast = Compiler.generateAST(inputString);
|
||||
assertTrue( ast.methods().size() == 2 );
|
||||
assertEquals(2, ast.methods().size());
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
package de.dhbw.horb;
|
||||
|
||||
import de.dhbw.horb.antlr.DecafLexer;
|
||||
import de.dhbw.horb.antlr.DecafParser;
|
||||
import de.dhbw.horb.ast.*;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
@ -34,8 +37,8 @@ public class ExpressionGeneratorTest
|
||||
{
|
||||
Expression mCall = generateExpression("m(x,y)");
|
||||
assertTrue(mCall instanceof FunctionCall);
|
||||
assertTrue(((FunctionCall) mCall).name().equals("m"));
|
||||
assertTrue(((FunctionCall) mCall).args().size() == 2);
|
||||
assertEquals("m", ((FunctionCall) mCall).name());
|
||||
assertEquals(2, ((FunctionCall) mCall).args().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1,32 +1,73 @@
|
||||
package de.dhbw.horb;
|
||||
|
||||
import de.dhbw.horb.antlr.DecafLexer;
|
||||
import de.dhbw.horb.antlr.DecafParser;
|
||||
import de.dhbw.horb.ast.*;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for AST Generation of Expressions.
|
||||
*/
|
||||
public class StatementGeneratorTest
|
||||
{
|
||||
public class StatementGeneratorTest {
|
||||
@Test
|
||||
public void whileTest()
|
||||
{
|
||||
public void whileTest() {
|
||||
Statement whileStmt = generateStatement("while(true){}");
|
||||
assertTrue(whileStmt instanceof While);
|
||||
assertTrue( ((While) whileStmt).block().stmts().size() == 0);
|
||||
assertEquals(0, ((While) whileStmt).block().stmts().size());
|
||||
}
|
||||
|
||||
private Statement generateStatement(String from){
|
||||
String inputString = from;
|
||||
CharStream input = CharStreams.fromString(inputString);
|
||||
@Test
|
||||
public void whileTest2() {
|
||||
Statement whileStmt = generateStatement("while(true){int x; x= 3;}");
|
||||
assertTrue(whileStmt instanceof While);
|
||||
assertEquals(1, ((While) whileStmt).block().vars().size());
|
||||
assertEquals(1, ((While) whileStmt).block().stmts().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifTest() {
|
||||
Statement ifStmt = generateStatement("if(true){}");
|
||||
assertTrue(ifStmt instanceof IfElse);
|
||||
assertTrue(((IfElse) ifStmt).ifBlock().stmts().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifTest2() {
|
||||
Statement ifStmt = generateStatement("if(true){bool cool; cool = true;}");
|
||||
assertTrue(ifStmt instanceof IfElse);
|
||||
assertEquals(1, ((IfElse) ifStmt).ifBlock().vars().size());
|
||||
assertEquals(1, ((IfElse) ifStmt).ifBlock().stmts().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifElseTest() {
|
||||
Statement ifElseStmt = generateStatement("if(true){}else{}");
|
||||
assertTrue(ifElseStmt instanceof IfElse);
|
||||
assertTrue(((IfElse) ifElseStmt).ifBlock().stmts().isEmpty());
|
||||
assertTrue(((IfElse) ifElseStmt).elseBlock().stmts().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifElseTest2() {
|
||||
Statement ifElseStmt = generateStatement("if(true){int x; x = 3;}else{int y; y = 4;}");
|
||||
assertTrue(ifElseStmt instanceof IfElse);
|
||||
assertEquals(1, ((IfElse) ifElseStmt).ifBlock().vars().size());
|
||||
assertEquals(1, ((IfElse) ifElseStmt).ifBlock().stmts().size());
|
||||
assertEquals(1, ((IfElse) ifElseStmt).elseBlock().vars().size());
|
||||
assertEquals(1, ((IfElse) ifElseStmt).elseBlock().stmts().size());
|
||||
}
|
||||
|
||||
private Statement generateStatement(String from) {
|
||||
CharStream input = CharStreams.fromString(from);
|
||||
DecafLexer lexer = new DecafLexer(input);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
DecafParser parser = new DecafParser(tokens);
|
||||
return parser.stmt().accept(new StatementGenerator());
|
||||
return new StatementGenerator().visit(parser.stmt());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user