tasks solved

This commit is contained in:
laurenz 2024-03-20 14:51:19 +01:00
parent 998174b5fa
commit 17f546c777
32 changed files with 6565 additions and 43 deletions

2
.idea/.gitignore vendored
View File

@ -6,3 +6,5 @@
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# GitHub Copilot persisted chat sessions
/copilot/chatSessions

View File

@ -1,5 +1,21 @@
<?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="src/main/java" />
<option name="libDir" value="" />
<option name="encoding" value="" />
<option name="pkg" value="de.dhbw.horb.ast" />
<option name="language" value="" />
<option name="generateVisitor" value="true" />
</PerGrammarGenerationSettings>
</list>
</option>
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">

View File

@ -2,7 +2,7 @@
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources" isTestSource="false" generated="true" />
</content>
</component>
</module>

78
gen/Decaf.interp Normal file
View 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
gen/Decaf.tokens Normal file
View 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

375
gen/DecafBaseListener.java Normal file
View File

@ -0,0 +1,375 @@
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/LearningANTLR/UeBung2/AntlrAssignment3/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
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) { }
}

210
gen/DecafBaseVisitor.java Normal file
View File

@ -0,0 +1,210 @@
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/LearningANTLR/UeBung2/AntlrAssignment3/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
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
gen/DecafLexer.interp Normal file
View 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]

209
gen/DecafLexer.java Normal file
View File

@ -0,0 +1,209 @@
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/LearningANTLR/UeBung2/AntlrAssignment3/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
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
gen/DecafLexer.tokens Normal file
View 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

315
gen/DecafListener.java Normal file
View File

@ -0,0 +1,315 @@
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/LearningANTLR/UeBung2/AntlrAssignment3/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
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);
}

1638
gen/DecafParser.java Normal file

File diff suppressed because it is too large Load Diff

193
gen/DecafVisitor.java Normal file
View File

@ -0,0 +1,193 @@
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/LearningANTLR/UeBung2/AntlrAssignment3/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
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);
}

View File

