Add java code and test cases
This commit is contained in:
15
parser/pom.xml
Normal file
15
parser/pom.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>compiler</artifactId>
|
||||
<groupId>org.example</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>parser</artifactId>
|
||||
|
||||
|
||||
</project>
|
@ -0,0 +1,52 @@
|
||||
token literal names:
|
||||
null
|
||||
';'
|
||||
'/'
|
||||
'*'
|
||||
'-'
|
||||
'+'
|
||||
'int'
|
||||
'='
|
||||
'print('
|
||||
')'
|
||||
'('
|
||||
'{'
|
||||
'return'
|
||||
'}'
|
||||
null
|
||||
null
|
||||
null
|
||||
|
||||
token symbolic names:
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
IDENTIFIER
|
||||
NUMBER
|
||||
WHITESPACE
|
||||
|
||||
rule names:
|
||||
program
|
||||
programPart
|
||||
statement
|
||||
expression
|
||||
varDeclaration
|
||||
assignment
|
||||
print
|
||||
functionDefinition
|
||||
functionCall
|
||||
|
||||
|
||||
atn:
|
||||
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 18, 85, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 3, 2, 6, 2, 22, 10, 2, 13, 2, 14, 2, 23, 3, 3, 3, 3, 3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 40, 38, 3, 2, 2, 2, 40, 39, 3, 2, 2, 2, 41, 56, 3, 2, 2, 2, 42, 43, 12, 9, 2, 2, 43, 44, 7, 4, 2, 2, 44, 55, 5, 8, 5, 10, 45, 46, 12, 8, 2, 2, 46, 47, 7, 5, 2, 2, 47, 55, 5, 8, 5, 9, 48, 49, 12, 7, 2, 2, 49, 50, 7, 6, 2, 2, 50, 55, 5, 8, 5, 8, 51, 52, 12, 6, 2, 2, 52, 53, 7, 7, 2, 2, 53, 55, 5, 8, 5, 7, 54, 42, 3, 2, 2, 2, 54, 45, 3, 2, 2, 2, 54, 48, 3, 2, 2, 2, 54, 51, 3, 2, 2, 2, 55, 58, 3, 2, 2, 2, 56, 54, 3, 2, 2, 2, 56, 57, 3, 2, 2, 2, 57, 9, 3, 2, 2, 2, 58, 56, 3, 2, 2, 2, 59, 60, 7, 8, 2, 2, 60, 61, 7, 16, 2, 2, 61, 11, 3, 2, 2, 2, 62, 63, 7, 16, 2, 2, 63, 64, 7, 9, 2, 2, 64, 65, 5, 8, 5, 2, 65, 13, 3, 2, 2, 2, 66, 67, 7, 10, 2, 2, 67, 68, 5, 8, 5, 2, 68, 69, 7, 11, 2, 2, 69, 15, 3, 2, 2, 2, 70, 71, 7, 8, 2, 2, 71, 72, 7, 16, 2, 2, 72, 73, 7, 12, 2, 2, 73, 74, 7, 11, 2, 2, 74, 75, 7, 13, 2, 2, 75, 76, 7, 14, 2, 2, 76, 77, 5, 8, 5, 2, 77, 78, 7, 3, 2, 2, 78, 79, 7, 15, 2, 2, 79, 17, 3, 2, 2, 2, 80, 81, 7, 16, 2, 2, 81, 82, 7, 12, 2, 2, 82, 83, 7, 11, 2, 2, 83, 19, 3, 2, 2, 2, 8, 23, 29, 34, 40, 54, 56]
|
@ -0,0 +1,50 @@
|
||||
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
|
||||
T__16=17
|
||||
T__17=18
|
||||
T__18=19
|
||||
T__19=20
|
||||
T__20=21
|
||||
T__21=22
|
||||
T__22=23
|
||||
IDENTIFIER=24
|
||||
NUMBER=25
|
||||
WHITESPACE=26
|
||||
STRING=27
|
||||
';'=1
|
||||
'if'=2
|
||||
'('=3
|
||||
')'=4
|
||||
'else'=5
|
||||
'{'=6
|
||||
'}'=7
|
||||
'/'=8
|
||||
'*'=9
|
||||
'-'=10
|
||||
'+'=11
|
||||
'<'=12
|
||||
'<='=13
|
||||
'>'=14
|
||||
'>='=15
|
||||
'&&'=16
|
||||
'||'=17
|
||||
'int'=18
|
||||
'='=19
|
||||
'println('=20
|
||||
'print('=21
|
||||
'return'=22
|
||||
','=23
|
@ -0,0 +1,196 @@
|
||||
// Generated from /home/thibaud/Programmation/Java/antlr-compiler/Demo.g4 by ANTLR 4.7
|
||||
package de.letsbuildacompiler.parser;
|
||||
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
||||
|
||||
/**
|
||||
* This class provides an empty implementation of {@link DemoVisitor},
|
||||
* which can be extended to create a visitor which only needs to handle a subset
|
||||
* of the available methods.
|
||||
*
|
||||
* @param <T> The return type of the visit operation. Use {@link Void} for
|
||||
* operations with no return type.
|
||||
*/
|
||||
public class DemoBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements DemoVisitor<T> {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitProgram(DemoParser.ProgramContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitMainStatement(DemoParser.MainStatementContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitProgPartFunctionDefinition(DemoParser.ProgPartFunctionDefinitionContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitStatement(DemoParser.StatementContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitBranch(DemoParser.BranchContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitBlock(DemoParser.BlockContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitDiv(DemoParser.DivContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitVariable(DemoParser.VariableContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitFuncCallExpression(DemoParser.FuncCallExpressionContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitOr(DemoParser.OrContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitNumber(DemoParser.NumberContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitMult(DemoParser.MultContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitAnd(DemoParser.AndContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitRelational(DemoParser.RelationalContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitString(DemoParser.StringContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitPlus(DemoParser.PlusContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitMinus(DemoParser.MinusContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitVarDeclaration(DemoParser.VarDeclarationContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitAssignment(DemoParser.AssignmentContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitPrintln(DemoParser.PrintlnContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitPrint(DemoParser.PrintContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitFunctionDefinition(DemoParser.FunctionDefinitionContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitStatementList(DemoParser.StatementListContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitParameters(DemoParser.ParametersContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitFunctionCall(DemoParser.FunctionCallContext ctx) { return visitChildren(ctx); }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation returns the result of calling
|
||||
* {@link #visitChildren} on {@code ctx}.</p>
|
||||
*/
|
||||
@Override public T visitExpressionList(DemoParser.ExpressionListContext ctx) { return visitChildren(ctx); }
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
token literal names:
|
||||
null
|
||||
';'
|
||||
'/'
|
||||
'*'
|
||||
'-'
|
||||
'+'
|
||||
'int'
|
||||
'='
|
||||
'print('
|
||||
')'
|
||||
'('
|
||||
'{'
|
||||
'return'
|
||||
'}'
|
||||
null
|
||||
null
|
||||
null
|
||||
|
||||
token symbolic names:
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
IDENTIFIER
|
||||
NUMBER
|
||||
WHITESPACE
|
||||
|
||||
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
|
||||
IDENTIFIER
|
||||
NUMBER
|
||||
WHITESPACE
|
||||
|
||||
channel names:
|
||||
DEFAULT_TOKEN_CHANNEL
|
||||
HIDDEN
|
||||
|
||||
mode names:
|
||||
DEFAULT_MODE
|
||||
|
||||
atn:
|
||||
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 18, 92, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 7, 3, 7, 3, 8, 3, 8, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 10, 3, 10, 3, 11, 3, 11, 3, 12, 3, 12, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 14, 3, 14, 3, 15, 3, 15, 7, 15, 76, 10, 15, 12, 15, 14, 15, 79, 11, 15, 3, 16, 6, 16, 82, 10, 16, 13, 16, 14, 16, 83, 3, 17, 6, 17, 87, 10, 17, 13, 17, 14, 17, 88, 3, 17, 3, 17, 2, 2, 18, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 25, 14, 27, 15, 29, 16, 31, 17, 33, 18, 3, 2, 6, 4, 2, 67, 92, 99, 124, 5, 2, 50, 59, 67, 92, 99, 124, 3, 2, 50, 59, 5, 2, 11, 12, 15, 15, 34, 34, 2, 94, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 2, 25, 3, 2, 2, 2, 2, 27, 3, 2, 2, 2, 2, 29, 3, 2, 2, 2, 2, 31, 3, 2, 2, 2, 2, 33, 3, 2, 2, 2, 3, 35, 3, 2, 2, 2, 5, 37, 3, 2, 2, 2, 7, 39, 3, 2, 2, 2, 9, 41, 3, 2, 2, 2, 11, 43, 3, 2, 2, 2, 13, 45, 3, 2, 2, 2, 15, 49, 3, 2, 2, 2, 17, 51, 3, 2, 2, 2, 19, 58, 3, 2, 2, 2, 21, 60, 3, 2, 2, 2, 23, 62, 3, 2, 2, 2, 25, 64, 3, 2, 2, 2, 27, 71, 3, 2, 2, 2, 29, 73, 3, 2, 2, 2, 31, 81, 3, 2, 2, 2, 33, 86, 3, 2, 2, 2, 35, 36, 7, 61, 2, 2, 36, 4, 3, 2, 2, 2, 37, 38, 7, 49, 2, 2, 38, 6, 3, 2, 2, 2, 39, 40, 7, 44, 2, 2, 40, 8, 3, 2, 2, 2, 41, 42, 7, 47, 2, 2, 42, 10, 3, 2, 2, 2, 43, 44, 7, 45, 2, 2, 44, 12, 3, 2, 2, 2, 45, 46, 7, 107, 2, 2, 46, 47, 7, 112, 2, 2, 47, 48, 7, 118, 2, 2, 48, 14, 3, 2, 2, 2, 49, 50, 7, 63, 2, 2, 50, 16, 3, 2, 2, 2, 51, 52, 7, 114, 2, 2, 52, 53, 7, 116, 2, 2, 53, 54, 7, 107, 2, 2, 54, 55, 7, 112, 2, 2, 55, 56, 7, 118, 2, 2, 56, 57, 7, 42, 2, 2, 57, 18, 3, 2, 2, 2, 58, 59, 7, 43, 2, 2, 59, 20, 3, 2, 2, 2, 60, 61, 7, 42, 2, 2, 61, 22, 3, 2, 2, 2, 62, 63, 7, 125, 2, 2, 63, 24, 3, 2, 2, 2, 64, 65, 7, 116, 2, 2, 65, 66, 7, 103, 2, 2, 66, 67, 7, 118, 2, 2, 67, 68, 7, 119, 2, 2, 68, 69, 7, 116, 2, 2, 69, 70, 7, 112, 2, 2, 70, 26, 3, 2, 2, 2, 71, 72, 7, 127, 2, 2, 72, 28, 3, 2, 2, 2, 73, 77, 9, 2, 2, 2, 74, 76, 9, 3, 2, 2, 75, 74, 3, 2, 2, 2, 76, 79, 3, 2, 2, 2, 77, 75, 3, 2, 2, 2, 77, 78, 3, 2, 2, 2, 78, 30, 3, 2, 2, 2, 79, 77, 3, 2, 2, 2, 80, 82, 9, 4, 2, 2, 81, 80, 3, 2, 2, 2, 82, 83, 3, 2, 2, 2, 83, 81, 3, 2, 2, 2, 83, 84, 3, 2, 2, 2, 84, 32, 3, 2, 2, 2, 85, 87, 9, 5, 2, 2, 86, 85, 3, 2, 2, 2, 87, 88, 3, 2, 2, 2, 88, 86, 3, 2, 2, 2, 88, 89, 3, 2, 2, 2, 89, 90, 3, 2, 2, 2, 90, 91, 8, 17, 2, 2, 91, 34, 3, 2, 2, 2, 6, 2, 77, 83, 88, 3, 8, 2, 2]
|
160
parser/src/main/java/de/letsbuildacompiler/parser/DemoLexer.java
Normal file
160
parser/src/main/java/de/letsbuildacompiler/parser/DemoLexer.java
Normal file
@ -0,0 +1,160 @@
|
||||
// Generated from /home/thibaud/Programmation/Java/antlr-compiler/Demo.g4 by ANTLR 4.7
|
||||
package de.letsbuildacompiler.parser;
|
||||
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"})
|
||||
public class DemoLexer extends Lexer {
|
||||
static { RuntimeMetaData.checkVersion("4.7", 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, T__16=17,
|
||||
T__17=18, T__18=19, T__19=20, T__20=21, T__21=22, T__22=23, IDENTIFIER=24,
|
||||
NUMBER=25, WHITESPACE=26, STRING=27;
|
||||
public static String[] channelNames = {
|
||||
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
|
||||
};
|
||||
|
||||
public static String[] modeNames = {
|
||||
"DEFAULT_MODE"
|
||||
};
|
||||
|
||||
public static final String[] ruleNames = {
|
||||
"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", "T__16",
|
||||
"T__17", "T__18", "T__19", "T__20", "T__21", "T__22", "IDENTIFIER", "NUMBER",
|
||||
"WHITESPACE", "STRING"
|
||||
};
|
||||
|
||||
private static final String[] _LITERAL_NAMES = {
|
||||
null, "';'", "'if'", "'('", "')'", "'else'", "'{'", "'}'", "'/'", "'*'",
|
||||
"'-'", "'+'", "'<'", "'<='", "'>'", "'>='", "'&&'", "'||'", "'int'", "'='",
|
||||
"'println('", "'print('", "'return'", "','"
|
||||
};
|
||||
private static final String[] _SYMBOLIC_NAMES = {
|
||||
null, null, null, null, null, null, null, null, null, null, null, null,
|
||||
null, null, null, null, null, null, null, null, null, null, null, null,
|
||||
"IDENTIFIER", "NUMBER", "WHITESPACE", "STRING"
|
||||
};
|
||||
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 DemoLexer(CharStream input) {
|
||||
super(input);
|
||||
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGrammarFileName() { return "Demo.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 =
|
||||
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\35\u009e\b\1\4\2"+
|
||||
"\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4"+
|
||||
"\13\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22"+
|
||||
"\t\22\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31"+
|
||||
"\t\31\4\32\t\32\4\33\t\33\4\34\t\34\3\2\3\2\3\3\3\3\3\3\3\4\3\4\3\5\3"+
|
||||
"\5\3\6\3\6\3\6\3\6\3\6\3\7\3\7\3\b\3\b\3\t\3\t\3\n\3\n\3\13\3\13\3\f\3"+
|
||||
"\f\3\r\3\r\3\16\3\16\3\16\3\17\3\17\3\20\3\20\3\20\3\21\3\21\3\21\3\22"+
|
||||
"\3\22\3\22\3\23\3\23\3\23\3\23\3\24\3\24\3\25\3\25\3\25\3\25\3\25\3\25"+
|
||||
"\3\25\3\25\3\25\3\26\3\26\3\26\3\26\3\26\3\26\3\26\3\27\3\27\3\27\3\27"+
|
||||
"\3\27\3\27\3\27\3\30\3\30\3\31\3\31\7\31\u0085\n\31\f\31\16\31\u0088\13"+
|
||||
"\31\3\32\6\32\u008b\n\32\r\32\16\32\u008c\3\33\6\33\u0090\n\33\r\33\16"+
|
||||
"\33\u0091\3\33\3\33\3\34\3\34\7\34\u0098\n\34\f\34\16\34\u009b\13\34\3"+
|
||||
"\34\3\34\3\u0099\2\35\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27"+
|
||||
"\r\31\16\33\17\35\20\37\21!\22#\23%\24\'\25)\26+\27-\30/\31\61\32\63\33"+
|
||||
"\65\34\67\35\3\2\6\4\2C\\c|\5\2\62;C\\c|\3\2\62;\5\2\13\f\17\17\"\"\2"+
|
||||
"\u00a1\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2"+
|
||||
"\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3"+
|
||||
"\2\2\2\2\31\3\2\2\2\2\33\3\2\2\2\2\35\3\2\2\2\2\37\3\2\2\2\2!\3\2\2\2"+
|
||||
"\2#\3\2\2\2\2%\3\2\2\2\2\'\3\2\2\2\2)\3\2\2\2\2+\3\2\2\2\2-\3\2\2\2\2"+
|
||||
"/\3\2\2\2\2\61\3\2\2\2\2\63\3\2\2\2\2\65\3\2\2\2\2\67\3\2\2\2\39\3\2\2"+
|
||||
"\2\5;\3\2\2\2\7>\3\2\2\2\t@\3\2\2\2\13B\3\2\2\2\rG\3\2\2\2\17I\3\2\2\2"+
|
||||
"\21K\3\2\2\2\23M\3\2\2\2\25O\3\2\2\2\27Q\3\2\2\2\31S\3\2\2\2\33U\3\2\2"+
|
||||
"\2\35X\3\2\2\2\37Z\3\2\2\2!]\3\2\2\2#`\3\2\2\2%c\3\2\2\2\'g\3\2\2\2)i"+
|
||||
"\3\2\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
||||
"\3\2\2\2\u0088\u0086\3\2\2\2\u0089\u008b\t\4\2\2\u008a\u0089\3\2\2\2\u008b"+
|
||||
"\u008c\3\2\2\2\u008c\u008a\3\2\2\2\u008c\u008d\3\2\2\2\u008d\64\3\2\2"+
|
||||
"\2\u008e\u0090\t\5\2\2\u008f\u008e\3\2\2\2\u0090\u0091\3\2\2\2\u0091\u008f"+
|
||||
"\3\2\2\2\u0091\u0092\3\2\2\2\u0092\u0093\3\2\2\2\u0093\u0094\b\33\2\2"+
|
||||
"\u0094\66\3\2\2\2\u0095\u0099\7$\2\2\u0096\u0098\13\2\2\2\u0097\u0096"+
|
||||
"\3\2\2\2\u0098\u009b\3\2\2\2\u0099\u009a\3\2\2\2\u0099\u0097\3\2\2\2\u009a"+
|
||||
"\u009c\3\2\2\2\u009b\u0099\3\2\2\2\u009c\u009d\7$\2\2\u009d8\3\2\2\2\7"+
|
||||
"\2\u0086\u008c\u0091\u0099\3\b\2\2";
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
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
|
||||
T__16=17
|
||||
T__17=18
|
||||
T__18=19
|
||||
T__19=20
|
||||
T__20=21
|
||||
T__21=22
|
||||
T__22=23
|
||||
IDENTIFIER=24
|
||||
NUMBER=25
|
||||
WHITESPACE=26
|
||||
STRING=27
|
||||
';'=1
|
||||
'if'=2
|
||||
'('=3
|
||||
')'=4
|
||||
'else'=5
|
||||
'{'=6
|
||||
'}'=7
|
||||
'/'=8
|
||||
'*'=9
|
||||
'-'=10
|
||||
'+'=11
|
||||
'<'=12
|
||||
'<='=13
|
||||
'>'=14
|
||||
'>='=15
|
||||
'&&'=16
|
||||
'||'=17
|
||||
'int'=18
|
||||
'='=19
|
||||
'println('=20
|
||||
'print('=21
|
||||
'return'=22
|
||||
','=23
|
1317
parser/src/main/java/de/letsbuildacompiler/parser/DemoParser.java
Normal file
1317
parser/src/main/java/de/letsbuildacompiler/parser/DemoParser.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,182 @@
|
||||
// Generated from /home/thibaud/Programmation/Java/antlr-compiler/Demo.g4 by ANTLR 4.7
|
||||
package de.letsbuildacompiler.parser;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
||||
|
||||
/**
|
||||
* This interface defines a complete generic visitor for a parse tree produced
|
||||
* by {@link DemoParser}.
|
||||
*
|
||||
* @param <T> The return type of the visit operation. Use {@link Void} for
|
||||
* operations with no return type.
|
||||
*/
|
||||
public interface DemoVisitor<T> extends ParseTreeVisitor<T> {
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DemoParser#program}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitProgram(DemoParser.ProgramContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code MainStatement}
|
||||
* labeled alternative in {@link DemoParser#programPart}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitMainStatement(DemoParser.MainStatementContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code ProgPartFunctionDefinition}
|
||||
* labeled alternative in {@link DemoParser#programPart}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitProgPartFunctionDefinition(DemoParser.ProgPartFunctionDefinitionContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DemoParser#statement}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitStatement(DemoParser.StatementContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DemoParser#branch}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitBranch(DemoParser.BranchContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DemoParser#block}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitBlock(DemoParser.BlockContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Div}
|
||||
* labeled alternative in {@link DemoParser#expression}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitDiv(DemoParser.DivContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Variable}
|
||||
* labeled alternative in {@link DemoParser#expression}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitVariable(DemoParser.VariableContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code FuncCallExpression}
|
||||
* labeled alternative in {@link DemoParser#expression}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitFuncCallExpression(DemoParser.FuncCallExpressionContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Or}
|
||||
* labeled alternative in {@link DemoParser#expression}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitOr(DemoParser.OrContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Number}
|
||||
* labeled alternative in {@link DemoParser#expression}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitNumber(DemoParser.NumberContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Mult}
|
||||
* labeled alternative in {@link DemoParser#expression}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitMult(DemoParser.MultContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code And}
|
||||
* labeled alternative in {@link DemoParser#expression}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitAnd(DemoParser.AndContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Relational}
|
||||
* labeled alternative in {@link DemoParser#expression}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitRelational(DemoParser.RelationalContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code String}
|
||||
* labeled alternative in {@link DemoParser#expression}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitString(DemoParser.StringContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Plus}
|
||||
* labeled alternative in {@link DemoParser#expression}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitPlus(DemoParser.PlusContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by the {@code Minus}
|
||||
* labeled alternative in {@link DemoParser#expression}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitMinus(DemoParser.MinusContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DemoParser#varDeclaration}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitVarDeclaration(DemoParser.VarDeclarationContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DemoParser#assignment}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitAssignment(DemoParser.AssignmentContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DemoParser#println}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitPrintln(DemoParser.PrintlnContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DemoParser#print}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitPrint(DemoParser.PrintContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DemoParser#functionDefinition}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitFunctionDefinition(DemoParser.FunctionDefinitionContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DemoParser#statementList}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitStatementList(DemoParser.StatementListContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DemoParser#parameters}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitParameters(DemoParser.ParametersContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DemoParser#functionCall}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitFunctionCall(DemoParser.FunctionCallContext ctx);
|
||||
/**
|
||||
* Visit a parse tree produced by {@link DemoParser#expressionList}.
|
||||
* @param ctx the parse tree
|
||||
* @return the visitor result
|
||||
*/
|
||||
T visitExpressionList(DemoParser.ExpressionListContext ctx);
|
||||
}
|
Reference in New Issue
Block a user