@ -28,7 +28,14 @@ public class ASTGenerator {
}
public static Function generateFunc(DecafParser.FuncContext ctx) {
throw new RuntimeException("TODO");
List<Variable> variableList = new ArrayList<>();
if (ctx.params() != null){
for (DecafParser.ParamContext paramContext : ctx.params().param()) {
variableList.add(new Variable(paramContext.id().getText(),getType(paramContext.type())));
}
}
StatementGenerator statementGenerator = new StatementGenerator();
return new Function(getType(ctx.type()),ctx.id().getText(), variableList, statementGenerator.generateBlock(ctx.block()));
}
public static Type getType(DecafParser.TypeContext ctx){

View File

@ -1,14 +1,12 @@
package de.dhbw.horb;
import de.dhbw.horb.ast.*;
import de.dhbw.horb.ast.DecafLexer;
import de.dhbw.horb.ast.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
*/

View File

@ -2,54 +2,73 @@ package de.dhbw.horb;
import de.dhbw.horb.ast.*;
public class ExpressionGenerator extends de.dhbw.horb.DecafBaseVisitor<Expression> {
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
@Override
public Expression visitBinaryOperation(de.dhbw.horb.DecafParser.BinaryOperationContext ctx) {
public Expression visitBinaryOperation(DecafParser.BinaryOperationContext ctx) {
return generateBinary(ctx);
}
@Override
public Expression visitFunCallExpression(de.dhbw.horb.DecafParser.FunCallExpressionContext ctx) {
throw new RuntimeException("TODO");
public Expression visitFunCallExpression(DecafParser.FunCallExpressionContext ctx) {
return generateFuncCallExpression(ctx);
}
@Override
public Expression visitConstant(de.dhbw.horb.DecafParser.ConstantContext ctx) {
public Expression visitConstant(DecafParser.ConstantContext ctx) {
return generateConstant(ctx.literal());
}
@Override
public Expression visitExpression(de.dhbw.horb.DecafParser.ExpressionContext ctx) {
public Expression visitExpression(DecafParser.ExpressionContext ctx) {
//ParseTree for ( expr )
//Just pass it down to the inner expr:
return this.visit(ctx.expr());
}
@Override
public Expression visitLocation(de.dhbw.horb.DecafParser.LocationContext ctx) {
public Expression visitLocation(DecafParser.LocationContext ctx) {
return generateLocation(ctx.loc());
}
public static Expression generateConstant(de.dhbw.horb.DecafParser.LiteralContext ctx){
public static Expression generateConstant(DecafParser.LiteralContext ctx){
if(ctx.number() != null)
return new IntConstant(Integer.valueOf(ctx.number().getText()));
if(ctx.boolean_() != null)
return new BoolConstant(Boolean.valueOf(ctx.boolean_().getText()));
throw new RuntimeException();
}
public static Operator generateOperator(de.dhbw.horb.DecafParser.BinaryOpContext ctx){
public Expression generateFuncCallExpression(DecafParser.FunCallExpressionContext ctx){
return new FunctionCall(ctx.funcCall().id().getText(), generateArgs(ctx.funcCall().args()));
}
public List<Expression> generateArgs(DecafParser.ArgsContext args) {
if(args == null){
return Collections.emptyList();
}
List<Expression> expressionList = new ArrayList<>();
for (DecafParser.ExprContext exprContext : args.expr()) {
expressionList.add(exprContext.accept(this));
}
return expressionList;
}
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(de.dhbw.horb.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(de.dhbw.horb.DecafParser.LocContext loc) {
public static Location generateLocation(DecafParser.LocContext loc) {
return new Location(loc.id().getText());
}
}

View File

@ -3,42 +3,81 @@ package de.dhbw.horb;
import de.dhbw.horb.ast.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static de.dhbw.horb.ASTGenerator.generateVariable;
public class StatementGenerator extends DecafBaseVisitor<Statement> {
@Override
public Statement visitAssign(DecafParser.AssignContext ctx) {
throw new RuntimeException("TODO");
ExpressionGenerator eGen = new ExpressionGenerator();
return new Assignment(ExpressionGenerator.generateLocation(ctx.loc()), ctx.expr().accept(eGen));
}
@Override
public Statement visitFunctionCall(DecafParser.FunctionCallContext ctx) {
ExpressionGenerator eGen = new ExpressionGenerator();
return new FunctionCall(ctx.funcCall().id().getText(), eGen.generateArgs(ctx.funcCall().args()));
}
@Override
public Statement visitIf(DecafParser.IfContext ctx) {
throw new RuntimeException("TODO");
ExpressionGenerator eGen = new ExpressionGenerator();
if (ctx.block().size() == 2){
return new IfElse(ctx.expr().accept(eGen), generateBlock(ctx.block(0)), generateBlock(ctx.block(1)));
}
if (ctx.block().size() == 1){
return new IfElse(ctx.expr().accept(eGen), generateBlock(ctx.block(0)),
new Block(Collections.emptyList(), Collections.emptyList()));
}
throw new RuntimeException();
}
@Override
public Statement visitWhile(DecafParser.WhileContext ctx) {
throw new RuntimeException("TODO");
ExpressionGenerator eGen = new ExpressionGenerator();
return new While(ctx.expr().accept(eGen), generateBlock(ctx.block()));
}
@Override
public Statement visitReturn(DecafParser.ReturnContext ctx) {
throw new RuntimeException("TODO");
ExpressionGenerator eGen = new ExpressionGenerator();
return new Return(ctx.expr().accept(eGen));
}
@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();
}
public Block generateBlock(DecafParser.BlockContext block) {
List<Variable> variableList = new ArrayList<>();
List<Statement> statementList = new ArrayList<>();
for (DecafParser.VarContext varContext : block.var()) {
variableList.add(generateVariable(varContext));
}
for (DecafParser.StmtContext stmtContext : block.stmt()) {
statementList.add(generateStatement(stmtContext));
}
return new Block(variableList, statementList);
}
private Statement generateStatement(DecafParser.StmtContext stmtContext) {
return stmtContext.accept(this);
}
}

View 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]

View 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

View File

@ -0,0 +1,376 @@
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/LearningANTLR/UeBung2/AntlrAssignment3/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
package de.dhbw.horb.ast;
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) { }
}

View File

@ -0,0 +1,211 @@
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/LearningANTLR/UeBung2/AntlrAssignment3/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
package de.dhbw.horb.ast;
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); }
}

View 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]

View File

@ -0,0 +1,210 @@
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/LearningANTLR/UeBung2/AntlrAssignment3/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
package de.dhbw.horb.ast;
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);
}
}
}

View 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

View File

@ -0,0 +1,316 @@
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/LearningANTLR/UeBung2/AntlrAssignment3/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
package de.dhbw.horb.ast;
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);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,194 @@
// Generated from C:/Users/laure/Documents/Dev/Compilerbau/LearningANTLR/UeBung2/AntlrAssignment3/src/main/antlr4/de/dhbw/horb/Decaf.g4 by ANTLR 4.13.1
package de.dhbw.horb.ast;
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);
}

View File

@ -2,6 +2,5 @@ package de.dhbw.horb.ast;
import java.util.List;
public record Function(Type type, String name, List<Variable> params,
Block block) implements Node {
public record Function(Type type, String name, List<Variable> params, Block block) implements Node {
}

View File

@ -2,5 +2,5 @@ package de.dhbw.horb.ast;
import java.util.List;
public record FunctionCall(String name, List<Expression> args) implements Expression {
public record FunctionCall(String name, List<Expression> args) implements Expression, Statement {
}

View File

@ -1,4 +1,4 @@
package de.dhbw.horb.ast;
public sealed interface Statement extends Node permits Assignment, VoidFunctionCall, IfElse, While, Return, ReturnVoid, Break, Continue {
public sealed interface Statement extends Node permits Assignment, VoidFunctionCall, IfElse, While, Return, ReturnVoid, Break, Continue, FunctionCall {
}

View File

@ -1,10 +1,10 @@
package de.dhbw.horb;
import static org.junit.Assert.assertTrue;
import de.dhbw.horb.ast.Program;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
/**
* Unit test for simple App.
*/
@ -16,16 +16,17 @@ public class CompilerTest
@Test
public void generateASTTest()
{
String inputString = "def int add(int x, int y)\n" +
"{\n" +
"return x + y;\n" +
"}\n" +
"def int main()\n" +
"{\n" +
"int a;\n" +
"a = 3;\n" +
"return add(a, 2);\n" +
"}";
String inputString = """
def int add(int x, int y)
{
return x + y;
}
def int main()
{
int a;
a = 3;
return add(a, 2);
}""";
Program ast = Compiler.generateAST(inputString);
assertTrue( ast.methods().size() == 2 );
}

View File

@ -6,6 +6,7 @@ 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;
/**
@ -18,7 +19,29 @@ public class StatementGeneratorTest
{
Statement whileStmt = generateStatement("while(true){}");
assertTrue(whileStmt instanceof While);
assertTrue( ((While) whileStmt).block().stmts().size() == 0);
assertEquals(0, ((While) whileStmt).block().stmts().size());
}
@Test
public void ifTest()
{
Statement ifStmt = generateStatement("if(x+3){}");
assertTrue(ifStmt instanceof IfElse);
assertEquals(0, ((IfElse) ifStmt).elseBlock().stmts().size());
}
@Test
public void ifElseTest()
{
Statement ifStmt = generateStatement("if(x+3){} else {int b;}");
assertTrue(ifStmt instanceof IfElse);
assertEquals(1, ((IfElse) ifStmt).elseBlock().vars().size());
}
@Test
public void functionCallTest()
{
Statement funcStmt = generateStatement("m(x,y);");
assertTrue(funcStmt instanceof FunctionCall);
assertEquals("m", ((FunctionCall) funcStmt).name());
assertEquals(2, ((FunctionCall) funcStmt).args().size());
}
private Statement generateStatement(String from){
@ -27,6 +50,6 @@ public class StatementGeneratorTest
DecafLexer lexer = new DecafLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
DecafParser parser = new DecafParser(tokens);
return new StatementGenerator().visit(parser.stmt());
return parser.stmt().accept(new StatementGenerator());
}
}