Compare commits

..

No commits in common. "main" and "johns-branch" have entirely different histories.

143 changed files with 2558 additions and 5186 deletions

8
.gitignore vendored
View File

@ -77,10 +77,10 @@ fabric.properties
.idea/caches/build_file_checksums.ser
/target
src/main/resources/logs/miniCompilerLog.log
src/test/java/main/CompilerInput.class
src/main/resources/logs/RaupenLog.log
src/main/resources/output/CompilerInput.class
src/test/resources/output/javac/CompilerInput$Test.class
src/test/resources/output/javac/CompilerInput.class
src/test/resources/output/miniCompiler/CompilerInput.class
src/test/resources/output/miniCompiler/CompilerInput$Test.class
src/test/resources/output/raupenpiler/CompilerInput.class
src/test/resources/output/raupenpiler/CompilerInput$Test.class
.idea/inspectionProfiles/Project_Default.xml

58
.lib/Kurzdokumentation.md Normal file
View File

@ -0,0 +1,58 @@
# Kurzdokumentation
## Aufgabenverteilung
### Maximilian Stahl und Jannik Rombach:
- **Scanner**
- **Parser**
- **AST**
- **AstBuilder**
- **Modul: ast**
- Alle
- **Modul: parser**
- Alle
- **Modul: visitor**
- Alle
- **Testmodul: parser**
- AstBuildertest.java
- Helper.java
- **Testfiles: singleFeatureTests**
- Alle
### Johannes Ehlert:
- **Semantische Analyse**
- **Modul: semantic**
- **Modul: typecheck**
- **Testmodul: parser**
- AstBuildertest.java
- **Testfiles: typedAstFeatureTests**
- Großteil
- **Testfiles: typedAstExceptionsTests**
- Großteil
### David Große:
- **Bytecodegenerator**
- **Modul: bytecode**
- Alle
### Lucas Janker:
- **Tests**
- **Modul: main**
- Alle
- **Testmodul: main**
- Alle
- **Testmodul: parser**
- ScannerTest.java
- ParserTest.java
- **Testmodul: semantic**
- **Testfiles: combinedFeatureTests**
- Alle
- **Testfiles: failureTests**
- Alle
- **Testfiles: Alle**
- Refactoring
- **Ordnerstrukturen**
- Großteil
- **Build**
- **Makefile**
- **Dokumentation**

View File

@ -1,37 +0,0 @@
### IntelliJs play buttons do not work. Run in "src/test" folder with "make" command to run all
### Or run only parts with "make compile-javac", "make clean" etc.
all: compile-javac compile-miniCompiler
compile-javac:
#javac -d src/test/resources/output/javac src/test/resources/input/CompilerInput.java
compile-miniCompiler:
cd ../.. ; mvn -DskipTests install
cd ../.. ; mvn exec:java -DgenJar=true -DgenClass=true -Dexec.mainClass="main.Main" -Dexec.args="'src/main/resources/input/CompilerInput.java' 'src/main/resources/output'"
# cp src/main/resources/output/CompilerInput.class src/test/resources/output/miniCompiler
test-miniCompiler:
# move the compiled class to the test/main folder
mv src/main/resources/output/CompilerInput.class src/test/java/main/
# compile the test class
javac src/test/java/main/EndToEndTester.java
# run the test class
java -cp src/test/java/main EndToEndTester
clean:
# clean main output folders
rm -f src/main/resources/output/*.class
rm -f src/main/resources/output/*.jar
# clean resources output folders
rm -f src/test/resources/output/javac/*.class
rm -f src/test/resources/output/miniCompiler/*.class
rm -f src/test/resources/output/miniCompiler/*.jar
# clean logs
rm -f src/main/resources/logs/*
# clean test/java/main folders from .class files for End-to-End tests
rm -f src/test/java/main/*.class
# clean javac output from every folder
rm -f src/test/resources/input/*/*.class
# clean test results from maven surefire plugin
rm -f ../../target/surefire-reports/*.txt

Binary file not shown.

136
README.md
View File

@ -1,136 +0,0 @@
# "Nicht Haskel 2.0" Java Compiler
Realisation of a subset of the Java Standard Compiler in the course Compiler Construction of the 4th semester Computer Science at the Duale Hochschule Stuttgart (Horb).
This project aims to provide a simplified version of the Java compiler, focusing on key language features and demonstrating the principles of compiler construction.
## Realised Java syntax
- **Data types**: `int`, `boolean`, `char`
- **Access modifier**: `public`, `protected`, `private`
- **Operators**: `=` `+` `-` `*` `%` `/` `>` `<` `>=` `<=` `==` `!=` `!` `&&` `||` `++` `--`
- **Keywords**: `class`, `this`, `while`, `do`, `if`, `else`, `for`, `return`, `new`, `switch`, `case`, `break`, `default`, `:`
- **Statements**:
- `if` ... `if else` ... `else`;
- `while` ... ;
- `do` ... `while`;
- `for`;
- **Comments**:
- Single line: `// comment`
- Multi-line: `/* comment */`
- **Further functions**:
- All methods are overloadable
- High maintainability and expandability through implementation of the visitor pattern
- Logging Input and Outputs
- Error Handling in the Semantic Check
## Project Structure
```plain
src/
└── main/
├── java/
│ ├── ast/ -> Defining the structure of the AST
│ ├── bytecode/ -> Generate Java bytecode
│ ├── main/ -> Running the compiler
│ ├── parser/
│ │ ├── astBuilder/ -> Builder creating the AST
│ │ ├── generated/ -> Antlr generated grammar
│ │ └── grammar/ -> Antlr grammar
│ ├── semantic/ -> Running the semantic check
│ └── visitor/ -> Visitor interface
└── resources/
test/
└── java/
│ ├── main/ -> Running E2E tests
│ ├── parser/ -> Performs tests on the parser
│ ├── semantic/ -> Performs tests on the semantic check
└── resources/ -> Ressources for running the Tests
```
## Class-Diagramm AST
![AST Diagramm](ast.png)
## Distribution of the realisation
### i22030 & i22035
Ausführliche Beschreibung der Parser Umsetzung:
![Parserumsetzung](Parser_Dokumentation.pdf)
Parser:
- Grammar -> (src/main/java/parser/grammar)
- Scanner
- Parser
- Abstract Syntax Tree (AST) -> (src/main/java/ast)
- AstBuilder -> (src/main/java/parser/astBuilder)
Parser tests:
- ParserTests -> (src/test/java/parser)
- TestCases -> (src/test/resources/input/singeFeatureTests)
Other:
- Documentation -> (README.md)
- Ast Class-Diagramm -> (ast.png)
- PowerPoint
### i22005
Semantic check:
- Set all types and check whether types have been used correctly
- Contexts -> (src/main/java/semantic/context)
- Exceptions Handling -> (src/main/java/semantic/exceptions)
Semantic Tests:
- Typing and Type checking -> (src/test/java/semantic/EndToTypedAstTest)
- Exception and feature test -> (src/test/resources/input/typedAstExceptionsTests)
### i22007
Bytecode generation:
- Complete bytecode generation -> (src/mein/java/bytecode)
### i22011
Tests and execution:
- Makefile
- Running Compiler -> (src/main/main)
- Running E2E tests -> (src/test/main)
- Typing and Type checking -> (src/test/java/semantic/EndToTypedAstTest)
## Used Tools
- [Maven 4.0](https://maven.apache.org/index.html)
- Used for automating the build process and managing dependencies.
- [ANTLR4 v.13.1](https://www.antlr.org/)
- Used to parse the input Java code into the Abstract Syntax Tree.
## How to run the compiler
### Possibilities
### 1. Start miniCompiler using make:
Make needs to be installed
```bash
cd .\src\test\ ; make clean compile-miniCompiler
```
### 2. Start miniCompiler using jar:
If you do not have the .jar, download it [here](https://gitea.hb.dhbw-stuttgart.de/i22005/NichtHaskell2.0/src/branch/main/JavaCompiler-1.0-jar-with-dependencies.jar) or compile it using mvn package or make first
```
java.exe -DgenJar=bool -DgenClass=bool -jar path_to_jar\jarName.jar 'path_to_input_file.java' 'path_to_output_directory'
```
Example (jar needs to be in the target directory)
```bash
java.exe -DgenJar=true -DgenClass=true -jar .\target\JavaCompiler-1.0-jar-with-dependencies.jar 'src/main/resources/input/CompilerInput.java' 'src/main/resources/output'
```
- set DgenJar true, to generate the jar, false for no jar
```
DgenJar=true
```
- set DgenClass true, to generate class files, false for no class files
```
DgenClass=true
```

BIN
ast.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

35
pom.xml
View File

@ -23,24 +23,6 @@
<version>5.11.0-M2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-engine</artifactId>
<version>1.11.0-M2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.0-M2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
@ -62,6 +44,18 @@
<version>3.26.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.0-M2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@ -71,11 +65,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version> <!-- Change the version as needed -->
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>

View File

@ -1,6 +1,20 @@
package ast;
import bytecode.visitor.ClassVisitor;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public interface ASTNode {
//Todo: @BruderJohn & @i22007 Interface anwenden + geeignetetn Methodename.
/*
Typecheck:
public TypeCheckResult acceptType(SemanticVisitor visitor);
Bytecode:
public void accepByteCode(ClassVisitor classVisitor);
*/
}

View File

@ -1,11 +1,12 @@
package ast;
import ast.type.AccessModifierNode;
import ast.members.ConstructorNode;
import ast.members.MemberNode;
import ast.members.MethodNode;
import bytecode.visitor.ClassVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;
@ -16,11 +17,11 @@ public class ClassNode implements ASTNode, Visitable {
public String identifier;
public List<MemberNode> members = new ArrayList<>();
public ClassNode() {
public ClassNode(){
}
public ClassNode(String accessType, String identifier) {
public ClassNode(String accessType, String identifier){
this.accessType = new AccessModifierNode(accessType);
this.identifier = identifier;
}
@ -29,7 +30,7 @@ public class ClassNode implements ASTNode, Visitable {
members.add(member);
}
public List<MethodNode> getMethods() {
public List<MethodNode> getMethods(){
List<MethodNode> methods = new ArrayList<>();
for (MemberNode member : members) {
if (member instanceof MethodNode methodNode) {

View File

@ -2,7 +2,7 @@ package ast;
import bytecode.visitor.ProgramVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;

View File

@ -4,12 +4,12 @@ import ast.expressions.IExpressionNode;
import ast.type.type.*;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import visitor.Visitable;
public class BinaryNode implements IExpressionNode, Visitable {
public ITypeNode typeNode;
private ITypeNode typeNode;
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {

View File

@ -1,13 +1,15 @@
package ast.expressions.binaryexpressions;
import ast.type.type.*;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
public class CalculationNode extends BinaryNode {
public CalculationNode calculationExpression;
public EnumLineOperator operator;
public DotNode dotExpression;
private ITypeNode typeNode;
public CalculationNode(CalculationNode calculationExpression, String operator, DotNode dotExpression) {
this.calculationExpression = calculationExpression;
@ -19,13 +21,11 @@ public class CalculationNode extends BinaryNode {
this.dotExpression = dotExpression;
}
public void setOperator(String operator) {
if (operator != null) {
if (operator.equals("+")) {
this.operator = EnumLineOperator.PLUS;
} else if (operator.equals("-")) {
this.operator = EnumLineOperator.MINUS;
}
private void setOperator(String operator) {
if(operator.equals("+")) {
this.operator = EnumLineOperator.PLUS;
} else if(operator.equals("-")) {
this.operator = EnumLineOperator.MINUS;
}
}
@ -40,4 +40,4 @@ public class CalculationNode extends BinaryNode {
methodVisitor.visit(this);
}
}
}

View File

@ -2,28 +2,30 @@ package ast.expressions.binaryexpressions;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
public class DotNode extends BinaryNode {
public DotNode dotExpression;
public EnumDotOperator operator;
public DotSubtractionNode dotSubtractionExpression;
public DotSubstractionNode dotSubstractionExpression;
public DotNode(DotNode dotExpression, String operator, DotSubtractionNode dotSubtractionExpression) {
public DotNode(DotNode dotExpression, String operator, DotSubstractionNode dotSubstractionExpression) {
this.dotExpression = dotExpression;
setOperator(operator);
this.dotSubtractionExpression = dotSubtractionExpression;
this.dotSubstractionExpression = dotSubstractionExpression;
}
public DotNode(DotSubtractionNode dotSubtractionExpression) {
this.dotSubtractionExpression = dotSubtractionExpression;
public DotNode(DotSubstractionNode dotSubstractionExpression) {
this.dotSubstractionExpression = dotSubstractionExpression;
}
public void setOperator(String operator) {
switch (operator) {
case "*" -> this.operator = EnumDotOperator.MULT;
case "/" -> this.operator = EnumDotOperator.DIV;
case "%" -> this.operator = EnumDotOperator.MOD;
private void setOperator(String operator) {
if(operator.equals("*")) {
this.operator = EnumDotOperator.MULT;
} else if(operator.equals("/")) {
this.operator = EnumDotOperator.DIV;
} else if(operator.equals("%")) {
this.operator = EnumDotOperator.MOD;
}
}

View File

@ -1,44 +1,45 @@
package ast.expressions.binaryexpressions;
import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.type.ValueNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
public class DotSubtractionNode extends BinaryNode {
public ValueNode value;
public String identifier;
public MemberAccessNode memberAccess;
public MethodCallNode methodCall;
public CalculationNode calculationExpression;
public DotSubtractionNode(ValueNode value) {
this.value = value;
}
public DotSubtractionNode(String identifier) {
this.identifier = identifier;
}
public DotSubtractionNode(MemberAccessNode memberAccess) {
this.memberAccess = memberAccess;
}
public DotSubtractionNode(MethodCallNode methodCall, CalculationNode calculationExpression) {
this.methodCall = methodCall;
this.calculationExpression = calculationExpression;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}
package ast.expressions.binaryexpressions;
import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.type.type.*;
import ast.type.ValueNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class DotSubstractionNode extends BinaryNode {
public ValueNode value;
public String identifier;
public MemberAccessNode memberAccess;
public MethodCallNode methodCall;
public CalculationNode calculationExpression;
public DotSubstractionNode(ValueNode value) {
this.value = value;
}
public DotSubstractionNode(String identifier) {
this.identifier = identifier;
}
public DotSubstractionNode(MemberAccessNode memberAccess) {
this.memberAccess = memberAccess;
}
public DotSubstractionNode(MethodCallNode methodCall, CalculationNode calculationExpression) {
this.methodCall = methodCall;
this.calculationExpression = calculationExpression;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@ -2,9 +2,10 @@ package ast.expressions.binaryexpressions;
import ast.expressions.IExpressionNode;
import ast.expressions.unaryexpressions.UnaryNode;
import ast.type.type.*;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
public class NonCalculationNode extends BinaryNode {
public UnaryNode unaryExpression;
@ -17,16 +18,23 @@ public class NonCalculationNode extends BinaryNode {
this.expression = expression;
}
public void setOperator(String operator) {
switch (operator) {
case "&&" -> this.operator = EnumNonCalculationOperator.AND;
case "||" -> this.operator = EnumNonCalculationOperator.OR;
case ">" -> this.operator = EnumNonCalculationOperator.GREATER;
case "<" -> this.operator = EnumNonCalculationOperator.LESS;
case ">=" -> this.operator = EnumNonCalculationOperator.GREATER_EQUAL;
case "<=" -> this.operator = EnumNonCalculationOperator.LESS_EQUAL;
case "==" -> this.operator = EnumNonCalculationOperator.EQUAL;
case "!=" -> this.operator = EnumNonCalculationOperator.NOT_EQUAL;
private void setOperator(String operator) {
if(operator.equals("&&")) {
this.operator = EnumNonCalculationOperator.AND;
} else if(operator.equals("||")) {
this.operator = EnumNonCalculationOperator.OR;
} else if(operator.equals(">")) {
this.operator = EnumNonCalculationOperator.GREATER;
} else if(operator.equals("<")) {
this.operator = EnumNonCalculationOperator.LESS;
} else if(operator.equals(">=")) {
this.operator = EnumNonCalculationOperator.GREATER_EQUAL;
} else if(operator.equals("<=")) {
this.operator = EnumNonCalculationOperator.LESS_EQUAL;
} else if(operator.equals("==")) {
this.operator = EnumNonCalculationOperator.EQUAL;
} else if(operator.equals("!=")) {
this.operator = EnumNonCalculationOperator.NOT_EQUAL;
}
}

View File

@ -1,11 +1,10 @@
package ast.expressions.unaryexpressions;
import ast.ASTNode;
import ast.type.type.ITypeNode;
import bytecode.visitor.MethodVisitor;
import ast.type.type.ITypeNode;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;
@ -28,7 +27,7 @@ public class MemberAccessNode implements ASTNode, Visitable {
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@ -41,5 +40,4 @@ public class MemberAccessNode implements ASTNode, Visitable {
this.typeNode = typeNode;
}
}

View File

@ -1,12 +1,13 @@
package ast.expressions.unaryexpressions;
import ast.ASTNode;
import ast.expressions.IExpressionNode;
import ast.type.type.ITypeNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import visitor.Visitable;
public class NotNode implements IExpressionNode {
public class NotNode implements ASTNode, Visitable {
public IExpressionNode expression;
public NotNode(IExpressionNode expression) {
@ -23,13 +24,4 @@ public class NotNode implements IExpressionNode {
return null;
}
@Override
public ITypeNode getType() {
return expression.getType();
}
@Override
public void setType(ITypeNode type) {
this.expression.setType(type);
}
}
}

View File

@ -6,7 +6,7 @@ import ast.type.type.*;
import ast.type.ValueNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import java.util.Objects;
@ -18,10 +18,10 @@ public class UnaryNode implements IExpressionNode {
public NotNode notExpression;
public IStatementNode statement;
public IExpressionNode expression;
public ITypeNode type;
private ITypeNode type;
public UnaryNode(String value) {
if (Objects.equals(value, "this")) {
if(Objects.equals(value, "this")) {
this.thisExp = "this";
} else {
this.identifier = value;

View File

@ -0,0 +1,11 @@
package ast.literal;
public class BooleanLiteralNode {
private String value;
public BooleanLiteralNode(String value) {this.value = value;}
public String getValue() {
return value;
}
}

View File

@ -0,0 +1,11 @@
package ast.literal;
public class CharLiteralNode {
public String value;
public CharLiteralNode(String value) {this.value = value;}
public String getValue() {
return value;
}
}

View File

@ -0,0 +1,31 @@
package ast.literal;
import ast.expressions.IExpressionNode;
import ast.type.type.ITypeNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class LiteralNode implements IExpressionNode {
public String value;
private ITypeNode type;
public LiteralNode(String value, ITypeNode type) {
this.value = value;
this.type = type;
}
public ITypeNode getType() {
return type;
}
public void setType(ITypeNode type) {
this.type = type;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return null;
}
}

View File

@ -11,8 +11,13 @@ import java.util.List;
import java.util.Objects;
public class ConstructorNode extends MethodNode implements Visitable {
public AccessModifierNode accessType;
public String identifier;
public List<ParameterNode> parameters = new ArrayList<>();
public BlockNode block;
public ConstructorNode(String accessType, String identifier, BlockNode block) {
this.accesModifier = new AccessModifierNode(accessType);
this.accessType = new AccessModifierNode(accessType);
this.identifier = identifier;
this.block = block;
}
@ -27,7 +32,8 @@ public class ConstructorNode extends MethodNode implements Visitable {
}
public boolean isSame(MethodNode methodNode) {
if (!(Objects.equals(this.identifier, methodNode.getIdentifier())) || getParameters().size() != methodNode.getParameters().size()) {
if (!(Objects.equals(this.identifier, methodNode.getIdentifier()))
|| getParameters().size() != methodNode.getParameters().size()) {
return false;
}

View File

@ -3,8 +3,9 @@ package ast.members;
import ast.type.AccessModifierNode;
import ast.type.type.ITypeNode;
import bytecode.visitor.ClassVisitor;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import visitor.Visitable;
public class FieldNode implements MemberNode, Visitable {
@ -12,7 +13,7 @@ public class FieldNode implements MemberNode, Visitable {
public ITypeNode type;
public String identifier;
public FieldNode(AccessModifierNode accessTypeNode, ITypeNode type, String name) {
public FieldNode(AccessModifierNode accessTypeNode, ITypeNode type, String name){
this.accessTypeNode = accessTypeNode;
this.type = type;
this.identifier = name;

View File

@ -5,6 +5,7 @@ import bytecode.visitor.MethodVisitor;
import visitor.Visitable;
public class MainMethodNode extends MethodNode implements Visitable {
public BlockNode block;
public MainMethodNode(BlockNode block) {
this.block = block;

View File

@ -10,8 +10,7 @@ import ast.ASTNode;
@JsonSubTypes({
@JsonSubTypes.Type(value = MethodNode.class, name = "Method"),
@JsonSubTypes.Type(value = FieldNode.class, name = "Field")}
@JsonSubTypes.Type(value = FieldNode.class, name = "Field") }
)
public interface MemberNode extends ASTNode {
}
public interface MemberNode extends ASTNode {}

View File

@ -6,7 +6,7 @@ import ast.type.AccessModifierNode;
import ast.type.type.*;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;
@ -15,16 +15,16 @@ import java.util.Objects;
public class MethodNode implements MemberNode, Visitable {
public AccessModifierNode accesModifier;
public ITypeNode type;
private ITypeNode type;
public Boolean voidType;
public String identifier;
private String identifier;
public List<ParameterNode> parameters = new ArrayList<>();
public BlockNode block;
public MethodNode() {
}
public MethodNode(String accessModifier, ITypeNode type, Boolean voidType, String identifier, BlockNode block) {
public MethodNode(String accessModifier, ITypeNode type, Boolean voidType, String identifier, BlockNode block){
this.accesModifier = new AccessModifierNode(accessModifier);
this.type = type;
this.voidType = voidType;
@ -40,7 +40,7 @@ public class MethodNode implements MemberNode, Visitable {
return parameters;
}
public boolean isSame(MethodNode methodNode) {
public boolean isSame(MethodNode methodNode){
if (!(Objects.equals(this.identifier, methodNode.getIdentifier())) || type.equals(methodNode.type)
|| getParameters().size() != methodNode.getParameters().size()) {
return false;

View File

@ -3,7 +3,7 @@ package ast.parameters;
import ast.ASTNode;
import ast.type.type.*;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import visitor.Visitable;
public class ParameterNode implements ASTNode, Visitable {

View File

@ -0,0 +1,11 @@
package ast.statement;
import ast.statements.IStatementNode;
import java.util.List;
public class BlockStatementNode {
List<IStatementNode> statements;
public BlockStatementNode(List<IStatementNode> statements) {this.statements = statements;}
}

View File

@ -3,7 +3,7 @@ package ast.statementexpressions;
import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
public class AssignNode implements IStatementExpressionNode {
public AssignableNode assignable;

View File

@ -2,13 +2,12 @@ package ast.statementexpressions;
import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.type.type.ITypeNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
public class AssignableNode implements IStatementExpressionNode {
public String identifier;
public ITypeNode typeNode;
private ITypeNode typeNode;
public MemberAccessNode memberAccess;
@ -25,6 +24,10 @@ public class AssignableNode implements IStatementExpressionNode {
return visitor.analyze(this);
}
public ITypeNode getTypeNode() {
return typeNode;
}
public void setTypeNode(ITypeNode typeNode) {
this.typeNode = typeNode;
}

View File

@ -2,5 +2,4 @@ package ast.statementexpressions;
import ast.statements.IStatementNode;
public interface IStatementExpressionNode extends IStatementNode {
}
public interface IStatementExpressionNode extends IStatementNode {}

View File

@ -3,7 +3,7 @@ package ast.statementexpressions;
import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import java.util.ArrayList;
import java.util.List;

View File

@ -4,10 +4,10 @@ import ast.statementexpressions.AssignableNode;
import ast.statementexpressions.IStatementExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import visitor.Visitable;
public class DecrementNode implements IStatementExpressionNode, Visitable {
public class DecrementNode implements IStatementExpressionNode {
public CrementType crementType;
public AssignableNode assignableExpression;
@ -20,9 +20,4 @@ public class DecrementNode implements IStatementExpressionNode, Visitable {
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@ -4,10 +4,9 @@ import ast.statementexpressions.AssignableNode;
import ast.statementexpressions.IStatementExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import visitor.Visitable;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
public class IncrementNode implements IStatementExpressionNode, Visitable {
public class IncrementNode implements IStatementExpressionNode {
public CrementType crementType;
public AssignableNode assignableExpression;
@ -20,9 +19,4 @@ public class IncrementNode implements IStatementExpressionNode, Visitable {
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@ -4,7 +4,7 @@ import ast.ASTNode;
import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;
@ -22,6 +22,11 @@ public class ChainedMethodNode implements ASTNode, Visitable {
expressions.add(expression);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return null;

View File

@ -2,17 +2,15 @@ package ast.statementexpressions.methodcallstatementnexpressions;
import ast.expressions.IExpressionNode;
import ast.statements.IStatementNode;
import ast.type.type.ITypeNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import java.util.ArrayList;
import java.util.List;
public class MethodCallNode implements IStatementNode {
public TargetNode target;
public ITypeNode type;
public List<ChainedMethodNode> chainedMethods = new ArrayList<>();
public String identifier;
public List<IExpressionNode> parameters = new ArrayList<>();

View File

@ -3,8 +3,9 @@ package ast.statementexpressions.methodcallstatementnexpressions;
import ast.ASTNode;
import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.statementexpressions.NewDeclarationNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import visitor.Visitable;
public class TargetNode implements ASTNode, Visitable {

View File

@ -1,8 +1,8 @@
package ast.statements;
import bytecode.visitor.MethodVisitor;
import ast.ASTNode;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import visitor.Visitable;
import java.util.ArrayList;
@ -11,8 +11,7 @@ import java.util.List;
public class BlockNode implements IStatementNode, Visitable {
public List<IStatementNode> statements = new ArrayList<>();
public BlockNode() {
}
public BlockNode() {}
public void addStatement(IStatementNode statement) {
statements.add(statement);
@ -23,9 +22,4 @@ public class BlockNode implements IStatementNode, Visitable {
return visitor.analyze(this);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
}

View File

@ -0,0 +1,10 @@
package ast.statements;
import java.util.List;
public class BlockStatementNode {
List<IStatementNode> statements;
public BlockStatementNode(List<IStatementNode> statements) {this.statements = statements;}
}

View File

@ -1,8 +1,7 @@
package ast.statements;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
public class ElseNode implements IStatementNode {
public BlockNode block;

View File

@ -1,8 +1,7 @@
package ast.statements;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import java.util.ArrayList;
import java.util.List;
@ -21,11 +20,6 @@ public class IfElseNode implements IStatementNode {
elseIfStatements.add(elseIfStament);
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);

View File

@ -2,7 +2,7 @@ package ast.statements;
import ast.expressions.IExpressionNode;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
public class IfNode implements IStatementNode {
public IExpressionNode expression;

View File

@ -4,7 +4,7 @@ import ast.expressions.IExpressionNode;
import ast.type.type.*;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
public class LocalVariableDeclarationNode implements IStatementNode {
public ITypeNode type;

View File

@ -3,14 +3,14 @@ package ast.statements;
import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
public class ReturnNode implements IStatementNode {
public IExpressionNode expression;
public Boolean voidReturn = false;
public ReturnNode(IExpressionNode expression) {
if (expression != null) {
if(expression != null) {
this.expression = expression;
} else {
voidReturn = true;

View File

@ -1,9 +1,8 @@
package ast.statements;
import ast.expressions.IExpressionNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
public class WhileNode implements IStatementNode {
public IExpressionNode expression;
@ -15,14 +14,10 @@ public class WhileNode implements IStatementNode {
}
public void test() {
return;
}
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);

View File

@ -8,7 +8,7 @@ public class AccessModifierNode {
}
private void setModifier(String accessType) {
switch (accessType) {
switch(accessType) {
case "public":
this.accessType = EnumAccessModifierNode.PUBLIC;
break;

View File

@ -3,7 +3,7 @@ package ast.type;
import ast.ASTNode;
import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
import visitor.Visitable;
public class ValueNode implements ASTNode, Visitable {

View File

@ -2,7 +2,7 @@ package ast.type.type;
public class BaseType implements ITypeNode {
public final TypeEnum typeEnum;
private TypeEnum typeEnum;
public BaseType(TypeEnum typeEnum) {
this.typeEnum = typeEnum;
@ -21,6 +21,8 @@ public class BaseType implements ITypeNode {
if (getClass() != obj.getClass())
return false;
BaseType other = (BaseType) obj;
return typeEnum == other.typeEnum;
if (typeEnum != other.typeEnum)
return false;
return true;
}
}

View File

@ -1,4 +1,5 @@
package ast.type.type;
public interface ITypeNode {
}

View File

@ -1,8 +1,8 @@
package ast.type.type;
public class ReferenceType implements ITypeNode {
public class ReferenceType implements ITypeNode{
public final String identifier;
private String identifier;
public ReferenceType(String identifier) {
this.identifier = identifier;
@ -22,8 +22,11 @@ public class ReferenceType implements ITypeNode {
return false;
ReferenceType other = (ReferenceType) obj;
if (identifier == null) {
return other.identifier == null;
} else return identifier.equals(other.identifier);
if (other.identifier != null)
return false;
} else if (!identifier.equals(other.identifier))
return false;
return true;
}

View File

@ -4,6 +4,6 @@ public enum TypeEnum {
VOID,
INT,
CHAR,
BOOL,
NULL
BOOL;
}

View File

@ -17,9 +17,9 @@ public class ByteCodeGenerator implements ProgramVisitor {
private JarOutputStream jarOutputStream;
private ByteArrayOutputStream byteArrayOutputStream;
private final String outputDirectory;
private final boolean generateJar;
private final boolean generateClassFiles;
private String outputDirectory;
private boolean generateJar;
private boolean generateClassFiles;
public ByteCodeGenerator(String outputDirectory, boolean generateJar, boolean generateClassFiles) {
this.outputDirectory = outputDirectory;

View File

@ -19,15 +19,15 @@ import java.util.jar.JarOutputStream;
public class ClassCodeGen implements ClassVisitor {
private final Mapper mapper;
private Mapper mapper;
private ClassWriter classWriter;
private final JarOutputStream jarOutputStream;
private final String outputDirectory;
private final boolean generateJar;
private final boolean generateClassFiles;
private JarOutputStream jarOutputStream;
private String outputDirectory;
private boolean generateJar;
private boolean generateClassFiles;
public ClassCodeGen(JarOutputStream jarOutputStream, String outputDirectory, boolean generateJar, boolean generateClassFiles) {
this.mapper = new Mapper();
mapper = new Mapper();
this.jarOutputStream = jarOutputStream;
this.outputDirectory = outputDirectory;
this.generateJar = generateJar;

View File

@ -3,7 +3,6 @@ package bytecode;
import ast.parameters.ParameterNode;
import ast.type.*;
import ast.type.type.BaseType;
import ast.type.type.ITypeNode;
import ast.type.type.ReferenceType;
import ast.type.type.TypeEnum;
import org.objectweb.asm.Opcodes;
@ -25,7 +24,7 @@ public class Mapper {
return 0;
}
public String generateMethodDescriptor(ITypeNode type, List<ParameterNode> parameters) {
public String generateMethodDescriptor(BaseType type, List<ParameterNode> parameters) {
String descriptor = "(";
for (ParameterNode parameterNode : parameters) {
if(parameterNode.type instanceof BaseType) {
@ -36,11 +35,7 @@ public class Mapper {
}
}
descriptor += ")";
if(type instanceof BaseType) {
descriptor += getTypeChar((BaseType) type);
} else if(type instanceof ReferenceType) {
descriptor += "L" + ((ReferenceType) type).getIdentifier() +";";
}
descriptor += getTypeChar(type);
return descriptor;
}

View File

@ -10,15 +10,14 @@ import ast.members.MainMethodNode;
import ast.members.MethodNode;
import ast.parameters.ParameterNode;
import ast.statementexpressions.AssignNode;
import ast.statementexpressions.AssignableNode;
import ast.statementexpressions.NewDeclarationNode;
import ast.statementexpressions.crementexpressions.CrementType;
import ast.statementexpressions.crementexpressions.DecrementNode;
import ast.statementexpressions.crementexpressions.IncrementNode;
import ast.statementexpressions.methodcallstatementnexpressions.ChainedMethodNode;
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
import ast.statements.*;
import ast.type.AccessModifierNode;
import ast.type.EnumAccessModifierNode;
import ast.type.ValueNode;
import ast.type.type.BaseType;
import ast.type.type.ReferenceType;
@ -36,11 +35,11 @@ import static org.objectweb.asm.Opcodes.*;
public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
private final ClassWriter classWriter;
private final Mapper mapper;
private ClassWriter classWriter;
private Mapper mapper;
private MethodVisitor methodVisitor;
private final List<String> localVariables;
private List<String> localVariables;
public MethodCodeGen(ClassWriter classWriter) {
this.classWriter = classWriter;
@ -54,7 +53,7 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
@Override
public void visit(ConstructorNode constructorNode) {
methodVisitor =
classWriter.visitMethod(mapper.mapAccessTypeToOpcode(constructorNode.accesModifier),
classWriter.visitMethod(mapper.mapAccessTypeToOpcode(constructorNode.accessType),
"<init>",
mapper.generateMethodDescriptor(new BaseType(TypeEnum.VOID), constructorNode.parameters),
null,
@ -72,7 +71,9 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
// Visit all statements
for (IStatementNode statementNode : constructorNode.block.statements) {
statementNode.accept(this);
if (statementNode != null) {
statementNode.accept(this);
}
}
methodVisitor.visitMaxs(0, 0);
@ -81,10 +82,8 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
@Override
public void visit(MainMethodNode mainMethodNode) {
AccessModifierNode accessModifierNode = new AccessModifierNode("");
accessModifierNode.accessType = EnumAccessModifierNode.PUBLIC_STATIC;
methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC,
"main",
methodVisitor = classWriter.visitMethod(mapper.mapAccessTypeToOpcode(mainMethodNode.accesModifier),
mainMethodNode.getIdentifier(),
"([Ljava/lang/String;)V",
null,
null);
@ -106,7 +105,7 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
public void visit(MethodNode methodNode) {
methodVisitor = classWriter.visitMethod(mapper.mapAccessTypeToOpcode(methodNode.accesModifier),
methodNode.getIdentifier(),
mapper.generateMethodDescriptor(methodNode.getType(), methodNode.parameters),
mapper.generateMethodDescriptor((BaseType) methodNode.getType(), methodNode.parameters),
null,
null);
@ -136,12 +135,12 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
@Override
public void visit(CalculationNode calculationNode) {
if (calculationNode.calculationExpression != null) {
calculationNode.calculationExpression.accept(this);
}
if (calculationNode.dotExpression != null) {
calculationNode.dotExpression.accept(this);
}
if (calculationNode.calculationExpression != null) {
calculationNode.calculationExpression.accept(this);
}
if (calculationNode.operator != null) {
switch (calculationNode.operator) {
case PLUS:
@ -159,8 +158,8 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
if (dotNode.dotExpression != null) {
dotNode.dotExpression.accept(this);
}
if (dotNode.dotSubtractionExpression != null) {
dotNode.dotSubtractionExpression.accept(this);
if (dotNode.dotSubstractionExpression != null) {
dotNode.dotSubstractionExpression.accept(this);
}
if (dotNode.operator != null) {
switch (dotNode.operator) {
@ -178,17 +177,17 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
}
@Override
public void visit(DotSubtractionNode dotSubtractionNode) {
if (dotSubtractionNode.value != null) {
dotSubtractionNode.value.accept(this);
} else if (dotSubtractionNode.identifier != null) {
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(dotSubtractionNode.identifier));
} else if (dotSubtractionNode.memberAccess != null) {
dotSubtractionNode.memberAccess.accept(this);
} else if (dotSubtractionNode.methodCall != null) {
dotSubtractionNode.methodCall.accept(this);
} else if (dotSubtractionNode.calculationExpression != null) {
dotSubtractionNode.calculationExpression.accept(this);
public void visit(DotSubstractionNode dotSubstractionNode) {
if (dotSubstractionNode.value != null) {
dotSubstractionNode.value.accept(this);
} else if (dotSubstractionNode.identifier != null) {
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(dotSubstractionNode.identifier));
} else if (dotSubstractionNode.memberAccess != null) {
dotSubstractionNode.memberAccess.accept(this);
} else if (dotSubstractionNode.methodCall != null) {
dotSubstractionNode.methodCall.accept(this);
} else if (dotSubstractionNode.calculationExpression != null) {
dotSubstractionNode.calculationExpression.accept(this);
}
}
@ -242,7 +241,7 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
nonCalculationNode.unaryExpression.accept(this);
nonCalculationNode.expression.accept(this);
if (nonCalculationNode.unaryExpression.getType() instanceof BaseType && nonCalculationNode.expression.getType() instanceof BaseType) {
methodVisitor.visitJumpInsn(IF_ICMPEQ, labelFalse);
methodVisitor.visitJumpInsn(IF_ACMPEQ, labelFalse);
} else {
methodVisitor.visitJumpInsn(IF_ACMPEQ, labelFalse);
}
@ -267,17 +266,9 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
@Override
public void visit(MemberAccessNode memberAccessNode) {
// Only used to get, not to put
int localVarIndex = localVariables.indexOf("memberAccessNode.identifier"); // TODO
if (localVarIndex >= 0) { // local var object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else { // this field
methodVisitor.visitVarInsn(ALOAD, 0);
}
if (memberAccessNode.getTypeNode() instanceof BaseType) {
methodVisitor.visitFieldInsn(GETFIELD, memberAccessNode.identifiers.get(0), memberAccessNode.identifiers.get(1), mapper.getTypeChar((BaseType) memberAccessNode.getTypeNode()));
} else if (memberAccessNode.getTypeNode() instanceof ReferenceType) {
methodVisitor.visitFieldInsn(GETFIELD, memberAccessNode.identifiers.get(0), memberAccessNode.identifiers.get(1), "L" + ((ReferenceType) memberAccessNode.getTypeNode()).getIdentifier() + ";");
if (memberAccessNode.thisExpr) { // Field
// methodVisitor.visitFieldInsn(GETFIELD, memberAccessNode.identifiers.get(0), memberAccessNode.identifiers.get(1), );
} else { // Object Attribut
}
}
@ -305,8 +296,9 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
public void visit(UnaryNode unaryNode) {
if (unaryNode.thisExp != null) {
methodVisitor.visitVarInsn(ALOAD, 0); // this
} else if (unaryNode.identifier != null) {
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(unaryNode.identifier));
} else if (unaryNode.memberAccess != null) {
unaryNode.memberAccess.setTypeNode(unaryNode.getType());
unaryNode.memberAccess.accept(this);
} else if (unaryNode.value != null) {
unaryNode.value.accept(this);
@ -316,25 +308,15 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
unaryNode.statement.accept(this);
} else if (unaryNode.expression != null) {
unaryNode.expression.accept(this);
} else if (unaryNode.identifier != null) {
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(unaryNode.identifier));
}
}
// Statements
@Override
public void visit(BlockNode blockNode) {
for (IStatementNode statementNode : blockNode.statements) {
statementNode.accept(this);
}
}
@Override
public void visit(IfElseNode ifElseNode) {
Label elseLabel = new Label();
Label endLabel = new Label();
Label[] elseIfLabels = new Label[ifElseNode.elseIfStatements.size()];
for (int i = 0; i < ifElseNode.elseIfStatements.size(); i++) {
@ -349,9 +331,9 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
// else if statements
methodVisitor.visitJumpInsn(IFEQ, elseIfLabels[0]);
}
ifElseNode.ifStatement.block.accept(this); // accept if block
Label endLabel = new Label();
methodVisitor.visitJumpInsn(GOTO, endLabel);
for (int i = 0; i < ifElseNode.elseIfStatements.size(); i++) {
@ -370,8 +352,6 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
if (ifElseNode.elseStatement != null) {
methodVisitor.visitLabel(elseLabel);
ifElseNode.elseStatement.block.accept(this);
} else {
methodVisitor.visitLabel(elseLabel);
}
methodVisitor.visitLabel(endLabel);
@ -382,31 +362,22 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
if (localVariableDeclarationNode.expression != null) {
// Process expression
localVariableDeclarationNode.expression.accept(this);
if (localVariableDeclarationNode.expression instanceof UnaryNode) {
UnaryNode unaryNode = (UnaryNode) localVariableDeclarationNode.expression;
if (unaryNode.statement instanceof IncrementNode) {
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
incrementNode.assignableExpression.typeNode = unaryNode.type;
loadIncrement(incrementNode);
} else if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
decrementNode.assignableExpression.typeNode = unaryNode.type;
loadDecrement(decrementNode);
// Store result of expression in variable
if (localVariables.contains(localVariableDeclarationNode.identifier)) {
if (localVariableDeclarationNode.type instanceof BaseType) {
methodVisitor.visitVarInsn(ISTORE, localVariables.indexOf(localVariableDeclarationNode.identifier));
} else if (localVariableDeclarationNode.type instanceof ReferenceType) {
methodVisitor.visitVarInsn(ASTORE, localVariables.indexOf(localVariableDeclarationNode.identifier));
}
} else {
localVariables.add(localVariableDeclarationNode.identifier);
if (localVariableDeclarationNode.type instanceof BaseType) {
methodVisitor.visitVarInsn(ISTORE, localVariables.indexOf(localVariableDeclarationNode.identifier));
} else if (localVariableDeclarationNode.type instanceof ReferenceType) {
methodVisitor.visitVarInsn(ASTORE, localVariables.indexOf(localVariableDeclarationNode.identifier));
}
}
// add local var to list if not in list
if (!localVariables.contains(localVariableDeclarationNode.identifier)) {
localVariables.add(localVariableDeclarationNode.identifier);
}
if (localVariableDeclarationNode.type instanceof BaseType) {
methodVisitor.visitVarInsn(ISTORE, localVariables.indexOf(localVariableDeclarationNode.identifier));
} else if (localVariableDeclarationNode.type instanceof ReferenceType) {
methodVisitor.visitVarInsn(ASTORE, localVariables.indexOf(localVariableDeclarationNode.identifier));
}
} else {
// Local var declaration
if (!localVariables.contains(localVariableDeclarationNode.identifier)) {
localVariables.add(localVariableDeclarationNode.identifier);
}
@ -415,212 +386,53 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
@Override
public void visit(AssignNode assignNode) {
if (assignNode.assignable.memberAccess != null) { // this / object
assignNode.assignable.memberAccess.setTypeNode(assignNode.assignable.typeNode);
if (assignNode.expression instanceof UnaryNode) {
UnaryNode unaryNode = (UnaryNode) assignNode.expression;
if (unaryNode.statement instanceof IncrementNode) {
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
if (incrementNode.crementType.equals(CrementType.PREFIX)) { // ++i
incrementNode.accept(this); // crement
fieldOrObjectVarCrementAssign(assignNode); // assign
} else { // i++
fieldOrObjectVarCrementAssign(assignNode); // assign
incrementNode.accept(this); // crement
}
} else if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
if (decrementNode.crementType.equals(CrementType.PREFIX)) {
decrementNode.accept(this); // crement
fieldOrObjectVarCrementAssign(assignNode); // assign
} else {
fieldOrObjectVarCrementAssign(assignNode); // assign
decrementNode.accept(this); // crement
}
}
} else {
assignFieldOrObjectVar(assignNode);
// Process expression
if (assignNode.expression instanceof IncrementNode) {
IncrementNode incrementNode = (IncrementNode) assignNode.expression;
if (incrementNode.crementType.equals(CrementType.PREFIX)) { // ++i
methodVisitor.visitIincInsn(localVariables.indexOf(incrementNode.assignableExpression.identifier), 1);
assign(assignNode);
} else if (incrementNode.crementType.equals(CrementType.SUFFIX)) { // Suffix: i++
assign(assignNode);
methodVisitor.visitIincInsn(localVariables.indexOf(incrementNode.assignableExpression.identifier), 1);
}
} else { // local var
if (assignNode.expression instanceof UnaryNode) {
UnaryNode unaryNode = (UnaryNode) assignNode.expression;
if (unaryNode.statement instanceof IncrementNode || unaryNode.statement instanceof DecrementNode) {
localVarCrementAssign(assignNode);
}
} else {
assignNode.expression.accept(this);
assignLocalVar(assignNode);
} else if (assignNode.expression instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) assignNode.expression;
if (decrementNode.crementType.equals(CrementType.PREFIX)) {
methodVisitor.visitIincInsn(localVariables.indexOf(decrementNode.assignableExpression.identifier), -1);
assign(assignNode);
} else if (decrementNode.crementType.equals(CrementType.SUFFIX)) {
assign(assignNode);
methodVisitor.visitIincInsn(localVariables.indexOf(decrementNode.assignableExpression.identifier), 1);
}
} else {
assignNode.expression.accept(this);
assign(assignNode);
}
}
private void loadIncrement(IncrementNode incrementNode) {
AssignableNode assignableNode = incrementNode.assignableExpression;
if (assignableNode.memberAccess != null) {
assignableNode.memberAccess.accept(this);
private void assign(AssignNode assignNode) {
if (assignNode.assignable.memberAccess.thisExpr) {
assignField(assignNode);
} else {
if (assignableNode.typeNode instanceof BaseType) {
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(assignableNode.identifier));
} else if (assignableNode.typeNode instanceof ReferenceType) {
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignableNode.identifier));
}
}
}
private void loadDecrement(DecrementNode decrementNode) {
AssignableNode assignableNode = decrementNode.assignableExpression;
if (assignableNode.memberAccess != null) {
assignableNode.memberAccess.accept(this);
} else {
if (assignableNode.typeNode instanceof BaseType) {
methodVisitor.visitVarInsn(ILOAD, localVariables.indexOf(assignableNode.identifier));
} else if (assignableNode.typeNode instanceof ReferenceType) {
methodVisitor.visitVarInsn(ALOAD, localVariables.indexOf(assignableNode.identifier));
}
assignLocalVar(assignNode);
}
}
private void assignLocalVar(AssignNode assignNode) {
if (!localVariables.contains(assignNode.assignable.identifier)) {
localVariables.add(assignNode.assignable.identifier);
}
if (assignNode.expression.getType() instanceof BaseType) {
if (assignNode.expression instanceof BaseType) {
methodVisitor.visitVarInsn(ISTORE, localVariables.indexOf(assignNode.assignable.identifier));
} else if (assignNode.expression.getType() instanceof ReferenceType) {
} else if (assignNode.expression instanceof ReferenceType) {
methodVisitor.visitVarInsn(ASTORE, localVariables.indexOf(assignNode.assignable.identifier));
}
}
private void assignFieldOrObjectVar(AssignNode assignNode) {
int localVarIndex = localVariables.indexOf(assignNode.assignable.identifier);
if (localVarIndex >= 0) { // object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else if (assignNode.assignable.memberAccess.thisExpr) { // this
methodVisitor.visitVarInsn(ALOAD, 0);
} else {
localVariables.add(assignNode.assignable.identifier);
}
assignNode.expression.accept(this);
if (assignNode.expression.getType() instanceof BaseType) {
private void assignField(AssignNode assignNode) {
if (assignNode.expression instanceof BaseType) {
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) assignNode.expression.getType()));
} else if (assignNode.expression.getType() instanceof ReferenceType) {
} else if (assignNode.expression instanceof ReferenceType) {
ReferenceType referenceType = (ReferenceType) assignNode.expression.getType();
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), "L" + referenceType.getIdentifier() + ";");
}
}
private void localVarCrementAssign(AssignNode assignNode) {
UnaryNode unaryNode = (UnaryNode) assignNode.expression;
if (unaryNode.statement instanceof IncrementNode) {
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
if (incrementNode.crementType.equals(CrementType.PREFIX)) { // ++i
incrementNode.accept(this);
incrementNode.assignableExpression.typeNode = unaryNode.getType();
loadIncrement(incrementNode);
assignLocalVar(assignNode);
} else { // i++
incrementNode.assignableExpression.typeNode = unaryNode.getType();
loadIncrement(incrementNode);
assignLocalVar(assignNode);
incrementNode.accept(this);
}
} else if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
if (decrementNode.crementType.equals(CrementType.PREFIX)) {
decrementNode.accept(this);
decrementNode.assignableExpression.typeNode = unaryNode.getType();
loadDecrement(decrementNode);
assignLocalVar(assignNode);
} else {
decrementNode.assignableExpression.typeNode = unaryNode.getType();
loadDecrement(decrementNode);
assignLocalVar(assignNode);
decrementNode.accept(this);
}
}
}
private void fieldOrObjectVarCrementAssign(AssignNode assignNode) {
int localVarIndex = localVariables.indexOf(assignNode.assignable.identifier);
if (localVarIndex >= 0) { // object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else if (assignNode.assignable.memberAccess.thisExpr) { // field
methodVisitor.visitVarInsn(ALOAD, 0);
} else {
localVariables.add(assignNode.assignable.identifier);
}
UnaryNode unaryNode = (UnaryNode) assignNode.expression;
if (unaryNode.statement instanceof IncrementNode) {
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
incrementNode.assignableExpression.typeNode = unaryNode.getType();
loadIncrement((incrementNode));
} else if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
decrementNode.assignableExpression.typeNode = unaryNode.getType();
loadDecrement(decrementNode);
}
if (assignNode.expression.getType() instanceof BaseType) {
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) assignNode.expression.getType()));
} else if (assignNode.expression.getType() instanceof ReferenceType) {
ReferenceType referenceType = (ReferenceType) assignNode.expression.getType();
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), "L" + referenceType.getIdentifier() + ";");
}
}
@Override
public void visit(IncrementNode incrementNode) {
if (incrementNode.assignableExpression.memberAccess != null) { // Object var / field
int localVarIndex = localVariables.indexOf(incrementNode.assignableExpression.identifier);
if (localVarIndex >= 0) { // object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else { // this
methodVisitor.visitVarInsn(ALOAD, 0);
}
if (incrementNode.assignableExpression.memberAccess.getTypeNode() instanceof BaseType) {
methodVisitor.visitFieldInsn(GETFIELD, incrementNode.assignableExpression.memberAccess.identifiers.get(0), incrementNode.assignableExpression.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) incrementNode.assignableExpression.memberAccess.getTypeNode()));
} else if (incrementNode.assignableExpression.memberAccess.getTypeNode() instanceof ReferenceType) {
methodVisitor.visitFieldInsn(GETFIELD, incrementNode.assignableExpression.memberAccess.identifiers.get(0), incrementNode.assignableExpression.memberAccess.identifiers.get(1), "L" + (((ReferenceType) incrementNode.assignableExpression.memberAccess.getTypeNode()).getIdentifier() + ";"));
}
methodVisitor.visitInsn(ICONST_1);
methodVisitor.visitInsn(IADD);
if (incrementNode.assignableExpression.memberAccess.getTypeNode() instanceof BaseType) {
methodVisitor.visitFieldInsn(PUTFIELD, incrementNode.assignableExpression.memberAccess.identifiers.get(0), incrementNode.assignableExpression.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) incrementNode.assignableExpression.memberAccess.getTypeNode()));
} else if (incrementNode.assignableExpression.memberAccess.getTypeNode() instanceof ReferenceType) {
methodVisitor.visitFieldInsn(PUTFIELD, incrementNode.assignableExpression.memberAccess.identifiers.get(0), incrementNode.assignableExpression.memberAccess.identifiers.get(1), "L" + (((ReferenceType) incrementNode.assignableExpression.memberAccess.getTypeNode()).getIdentifier() + ";"));
}
} else { // local var
methodVisitor.visitIincInsn(localVariables.indexOf(incrementNode.assignableExpression.identifier), 1);
}
}
@Override
public void visit(DecrementNode decrementNode) {
if (decrementNode.assignableExpression.memberAccess != null) { // Object var / field
int localVarIndex = localVariables.indexOf(decrementNode.assignableExpression.identifier);
if (localVarIndex >= 0) { // object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else { // this
methodVisitor.visitVarInsn(ALOAD, 0);
}
if (decrementNode.assignableExpression.memberAccess.getTypeNode() instanceof BaseType) {
methodVisitor.visitFieldInsn(GETFIELD, decrementNode.assignableExpression.memberAccess.identifiers.get(0), decrementNode.assignableExpression.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) decrementNode.assignableExpression.memberAccess.getTypeNode()));
} else if (decrementNode.assignableExpression.memberAccess.getTypeNode() instanceof ReferenceType) {
methodVisitor.visitFieldInsn(GETFIELD, decrementNode.assignableExpression.memberAccess.identifiers.get(0), decrementNode.assignableExpression.memberAccess.identifiers.get(1), "L" + (((ReferenceType) decrementNode.assignableExpression.memberAccess.getTypeNode()).getIdentifier() + ";"));
}
methodVisitor.visitInsn(ICONST_1);
methodVisitor.visitInsn(ISUB);
if (decrementNode.assignableExpression.memberAccess.getTypeNode() instanceof BaseType) {
methodVisitor.visitFieldInsn(PUTFIELD, decrementNode.assignableExpression.memberAccess.identifiers.get(0), decrementNode.assignableExpression.memberAccess.identifiers.get(1), mapper.getTypeChar((BaseType) decrementNode.assignableExpression.memberAccess.getTypeNode()));
} else if (decrementNode.assignableExpression.memberAccess.getTypeNode() instanceof ReferenceType) {
methodVisitor.visitFieldInsn(PUTFIELD, decrementNode.assignableExpression.memberAccess.identifiers.get(0), decrementNode.assignableExpression.memberAccess.identifiers.get(1), "L" + (((ReferenceType) decrementNode.assignableExpression.memberAccess.getTypeNode()).getIdentifier() + ";"));
}
} else { // local var
methodVisitor.visitIincInsn(localVariables.indexOf(decrementNode.assignableExpression.identifier), -1);
methodVisitor.visitFieldInsn(PUTFIELD, assignNode.assignable.memberAccess.identifiers.get(0), assignNode.assignable.memberAccess.identifiers.get(1), "L"+referenceType.getIdentifier()+";");
}
}
@ -633,7 +445,8 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
expressionNode.accept(this);
parameterNodes.add(new ParameterNode(expressionNode.getType(), ""));
}
methodVisitor.visitMethodInsn(INVOKESPECIAL, newDeclarationNode.identifier, "<init>", mapper.generateMethodDescriptor(new BaseType(TypeEnum.VOID), parameterNodes), false);
methodVisitor.visitMethodInsn(INVOKESPECIAL, newDeclarationNode.identifier, "<init>", mapper.generateMethodDescriptor(new BaseType(TypeEnum.VOID),parameterNodes), false);
localVariables.add(newDeclarationNode.identifier);
}
@Override
@ -679,21 +492,6 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
} else { // Return something
// Process expression
returnNode.expression.accept(this);
if (returnNode.expression instanceof UnaryNode) {
UnaryNode unaryNode = (UnaryNode) returnNode.expression;
if (unaryNode.statement instanceof IncrementNode) {
IncrementNode incrementNode = (IncrementNode) unaryNode.statement;
incrementNode.assignableExpression.typeNode = unaryNode.getType();
loadIncrement(incrementNode);
}
if (unaryNode.statement instanceof DecrementNode) {
DecrementNode decrementNode = (DecrementNode) unaryNode.statement;
decrementNode.assignableExpression.typeNode = unaryNode.getType();
loadDecrement(decrementNode);
}
}
// Return result of expression
if (returnNode.expression.getType() instanceof BaseType) {
methodVisitor.visitInsn(IRETURN);
@ -720,25 +518,19 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
methodVisitor.visitLabel(endOfLoopLabel);
}
@Override
public void visit(ChainedMethodNode chainedMethodNode) {
// TODO: Erstmal abwarten
}
@Override
public void visit(MethodCallNode methodCallNode) {
List<ParameterNode> parameterNodes = new ArrayList<>();
int localVarIndex = -1;
if (methodCallNode.target.memberAccess.identifiers.size() > 1) {
localVarIndex = localVariables.indexOf(methodCallNode.target.memberAccess.identifiers.get(1));
}
if (localVarIndex >= 0) { // local var object
methodVisitor.visitVarInsn(ALOAD, localVarIndex);
} else { // this field
methodVisitor.visitVarInsn(ALOAD, 0);
}
for (IExpressionNode expressionNode : methodCallNode.parameters) {
for(IExpressionNode expressionNode : methodCallNode.parameters) {
expressionNode.accept(this);
parameterNodes.add(new ParameterNode(expressionNode.getType(), ""));
}
if(methodCallNode.type == null) {
methodCallNode.type = new BaseType(TypeEnum.INT);
}
methodVisitor.visitMethodInsn(INVOKEVIRTUAL, methodCallNode.target.memberAccess.identifiers.get(0), methodCallNode.identifier, mapper.generateMethodDescriptor(methodCallNode.type, parameterNodes), false);
// TODO: Klassenname und Returntype
//methodVisitor.visitMethodInsn(INVOKEVIRTUAL, classname, methodCallNode.identifier, mapper.generateMethodDescriptor(returntype, parameterNodes), false);
}
}

View File

@ -5,5 +5,6 @@ import ast.members.FieldNode;
public interface ClassVisitor {
void visit(ClassNode classNode);
void visit(FieldNode fieldNode);
}

View File

@ -8,58 +8,46 @@ import ast.members.ConstructorNode;
import ast.members.MainMethodNode;
import ast.members.MethodNode;
import ast.statementexpressions.AssignNode;
import ast.statementexpressions.AssignableNode;
import ast.statementexpressions.NewDeclarationNode;
import ast.statementexpressions.crementexpressions.DecrementNode;
import ast.statementexpressions.crementexpressions.IncrementNode;
import ast.statementexpressions.methodcallstatementnexpressions.ChainedMethodNode;
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
import ast.statements.*;
import ast.type.ValueNode;
public interface MethodVisitor {
// members
void visit(ConstructorNode constructorNode);
void visit(MethodNode methodNode);
void visit(MainMethodNode mainMethodNode);
// Binary expressions
void visit(BinaryNode binaryNode);
void visit(CalculationNode calculationNode);
void visit(DotNode dotNode);
void visit(DotSubtractionNode dotSubtractionNode);
void visit(DotSubstractionNode dotSubstractionNode);
void visit(NonCalculationNode nonCalculationNode);
// Unary expressions
void visit(MemberAccessNode memberAccessNode);
void visit(NotNode notExpressionNode);
void visit(UnaryNode unaryExpressionNode);
// statements
void visit(BlockNode blockNode);
void visit(IfElseNode ifElseNode);
void visit(IncrementNode incrementNode);
void visit(DecrementNode decrementNode);
void visit(LocalVariableDeclarationNode localVariableDeclarationNode);
void visit(ReturnNode returnNode);
void visit(WhileNode whileNode);
// statement expression
void visit(ChainedMethodNode chainedMethodNode);
void visit(MethodCallNode methodCallNode);
void visit(AssignNode assignNode);
void visit(NewDeclarationNode newDeclarationNode);
// type

View File

@ -3,5 +3,5 @@ package bytecode.visitor;
import ast.ProgramNode;
public interface ProgramVisitor {
void visit(ProgramNode programNode);
void visit(ProgramNode programNode);
}

View File

@ -15,11 +15,12 @@ import java.io.IOException;
import java.nio.file.Paths;
import java.util.Optional;
/**
* Start miniCompiler using make:
* Start Raupenpiler using make:
* <p> <code> cd .\src\test\ </code>
* <p> <code> make clean compile-miniCompiler </code>
* <p> Start miniCompiler using jar:
* <p> <code> make clean compile-raupenpiler </code>
* <p> Start Raupenpiler using jar:
* <p> <code> java.exe -DgenJar=true_OR_false -DgenClass=true_OR_false -jar path_to_jar\JavaCompiler-1.0-jar-with-dependencies.jar 'path_to_input_file.java' 'path_to_output_directory' </code>
* <p> Example (jar needs to be in the target directory, compile with make or mvn package first):
* <code> java.exe -DgenJar=true -DgenClass=true -jar .\target\JavaCompiler-1.0-jar-with-dependencies.jar 'src/main/resources/input/CompilerInput.java' 'src/main/resources/output' </code>
@ -39,14 +40,16 @@ public class Main {
System.err.println("Error reading the file: " + e.getMessage());
}
}
/* !!! Else Branch (main ohne args starten) ist nicht zur Verwendung vorgesehen, immer mit args starten !!!
else {
try {
CharStream codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/input/finalTest/Car.java"));
compileFile(codeCharStream, "src/test/resources/input/finalTest");
CharStream codeCharStream = CharStreams.fromPath(Paths.get("src/main/resources/input/CompilerInput.java"));
compileFile(codeCharStream);
} catch (IOException e) {
System.err.println("Error reading the file: " + e.getMessage());
}
}
*/
}
/**
@ -63,7 +66,7 @@ public class Main {
*/
static void compileFile(CharStream inputCharStream, String outputDirectoryPath) {
// Initialize the logger
new MiniCompilerLogger();
new RaupenLogger();
/* ------------------------- Scanner -> tokens ------------------------- */
// Use the SimpleJavaLexer to tokenize the input CharStream
@ -71,46 +74,38 @@ public class Main {
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
tokenStream.fill();
// Log the tokens
MiniCompilerLogger.logScanner(tokenStream);
RaupenLogger.logScanner(tokenStream);
/*------------------------- Parser -> Parsetree -------------------------*/
// Use the SimpleJavaParser to parse the tokens and generate a ParseTree
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
ParseTree parseTree = parser.program(); // parse the input
// Log the ParseTree
MiniCompilerLogger.logParser(parseTree, parser);
RaupenLogger.logParser(parseTree, parser);
/*------------------------- AST builder -> AST -------------------------*/
// Use the ASTBuilder to visit the ParseTree and generate an Abstract Syntax Tree (AST)
ASTBuilder astBuilder = new ASTBuilder();
ASTNode abstractSyntaxTree = astBuilder.visit(parseTree);
// Log the AST
MiniCompilerLogger.logAST(abstractSyntaxTree);
RaupenLogger.logAST(abstractSyntaxTree);
/*------------------------- Semantic Analyzer -> typed AST -------------------------*/
// Use the SemanticAnalyzer to generate a typed AST
ASTNode typedAst = SemanticAnalyzer.generateTast(abstractSyntaxTree);
// Log the typed AST
MiniCompilerLogger.logSemanticAnalyzer(typedAst);
RaupenLogger.logSemanticAnalyzer(typedAst);
if(SemanticAnalyzer.errors.isEmpty()){
/*------------------------- Bytecode Generator -> Bytecode -------------------------*/
// Use the ByteCodeGenerator to generate bytecode from the typed AST and output it to the specified directory
final boolean genJar = Optional.ofNullable(System.getProperty("genJar")).map(String::toLowerCase).map(Boolean::parseBoolean).orElse(true);
final boolean genClass = Optional.ofNullable(System.getProperty("genClass")).map(String::toLowerCase).map(Boolean::parseBoolean).orElse(true);
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator(outputDirectoryPath, genJar, genClass);
assert typedAst != null;
byteCodeGenerator.visit((ProgramNode) typedAst);
// Log the bytecode generation
MiniCompilerLogger.logBytecodeGenerator();
} else {
for(Exception exception : SemanticAnalyzer.errors){
exception.printStackTrace();
}
}
/*------------------------- Bytecode Generator -> Bytecode -------------------------*/
// Use the ByteCodeGenerator to generate bytecode from the typed AST and output it to the specified directory
final boolean genJar = Optional.ofNullable(System.getProperty("genJar")).map(String::toLowerCase).map(Boolean::parseBoolean).orElse(true);
final boolean genClass = Optional.ofNullable(System.getProperty("genClass")).map(String::toLowerCase).map(Boolean::parseBoolean).orElse(true);
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator(outputDirectoryPath, genJar, genClass);
assert typedAst != null;
byteCodeGenerator.visit((ProgramNode) typedAst);
// Log the bytecode generation
RaupenLogger.logBytecodeGenerator();
}
}

View File

@ -29,15 +29,11 @@ import java.util.logging.*;
* <code>consoleHandler.setLevel(Level.OFF);</code>
* <code>fileHandler.setLevel(Level.ALL);</code>
*/
public class RaupenLogger {
static Logger logger = Logger.getLogger("RaupenLogs");
public class MiniCompilerLogger {
static Logger logger = Logger.getLogger("miniCompilerLogs");
public MiniCompilerLogger() {
public RaupenLogger() {
// ------------------------- Logging -------------------------
logger.setLevel(Level.ALL);
logger.getParent().getHandlers()[0].setLevel(Level.ALL);
@ -70,16 +66,14 @@ public class MiniCompilerLogger {
logger.addHandler(consoleHandler);
// Configure file handler
Handler fileHandler = new FileHandler("src/main/resources/logs/miniCompiler.log");
Handler fileHandler = new FileHandler("src/main/resources/logs/RaupenLog.log");
// Toggle file logging on/off
fileHandler.setLevel(Level.ALL);
fileHandler.setFormatter(new CustomFormatter());
logger.addHandler(fileHandler);
} catch (SecurityException e) {
} catch (SecurityException | IOException e) {
e.printStackTrace();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@ -108,7 +102,7 @@ public class MiniCompilerLogger {
public static void logAST(ASTNode abstractSyntaxTree) {
// Printing the AST
logger.info("-------------------- AST builder -> AST --------------------");
logger.info("Abstract Syntax Tree generated, Startnode:");
// logger.info("AST: " + ast.toString());
logAST(abstractSyntaxTree, 0);
logger.info("\n");
}
@ -116,15 +110,14 @@ public class MiniCompilerLogger {
public static void logSemanticAnalyzer(ASTNode typedAst) {
// Printing the typed AST
logger.info("-------------------- Semantic Analyzer -> typed AST --------------------");
// logAST(typedAst, 0);
logger.info("Typed Abstract Syntax Tree generated without errors");
logAST(typedAst, 0);
logger.info("\n");
}
public static void logBytecodeGenerator() {
// Printing the bytecode
logger.info("-------------------- Bytecode Generator -> Bytecode --------------------");
logger.info("Bytecode generated without errors");
logger.info("Bytecode generated");
logger.info("\n");
}
@ -171,6 +164,7 @@ public class MiniCompilerLogger {
}
}
// TODO: Fix this method
public static void logAST(ASTNode abstractSyntaxTree, int indent) {
if (abstractSyntaxTree == null) {
logger.severe("AST is null !!!");
@ -178,9 +172,9 @@ public class MiniCompilerLogger {
}
String indentString = " ".repeat(indent * 2);
logger.info(indentString + abstractSyntaxTree.getClass());
// for (ASTNode child : abstractSyntaxTree.getChildren()) {
//for (ASTNode child : abstractSyntaxTree.getChildren()) {
// logAST(child, indent + 1);
// }
// }
}
}

View File

@ -3,7 +3,10 @@ package parser.astBuilder;
import ast.*;
import ast.expressions.IExpressionNode;
import ast.expressions.binaryexpressions.*;
import ast.expressions.binaryexpressions.CalculationNode;
import ast.expressions.binaryexpressions.DotNode;
import ast.expressions.binaryexpressions.DotSubstractionNode;
import ast.expressions.binaryexpressions.NonCalculationNode;
import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.expressions.unaryexpressions.NotNode;
import ast.expressions.unaryexpressions.UnaryNode;
@ -11,7 +14,6 @@ import ast.members.*;
import ast.parameters.ParameterNode;
import ast.statementexpressions.AssignNode;
import ast.statementexpressions.AssignableNode;
import ast.statementexpressions.IStatementExpressionNode;
import ast.statementexpressions.NewDeclarationNode;
import ast.statementexpressions.crementexpressions.CrementType;
import ast.statementexpressions.crementexpressions.DecrementNode;
@ -30,18 +32,7 @@ import parser.generated.*;
import java.util.ArrayList;
import java.util.List;
/**
* ASTBuilder is a visitor that converts the parse tree into an abstract syntax tree (AST).
*/
public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
/**
* Visits a program node and creates a ProgramNode.
* It iterates through all class declarations in the context and adds them to the ProgramNode.
*
* @param ctx the program context
* @return the AST node for the program
*/
@Override
public ASTNode visitProgram(SimpleJavaParser.ProgramContext ctx) {
ProgramNode program = new ProgramNode();
@ -51,14 +42,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return program;
}
/**
* Visits a class declaration and creates a ClassNode.
* It checks for an access modifier, processes member declarations, and ensures the class has a constructor.
*
* @param ctx the class declaration context
* @return the AST node for the class
*/
@Override
public ASTNode visitClassDeclaration(SimpleJavaParser.ClassDeclarationContext ctx) {
ClassNode classNode;
@ -90,21 +73,9 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return classNode;
}
/**
* Visits a constructor declaration and creates a ConstructorNode.
* It processes access modifiers, block statements, and parameters.
*
* @param ctx the constructor declaration context
* @return the AST node for the constructor
*/
@Override
public ASTNode visitConstructorDeclaration(SimpleJavaParser.ConstructorDeclarationContext ctx) {
ConstructorNode constructorNode;
if(ctx.AccessModifier() != null) {
constructorNode = new ConstructorNode(ctx.AccessModifier().getText(), ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
} else {
constructorNode = new ConstructorNode("public", ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
}
ConstructorNode constructorNode = new ConstructorNode(ctx.AccessModifier().getText(), ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
if(ctx.parameterList() != null) {
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
constructorNode.addParameter((ParameterNode) visit(parameter));
@ -114,13 +85,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return constructorNode;
}
/**
* Visits a method declaration and creates a MethodNode or MainMethodNode.
* It handles method types, access modifiers, block statements, and parameters.
*
* @param ctx the method declaration context
* @return the AST node for the method
*/
@Override
public ASTNode visitMethodDeclaration(SimpleJavaParser.MethodDeclarationContext ctx) {
if(ctx.MainMethodDeclaration() != null) {
@ -170,14 +134,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
}
}
/**
* Visits a field declaration and creates a FieldNode.
* It handles access modifiers and types.
*
* @param ctx the field declaration context
* @return the AST node for the field
*/
@Override
public ASTNode visitFieldDeclaration(SimpleJavaParser.FieldDeclarationContext ctx) {
if(ctx.AccessModifier() != null) {
@ -187,25 +143,11 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
}
}
/**
* Visits a parameter and creates a ParameterNode.
* It handles the type and identifier of the parameter.
*
* @param ctx the parameter context
* @return the AST node for the parameter
*/
@Override
public ASTNode visitParameter(SimpleJavaParser.ParameterContext ctx) {
return new ParameterNode(createTypeNode(ctx.type().getText()), ctx.Identifier().getText());
}
/**
* Visits a statement and creates the corresponding AST node.
* It determines the specific type of statement and processes it accordingly.
*
* @param ctx the statement context
* @return the AST node for the statement
*/
@Override
public ASTNode visitStatement(SimpleJavaParser.StatementContext ctx) {
if(ctx.returnStatement() != null) {
@ -222,50 +164,22 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return visitForStatement(ctx.forStatement());
} else if(ctx.ifElseStatement() != null) {
return visitIfElseStatement(ctx.ifElseStatement());
} else if(ctx.switchStatement() != null) {
return visitSwitchStatement(ctx.switchStatement());
} else if(ctx.statementExpression() != null) {
return visitStatementExpression(ctx.statementExpression());
}
return null;
}
/**
* Visits a return statement and creates a ReturnNode.
* It processes the expression in the return statement.
*
* @param ctx the return statement context
* @return the AST node for the return statement
*/
@Override
public ASTNode visitReturnStatement(SimpleJavaParser.ReturnStatementContext ctx) {
return new ReturnNode((IExpressionNode) visit(ctx.expression()));
}
/**
* Visits a return statement and creates a ReturnNode.
* It processes the expression in the return statement.
*
* @param ctx the return statement context
* @return the AST node for the return statement
*/
@Override
public ASTNode visitLocalVariableDeclaration(SimpleJavaParser.LocalVariableDeclarationContext ctx) {
if(ctx.Assign() != null) {
return new LocalVariableDeclarationNode(createTypeNode(ctx.type().getText()), ctx.Identifier().getText(), ctx.Assign().getText(), (IExpressionNode) visit(ctx.expression()));
} else {
return new LocalVariableDeclarationNode(createTypeNode(ctx.type().getText()), ctx.Identifier().getText(), null, null);
}
return new LocalVariableDeclarationNode(createTypeNode(ctx.type().getText()), ctx.Identifier().getText(), ctx.Assign().getText(), (IExpressionNode) visit(ctx.expression()));
}
/**
* Visits a block statement and creates a BlockNode.
* It processes all statements within the block.
*
* @param ctx the block statement context
* @return the AST node for the block statement
*/
@Override
public ASTNode visitBlockStatement(SimpleJavaParser.BlockStatementContext ctx) {
BlockNode blockNode = new BlockNode();
@ -275,25 +189,11 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return blockNode;
}
/**
* Visits a while statement and creates a WhileNode.
* It processes the condition expression and the block statement.
*
* @param ctx the while statement context
* @return the AST node for the while statement
*/
@Override
public ASTNode visitWhileStatement(SimpleJavaParser.WhileStatementContext ctx) {
return new WhileNode((IExpressionNode) visit(ctx.expression()), (BlockNode) visit(ctx.blockStatement()));
}
/**
* Visits a do-while statement and creates a BlockNode containing a WhileNode.
* It processes the condition expression and the block statement.
*
* @param ctx the do-while statement context
* @return the AST node for the do-while statement
*/
@Override
public ASTNode visitDoWhileStatement(SimpleJavaParser.DoWhileStatementContext ctx) {
IExpressionNode condition = (IExpressionNode) visit(ctx.expression());
@ -301,85 +201,64 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
WhileNode While = new WhileNode(condition, doBlock);
BlockNode resultBlock = new BlockNode();
resultBlock.addStatement(doBlock);
resultBlock.addStatement(While);
resultBlock.addStatement((IStatementNode) doBlock);
resultBlock.addStatement((IStatementNode) While);
return resultBlock;
}
/**
* Visits a for statement and creates a BlockNode that contains a WhileNode.
* It processes the initialization, condition, and increment parts of the for loop.
*
* @param ctx the for statement context
* @return the AST node for the for statement
*/
@Override
public ASTNode visitForStatement(SimpleJavaParser.ForStatementContext ctx) {
List<IStatementNode> statements = new ArrayList<>();
// Initialisierung
//init
int i = 0;
if (ctx.localVariableDeclaration() != null) {
if(ctx.localVariableDeclaration() != null) {
statements.add((IStatementNode) visit(ctx.localVariableDeclaration()));
} else if (ctx.statementExpression(i) != null) {
} else if(ctx.statementExpression(i) != null){
statements.add((IStatementNode) visit(ctx.statementExpression(i)));
i++;
}
// Bedingung
//condition
IExpressionNode condition = (IExpressionNode) visit(ctx.expression());
// Inkrement
IStatementExpressionNode crement = null;
if (ctx.statementExpression(i) != null) {
crement = (IStatementExpressionNode) visit(ctx.statementExpression(i));
//ink
IStatementNode crement = null;
if(ctx.statementExpression(i) != null){
crement = (IStatementNode) visit(ctx.statementExpression(i));
}
BlockNode forBlock = (BlockNode) visit(ctx.blockStatement());
BlockNode forBlock = new BlockNode();
// While-Schleife
BlockNode whileBody = new BlockNode();
// Block Statements der For-Schleife in den While-Block kopieren
for (IStatementNode statement : forBlock.statements) {
whileBody.addStatement(statement);
BlockNode forStatements = (BlockNode) visit(ctx.blockStatement());
if(forStatements != null) {
forBlock.addStatement((IStatementNode) forStatements);
}
// Post-Inkrement: Das Inkrement kommt nach dem Block
if (crement != null) {
whileBody.addStatement(crement);
if(crement != null){
BlockNode forCrement = new BlockNode();
forCrement.addStatement((crement));
forBlock.addStatement(forCrement);
}
// Bedingung der While-Schleife
WhileNode whileNode = new WhileNode(condition, whileBody);
WhileNode While = new WhileNode(condition, forBlock);
statements.add(whileNode);
statements.add(While);
BlockNode resultBlock = new BlockNode();
for (IStatementNode statement : statements) {
resultBlock.addStatement(statement);
for(IStatementNode statement : statements) {
resultBlock.addStatement((IStatementNode) statement);
}
return resultBlock;
}
/**
* Visits an if-else statement and creates an IfElseNode.
* It processes the if, else-if, and else parts of the statement.
*
* @param ctx the if-else statement context
* @return the AST node for the if-else statement
*/
@Override
public ASTNode visitIfElseStatement(SimpleJavaParser.IfElseStatementContext ctx) {
IfElseNode ifElseStatementNode;
if(ctx.elseStatement() != null) {
ifElseStatementNode = new IfElseNode((IfNode) visit(ctx.ifStatement()),
(ElseNode) visit(ctx.elseStatement()));
} else {
ifElseStatementNode = new IfElseNode((IfNode) visit(ctx.ifStatement()), null);
}
IfElseNode ifElseStatementNode = new IfElseNode((IfNode) visit(ctx.ifStatement()),
(ElseNode) visit(ctx.elseStatement()));
for (SimpleJavaParser.ElseIfStatementContext elseIf : ctx.elseIfStatement()){
ifElseStatementNode.addElseIfStatement(((IfNode) visit(elseIf)));
@ -388,49 +267,21 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return ifElseStatementNode;
}
/**
* Visits an if statement and creates an IfNode.
* It processes the condition expression and the block statement.
*
* @param ctx the if statement context
* @return the AST node for the if statement
*/
@Override
public ASTNode visitIfStatement(SimpleJavaParser.IfStatementContext ctx) {
return new IfNode((IExpressionNode) visit(ctx.expression()), (BlockNode) visit(ctx.blockStatement()));
}
/**
* Visits an else-if statement and creates an IfNode.
* It processes the condition expression and the block statement.
*
* @param ctx the else-if statement context
* @return the AST node for the else-if statement
*/
@Override
public ASTNode visitElseIfStatement(SimpleJavaParser.ElseIfStatementContext ctx) {
return new IfNode((IExpressionNode) visit(ctx.expression()), (BlockNode) visit(ctx.blockStatement()));
}
/**
* Visits an else statement and creates an ElseNode.
* It processes the block statement of the else part.
*
* @param ctx the else statement context
* @return the AST node for the else statement
*/
@Override
public ASTNode visitElseStatement(SimpleJavaParser.ElseStatementContext ctx) {
return new ElseNode((BlockNode) visit(ctx.blockStatement()));
}
/**
* Visits a statement expression and creates the corresponding AST node.
* It handles assignments, new declarations, method calls, and increment/decrement expressions.
*
* @param ctx the statement expression context
* @return the AST node for the statement expression
*/
@Override
public ASTNode visitStatementExpression(SimpleJavaParser.StatementExpressionContext ctx) {
if(ctx.assign() != null) {
@ -445,75 +296,11 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return null;
}
/**
* Visits a switch statement and creates an IfElseNode representing the switch cases.
* It processes the switch expression, case statements, and default statement.
*
* @param ctx the switch statement context
* @return the AST node for the switch statement
*/
@Override
public ASTNode visitSwitchStatement(SimpleJavaParser.SwitchStatementContext ctx) {
UnaryNode switchExpression = (UnaryNode) visit(ctx.expression());
List<IfNode> ifNodes = new ArrayList<>();
for (SimpleJavaParser.CaseStatementContext caseCtx : ctx.caseStatement()) {
IExpressionNode caseExpression = (IExpressionNode) visit(caseCtx.value());
// Condition as NonCalculationNode -> Equals Expression
NonCalculationNode condition = new NonCalculationNode(switchExpression, "==", caseExpression);
BlockNode caseBlock = new BlockNode();
for (SimpleJavaParser.StatementContext stmtCtx : caseCtx.statement()) {
caseBlock.addStatement((IStatementNode) visit(stmtCtx));
}
// Each case as if
IfNode ifNode = new IfNode(condition, caseBlock);
ifNodes.add(ifNode);
}
// Check if has Default
ElseNode defaulElseNode = null;
if (ctx.defaultStatement() != null) {
BlockNode defaultBlock = new BlockNode();
for (SimpleJavaParser.StatementContext stmtCtx : ctx.defaultStatement().statement()) {
defaultBlock.addStatement((IStatementNode) visit(stmtCtx));
}
// Default als letztes Else Statement
defaulElseNode = new ElseNode(defaultBlock);
}
IfElseNode ifElseNode = new IfElseNode(ifNodes.getFirst(),defaulElseNode);
ifNodes.removeFirst();
for (IfNode ifNode : ifNodes){
ifElseNode.addElseIfStatement(ifNode);
}
return ifElseNode;
}
/**
* Visits an assignment expression and creates an AssignNode.
* It handles the assignable expression and the assigned expression.
*
* @param ctx the assignment context
* @return the AST node for the assignment
*/
@Override
public ASTNode visitAssign(SimpleJavaParser.AssignContext ctx) {
return new AssignNode((AssignableNode) visit(ctx.assignableExpression()), (IExpressionNode) visit(ctx.expression()));
}
/**
* Visits a new declaration and creates a NewDeclarationNode.
* It processes the identifier and the argument list.
*
* @param ctx the new declaration context
* @return the AST node for the new declaration
*/
@Override
public ASTNode visitNewDeclaration(SimpleJavaParser.NewDeclarationContext ctx) {
NewDeclarationNode newDeclarationNode = new NewDeclarationNode(ctx.Identifier().getText());
@ -523,13 +310,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return newDeclarationNode;
}
/**
* Visits a method call and creates a MethodCallNode.
* It processes the target, chained methods, and argument list.
*
* @param ctx the method call context
* @return the AST node for the method call
*/
@Override
public ASTNode visitMethodCall(SimpleJavaParser.MethodCallContext ctx) {
MethodCallNode methodCallStatementExpressionNode;
@ -547,13 +327,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return methodCallStatementExpressionNode;
}
/**
* Visits the target of a method call and creates a TargetNode.
* It handles various types of targets including 'this', member access, new declarations, and identifiers.
*
* @param ctx the target context
* @return the AST node for the target
*/
@Override
public ASTNode visitTarget(SimpleJavaParser.TargetContext ctx) {
if(ctx.This() != null) {
@ -568,13 +341,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return null;
}
/**
* Visits a chained method and creates a ChainedMethodNode.
* It processes the identifier and the argument list.
*
* @param ctx the chained method context
* @return the AST node for the chained method
*/
@Override
public ASTNode visitChainedMethod(SimpleJavaParser.ChainedMethodContext ctx) {
ChainedMethodNode chainedMethodNode = new ChainedMethodNode(ctx.Identifier().getText());
@ -584,13 +350,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return chainedMethodNode;
}
/**
* Visits an increment or decrement expression and creates the corresponding AST node.
* It handles both prefix and suffix forms of increment and decrement.
*
* @param ctx the crement expression context
* @return the AST node for the crement expression
*/
@Override
public ASTNode visitCrementExpression(SimpleJavaParser.CrementExpressionContext ctx) {
if(ctx.incrementExpression() != null) {
@ -601,13 +360,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return null;
}
/**
* Visits an increment expression and creates an IncrementNode.
* It handles both prefix and suffix forms.
*
* @param ctx the increment expression context
* @return the AST node for the increment expression
*/
@Override
public ASTNode visitIncrementExpression(SimpleJavaParser.IncrementExpressionContext ctx) {
if(ctx.prefixIncrementExpression() != null) {
@ -618,35 +370,16 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return null;
}
/**
* Visits a prefix increment expression and creates an IncrementNode.
*
* @param ctx the prefix increment expression context
* @return the AST node for the prefix increment expression
*/
@Override
public ASTNode visitPrefixIncrementExpression(SimpleJavaParser.PrefixIncrementExpressionContext ctx) {
return new IncrementNode(CrementType.PREFIX, (AssignableNode) visit(ctx.assignableExpression()));
}
/**
* Visits a suffix increment expression and creates an IncrementNode.
*
* @param ctx the suffix increment expression context
* @return the AST node for the suffix increment expression
*/
@Override
public ASTNode visitSuffixIncrementExpression(SimpleJavaParser.SuffixIncrementExpressionContext ctx) {
return new IncrementNode(CrementType.SUFFIX, (AssignableNode) visit(ctx.assignableExpression()));
}
/**
* Visits a decrement expression and creates a DecrementNode.
* It handles both prefix and suffix forms.
*
* @param ctx the decrement expression context
* @return the AST node for the decrement expression
*/
@Override
public ASTNode visitDecrementExpression(SimpleJavaParser.DecrementExpressionContext ctx) {
if(ctx.prefixDecrementExpression() != null) {
@ -657,35 +390,16 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return null;
}
/**
* Visits a prefix decrement expression and creates a DecrementNode.
*
* @param ctx the prefix decrement expression context
* @return the AST node for the prefix decrement expression
*/
@Override
public ASTNode visitPrefixDecrementExpression(SimpleJavaParser.PrefixDecrementExpressionContext ctx) {
return new DecrementNode(CrementType.PREFIX, (AssignableNode) visit(ctx.assignableExpression()));
}
/**
* Visits a suffix decrement expression and creates a DecrementNode.
*
* @param ctx the suffix decrement expression context
* @return the AST node for the suffix decrement expression
*/
@Override
public ASTNode visitSuffixDecrementExpression(SimpleJavaParser.SuffixDecrementExpressionContext ctx) {
return new DecrementNode(CrementType.SUFFIX, (AssignableNode) visit(ctx.assignableExpression()));
}
/**
* Visits an expression and creates the corresponding AST node.
* It handles both unary and binary expressions.
*
* @param ctx the expression context
* @return the AST node for the expression
*/
@Override
public ASTNode visitExpression(SimpleJavaParser.ExpressionContext ctx) {
if(ctx.unaryExpression() != null) {
@ -696,13 +410,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return null;
}
/**
* Visits a unary expression and creates a UnaryNode.
* It handles various forms of unary expressions including 'this', identifiers, member access, values, and more.
*
* @param ctx the unary expression context
* @return the AST node for the unary expression
*/
@Override
public ASTNode visitUnaryExpression(SimpleJavaParser.UnaryExpressionContext ctx) {
if(ctx.This() != null) {
@ -723,13 +430,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return null;
}
/**
* Visits a member access expression and creates a MemberAccessNode.
* It processes the 'this' keyword and identifiers for member access.
*
* @param ctx the member access context
* @return the AST node for the member access
*/
@Override
public ASTNode visitMemberAccess(SimpleJavaParser.MemberAccessContext ctx) {
MemberAccessNode memberAccessNode;
@ -744,13 +444,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return memberAccessNode;
}
/**
* Visits a value and creates a ValueNode.
* It handles integer, boolean, char, and null values.
*
* @param ctx the value context
* @return the AST node for the value
*/
@Override
public ASTNode visitValue(SimpleJavaParser.ValueContext ctx) {
if(ctx.IntValue() != null) {
@ -765,25 +458,12 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return null;
}
/**
* Visits a not expression and creates a NotNode.
* It processes the expression to which the 'not' operator is applied.
*
* @param ctx the not expression context
* @return the AST node for the not expression
*/
@Override
public ASTNode visitNotExpression(SimpleJavaParser.NotExpressionContext ctx) {
return new NotNode((IExpressionNode) visitExpression(ctx.expression()));
}
/**
* Visits a binary expression and creates the corresponding AST node.
* It handles both calculation and non-calculation expressions.
*
* @param ctx the binary expression context
* @return the AST node for the binary expression
*/
@Override
public ASTNode visitBinaryExpression(SimpleJavaParser.BinaryExpressionContext ctx) {
if(ctx.calculationExpression() != null) {
@ -794,13 +474,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return null;
}
/**
* Visits a calculation expression and creates a CalculationNode.
* It handles line operators and dot expressions.
*
* @param ctx the calculation expression context
* @return the AST node for the calculation expression
*/
@Override
public ASTNode visitCalculationExpression(SimpleJavaParser.CalculationExpressionContext ctx) {
if(ctx.calculationExpression() != null) {
@ -811,69 +484,35 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return null;
}
/**
* Visits a dot expression and creates a DotNode.
* It handles dot operators and dot subtraction expressions.
*
* @param ctx the dot expression context
* @return the AST node for the dot expression
*/
@Override
public ASTNode visitDotExpression(SimpleJavaParser.DotExpressionContext ctx) {
if(ctx.dotExpression() != null) {
return new DotNode((DotNode) visit(ctx.dotExpression()), ctx.DotOperator().getText(), (DotSubtractionNode) visit(ctx.dotSubtractionExpression()));
return new DotNode((DotNode) visit(ctx.dotExpression()), ctx.DotOperator().getText(), (DotSubstractionNode) visit(ctx.dotSubtractionExpression()));
} else if(ctx.dotSubtractionExpression() != null) {
return new DotNode((DotSubtractionNode) visit(ctx.dotSubtractionExpression()));
return new DotNode((DotSubstractionNode) visit(ctx.dotSubtractionExpression()));
}
return null;
}
/**
* Visits a dot subtraction expression and creates a DotSubtractionNode.
* It handles integer values, identifiers, member access, and method calls.
*
* @param ctx the dot subtraction expression context
* @return the AST node for the dot subtraction expression
*//**
* Creates an ITypeNode based on the type identifier.
* It handles basic types and reference types.
*
* @param identifier the type identifier
* @return the type node
*/
@Override
public ASTNode visitDotSubtractionExpression(SimpleJavaParser.DotSubtractionExpressionContext ctx) {
if(ctx.IntValue() != null) {
return new DotSubtractionNode(new ValueNode(EnumValueNode.INT_VALUE, ctx.IntValue().getText()));
return new DotSubstractionNode(new ValueNode(EnumValueNode.INT_VALUE, ctx.IntValue().getText()));
} else if(ctx.Identifier() != null) {
return new DotSubtractionNode(ctx.Identifier().getText());
return new DotSubstractionNode(ctx.Identifier().getText());
} else if(ctx.memberAccess() != null) {
return new DotSubtractionNode((MemberAccessNode) visit(ctx.memberAccess()));
return new DotSubstractionNode((MemberAccessNode) visit(ctx.memberAccess()));
} else if(ctx.methodCall() != null && ctx.calculationExpression() != null) {
return new DotSubtractionNode((MethodCallNode) visit(ctx.methodCall()), (CalculationNode) visit(ctx.calculationExpression()));
return new DotSubstractionNode((MethodCallNode) visit(ctx.methodCall()), (CalculationNode) visit(ctx.calculationExpression()));
}
return null;
}
/**
* Visits a non-calculation expression and creates a NonCalculationNode.
* It handles unary expressions combined with non-calculation operators.
*
* @param ctx the non-calculation expression context
* @return the AST node for the non-calculation expression
*/
@Override
public ASTNode visitNonCalculationExpression(SimpleJavaParser.NonCalculationExpressionContext ctx) {
return new NonCalculationNode((UnaryNode) visit(ctx.unaryExpression()), ctx.nonCalculationOperator().getText(), (IExpressionNode) visit(ctx.expression()));
}
/**
* Visits an assignable expression and creates an AssignableNode.
* It handles identifiers and member access.
*
* @param ctx the assignable expression context
* @return the AST node for the assignable expression
*/
@Override
public ASTNode visitAssignableExpression(SimpleJavaParser.AssignableExpressionContext ctx) {
if(ctx.Identifier() != null) {
@ -884,13 +523,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return null;
}
/**
* Creates an ITypeNode based on the type identifier.
* It handles basic types and reference types.
*
* @param identifier the type identifier
* @return the type node
*/
public ITypeNode createTypeNode(String identifier){
return switch (identifier) {
case "int" -> new BaseType(TypeEnum.INT);
@ -900,4 +532,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
default -> new ReferenceType(identifier);
};
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -41,18 +41,14 @@ Else=40
For=41
Return=42
New=43
Switch=44
Case=45
Default=46
Colon=47
CharValue=48
IntValue=49
BooleanValue=50
NullValue=51
Identifier=52
WS=53
InlineComment=54
MultilineComment=55
CharValue=44
IntValue=45
BooleanValue=46
NullValue=47
Identifier=48
WS=49
InlineComment=50
MultilineComment=51
'++'=1
'--'=2
'void'=3
@ -91,8 +87,4 @@ MultilineComment=55
'for'=41
'return'=42
'new'=43
'switch'=44
'case'=45
'default'=46
':'=47
'null'=51
'null'=47

View File

@ -1,4 +1,4 @@
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated;
import org.antlr.v4.runtime.ParserRuleContext;
@ -252,42 +252,6 @@ public class SimpleJavaBaseListener implements SimpleJavaListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitElseStatement(SimpleJavaParser.ElseStatementContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterSwitchStatement(SimpleJavaParser.SwitchStatementContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitSwitchStatement(SimpleJavaParser.SwitchStatementContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterCaseStatement(SimpleJavaParser.CaseStatementContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitCaseStatement(SimpleJavaParser.CaseStatementContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDefaultStatement(SimpleJavaParser.DefaultStatementContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDefaultStatement(SimpleJavaParser.DefaultStatementContext ctx) { }
/**
* {@inheritDoc}
*

View File

@ -1,4 +1,4 @@
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
@ -152,27 +152,6 @@ public class SimpleJavaBaseVisitor<T> extends AbstractParseTreeVisitor<T> implem
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitElseStatement(SimpleJavaParser.ElseStatementContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitSwitchStatement(SimpleJavaParser.SwitchStatementContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitCaseStatement(SimpleJavaParser.CaseStatementContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDefaultStatement(SimpleJavaParser.DefaultStatementContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
@ -23,9 +23,9 @@ public class SimpleJavaLexer extends Lexer {
Less=20, GreaterEqual=21, LessEqual=22, Equal=23, NotEqual=24, Not=25,
And=26, Or=27, Dot=28, OpenRoundBracket=29, ClosedRoundBracket=30, OpenCurlyBracket=31,
ClosedCurlyBracket=32, Semicolon=33, Comma=34, Class=35, This=36, While=37,
Do=38, If=39, Else=40, For=41, Return=42, New=43, Switch=44, Case=45,
Default=46, Colon=47, CharValue=48, IntValue=49, BooleanValue=50, NullValue=51,
Identifier=52, WS=53, InlineComment=54, MultilineComment=55;
Do=38, If=39, Else=40, For=41, Return=42, New=43, CharValue=44, IntValue=45,
BooleanValue=46, NullValue=47, Identifier=48, WS=49, InlineComment=50,
MultilineComment=51;
public static String[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
};
@ -42,10 +42,9 @@ public class SimpleJavaLexer extends Lexer {
"GreaterEqual", "LessEqual", "Equal", "NotEqual", "Not", "And", "Or",
"Dot", "OpenRoundBracket", "ClosedRoundBracket", "OpenCurlyBracket",
"ClosedCurlyBracket", "Semicolon", "Comma", "Class", "This", "While",
"Do", "If", "Else", "For", "Return", "New", "Switch", "Case", "Default",
"Colon", "CharValue", "IntValue", "BooleanValue", "NullValue", "Alphabetic",
"Numeric", "ValidIdentSymbols", "Identifier", "WS", "InlineComment",
"MultilineComment"
"Do", "If", "Else", "For", "Return", "New", "CharValue", "IntValue",
"BooleanValue", "NullValue", "Alphabetic", "Numeric", "ValidIdentSymbols",
"Identifier", "WS", "InlineComment", "MultilineComment"
};
}
public static final String[] ruleNames = makeRuleNames();
@ -57,8 +56,7 @@ public class SimpleJavaLexer extends Lexer {
"'+'", "'-'", "'*'", "'%'", "'/'", "'>'", "'<'", "'>='", "'<='", "'=='",
"'!='", "'!'", "'&&'", "'||'", "'.'", "'('", "')'", "'{'", "'}'", "';'",
"','", "'class'", "'this'", "'while'", "'do'", "'if'", "'else'", "'for'",
"'return'", "'new'", "'switch'", "'case'", "'default'", "':'", null,
null, null, "'null'"
"'return'", "'new'", null, null, null, "'null'"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
@ -70,9 +68,9 @@ public class SimpleJavaLexer extends Lexer {
"Greater", "Less", "GreaterEqual", "LessEqual", "Equal", "NotEqual",
"Not", "And", "Or", "Dot", "OpenRoundBracket", "ClosedRoundBracket",
"OpenCurlyBracket", "ClosedCurlyBracket", "Semicolon", "Comma", "Class",
"This", "While", "Do", "If", "Else", "For", "Return", "New", "Switch",
"Case", "Default", "Colon", "CharValue", "IntValue", "BooleanValue",
"NullValue", "Identifier", "WS", "InlineComment", "MultilineComment"
"This", "While", "Do", "If", "Else", "For", "Return", "New", "CharValue",
"IntValue", "BooleanValue", "NullValue", "Identifier", "WS", "InlineComment",
"MultilineComment"
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
@ -134,7 +132,7 @@ public class SimpleJavaLexer extends Lexer {
public ATN getATN() { return _ATN; }
public static final String _serializedATN =
"\u0004\u00007\u01bb\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+
"\u0004\u00003\u019d\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"+
@ -149,263 +147,245 @@ public class SimpleJavaLexer extends Lexer {
"&\u0002\'\u0007\'\u0002(\u0007(\u0002)\u0007)\u0002*\u0007*\u0002+\u0007"+
"+\u0002,\u0007,\u0002-\u0007-\u0002.\u0007.\u0002/\u0007/\u00020\u0007"+
"0\u00021\u00071\u00022\u00072\u00023\u00073\u00024\u00074\u00025\u0007"+
"5\u00026\u00076\u00027\u00077\u00028\u00078\u00029\u00079\u0001\u0000"+
"\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0002"+
"\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0003\u0001\u0003"+
"5\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0003"+
"\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003"+
"\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0005"+
"\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0006\u0001\u0006\u0001\u0006"+
"\u0001\u0003\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004"+
"\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0006\u0001\u0006"+
"\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006"+
"\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006"+
"\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006"+
"\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006"+
"\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006"+
"\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006"+
"\u0001\u0006\u0003\u0006\u00ba\b\u0006\u0001\u0007\u0001\u0007\u0001\u0007"+
"\u0001\u0006\u0001\u0006\u0003\u0006\u00b2\b\u0006\u0001\u0007\u0001\u0007"+
"\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+
"\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+
"\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+
"\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+
"\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+
"\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+
"\u0001\b\u0001\b\u0001\b\u0003\b\u00e6\b\b\u0001\t\u0001\t\u0003\t\u00ea"+
"\b\t\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0003\n\u00f2\b\n"+
"\u0001\u000b\u0001\u000b\u0003\u000b\u00f6\b\u000b\u0001\f\u0001\f\u0001"+
"\r\u0001\r\u0001\u000e\u0001\u000e\u0001\u000f\u0001\u000f\u0001\u0010"+
"\u0001\u0010\u0001\u0011\u0001\u0011\u0001\u0012\u0001\u0012\u0001\u0013"+
"\u0001\u0013\u0001\u0014\u0001\u0014\u0001\u0014\u0001\u0015\u0001\u0015"+
"\u0001\u0015\u0001\u0016\u0001\u0016\u0001\u0016\u0001\u0017\u0001\u0017"+
"\u0001\u0017\u0001\u0018\u0001\u0018\u0001\u0019\u0001\u0019\u0001\u0019"+
"\u0001\u001a\u0001\u001a\u0001\u001a\u0001\u001b\u0001\u001b\u0001\u001c"+
"\u0001\u001c\u0001\u001d\u0001\u001d\u0001\u001e\u0001\u001e\u0001\u001f"+
"\u0001\u001f\u0001 \u0001 \u0001!\u0001!\u0001\"\u0001\"\u0001\"\u0001"+
"\"\u0001\"\u0001\"\u0001#\u0001#\u0001#\u0001#\u0001#\u0001$\u0001$\u0001"+
"$\u0001$\u0001$\u0001$\u0001%\u0001%\u0001%\u0001&\u0001&\u0001&\u0001"+
"\'\u0001\'\u0001\'\u0001\'\u0001\'\u0001(\u0001(\u0001(\u0001(\u0001)"+
"\u0001)\u0001)\u0001)\u0001)\u0001)\u0001)\u0001*\u0001*\u0001*\u0001"+
"*\u0001+\u0001+\u0001+\u0001+\u0001+\u0001+\u0001+\u0001,\u0001,\u0001"+
",\u0001,\u0001,\u0001-\u0001-\u0001-\u0001-\u0001-\u0001-\u0001-\u0001"+
"-\u0001.\u0001.\u0001/\u0001/\u0005/\u016d\b/\n/\f/\u0170\t/\u0001/\u0001"+
"/\u00010\u00030\u0175\b0\u00010\u00040\u0178\b0\u000b0\f0\u0179\u0001"+
"1\u00011\u00011\u00011\u00011\u00011\u00011\u00011\u00011\u00031\u0185"+
"\b1\u00012\u00012\u00012\u00012\u00012\u00013\u00013\u00014\u00014\u0001"+
"5\u00015\u00015\u00035\u0193\b5\u00016\u00016\u00056\u0197\b6\n6\f6\u019a"+
"\t6\u00017\u00047\u019d\b7\u000b7\f7\u019e\u00017\u00017\u00018\u0001"+
"8\u00018\u00018\u00058\u01a7\b8\n8\f8\u01aa\t8\u00018\u00018\u00019\u0001"+
"9\u00019\u00019\u00059\u01b2\b9\n9\f9\u01b5\t9\u00019\u00019\u00019\u0001"+
"9\u00019\u0001\u01b3\u0000:\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\u00193\u001a5\u001b7\u001c9\u001d"+
";\u001e=\u001f? A!C\"E#G$I%K&M\'O(Q)S*U+W,Y-[.]/_0a1c2e3g\u0000i\u0000"+
"k\u0000m4o5q6s7\u0001\u0000\u0005\u0002\u0000\n\n\r\r\u0002\u0000AZaz"+
"\u0001\u000009\u0002\u0000$$__\u0003\u0000\t\n\r\r \u01cd\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\u00003\u0001\u0000\u0000\u0000\u0000"+
"5\u0001\u0000\u0000\u0000\u00007\u0001\u0000\u0000\u0000\u00009\u0001"+
"\u0000\u0000\u0000\u0000;\u0001\u0000\u0000\u0000\u0000=\u0001\u0000\u0000"+
"\u0000\u0000?\u0001\u0000\u0000\u0000\u0000A\u0001\u0000\u0000\u0000\u0000"+
"C\u0001\u0000\u0000\u0000\u0000E\u0001\u0000\u0000\u0000\u0000G\u0001"+
"\u0000\u0000\u0000\u0000I\u0001\u0000\u0000\u0000\u0000K\u0001\u0000\u0000"+
"\u0000\u0000M\u0001\u0000\u0000\u0000\u0000O\u0001\u0000\u0000\u0000\u0000"+
"Q\u0001\u0000\u0000\u0000\u0000S\u0001\u0000\u0000\u0000\u0000U\u0001"+
"\u0000\u0000\u0000\u0000W\u0001\u0000\u0000\u0000\u0000Y\u0001\u0000\u0000"+
"\u0000\u0000[\u0001\u0000\u0000\u0000\u0000]\u0001\u0000\u0000\u0000\u0000"+
"_\u0001\u0000\u0000\u0000\u0000a\u0001\u0000\u0000\u0000\u0000c\u0001"+
"\u0000\u0000\u0000\u0000e\u0001\u0000\u0000\u0000\u0000m\u0001\u0000\u0000"+
"\u0000\u0000o\u0001\u0000\u0000\u0000\u0000q\u0001\u0000\u0000\u0000\u0000"+
"s\u0001\u0000\u0000\u0000\u0001u\u0001\u0000\u0000\u0000\u0003x\u0001"+
"\u0000\u0000\u0000\u0005{\u0001\u0000\u0000\u0000\u0007\u0080\u0001\u0000"+
"\u0000\u0000\t\u0088\u0001\u0000\u0000\u0000\u000b\u008d\u0001\u0000\u0000"+
"\u0000\r\u00b9\u0001\u0000\u0000\u0000\u000f\u00bb\u0001\u0000\u0000\u0000"+
"\u0011\u00e5\u0001\u0000\u0000\u0000\u0013\u00e9\u0001\u0000\u0000\u0000"+
"\u0015\u00f1\u0001\u0000\u0000\u0000\u0017\u00f5\u0001\u0000\u0000\u0000"+
"\u0019\u00f7\u0001\u0000\u0000\u0000\u001b\u00f9\u0001\u0000\u0000\u0000"+
"\u001d\u00fb\u0001\u0000\u0000\u0000\u001f\u00fd\u0001\u0000\u0000\u0000"+
"!\u00ff\u0001\u0000\u0000\u0000#\u0101\u0001\u0000\u0000\u0000%\u0103"+
"\u0001\u0000\u0000\u0000\'\u0105\u0001\u0000\u0000\u0000)\u0107\u0001"+
"\u0000\u0000\u0000+\u010a\u0001\u0000\u0000\u0000-\u010d\u0001\u0000\u0000"+
"\u0000/\u0110\u0001\u0000\u0000\u00001\u0113\u0001\u0000\u0000\u00003"+
"\u0115\u0001\u0000\u0000\u00005\u0118\u0001\u0000\u0000\u00007\u011b\u0001"+
"\u0000\u0000\u00009\u011d\u0001\u0000\u0000\u0000;\u011f\u0001\u0000\u0000"+
"\u0000=\u0121\u0001\u0000\u0000\u0000?\u0123\u0001\u0000\u0000\u0000A"+
"\u0125\u0001\u0000\u0000\u0000C\u0127\u0001\u0000\u0000\u0000E\u0129\u0001"+
"\u0000\u0000\u0000G\u012f\u0001\u0000\u0000\u0000I\u0134\u0001\u0000\u0000"+
"\u0000K\u013a\u0001\u0000\u0000\u0000M\u013d\u0001\u0000\u0000\u0000O"+
"\u0140\u0001\u0000\u0000\u0000Q\u0145\u0001\u0000\u0000\u0000S\u0149\u0001"+
"\u0000\u0000\u0000U\u0150\u0001\u0000\u0000\u0000W\u0154\u0001\u0000\u0000"+
"\u0000Y\u015b\u0001\u0000\u0000\u0000[\u0160\u0001\u0000\u0000\u0000]"+
"\u0168\u0001\u0000\u0000\u0000_\u016a\u0001\u0000\u0000\u0000a\u0174\u0001"+
"\u0000\u0000\u0000c\u0184\u0001\u0000\u0000\u0000e\u0186\u0001\u0000\u0000"+
"\u0000g\u018b\u0001\u0000\u0000\u0000i\u018d\u0001\u0000\u0000\u0000k"+
"\u0192\u0001\u0000\u0000\u0000m\u0194\u0001\u0000\u0000\u0000o\u019c\u0001"+
"\u0000\u0000\u0000q\u01a2\u0001\u0000\u0000\u0000s\u01ad\u0001\u0000\u0000"+
"\u0000uv\u0005+\u0000\u0000vw\u0005+\u0000\u0000w\u0002\u0001\u0000\u0000"+
"\u0000xy\u0005-\u0000\u0000yz\u0005-\u0000\u0000z\u0004\u0001\u0000\u0000"+
"\u0000{|\u0005v\u0000\u0000|}\u0005o\u0000\u0000}~\u0005i\u0000\u0000"+
"~\u007f\u0005d\u0000\u0000\u007f\u0006\u0001\u0000\u0000\u0000\u0080\u0081"+
"\u0005b\u0000\u0000\u0081\u0082\u0005o\u0000\u0000\u0082\u0083\u0005o"+
"\u0000\u0000\u0083\u0084\u0005l\u0000\u0000\u0084\u0085\u0005e\u0000\u0000"+
"\u0085\u0086\u0005a\u0000\u0000\u0086\u0087\u0005n\u0000\u0000\u0087\b"+
"\u0001\u0000\u0000\u0000\u0088\u0089\u0005c\u0000\u0000\u0089\u008a\u0005"+
"h\u0000\u0000\u008a\u008b\u0005a\u0000\u0000\u008b\u008c\u0005r\u0000"+
"\u0000\u008c\n\u0001\u0000\u0000\u0000\u008d\u008e\u0005i\u0000\u0000"+
"\u008e\u008f\u0005n\u0000\u0000\u008f\u0090\u0005t\u0000\u0000\u0090\f"+
"\u0001\u0000\u0000\u0000\u0091\u0092\u0005p\u0000\u0000\u0092\u0093\u0005"+
"u\u0000\u0000\u0093\u0094\u0005b\u0000\u0000\u0094\u0095\u0005l\u0000"+
"\u0000\u0095\u0096\u0005i\u0000\u0000\u0096\u00ba\u0005c\u0000\u0000\u0097"+
"\u0098\u0005p\u0000\u0000\u0098\u0099\u0005r\u0000\u0000\u0099\u009a\u0005"+
"i\u0000\u0000\u009a\u009b\u0005v\u0000\u0000\u009b\u009c\u0005a\u0000"+
"\u0000\u009c\u009d\u0005t\u0000\u0000\u009d\u00ba\u0005e\u0000\u0000\u009e"+
"\u009f\u0005p\u0000\u0000\u009f\u00a0\u0005u\u0000\u0000\u00a0\u00a1\u0005"+
"b\u0000\u0000\u00a1\u00a2\u0005l\u0000\u0000\u00a2\u00a3\u0005i\u0000"+
"\u0000\u00a3\u00a4\u0005c\u0000\u0000\u00a4\u00a5\u0005 \u0000\u0000\u00a5"+
"\u00a6\u0005s\u0000\u0000\u00a6\u00a7\u0005t\u0000\u0000\u00a7\u00a8\u0005"+
"a\u0000\u0000\u00a8\u00a9\u0005t\u0000\u0000\u00a9\u00aa\u0005i\u0000"+
"\u0000\u00aa\u00ba\u0005c\u0000\u0000\u00ab\u00ac\u0005p\u0000\u0000\u00ac"+
"\u00ad\u0005r\u0000\u0000\u00ad\u00ae\u0005i\u0000\u0000\u00ae\u00af\u0005"+
"v\u0000\u0000\u00af\u00b0\u0005a\u0000\u0000\u00b0\u00b1\u0005t\u0000"+
"\u0000\u00b1\u00b2\u0005e\u0000\u0000\u00b2\u00b3\u0005 \u0000\u0000\u00b3"+
"\u00b4\u0005s\u0000\u0000\u00b4\u00b5\u0005t\u0000\u0000\u00b5\u00b6\u0005"+
"a\u0000\u0000\u00b6\u00b7\u0005t\u0000\u0000\u00b7\u00b8\u0005i\u0000"+
"\u0000\u00b8\u00ba\u0005c\u0000\u0000\u00b9\u0091\u0001\u0000\u0000\u0000"+
"\u00b9\u0097\u0001\u0000\u0000\u0000\u00b9\u009e\u0001\u0000\u0000\u0000"+
"\u00b9\u00ab\u0001\u0000\u0000\u0000\u00ba\u000e\u0001\u0000\u0000\u0000"+
"\u00bb\u00bc\u0005p\u0000\u0000\u00bc\u00bd\u0005u\u0000\u0000\u00bd\u00be"+
"\u0005b\u0000\u0000\u00be\u00bf\u0005l\u0000\u0000\u00bf\u00c0\u0005i"+
"\u0000\u0000\u00c0\u00c1\u0005c\u0000\u0000\u00c1\u00c2\u0005 \u0000\u0000"+
"\u00c2\u00c3\u0005s\u0000\u0000\u00c3\u00c4\u0005t\u0000\u0000\u00c4\u00c5"+
"\u0005a\u0000\u0000\u00c5\u00c6\u0005t\u0000\u0000\u00c6\u00c7\u0005i"+
"\u0000\u0000\u00c7\u00c8\u0005c\u0000\u0000\u00c8\u00c9\u0005 \u0000\u0000"+
"\u00c9\u00ca\u0005v\u0000\u0000\u00ca\u00cb\u0005o\u0000\u0000\u00cb\u00cc"+
"\u0005i\u0000\u0000\u00cc\u00cd\u0005d\u0000\u0000\u00cd\u00ce\u0005 "+
"\u0000\u0000\u00ce\u00cf\u0005m\u0000\u0000\u00cf\u00d0\u0005a\u0000\u0000"+
"\u00d0\u00d1\u0005i\u0000\u0000\u00d1\u00d2\u0005n\u0000\u0000\u00d2\u00d3"+
"\u0005(\u0000\u0000\u00d3\u00d4\u0005S\u0000\u0000\u00d4\u00d5\u0005t"+
"\u0000\u0000\u00d5\u00d6\u0005r\u0000\u0000\u00d6\u00d7\u0005i\u0000\u0000"+
"\u00d7\u00d8\u0005n\u0000\u0000\u00d8\u00d9\u0005g\u0000\u0000\u00d9\u00da"+
"\u0005[\u0000\u0000\u00da\u00db\u0005]\u0000\u0000\u00db\u00dc\u0005 "+
"\u0000\u0000\u00dc\u00dd\u0005a\u0000\u0000\u00dd\u00de\u0005r\u0000\u0000"+
"\u00de\u00df\u0005g\u0000\u0000\u00df\u00e0\u0005s\u0000\u0000\u00e0\u00e1"+
"\u0005)\u0000\u0000\u00e1\u0010\u0001\u0000\u0000\u0000\u00e2\u00e6\u0003"+
"\u001f\u000f\u0000\u00e3\u00e6\u0003#\u0011\u0000\u00e4\u00e6\u0003!\u0010"+
"\u0000\u00e5\u00e2\u0001\u0000\u0000\u0000\u00e5\u00e3\u0001\u0000\u0000"+
"\u0000\u00e5\u00e4\u0001\u0000\u0000\u0000\u00e6\u0012\u0001\u0000\u0000"+
"\u0000\u00e7\u00ea\u0003\u001b\r\u0000\u00e8\u00ea\u0003\u001d\u000e\u0000"+
"\u00e9\u00e7\u0001\u0000\u0000\u0000\u00e9\u00e8\u0001\u0000\u0000\u0000"+
"\u00ea\u0014\u0001\u0000\u0000\u0000\u00eb\u00f2\u0003%\u0012\u0000\u00ec"+
"\u00f2\u0003\'\u0013\u0000\u00ed\u00f2\u0003)\u0014\u0000\u00ee\u00f2"+
"\u0003+\u0015\u0000\u00ef\u00f2\u0003-\u0016\u0000\u00f0\u00f2\u0003/"+
"\u0017\u0000\u00f1\u00eb\u0001\u0000\u0000\u0000\u00f1\u00ec\u0001\u0000"+
"\u0000\u0000\u00f1\u00ed\u0001\u0000\u0000\u0000\u00f1\u00ee\u0001\u0000"+
"\u0000\u0000\u00f1\u00ef\u0001\u0000\u0000\u0000\u00f1\u00f0\u0001\u0000"+
"\u0000\u0000\u00f2\u0016\u0001\u0000\u0000\u0000\u00f3\u00f6\u00033\u0019"+
"\u0000\u00f4\u00f6\u00035\u001a\u0000\u00f5\u00f3\u0001\u0000\u0000\u0000"+
"\u00f5\u00f4\u0001\u0000\u0000\u0000\u00f6\u0018\u0001\u0000\u0000\u0000"+
"\u00f7\u00f8\u0005=\u0000\u0000\u00f8\u001a\u0001\u0000\u0000\u0000\u00f9"+
"\u00fa\u0005+\u0000\u0000\u00fa\u001c\u0001\u0000\u0000\u0000\u00fb\u00fc"+
"\u0005-\u0000\u0000\u00fc\u001e\u0001\u0000\u0000\u0000\u00fd\u00fe\u0005"+
"*\u0000\u0000\u00fe \u0001\u0000\u0000\u0000\u00ff\u0100\u0005%\u0000"+
"\u0000\u0100\"\u0001\u0000\u0000\u0000\u0101\u0102\u0005/\u0000\u0000"+
"\u0102$\u0001\u0000\u0000\u0000\u0103\u0104\u0005>\u0000\u0000\u0104&"+
"\u0001\u0000\u0000\u0000\u0105\u0106\u0005<\u0000\u0000\u0106(\u0001\u0000"+
"\u0000\u0000\u0107\u0108\u0005>\u0000\u0000\u0108\u0109\u0005=\u0000\u0000"+
"\u0109*\u0001\u0000\u0000\u0000\u010a\u010b\u0005<\u0000\u0000\u010b\u010c"+
"\u0005=\u0000\u0000\u010c,\u0001\u0000\u0000\u0000\u010d\u010e\u0005="+
"\u0000\u0000\u010e\u010f\u0005=\u0000\u0000\u010f.\u0001\u0000\u0000\u0000"+
"\u0110\u0111\u0005!\u0000\u0000\u0111\u0112\u0005=\u0000\u0000\u01120"+
"\u0001\u0000\u0000\u0000\u0113\u0114\u0005!\u0000\u0000\u01142\u0001\u0000"+
"\u0000\u0000\u0115\u0116\u0005&\u0000\u0000\u0116\u0117\u0005&\u0000\u0000"+
"\u01174\u0001\u0000\u0000\u0000\u0118\u0119\u0005|\u0000\u0000\u0119\u011a"+
"\u0005|\u0000\u0000\u011a6\u0001\u0000\u0000\u0000\u011b\u011c\u0005."+
"\u0000\u0000\u011c8\u0001\u0000\u0000\u0000\u011d\u011e\u0005(\u0000\u0000"+
"\u011e:\u0001\u0000\u0000\u0000\u011f\u0120\u0005)\u0000\u0000\u0120<"+
"\u0001\u0000\u0000\u0000\u0121\u0122\u0005{\u0000\u0000\u0122>\u0001\u0000"+
"\u0000\u0000\u0123\u0124\u0005}\u0000\u0000\u0124@\u0001\u0000\u0000\u0000"+
"\u0125\u0126\u0005;\u0000\u0000\u0126B\u0001\u0000\u0000\u0000\u0127\u0128"+
"\u0005,\u0000\u0000\u0128D\u0001\u0000\u0000\u0000\u0129\u012a\u0005c"+
"\u0000\u0000\u012a\u012b\u0005l\u0000\u0000\u012b\u012c\u0005a\u0000\u0000"+
"\u012c\u012d\u0005s\u0000\u0000\u012d\u012e\u0005s\u0000\u0000\u012eF"+
"\u0001\u0000\u0000\u0000\u012f\u0130\u0005t\u0000\u0000\u0130\u0131\u0005"+
"h\u0000\u0000\u0131\u0132\u0005i\u0000\u0000\u0132\u0133\u0005s\u0000"+
"\u0000\u0133H\u0001\u0000\u0000\u0000\u0134\u0135\u0005w\u0000\u0000\u0135"+
"\u0136\u0005h\u0000\u0000\u0136\u0137\u0005i\u0000\u0000\u0137\u0138\u0005"+
"l\u0000\u0000\u0138\u0139\u0005e\u0000\u0000\u0139J\u0001\u0000\u0000"+
"\u0000\u013a\u013b\u0005d\u0000\u0000\u013b\u013c\u0005o\u0000\u0000\u013c"+
"L\u0001\u0000\u0000\u0000\u013d\u013e\u0005i\u0000\u0000\u013e\u013f\u0005"+
"f\u0000\u0000\u013fN\u0001\u0000\u0000\u0000\u0140\u0141\u0005e\u0000"+
"\u0000\u0141\u0142\u0005l\u0000\u0000\u0142\u0143\u0005s\u0000\u0000\u0143"+
"\u0144\u0005e\u0000\u0000\u0144P\u0001\u0000\u0000\u0000\u0145\u0146\u0005"+
"f\u0000\u0000\u0146\u0147\u0005o\u0000\u0000\u0147\u0148\u0005r\u0000"+
"\u0000\u0148R\u0001\u0000\u0000\u0000\u0149\u014a\u0005r\u0000\u0000\u014a"+
"\u014b\u0005e\u0000\u0000\u014b\u014c\u0005t\u0000\u0000\u014c\u014d\u0005"+
"u\u0000\u0000\u014d\u014e\u0005r\u0000\u0000\u014e\u014f\u0005n\u0000"+
"\u0000\u014fT\u0001\u0000\u0000\u0000\u0150\u0151\u0005n\u0000\u0000\u0151"+
"\u0152\u0005e\u0000\u0000\u0152\u0153\u0005w\u0000\u0000\u0153V\u0001"+
"\u0000\u0000\u0000\u0154\u0155\u0005s\u0000\u0000\u0155\u0156\u0005w\u0000"+
"\u0000\u0156\u0157\u0005i\u0000\u0000\u0157\u0158\u0005t\u0000\u0000\u0158"+
"\u0159\u0005c\u0000\u0000\u0159\u015a\u0005h\u0000\u0000\u015aX\u0001"+
"\u0000\u0000\u0000\u015b\u015c\u0005c\u0000\u0000\u015c\u015d\u0005a\u0000"+
"\u0000\u015d\u015e\u0005s\u0000\u0000\u015e\u015f\u0005e\u0000\u0000\u015f"+
"Z\u0001\u0000\u0000\u0000\u0160\u0161\u0005d\u0000\u0000\u0161\u0162\u0005"+
"e\u0000\u0000\u0162\u0163\u0005f\u0000\u0000\u0163\u0164\u0005a\u0000"+
"\u0000\u0164\u0165\u0005u\u0000\u0000\u0165\u0166\u0005l\u0000\u0000\u0166"+
"\u0167\u0005t\u0000\u0000\u0167\\\u0001\u0000\u0000\u0000\u0168\u0169"+
"\u0005:\u0000\u0000\u0169^\u0001\u0000\u0000\u0000\u016a\u016e\u0005\'"+
"\u0000\u0000\u016b\u016d\b\u0000\u0000\u0000\u016c\u016b\u0001\u0000\u0000"+
"\u0000\u016d\u0170\u0001\u0000\u0000\u0000\u016e\u016c\u0001\u0000\u0000"+
"\u0000\u016e\u016f\u0001\u0000\u0000\u0000\u016f\u0171\u0001\u0000\u0000"+
"\u0000\u0170\u016e\u0001\u0000\u0000\u0000\u0171\u0172\u0005\'\u0000\u0000"+
"\u0172`\u0001\u0000\u0000\u0000\u0173\u0175\u0003\u001d\u000e\u0000\u0174"+
"\u0173\u0001\u0000\u0000\u0000\u0174\u0175\u0001\u0000\u0000\u0000\u0175"+
"\u0177\u0001\u0000\u0000\u0000\u0176\u0178\u0003i4\u0000\u0177\u0176\u0001"+
"\u0000\u0000\u0000\u0178\u0179\u0001\u0000\u0000\u0000\u0179\u0177\u0001"+
"\u0000\u0000\u0000\u0179\u017a\u0001\u0000\u0000\u0000\u017ab\u0001\u0000"+
"\u0000\u0000\u017b\u017c\u0005t\u0000\u0000\u017c\u017d\u0005r\u0000\u0000"+
"\u017d\u017e\u0005u\u0000\u0000\u017e\u0185\u0005e\u0000\u0000\u017f\u0180"+
"\u0005f\u0000\u0000\u0180\u0181\u0005a\u0000\u0000\u0181\u0182\u0005l"+
"\u0000\u0000\u0182\u0183\u0005s\u0000\u0000\u0183\u0185\u0005e\u0000\u0000"+
"\u0184\u017b\u0001\u0000\u0000\u0000\u0184\u017f\u0001\u0000\u0000\u0000"+
"\u0185d\u0001\u0000\u0000\u0000\u0186\u0187\u0005n\u0000\u0000\u0187\u0188"+
"\u0005u\u0000\u0000\u0188\u0189\u0005l\u0000\u0000\u0189\u018a\u0005l"+
"\u0000\u0000\u018af\u0001\u0000\u0000\u0000\u018b\u018c\u0007\u0001\u0000"+
"\u0000\u018ch\u0001\u0000\u0000\u0000\u018d\u018e\u0007\u0002\u0000\u0000"+
"\u018ej\u0001\u0000\u0000\u0000\u018f\u0193\u0003g3\u0000\u0190\u0193"+
"\u0003i4\u0000\u0191\u0193\u0007\u0003\u0000\u0000\u0192\u018f\u0001\u0000"+
"\u0000\u0000\u0192\u0190\u0001\u0000\u0000\u0000\u0192\u0191\u0001\u0000"+
"\u0000\u0000\u0193l\u0001\u0000\u0000\u0000\u0194\u0198\u0003g3\u0000"+
"\u0195\u0197\u0003k5\u0000\u0196\u0195\u0001\u0000\u0000\u0000\u0197\u019a"+
"\u0001\u0000\u0000\u0000\u0198\u0196\u0001\u0000\u0000\u0000\u0198\u0199"+
"\u0001\u0000\u0000\u0000\u0199n\u0001\u0000\u0000\u0000\u019a\u0198\u0001"+
"\u0000\u0000\u0000\u019b\u019d\u0007\u0004\u0000\u0000\u019c\u019b\u0001"+
"\u0000\u0000\u0000\u019d\u019e\u0001\u0000\u0000\u0000\u019e\u019c\u0001"+
"\u0000\u0000\u0000\u019e\u019f\u0001\u0000\u0000\u0000\u019f\u01a0\u0001"+
"\u0000\u0000\u0000\u01a0\u01a1\u00067\u0000\u0000\u01a1p\u0001\u0000\u0000"+
"\u0000\u01a2\u01a3\u0005/\u0000\u0000\u01a3\u01a4\u0005/\u0000\u0000\u01a4"+
"\u01a8\u0001\u0000\u0000\u0000\u01a5\u01a7\b\u0000\u0000\u0000\u01a6\u01a5"+
"\u0001\u0000\u0000\u0000\u01a7\u01aa\u0001\u0000\u0000\u0000\u01a8\u01a6"+
"\u0001\u0000\u0000\u0000\u01a8\u01a9\u0001\u0000\u0000\u0000\u01a9\u01ab"+
"\u0001\u0000\u0000\u0000\u01aa\u01a8\u0001\u0000\u0000\u0000\u01ab\u01ac"+
"\u00068\u0000\u0000\u01acr\u0001\u0000\u0000\u0000\u01ad\u01ae\u0005/"+
"\u0000\u0000\u01ae\u01af\u0005*\u0000\u0000\u01af\u01b3\u0001\u0000\u0000"+
"\u0000\u01b0\u01b2\t\u0000\u0000\u0000\u01b1\u01b0\u0001\u0000\u0000\u0000"+
"\u01b2\u01b5\u0001\u0000\u0000\u0000\u01b3\u01b4\u0001\u0000\u0000\u0000"+
"\u01b3\u01b1\u0001\u0000\u0000\u0000\u01b4\u01b6\u0001\u0000\u0000\u0000"+
"\u01b5\u01b3\u0001\u0000\u0000\u0000\u01b6\u01b7\u0005*\u0000\u0000\u01b7"+
"\u01b8\u0005/\u0000\u0000\u01b8\u01b9\u0001\u0000\u0000\u0000\u01b9\u01ba"+
"\u00069\u0000\u0000\u01bat\u0001\u0000\u0000\u0000\u000f\u0000\u00b9\u00e5"+
"\u00e9\u00f1\u00f5\u016e\u0174\u0179\u0184\u0192\u0198\u019e\u01a8\u01b3"+
"\u0001\u0006\u0000\u0000";
"\u0001\u0007\u0001\b\u0001\b\u0001\b\u0003\b\u00de\b\b\u0001\t\u0001\t"+
"\u0003\t\u00e2\b\t\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0003"+
"\n\u00ea\b\n\u0001\u000b\u0001\u000b\u0003\u000b\u00ee\b\u000b\u0001\f"+
"\u0001\f\u0001\r\u0001\r\u0001\u000e\u0001\u000e\u0001\u000f\u0001\u000f"+
"\u0001\u0010\u0001\u0010\u0001\u0011\u0001\u0011\u0001\u0012\u0001\u0012"+
"\u0001\u0013\u0001\u0013\u0001\u0014\u0001\u0014\u0001\u0014\u0001\u0015"+
"\u0001\u0015\u0001\u0015\u0001\u0016\u0001\u0016\u0001\u0016\u0001\u0017"+
"\u0001\u0017\u0001\u0017\u0001\u0018\u0001\u0018\u0001\u0019\u0001\u0019"+
"\u0001\u0019\u0001\u001a\u0001\u001a\u0001\u001a\u0001\u001b\u0001\u001b"+
"\u0001\u001c\u0001\u001c\u0001\u001d\u0001\u001d\u0001\u001e\u0001\u001e"+
"\u0001\u001f\u0001\u001f\u0001 \u0001 \u0001!\u0001!\u0001\"\u0001\"\u0001"+
"\"\u0001\"\u0001\"\u0001\"\u0001#\u0001#\u0001#\u0001#\u0001#\u0001$\u0001"+
"$\u0001$\u0001$\u0001$\u0001$\u0001%\u0001%\u0001%\u0001&\u0001&\u0001"+
"&\u0001\'\u0001\'\u0001\'\u0001\'\u0001\'\u0001(\u0001(\u0001(\u0001("+
"\u0001)\u0001)\u0001)\u0001)\u0001)\u0001)\u0001)\u0001*\u0001*\u0001"+
"*\u0001*\u0001+\u0001+\u0005+\u014f\b+\n+\f+\u0152\t+\u0001+\u0001+\u0001"+
",\u0003,\u0157\b,\u0001,\u0004,\u015a\b,\u000b,\f,\u015b\u0001-\u0001"+
"-\u0001-\u0001-\u0001-\u0001-\u0001-\u0001-\u0001-\u0003-\u0167\b-\u0001"+
".\u0001.\u0001.\u0001.\u0001.\u0001/\u0001/\u00010\u00010\u00011\u0001"+
"1\u00011\u00031\u0175\b1\u00012\u00012\u00052\u0179\b2\n2\f2\u017c\t2"+
"\u00013\u00043\u017f\b3\u000b3\f3\u0180\u00013\u00013\u00014\u00014\u0001"+
"4\u00014\u00054\u0189\b4\n4\f4\u018c\t4\u00014\u00014\u00015\u00015\u0001"+
"5\u00015\u00055\u0194\b5\n5\f5\u0197\t5\u00015\u00015\u00015\u00015\u0001"+
"5\u0001\u0195\u00006\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\u00193\u001a5\u001b7\u001c9\u001d;\u001e"+
"=\u001f? A!C\"E#G$I%K&M\'O(Q)S*U+W,Y-[.]/_\u0000a\u0000c\u0000e0g1i2k"+
"3\u0001\u0000\u0005\u0002\u0000\n\n\r\r\u0002\u0000AZaz\u0001\u000009"+
"\u0002\u0000$$__\u0003\u0000\t\n\r\r \u01af\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\u00003\u0001\u0000\u0000\u0000\u00005\u0001\u0000"+
"\u0000\u0000\u00007\u0001\u0000\u0000\u0000\u00009\u0001\u0000\u0000\u0000"+
"\u0000;\u0001\u0000\u0000\u0000\u0000=\u0001\u0000\u0000\u0000\u0000?"+
"\u0001\u0000\u0000\u0000\u0000A\u0001\u0000\u0000\u0000\u0000C\u0001\u0000"+
"\u0000\u0000\u0000E\u0001\u0000\u0000\u0000\u0000G\u0001\u0000\u0000\u0000"+
"\u0000I\u0001\u0000\u0000\u0000\u0000K\u0001\u0000\u0000\u0000\u0000M"+
"\u0001\u0000\u0000\u0000\u0000O\u0001\u0000\u0000\u0000\u0000Q\u0001\u0000"+
"\u0000\u0000\u0000S\u0001\u0000\u0000\u0000\u0000U\u0001\u0000\u0000\u0000"+
"\u0000W\u0001\u0000\u0000\u0000\u0000Y\u0001\u0000\u0000\u0000\u0000["+
"\u0001\u0000\u0000\u0000\u0000]\u0001\u0000\u0000\u0000\u0000e\u0001\u0000"+
"\u0000\u0000\u0000g\u0001\u0000\u0000\u0000\u0000i\u0001\u0000\u0000\u0000"+
"\u0000k\u0001\u0000\u0000\u0000\u0001m\u0001\u0000\u0000\u0000\u0003p"+
"\u0001\u0000\u0000\u0000\u0005s\u0001\u0000\u0000\u0000\u0007x\u0001\u0000"+
"\u0000\u0000\t\u0080\u0001\u0000\u0000\u0000\u000b\u0085\u0001\u0000\u0000"+
"\u0000\r\u00b1\u0001\u0000\u0000\u0000\u000f\u00b3\u0001\u0000\u0000\u0000"+
"\u0011\u00dd\u0001\u0000\u0000\u0000\u0013\u00e1\u0001\u0000\u0000\u0000"+
"\u0015\u00e9\u0001\u0000\u0000\u0000\u0017\u00ed\u0001\u0000\u0000\u0000"+
"\u0019\u00ef\u0001\u0000\u0000\u0000\u001b\u00f1\u0001\u0000\u0000\u0000"+
"\u001d\u00f3\u0001\u0000\u0000\u0000\u001f\u00f5\u0001\u0000\u0000\u0000"+
"!\u00f7\u0001\u0000\u0000\u0000#\u00f9\u0001\u0000\u0000\u0000%\u00fb"+
"\u0001\u0000\u0000\u0000\'\u00fd\u0001\u0000\u0000\u0000)\u00ff\u0001"+
"\u0000\u0000\u0000+\u0102\u0001\u0000\u0000\u0000-\u0105\u0001\u0000\u0000"+
"\u0000/\u0108\u0001\u0000\u0000\u00001\u010b\u0001\u0000\u0000\u00003"+
"\u010d\u0001\u0000\u0000\u00005\u0110\u0001\u0000\u0000\u00007\u0113\u0001"+
"\u0000\u0000\u00009\u0115\u0001\u0000\u0000\u0000;\u0117\u0001\u0000\u0000"+
"\u0000=\u0119\u0001\u0000\u0000\u0000?\u011b\u0001\u0000\u0000\u0000A"+
"\u011d\u0001\u0000\u0000\u0000C\u011f\u0001\u0000\u0000\u0000E\u0121\u0001"+
"\u0000\u0000\u0000G\u0127\u0001\u0000\u0000\u0000I\u012c\u0001\u0000\u0000"+
"\u0000K\u0132\u0001\u0000\u0000\u0000M\u0135\u0001\u0000\u0000\u0000O"+
"\u0138\u0001\u0000\u0000\u0000Q\u013d\u0001\u0000\u0000\u0000S\u0141\u0001"+
"\u0000\u0000\u0000U\u0148\u0001\u0000\u0000\u0000W\u014c\u0001\u0000\u0000"+
"\u0000Y\u0156\u0001\u0000\u0000\u0000[\u0166\u0001\u0000\u0000\u0000]"+
"\u0168\u0001\u0000\u0000\u0000_\u016d\u0001\u0000\u0000\u0000a\u016f\u0001"+
"\u0000\u0000\u0000c\u0174\u0001\u0000\u0000\u0000e\u0176\u0001\u0000\u0000"+
"\u0000g\u017e\u0001\u0000\u0000\u0000i\u0184\u0001\u0000\u0000\u0000k"+
"\u018f\u0001\u0000\u0000\u0000mn\u0005+\u0000\u0000no\u0005+\u0000\u0000"+
"o\u0002\u0001\u0000\u0000\u0000pq\u0005-\u0000\u0000qr\u0005-\u0000\u0000"+
"r\u0004\u0001\u0000\u0000\u0000st\u0005v\u0000\u0000tu\u0005o\u0000\u0000"+
"uv\u0005i\u0000\u0000vw\u0005d\u0000\u0000w\u0006\u0001\u0000\u0000\u0000"+
"xy\u0005b\u0000\u0000yz\u0005o\u0000\u0000z{\u0005o\u0000\u0000{|\u0005"+
"l\u0000\u0000|}\u0005e\u0000\u0000}~\u0005a\u0000\u0000~\u007f\u0005n"+
"\u0000\u0000\u007f\b\u0001\u0000\u0000\u0000\u0080\u0081\u0005c\u0000"+
"\u0000\u0081\u0082\u0005h\u0000\u0000\u0082\u0083\u0005a\u0000\u0000\u0083"+
"\u0084\u0005r\u0000\u0000\u0084\n\u0001\u0000\u0000\u0000\u0085\u0086"+
"\u0005i\u0000\u0000\u0086\u0087\u0005n\u0000\u0000\u0087\u0088\u0005t"+
"\u0000\u0000\u0088\f\u0001\u0000\u0000\u0000\u0089\u008a\u0005p\u0000"+
"\u0000\u008a\u008b\u0005u\u0000\u0000\u008b\u008c\u0005b\u0000\u0000\u008c"+
"\u008d\u0005l\u0000\u0000\u008d\u008e\u0005i\u0000\u0000\u008e\u00b2\u0005"+
"c\u0000\u0000\u008f\u0090\u0005p\u0000\u0000\u0090\u0091\u0005r\u0000"+
"\u0000\u0091\u0092\u0005i\u0000\u0000\u0092\u0093\u0005v\u0000\u0000\u0093"+
"\u0094\u0005a\u0000\u0000\u0094\u0095\u0005t\u0000\u0000\u0095\u00b2\u0005"+
"e\u0000\u0000\u0096\u0097\u0005p\u0000\u0000\u0097\u0098\u0005u\u0000"+
"\u0000\u0098\u0099\u0005b\u0000\u0000\u0099\u009a\u0005l\u0000\u0000\u009a"+
"\u009b\u0005i\u0000\u0000\u009b\u009c\u0005c\u0000\u0000\u009c\u009d\u0005"+
" \u0000\u0000\u009d\u009e\u0005s\u0000\u0000\u009e\u009f\u0005t\u0000"+
"\u0000\u009f\u00a0\u0005a\u0000\u0000\u00a0\u00a1\u0005t\u0000\u0000\u00a1"+
"\u00a2\u0005i\u0000\u0000\u00a2\u00b2\u0005c\u0000\u0000\u00a3\u00a4\u0005"+
"p\u0000\u0000\u00a4\u00a5\u0005r\u0000\u0000\u00a5\u00a6\u0005i\u0000"+
"\u0000\u00a6\u00a7\u0005v\u0000\u0000\u00a7\u00a8\u0005a\u0000\u0000\u00a8"+
"\u00a9\u0005t\u0000\u0000\u00a9\u00aa\u0005e\u0000\u0000\u00aa\u00ab\u0005"+
" \u0000\u0000\u00ab\u00ac\u0005s\u0000\u0000\u00ac\u00ad\u0005t\u0000"+
"\u0000\u00ad\u00ae\u0005a\u0000\u0000\u00ae\u00af\u0005t\u0000\u0000\u00af"+
"\u00b0\u0005i\u0000\u0000\u00b0\u00b2\u0005c\u0000\u0000\u00b1\u0089\u0001"+
"\u0000\u0000\u0000\u00b1\u008f\u0001\u0000\u0000\u0000\u00b1\u0096\u0001"+
"\u0000\u0000\u0000\u00b1\u00a3\u0001\u0000\u0000\u0000\u00b2\u000e\u0001"+
"\u0000\u0000\u0000\u00b3\u00b4\u0005p\u0000\u0000\u00b4\u00b5\u0005u\u0000"+
"\u0000\u00b5\u00b6\u0005b\u0000\u0000\u00b6\u00b7\u0005l\u0000\u0000\u00b7"+
"\u00b8\u0005i\u0000\u0000\u00b8\u00b9\u0005c\u0000\u0000\u00b9\u00ba\u0005"+
" \u0000\u0000\u00ba\u00bb\u0005s\u0000\u0000\u00bb\u00bc\u0005t\u0000"+
"\u0000\u00bc\u00bd\u0005a\u0000\u0000\u00bd\u00be\u0005t\u0000\u0000\u00be"+
"\u00bf\u0005i\u0000\u0000\u00bf\u00c0\u0005c\u0000\u0000\u00c0\u00c1\u0005"+
" \u0000\u0000\u00c1\u00c2\u0005v\u0000\u0000\u00c2\u00c3\u0005o\u0000"+
"\u0000\u00c3\u00c4\u0005i\u0000\u0000\u00c4\u00c5\u0005d\u0000\u0000\u00c5"+
"\u00c6\u0005 \u0000\u0000\u00c6\u00c7\u0005m\u0000\u0000\u00c7\u00c8\u0005"+
"a\u0000\u0000\u00c8\u00c9\u0005i\u0000\u0000\u00c9\u00ca\u0005n\u0000"+
"\u0000\u00ca\u00cb\u0005(\u0000\u0000\u00cb\u00cc\u0005S\u0000\u0000\u00cc"+
"\u00cd\u0005t\u0000\u0000\u00cd\u00ce\u0005r\u0000\u0000\u00ce\u00cf\u0005"+
"i\u0000\u0000\u00cf\u00d0\u0005n\u0000\u0000\u00d0\u00d1\u0005g\u0000"+
"\u0000\u00d1\u00d2\u0005[\u0000\u0000\u00d2\u00d3\u0005]\u0000\u0000\u00d3"+
"\u00d4\u0005 \u0000\u0000\u00d4\u00d5\u0005a\u0000\u0000\u00d5\u00d6\u0005"+
"r\u0000\u0000\u00d6\u00d7\u0005g\u0000\u0000\u00d7\u00d8\u0005s\u0000"+
"\u0000\u00d8\u00d9\u0005)\u0000\u0000\u00d9\u0010\u0001\u0000\u0000\u0000"+
"\u00da\u00de\u0003\u001f\u000f\u0000\u00db\u00de\u0003#\u0011\u0000\u00dc"+
"\u00de\u0003!\u0010\u0000\u00dd\u00da\u0001\u0000\u0000\u0000\u00dd\u00db"+
"\u0001\u0000\u0000\u0000\u00dd\u00dc\u0001\u0000\u0000\u0000\u00de\u0012"+
"\u0001\u0000\u0000\u0000\u00df\u00e2\u0003\u001b\r\u0000\u00e0\u00e2\u0003"+
"\u001d\u000e\u0000\u00e1\u00df\u0001\u0000\u0000\u0000\u00e1\u00e0\u0001"+
"\u0000\u0000\u0000\u00e2\u0014\u0001\u0000\u0000\u0000\u00e3\u00ea\u0003"+
"%\u0012\u0000\u00e4\u00ea\u0003\'\u0013\u0000\u00e5\u00ea\u0003)\u0014"+
"\u0000\u00e6\u00ea\u0003+\u0015\u0000\u00e7\u00ea\u0003-\u0016\u0000\u00e8"+
"\u00ea\u0003/\u0017\u0000\u00e9\u00e3\u0001\u0000\u0000\u0000\u00e9\u00e4"+
"\u0001\u0000\u0000\u0000\u00e9\u00e5\u0001\u0000\u0000\u0000\u00e9\u00e6"+
"\u0001\u0000\u0000\u0000\u00e9\u00e7\u0001\u0000\u0000\u0000\u00e9\u00e8"+
"\u0001\u0000\u0000\u0000\u00ea\u0016\u0001\u0000\u0000\u0000\u00eb\u00ee"+
"\u00033\u0019\u0000\u00ec\u00ee\u00035\u001a\u0000\u00ed\u00eb\u0001\u0000"+
"\u0000\u0000\u00ed\u00ec\u0001\u0000\u0000\u0000\u00ee\u0018\u0001\u0000"+
"\u0000\u0000\u00ef\u00f0\u0005=\u0000\u0000\u00f0\u001a\u0001\u0000\u0000"+
"\u0000\u00f1\u00f2\u0005+\u0000\u0000\u00f2\u001c\u0001\u0000\u0000\u0000"+
"\u00f3\u00f4\u0005-\u0000\u0000\u00f4\u001e\u0001\u0000\u0000\u0000\u00f5"+
"\u00f6\u0005*\u0000\u0000\u00f6 \u0001\u0000\u0000\u0000\u00f7\u00f8\u0005"+
"%\u0000\u0000\u00f8\"\u0001\u0000\u0000\u0000\u00f9\u00fa\u0005/\u0000"+
"\u0000\u00fa$\u0001\u0000\u0000\u0000\u00fb\u00fc\u0005>\u0000\u0000\u00fc"+
"&\u0001\u0000\u0000\u0000\u00fd\u00fe\u0005<\u0000\u0000\u00fe(\u0001"+
"\u0000\u0000\u0000\u00ff\u0100\u0005>\u0000\u0000\u0100\u0101\u0005=\u0000"+
"\u0000\u0101*\u0001\u0000\u0000\u0000\u0102\u0103\u0005<\u0000\u0000\u0103"+
"\u0104\u0005=\u0000\u0000\u0104,\u0001\u0000\u0000\u0000\u0105\u0106\u0005"+
"=\u0000\u0000\u0106\u0107\u0005=\u0000\u0000\u0107.\u0001\u0000\u0000"+
"\u0000\u0108\u0109\u0005!\u0000\u0000\u0109\u010a\u0005=\u0000\u0000\u010a"+
"0\u0001\u0000\u0000\u0000\u010b\u010c\u0005!\u0000\u0000\u010c2\u0001"+
"\u0000\u0000\u0000\u010d\u010e\u0005&\u0000\u0000\u010e\u010f\u0005&\u0000"+
"\u0000\u010f4\u0001\u0000\u0000\u0000\u0110\u0111\u0005|\u0000\u0000\u0111"+
"\u0112\u0005|\u0000\u0000\u01126\u0001\u0000\u0000\u0000\u0113\u0114\u0005"+
".\u0000\u0000\u01148\u0001\u0000\u0000\u0000\u0115\u0116\u0005(\u0000"+
"\u0000\u0116:\u0001\u0000\u0000\u0000\u0117\u0118\u0005)\u0000\u0000\u0118"+
"<\u0001\u0000\u0000\u0000\u0119\u011a\u0005{\u0000\u0000\u011a>\u0001"+
"\u0000\u0000\u0000\u011b\u011c\u0005}\u0000\u0000\u011c@\u0001\u0000\u0000"+
"\u0000\u011d\u011e\u0005;\u0000\u0000\u011eB\u0001\u0000\u0000\u0000\u011f"+
"\u0120\u0005,\u0000\u0000\u0120D\u0001\u0000\u0000\u0000\u0121\u0122\u0005"+
"c\u0000\u0000\u0122\u0123\u0005l\u0000\u0000\u0123\u0124\u0005a\u0000"+
"\u0000\u0124\u0125\u0005s\u0000\u0000\u0125\u0126\u0005s\u0000\u0000\u0126"+
"F\u0001\u0000\u0000\u0000\u0127\u0128\u0005t\u0000\u0000\u0128\u0129\u0005"+
"h\u0000\u0000\u0129\u012a\u0005i\u0000\u0000\u012a\u012b\u0005s\u0000"+
"\u0000\u012bH\u0001\u0000\u0000\u0000\u012c\u012d\u0005w\u0000\u0000\u012d"+
"\u012e\u0005h\u0000\u0000\u012e\u012f\u0005i\u0000\u0000\u012f\u0130\u0005"+
"l\u0000\u0000\u0130\u0131\u0005e\u0000\u0000\u0131J\u0001\u0000\u0000"+
"\u0000\u0132\u0133\u0005d\u0000\u0000\u0133\u0134\u0005o\u0000\u0000\u0134"+
"L\u0001\u0000\u0000\u0000\u0135\u0136\u0005i\u0000\u0000\u0136\u0137\u0005"+
"f\u0000\u0000\u0137N\u0001\u0000\u0000\u0000\u0138\u0139\u0005e\u0000"+
"\u0000\u0139\u013a\u0005l\u0000\u0000\u013a\u013b\u0005s\u0000\u0000\u013b"+
"\u013c\u0005e\u0000\u0000\u013cP\u0001\u0000\u0000\u0000\u013d\u013e\u0005"+
"f\u0000\u0000\u013e\u013f\u0005o\u0000\u0000\u013f\u0140\u0005r\u0000"+
"\u0000\u0140R\u0001\u0000\u0000\u0000\u0141\u0142\u0005r\u0000\u0000\u0142"+
"\u0143\u0005e\u0000\u0000\u0143\u0144\u0005t\u0000\u0000\u0144\u0145\u0005"+
"u\u0000\u0000\u0145\u0146\u0005r\u0000\u0000\u0146\u0147\u0005n\u0000"+
"\u0000\u0147T\u0001\u0000\u0000\u0000\u0148\u0149\u0005n\u0000\u0000\u0149"+
"\u014a\u0005e\u0000\u0000\u014a\u014b\u0005w\u0000\u0000\u014bV\u0001"+
"\u0000\u0000\u0000\u014c\u0150\u0005\'\u0000\u0000\u014d\u014f\b\u0000"+
"\u0000\u0000\u014e\u014d\u0001\u0000\u0000\u0000\u014f\u0152\u0001\u0000"+
"\u0000\u0000\u0150\u014e\u0001\u0000\u0000\u0000\u0150\u0151\u0001\u0000"+
"\u0000\u0000\u0151\u0153\u0001\u0000\u0000\u0000\u0152\u0150\u0001\u0000"+
"\u0000\u0000\u0153\u0154\u0005\'\u0000\u0000\u0154X\u0001\u0000\u0000"+
"\u0000\u0155\u0157\u0003\u001d\u000e\u0000\u0156\u0155\u0001\u0000\u0000"+
"\u0000\u0156\u0157\u0001\u0000\u0000\u0000\u0157\u0159\u0001\u0000\u0000"+
"\u0000\u0158\u015a\u0003a0\u0000\u0159\u0158\u0001\u0000\u0000\u0000\u015a"+
"\u015b\u0001\u0000\u0000\u0000\u015b\u0159\u0001\u0000\u0000\u0000\u015b"+
"\u015c\u0001\u0000\u0000\u0000\u015cZ\u0001\u0000\u0000\u0000\u015d\u015e"+
"\u0005t\u0000\u0000\u015e\u015f\u0005r\u0000\u0000\u015f\u0160\u0005u"+
"\u0000\u0000\u0160\u0167\u0005e\u0000\u0000\u0161\u0162\u0005f\u0000\u0000"+
"\u0162\u0163\u0005a\u0000\u0000\u0163\u0164\u0005l\u0000\u0000\u0164\u0165"+
"\u0005s\u0000\u0000\u0165\u0167\u0005e\u0000\u0000\u0166\u015d\u0001\u0000"+
"\u0000\u0000\u0166\u0161\u0001\u0000\u0000\u0000\u0167\\\u0001\u0000\u0000"+
"\u0000\u0168\u0169\u0005n\u0000\u0000\u0169\u016a\u0005u\u0000\u0000\u016a"+
"\u016b\u0005l\u0000\u0000\u016b\u016c\u0005l\u0000\u0000\u016c^\u0001"+
"\u0000\u0000\u0000\u016d\u016e\u0007\u0001\u0000\u0000\u016e`\u0001\u0000"+
"\u0000\u0000\u016f\u0170\u0007\u0002\u0000\u0000\u0170b\u0001\u0000\u0000"+
"\u0000\u0171\u0175\u0003_/\u0000\u0172\u0175\u0003a0\u0000\u0173\u0175"+
"\u0007\u0003\u0000\u0000\u0174\u0171\u0001\u0000\u0000\u0000\u0174\u0172"+
"\u0001\u0000\u0000\u0000\u0174\u0173\u0001\u0000\u0000\u0000\u0175d\u0001"+
"\u0000\u0000\u0000\u0176\u017a\u0003_/\u0000\u0177\u0179\u0003c1\u0000"+
"\u0178\u0177\u0001\u0000\u0000\u0000\u0179\u017c\u0001\u0000\u0000\u0000"+
"\u017a\u0178\u0001\u0000\u0000\u0000\u017a\u017b\u0001\u0000\u0000\u0000"+
"\u017bf\u0001\u0000\u0000\u0000\u017c\u017a\u0001\u0000\u0000\u0000\u017d"+
"\u017f\u0007\u0004\u0000\u0000\u017e\u017d\u0001\u0000\u0000\u0000\u017f"+
"\u0180\u0001\u0000\u0000\u0000\u0180\u017e\u0001\u0000\u0000\u0000\u0180"+
"\u0181\u0001\u0000\u0000\u0000\u0181\u0182\u0001\u0000\u0000\u0000\u0182"+
"\u0183\u00063\u0000\u0000\u0183h\u0001\u0000\u0000\u0000\u0184\u0185\u0005"+
"/\u0000\u0000\u0185\u0186\u0005/\u0000\u0000\u0186\u018a\u0001\u0000\u0000"+
"\u0000\u0187\u0189\b\u0000\u0000\u0000\u0188\u0187\u0001\u0000\u0000\u0000"+
"\u0189\u018c\u0001\u0000\u0000\u0000\u018a\u0188\u0001\u0000\u0000\u0000"+
"\u018a\u018b\u0001\u0000\u0000\u0000\u018b\u018d\u0001\u0000\u0000\u0000"+
"\u018c\u018a\u0001\u0000\u0000\u0000\u018d\u018e\u00064\u0000\u0000\u018e"+
"j\u0001\u0000\u0000\u0000\u018f\u0190\u0005/\u0000\u0000\u0190\u0191\u0005"+
"*\u0000\u0000\u0191\u0195\u0001\u0000\u0000\u0000\u0192\u0194\t\u0000"+
"\u0000\u0000\u0193\u0192\u0001\u0000\u0000\u0000\u0194\u0197\u0001\u0000"+
"\u0000\u0000\u0195\u0196\u0001\u0000\u0000\u0000\u0195\u0193\u0001\u0000"+
"\u0000\u0000\u0196\u0198\u0001\u0000\u0000\u0000\u0197\u0195\u0001\u0000"+
"\u0000\u0000\u0198\u0199\u0005*\u0000\u0000\u0199\u019a\u0005/\u0000\u0000"+
"\u019a\u019b\u0001\u0000\u0000\u0000\u019b\u019c\u00065\u0000\u0000\u019c"+
"l\u0001\u0000\u0000\u0000\u000f\u0000\u00b1\u00dd\u00e1\u00e9\u00ed\u0150"+
"\u0156\u015b\u0166\u0174\u017a\u0180\u018a\u0195\u0001\u0006\u0000\u0000";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {

View File

@ -41,18 +41,14 @@ Else=40
For=41
Return=42
New=43
Switch=44
Case=45
Default=46
Colon=47
CharValue=48
IntValue=49
BooleanValue=50
NullValue=51
Identifier=52
WS=53
InlineComment=54
MultilineComment=55
CharValue=44
IntValue=45
BooleanValue=46
NullValue=47
Identifier=48
WS=49
InlineComment=50
MultilineComment=51
'++'=1
'--'=2
'void'=3
@ -91,8 +87,4 @@ MultilineComment=55
'for'=41
'return'=42
'new'=43
'switch'=44
'case'=45
'default'=46
':'=47
'null'=51
'null'=47

View File

@ -1,4 +1,4 @@
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated;
import org.antlr.v4.runtime.tree.ParseTreeListener;
@ -207,36 +207,6 @@ public interface SimpleJavaListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitElseStatement(SimpleJavaParser.ElseStatementContext ctx);
/**
* Enter a parse tree produced by {@link SimpleJavaParser#switchStatement}.
* @param ctx the parse tree
*/
void enterSwitchStatement(SimpleJavaParser.SwitchStatementContext ctx);
/**
* Exit a parse tree produced by {@link SimpleJavaParser#switchStatement}.
* @param ctx the parse tree
*/
void exitSwitchStatement(SimpleJavaParser.SwitchStatementContext ctx);
/**
* Enter a parse tree produced by {@link SimpleJavaParser#caseStatement}.
* @param ctx the parse tree
*/
void enterCaseStatement(SimpleJavaParser.CaseStatementContext ctx);
/**
* Exit a parse tree produced by {@link SimpleJavaParser#caseStatement}.
* @param ctx the parse tree
*/
void exitCaseStatement(SimpleJavaParser.CaseStatementContext ctx);
/**
* Enter a parse tree produced by {@link SimpleJavaParser#defaultStatement}.
* @param ctx the parse tree
*/
void enterDefaultStatement(SimpleJavaParser.DefaultStatementContext ctx);
/**
* Exit a parse tree produced by {@link SimpleJavaParser#defaultStatement}.
* @param ctx the parse tree
*/
void exitDefaultStatement(SimpleJavaParser.DefaultStatementContext ctx);
/**
* Enter a parse tree produced by {@link SimpleJavaParser#statementExpression}.
* @param ctx the parse tree

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
@ -130,24 +130,6 @@ public interface SimpleJavaVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitElseStatement(SimpleJavaParser.ElseStatementContext ctx);
/**
* Visit a parse tree produced by {@link SimpleJavaParser#switchStatement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitSwitchStatement(SimpleJavaParser.SwitchStatementContext ctx);
/**
* Visit a parse tree produced by {@link SimpleJavaParser#caseStatement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitCaseStatement(SimpleJavaParser.CaseStatementContext ctx);
/**
* Visit a parse tree produced by {@link SimpleJavaParser#defaultStatement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDefaultStatement(SimpleJavaParser.DefaultStatementContext ctx);
/**
* Visit a parse tree produced by {@link SimpleJavaParser#statementExpression}.
* @param ctx the parse tree

View File

@ -1,18 +1,18 @@
grammar SimpleJava;
// Programm-Konstrukte
program: classDeclaration+; // Ein Programm besteht aus einer oder mehreren Klassendeklarationen
program: classDeclaration+;
classDeclaration: AccessModifier? 'class' Identifier OpenCurlyBracket memberDeclaration* ClosedCurlyBracket; // Deklariert eine Klasse mit optionalem Zugriffsmodifikator und mehreren Mitgliedern
memberDeclaration: constructorDeclaration | fieldDeclaration | methodDeclaration; // Ein Mitglied kann ein Konstruktor, ein Feld oder eine Methode sein
classDeclaration: AccessModifier? 'class' Identifier OpenCurlyBracket memberDeclaration* ClosedCurlyBracket;
memberDeclaration: constructorDeclaration | fieldDeclaration | methodDeclaration;
constructorDeclaration: AccessModifier? Identifier OpenRoundBracket parameterList? ClosedRoundBracket blockStatement; // Deklariert einen Konstruktor
fieldDeclaration: AccessModifier? type Identifier (Assign expression)? Semicolon; // Deklariert ein Feld mit optionaler Initialisierung
methodDeclaration: MainMethodDeclaration blockStatement | AccessModifier? (type | Void) Identifier OpenRoundBracket parameterList? ClosedRoundBracket blockStatement; // Deklariert eine Methode
constructorDeclaration: AccessModifier? Identifier OpenRoundBracket parameterList? ClosedRoundBracket blockStatement;
fieldDeclaration: AccessModifier? type Identifier Semicolon;
methodDeclaration: MainMethodDeclaration blockStatement | AccessModifier? (type | Void) Identifier OpenRoundBracket parameterList? ClosedRoundBracket blockStatement;
parameterList: parameter (Comma parameter)*; // Parameterliste für Methoden und Konstruktoren
parameter: type Identifier; // Ein einzelner Parameter mit Typ und Bezeichner
argumentList: (expression (Comma expression)*)?; // Argumentliste für Methodenaufrufe
parameterList: parameter (Comma parameter)*;
parameter: type Identifier;
argumentList: (expression (Comma expression)*)?;
// Anweisungen
statement: returnStatement Semicolon
@ -22,33 +22,28 @@ statement: returnStatement Semicolon
| doWhileStatement
| forStatement
| ifElseStatement
| switchStatement
| statementExpression Semicolon; // Verschiedene Arten von Anweisungen
| statementExpression Semicolon;
blockStatement: OpenCurlyBracket statement* ClosedCurlyBracket; // Ein Block von Anweisungen
blockStatement: OpenCurlyBracket statement* ClosedCurlyBracket;
returnStatement: Return (expression)?; // Rückgabe-Anweisung
localVariableDeclaration: type Identifier (Assign expression)?; // Deklaration einer lokalen Variable
returnStatement: Return (expression)?;
localVariableDeclaration: type Identifier (Assign expression)?;
whileStatement: While OpenRoundBracket expression ClosedRoundBracket blockStatement; // While-Schleife
doWhileStatement: Do blockStatement While OpenRoundBracket expression ClosedRoundBracket Semicolon; // Do-While-Schleife
forStatement: For OpenRoundBracket (statementExpression | localVariableDeclaration) Semicolon (expression)? Semicolon (statementExpression)? ClosedRoundBracket blockStatement; // For-Schleife
whileStatement: While OpenRoundBracket expression ClosedRoundBracket blockStatement;
doWhileStatement: Do blockStatement While OpenRoundBracket expression ClosedRoundBracket Semicolon;
forStatement: For OpenRoundBracket (statementExpression | localVariableDeclaration) Semicolon (expression)? Semicolon (statementExpression)? ClosedRoundBracket blockStatement;
ifElseStatement: ifStatement elseIfStatement* elseStatement?; // If-Else-Bedingung
ifStatement: If OpenRoundBracket expression ClosedRoundBracket blockStatement; // If-Teil der Bedingung
elseIfStatement: Else If OpenRoundBracket expression ClosedRoundBracket blockStatement; // Else-If-Teil der Bedingung
elseStatement: Else blockStatement; // Else-Teil der Bedingung
ifElseStatement: ifStatement elseIfStatement* elseStatement?;
ifStatement: If OpenRoundBracket expression ClosedRoundBracket blockStatement;
elseIfStatement: Else If OpenRoundBracket expression ClosedRoundBracket blockStatement;
elseStatement: Else blockStatement;
switchStatement: Switch OpenRoundBracket expression ClosedRoundBracket OpenCurlyBracket caseStatement+ defaultStatement? ClosedCurlyBracket; // Switch-Anweisung
caseStatement: Case value Colon statement*; // Ein Case-Teil einer Switch-Anweisung
defaultStatement: Default Colon statement*; // Default-Teil einer Switch-Anweisung
statementExpression: assign | newDeclaration | methodCall | crementExpression; // Ausdruck innerhalb einer Anweisung
assign: assignableExpression Assign expression; // Zuweisung
newDeclaration: New Identifier OpenRoundBracket argumentList ClosedRoundBracket; // Instanziierung eines neuen Objekts
statementExpression: assign | newDeclaration | methodCall | crementExpression;
assign: assignableExpression Assign expression;
newDeclaration: New Identifier OpenRoundBracket argumentList ClosedRoundBracket;
// Ausdrücke
expression: unaryExpression | binaryExpression; // Ein Ausdruck kann unär oder binär sein
expression: unaryExpression | binaryExpression;
unaryExpression: This
| Identifier
@ -56,97 +51,97 @@ unaryExpression: This
| value
| notExpression
| statementExpression
| OpenRoundBracket expression ClosedRoundBracket; // Unäre Ausdrücke
| OpenRoundBracket expression ClosedRoundBracket;
notExpression: Not expression; // Nicht-Ausdruck
notExpression: Not expression;
crementExpression: incrementExpression | decrementExpression; // Inkrement-/Dekrement-Ausdrücke
crementExpression: incrementExpression | decrementExpression;
incrementExpression: prefixIncrementExpression | suffixIncrementExpression;
prefixIncrementExpression: '++' assignableExpression; // Präfix-Inkrement
suffixIncrementExpression: assignableExpression '++'; // Suffix-Inkrement
prefixIncrementExpression: '++' assignableExpression;
suffixIncrementExpression: assignableExpression '++';
decrementExpression: prefixDecrementExpression | suffixDecrementExpression; // Dekrement-Ausdrücke
prefixDecrementExpression: '--' assignableExpression; // Präfix-Dekrement
suffixDecrementExpression: assignableExpression '--'; // Suffix-Dekrement
decrementExpression: prefixDecrementExpression | suffixDecrementExpression;
prefixDecrementExpression: '--' assignableExpression;
suffixDecrementExpression: assignableExpression '--';
assignableExpression: Identifier | memberAccess; // Zuweisbarer Ausdruck
assignableExpression: Identifier | memberAccess;
memberAccess: This Dot Identifier
| (This Dot)? (Identifier Dot)+ Identifier; // Mitgliedszugriff
| (This Dot)? (Identifier Dot)+ Identifier;
binaryExpression: calculationExpression | nonCalculationExpression; // Binäre Ausdrücke
binaryExpression: calculationExpression | nonCalculationExpression;
calculationExpression: calculationExpression LineOperator dotExpression
| dotExpression; // Berechnungsausdrücke
| dotExpression;
dotExpression: dotExpression DotOperator dotSubtractionExpression
| dotSubtractionExpression; // Punktoperationen
| dotSubtractionExpression;
dotSubtractionExpression: IntValue
| Identifier
| memberAccess
| methodCall OpenRoundBracket calculationExpression ClosedRoundBracket; // Punkt-Subtraktionsausdrücke
| methodCall OpenRoundBracket calculationExpression ClosedRoundBracket;
nonCalculationExpression: unaryExpression nonCalculationOperator expression; // Nicht-Berechnungsausdrücke
nonCalculationExpression: unaryExpression nonCalculationOperator expression;
// Methodenaufrufe
methodCall: target? chainedMethod* Identifier OpenRoundBracket argumentList ClosedRoundBracket; // Methodenaufruf
target: (This | memberAccess | newDeclaration | Identifier) Dot; // Ziel eines Methodenaufrufs
chainedMethod: Identifier OpenRoundBracket argumentList ClosedRoundBracket Dot; // Verkettete Methode
methodCall: target? chainedMethod* Identifier OpenRoundBracket argumentList ClosedRoundBracket;
target: (This | memberAccess | newDeclaration | Identifier) Dot;
chainedMethod: Identifier OpenRoundBracket argumentList ClosedRoundBracket Dot;
// Typen
type: Int
| Boolean
| Char
| Identifier; // Datentypen
| Identifier;
Void: 'void'; // Void-Typ
Boolean: 'boolean'; // Boolean-Typ
Char: 'char'; // Char-Typ
Int: 'int'; // Integer-Typ
Void: 'void';
Boolean: 'boolean';
Char: 'char';
Int: 'int';
value: IntValue
| BooleanValue
| CharValue
| NullValue; // Werte
| NullValue;
// Zugriffsmodifikatoren
AccessModifier: 'public' | 'private' | 'public static' | 'private static'; // Zugriffsmodifikatoren
MainMethodDeclaration: 'public static void main(String[] args)'; // Hauptmethoden-Deklaration
AccessModifier: 'public' | 'private' | 'public static' | 'private static';
MainMethodDeclaration: 'public static void main(String[] args)';
// Operatoren
nonCalculationOperator: LogicalOperator | ComparisonOperator; // Nicht-Berechnungsoperatoren
nonCalculationOperator: LogicalOperator | ComparisonOperator;
DotOperator: Mult | Div | Modulo; // Punktoperatoren
LineOperator: Plus | Minus; // Linienoperatoren
ComparisonOperator: Greater | Less | GreaterEqual | LessEqual | Equal | NotEqual; // Vergleichsoperatoren
LogicalOperator: And | Or; // Logische Operatoren
DotOperator: Mult | Div | Modulo;
LineOperator: Plus | Minus;
ComparisonOperator: Greater | Less | GreaterEqual | LessEqual | Equal | NotEqual;
LogicalOperator: And | Or;
Assign: '='; // Zuweisungsoperator
Plus: '+'; // Plus-Operator
Minus: '-'; // Minus-Operator
Mult: '*'; // Multiplikationsoperator
Modulo: '%'; // Modulo-Operator
Div: '/'; // Divisionsoperator
Greater: '>'; // Größer-Operator
Less: '<'; // Kleiner-Operator
GreaterEqual: '>='; // Größer-Gleich-Operator
LessEqual: '<='; // Kleiner-Gleich-Operator
Equal: '=='; // Gleichheitsoperator
NotEqual: '!='; // Ungleichheitsoperator
Not: '!'; // Nicht-Operator
And: '&&'; // Und-Operator
Or: '||'; // Oder-Operator
Assign: '=';
Plus: '+';
Minus: '-';
Mult: '*';
Modulo: '%';
Div: '/';
Greater: '>';
Less: '<';
GreaterEqual: '>=';
LessEqual: '<=';
Equal: '==';
NotEqual: '!=';
Not: '!';
And: '&&';
Or: '||';
// Symbole
Dot: '.'; // Punkt-Symbol
OpenRoundBracket: '('; // Öffnende runde Klammer
ClosedRoundBracket: ')'; // Schließende runde Klammer
OpenCurlyBracket: '{'; // Öffnende geschweifte Klammer
ClosedCurlyBracket: '}'; // Schließende geschweifte Klammer
Semicolon: ';'; // Semikolon
Comma: ','; // Komma
Dot: '.';
OpenRoundBracket: '(';
ClosedRoundBracket: ')';
OpenCurlyBracket: '{';
ClosedCurlyBracket: '}';
Semicolon: ';';
Comma: ',';
// Schlüsselwörter
Class: 'class';
@ -158,24 +153,20 @@ Else: 'else';
For: 'for';
Return: 'return';
New: 'new';
Switch: 'switch';
Case: 'case';
Default: 'default';
Colon: ':'; // Doppelpunkt
// Werte
CharValue: '\'' ~[\r\n]* '\''; // Zeichenwert
IntValue: Minus? Numeric+; // Ganzzahlwert
BooleanValue: 'true' | 'false'; // Boolean-Wert
NullValue: 'null'; // Null-Wert
CharValue: '\'' ~[\r\n]* '\'';
IntValue: Minus? Numeric+;
BooleanValue: 'true' | 'false';
NullValue: 'null';
// Bezeichner
fragment Alphabetic: [a-zA-Z];
fragment Numeric: [0-9];
fragment ValidIdentSymbols: Alphabetic | Numeric | '$' | '_';
Identifier: Alphabetic ValidIdentSymbols*; // Bezeichner
Identifier: Alphabetic ValidIdentSymbols*;
// Whitespaces und Kommentare ignorieren
WS: [ \t\r\n]+ -> skip; // Leerzeichen ignorieren
InlineComment: '//' ~[\r\n]* -> skip; // Einzeilige Kommentare ignorieren
MultilineComment: '/*' .*? '*/' -> skip; // Mehrzeilige Kommentare ignorieren
WS: [ \t\r\n]+ -> skip;
InlineComment: '//' ~[\r\n]* -> skip;
MultilineComment: '/*' .*? '*/' -> skip;

View File

@ -8,7 +8,7 @@ import java.util.Stack;
public class Scope {
private final Stack<HashMap<String, ITypeNode>> localVars;
private Stack<HashMap<String, ITypeNode>> localVars;
public Scope() {
localVars = new Stack<HashMap<String, ITypeNode>>();

View File

@ -1,5 +1,6 @@
package semantic;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -24,11 +25,15 @@ import ast.statementexpressions.methodcallstatementnexpressions.ChainedMethodNod
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
import ast.statements.*;
import ast.type.AccessModifierNode;
import ast.type.EnumAccessModifierNode;
import ast.type.ValueNode;
import ast.type.type.*;
import com.sun.jdi.IntegerType;
import semantic.context.ClassContext;
import semantic.context.Context;
import semantic.exceptions.*;
import typechecker.TypeCheckResult;
public class SemanticAnalyzer implements SemanticVisitor {
@ -109,6 +114,10 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override
public TypeCheckResult analyze(MethodNode methodNode) {
if (methodNode instanceof ConstructorNode) {
return new TypeCheckResult(true, new BaseType(TypeEnum.VOID));
} else {
var valid = true;
for (var otherMethod : currentClass.getMethods()) {
@ -150,12 +159,14 @@ public class SemanticAnalyzer implements SemanticVisitor {
}
return new TypeCheckResult(valid, resultType);
}
}
@Override
public TypeCheckResult analyze(FieldNode toCheck) {
if (toCheck.type instanceof ReferenceType referenceType) {
if (!context.containsClass(referenceType.getIdentifier())) {
if(!context.containsClass(referenceType.getIdentifier())){
errors.add(new NotDeclaredException(referenceType.getIdentifier() + " not declared"));
}
}
@ -166,6 +177,8 @@ public class SemanticAnalyzer implements SemanticVisitor {
currentFields.put(toCheck.identifier, toCheck.type);
}
return new TypeCheckResult(true, null);
}
@Override
@ -220,7 +233,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
}
for (IStatementNode statementNode : blockNode.statements) {
var result = statementNode.accept(this);
if (!(statementNode instanceof IncrementNode) && !(statementNode instanceof DecrementNode)) {
if(!(statementNode instanceof IncrementNode) && !(statementNode instanceof DecrementNode)){
if (result.getType() != null) {
if (blockReturnType == null) {
blockReturnType = result.getType();
@ -240,25 +253,21 @@ public class SemanticAnalyzer implements SemanticVisitor {
if (toCheck.memberAccess != null) {
var result = toCheck.memberAccess.accept(this);
toCheck.identifier = toCheck.memberAccess.identifiers.getLast();
toCheck.setTypeNode(result.getType());
return result;
} else {
if (currentFields.get(toCheck.identifier) != null) {
var type = currentFields.get(toCheck.identifier);
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
memberAccessNode.identifiers.add(currentClass.identifier);
memberAccessNode.identifiers.add(toCheck.identifier);
toCheck.memberAccess = memberAccessNode;
toCheck.setTypeNode(type);
return new TypeCheckResult(true, type);
} else if (currentScope.getLocalVar(toCheck.identifier) != null) {
var type = currentScope.getLocalVar(toCheck.identifier);
toCheck.setTypeNode(type);
return new TypeCheckResult(true, type);
}
}
return new TypeCheckResult(true, null);
}
@Override
@ -303,97 +312,50 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override
public TypeCheckResult analyze(IfElseNode toCheck) {
var resultIf = toCheck.ifStatement.accept(this);
var validElseIf = true;
var resultElse = toCheck.elseStatement.accept(this);
if(!toCheck.elseIfStatements.isEmpty()) {
for(IfNode ifNode : toCheck.elseIfStatements) {
var resultIfFor = ifNode.accept(this);
validElseIf = validElseIf && resultIfFor.isValid();
}
}
if(toCheck.elseStatement != null){
var resultElse = toCheck.elseStatement.accept(this);
return new TypeCheckResult(resultIf.isValid() && resultElse.isValid() && validElseIf, new BaseType(TypeEnum.VOID));
}
return new TypeCheckResult(resultIf.isValid(), new BaseType(TypeEnum.VOID));
return new TypeCheckResult(resultIf.isValid() && resultElse.isValid(), new BaseType(TypeEnum.VOID));
}
@Override
public TypeCheckResult analyze(MethodCallNode toCheck) {
if (toCheck.target != null) {
if(toCheck.target.memberAccess == null){
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
memberAccessNode.identifiers.add(currentClass.identifier);
memberAccessNode.identifiers.add(toCheck.target.identifier);
toCheck.target.memberAccess = memberAccessNode;
if (toCheck.target.identifier != null) {
var targetType = currentScope.getLocalVar(toCheck.target.identifier);
if (targetType == null) {
targetType = currentFields.get(toCheck.target.identifier);
}
if (toCheck.target.identifier != null) {
var targetType = currentScope.getLocalVar(toCheck.target.identifier);
if (targetType == null) {
targetType = currentFields.get(toCheck.target.identifier);
if (targetType instanceof ReferenceType reference) {
if (!toCheck.chainedMethods.isEmpty()) {
for (ChainedMethodNode chainedMethod : toCheck.chainedMethods) {
var type = getTypeFromMethod(chainedMethod, reference);
if (type instanceof ReferenceType referenceType)
reference = referenceType;
else
errors.add(new TypeMismatchException("Ein Basetyp hat keine funktionen"));
}
}
if (targetType instanceof ReferenceType reference) {
if (!toCheck.chainedMethods.isEmpty()) {
for (ChainedMethodNode chainedMethod : toCheck.chainedMethods) {
var type = getTypeFromMethod(chainedMethod, reference);
if (type instanceof ReferenceType referenceType)
reference = referenceType;
else
errors.add(new TypeMismatchException("Ein Basetyp hat keine funktionen"));
}
}
var type = getTypeFromMethod(toCheck, reference);
if (type != null) {
return new TypeCheckResult(true, type);
} else {
return new TypeCheckResult(false, null);
}
}
} else {
if (toCheck.target.thisTar != null) {
if (toCheck.target.thisTar) {
var type = getTypeFromMethod(toCheck, new ReferenceType(currentClass.identifier));
if (type != null) {
toCheck.type = type;
return new TypeCheckResult(true, type);
}
}
var type = getTypeFromMethod(toCheck, reference);
if (type != null) {
return new TypeCheckResult(true, type);
} else {
var result = toCheck.target.accept(this);
if (result.getType() instanceof ReferenceType reference) {
return new TypeCheckResult(true, getTypeFromMethod(toCheck, reference));
}
return new TypeCheckResult(false, null);
}
}
} else {
if(toCheck.identifier != null) {
toCheck.target = new TargetNode(new MemberAccessNode(false));
toCheck.target.memberAccess.identifiers.add(currentClass.identifier);
}
ReferenceType reference = new ReferenceType(currentClass.identifier);
if (!toCheck.chainedMethods.isEmpty()) {
for (ChainedMethodNode chainedMethod : toCheck.chainedMethods) {
var type = getTypeFromMethod(chainedMethod, reference);
if (type instanceof ReferenceType referenceType)
reference = referenceType;
else
errors.add(new TypeMismatchException("Ein Basetyp hat keine funktionen"));
if (toCheck.target.thisTar) {
var type = getTypeFromMethod(toCheck, new ReferenceType(currentClass.identifier));
if (type != null) {
return new TypeCheckResult(true, type);
}
} else {
var result = toCheck.target.accept(this);
if (result.getType() instanceof ReferenceType reference) {
return new TypeCheckResult(true, getTypeFromMethod(toCheck, reference));
}
}
var type = getTypeFromMethod(toCheck, reference);
if (type != null) {
return new TypeCheckResult(true, type);
} else {
return new TypeCheckResult(false, null);
}
}
return new TypeCheckResult(false, null);
}
@ -429,14 +391,12 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override
public TypeCheckResult analyze(NewDeclarationNode toCheck) {
if (context.containsClass(toCheck.identifier)) {
for(var t : toCheck.expressions) {
t.accept(this);
}
return new TypeCheckResult(true, new ReferenceType(toCheck.identifier));
} else {
throw new RuntimeException("Cannot find class " + toCheck.identifier);
}
return null;
}
@Override
@ -460,7 +420,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
case PLUS, MINUS:
if (calcRes.getType() instanceof BaseType calcType && dotRes.getType() instanceof BaseType dotType &&
calcType.getTypeEnum().equals(TypeEnum.INT) && dotType.getTypeEnum().equals(TypeEnum.INT)) {
calcNode.setType(new BaseType(TypeEnum.INT));
return new TypeCheckResult(true, new BaseType(TypeEnum.INT));
}
break;
@ -468,12 +427,10 @@ public class SemanticAnalyzer implements SemanticVisitor {
}
} else {
calcNode.setType(calcNode.getType());
return new TypeCheckResult(calcRes.isValid(), calcRes.getType());
}
} else if (calcNode.dotExpression != null) {
var dotRes = calcNode.dotExpression.accept(this);
calcNode.setType(dotRes.getType());
return new TypeCheckResult(dotRes.isValid(), dotRes.getType());
}
return new TypeCheckResult(false, null);
@ -481,46 +438,28 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override
public TypeCheckResult analyze(DotNode toCheck) {
if (toCheck.dotSubtractionExpression != null) {
var result = toCheck.dotSubtractionExpression.accept(this);
toCheck.setType(result.getType());
return result;
if (toCheck.dotSubstractionExpression != null) {
return toCheck.dotSubstractionExpression.accept(this);
}
return new TypeCheckResult(false, null);
}
@Override
public TypeCheckResult analyze(DotSubtractionNode toCheck) {
public TypeCheckResult analyze(DotSubstractionNode toCheck) {
if (toCheck.value != null) {
var result = toCheck.value.accept(this);
toCheck.setType(result.getType());
return result;
return toCheck.value.accept(this);
} else if (toCheck.memberAccess != null) {
var result = toCheck.memberAccess.accept(this);
toCheck.setType(result.getType());
return result;
return toCheck.memberAccess.accept(this);
} else if (toCheck.methodCall != null) {
var result = toCheck.methodCall.accept(this);
toCheck.setType(result.getType());
return result;
return toCheck.methodCall.accept(this);
} else if (toCheck.identifier != null) {
if (currentScope.contains(toCheck.identifier)) {
var type = currentScope.getLocalVar(toCheck.identifier);
toCheck.setType(type);
return new TypeCheckResult(true, type);
return new TypeCheckResult(true, currentScope.getLocalVar(toCheck.identifier));
} else if (currentFields.get(toCheck.identifier) != null) {
var type = currentFields.get(toCheck.identifier);
toCheck.setType(type);
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
memberAccessNode.identifiers.add(currentClass.identifier);
memberAccessNode.identifiers.add(toCheck.identifier);
toCheck.memberAccess = memberAccessNode;
return new TypeCheckResult(true, type);
return new TypeCheckResult(true, currentFields.get(toCheck.identifier));
}
} else if (toCheck.calculationExpression != null) {
var result = toCheck.calculationExpression.accept(this);
toCheck.setType(result.getType());
return result;
return toCheck.calculationExpression.accept(this);
}
return null;
}
@ -534,19 +473,15 @@ public class SemanticAnalyzer implements SemanticVisitor {
case LESS, LESS_EQUAL, GREATER, GREATER_EQUAL:
if (expResult.getType() instanceof BaseType expResultType && expResultType.getTypeEnum().equals(TypeEnum.INT) &&
unaryResult.getType() instanceof BaseType unaryResultType && unaryResultType.getTypeEnum().equals(TypeEnum.INT)) {
ITypeNode type = new BaseType(TypeEnum.BOOL);
nonCalculationNode.setType(type);
return new TypeCheckResult(true, type);
return new TypeCheckResult(true, new BaseType(TypeEnum.BOOL));
} else {
errors.add(new TypeMismatchException("Both types must be Integer"));
}
break;
case OR, AND:
if (expResult.getType() instanceof BaseType expResultType && expResultType.getTypeEnum().equals(TypeEnum.BOOL) &&
unaryResult.getType() instanceof BaseType unaryResultType && unaryResultType.getTypeEnum().equals(TypeEnum.BOOL)) {
ITypeNode type = new BaseType(TypeEnum.BOOL);
nonCalculationNode.setType(type);
return new TypeCheckResult(true, type);
if (expResult.getType() instanceof BaseType expResultType && expResultType.getTypeEnum().equals(TypeEnum.INT) &&
unaryResult.getType() instanceof BaseType unaryResultType && unaryResultType.getTypeEnum().equals(TypeEnum.INT)) {
return new TypeCheckResult(true, new BaseType(TypeEnum.BOOL));
} else {
errors.add(new TypeMismatchException("Both types must be Boolean"));
}
@ -554,9 +489,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
case EQUAL, NOT_EQUAL:
if (expResult.getType() instanceof BaseType expResultType && unaryResult.getType() instanceof BaseType unaryResultType
&& Objects.equals(expResultType, unaryResultType)) {
ITypeNode type = new BaseType(TypeEnum.BOOL);
nonCalculationNode.setType(type);
return new TypeCheckResult(true, type);
return new TypeCheckResult(true, new BaseType(TypeEnum.BOOL));
} else {
errors.add(new TypeMismatchException("Both types must be the same"));
}
@ -571,21 +504,9 @@ public class SemanticAnalyzer implements SemanticVisitor {
if (unary.identifier != null) {
if (currentScope.contains(unary.identifier)) {
var type = currentScope.getLocalVar(unary.identifier);
unary.setType(type);
return new TypeCheckResult(valid, type);
return new TypeCheckResult(valid, currentScope.getLocalVar(unary.identifier));
} else if (currentFields.get(unary.identifier) != null) {
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
memberAccessNode.identifiers.add(currentClass.identifier);
memberAccessNode.identifiers.add(unary.identifier);
unary.memberAccess = memberAccessNode;
var type = currentFields.get(unary.identifier);
unary.setType(type);
return new TypeCheckResult(valid,type );
} else if (unary.value != null) {
var result = unary.value.accept(this);
unary.setType(result.getType());
return new TypeCheckResult(result.isValid(), result.getType());
return new TypeCheckResult(valid, currentFields.get(unary.identifier));
} else if (unary.statement != null) {
var result = unary.statement.accept(this);
unary.setType(result.getType());
@ -595,19 +516,15 @@ public class SemanticAnalyzer implements SemanticVisitor {
}
} else if (unary.statement != null) {
var result = unary.statement.accept(this);
unary.setType(result.getType());
return new TypeCheckResult(result.isValid(), result.getType());
} else if (unary.value != null) {
var result = unary.value.accept(this);
unary.setType(result.getType());
return new TypeCheckResult(result.isValid(), result.getType());
} else if (unary.memberAccess != null) {
var result = unary.memberAccess.accept(this);
unary.setType(result.getType());
return new TypeCheckResult(result.isValid(), result.getType());
} else if (unary.expression != null) {
var result = unary.expression.accept(this);
unary.setType(result.getType());
return new TypeCheckResult(result.isValid(), result.getType());
}
@ -618,23 +535,12 @@ public class SemanticAnalyzer implements SemanticVisitor {
public TypeCheckResult analyze(MemberAccessNode memberAccessNode) {
ITypeNode currentType = null;
int start = 0;
if(!memberAccessNode.identifiers.isEmpty()){
if(currentFields.get(memberAccessNode.identifiers.getFirst()) != null){
memberAccessNode.identifiers.addFirst(currentClass.identifier);
start++;
}
}
if(context.getClasses().get(memberAccessNode.identifiers.getFirst()) == null){
memberAccessNode.identifiers.addFirst(currentClass.identifier);
start++;
}
for (int i = start; i < memberAccessNode.identifiers.size(); i++) {
String s = memberAccessNode.identifiers.get(i);
for (String s : memberAccessNode.identifiers) {
if (currentType == null) {
if (currentScope.getLocalVar(s) != null) {
currentType = currentScope.getLocalVar(s);
} else if (currentFields.get(s) != null) {
currentType = currentFields.get(s);
} else {
@ -645,8 +551,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
} else {
if (currentType instanceof ReferenceType reference) {
var currentTypeClass = context.getClass(reference.getIdentifier());
memberAccessNode.identifiers.add(i, reference.getIdentifier());
i++;
var currentField = currentTypeClass.getField(s);
if (currentField.getAccessModifier().accessType == EnumAccessModifierNode.PUBLIC) {
currentType = currentField.getType();
@ -658,7 +563,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
}
}
memberAccessNode.setTypeNode(currentType);
return new TypeCheckResult(true, currentType);
}
@ -667,11 +572,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
if (targetNode.memberAccess != null) {
return targetNode.memberAccess.accept(this);
} else if(targetNode.identifier != null) {
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
memberAccessNode.identifiers.add(currentClass.identifier);
memberAccessNode.identifiers.add(targetNode.identifier);
targetNode.memberAccess = memberAccessNode;
}
return null;
}
@ -684,7 +584,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
return new TypeCheckResult(true, new BaseType(TypeEnum.INT));
}
case CHAR_VALUE -> {
valueNode.value = valueNode.value.replace("'", "");
return new TypeCheckResult(true, new BaseType(TypeEnum.CHAR));
}
case BOOLEAN_VALUE -> {

View File

@ -15,6 +15,7 @@ import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
import ast.statements.*;
import ast.type.ValueNode;
import typechecker.TypeCheckResult;
public interface SemanticVisitor {
@ -60,7 +61,7 @@ public interface SemanticVisitor {
TypeCheckResult analyze(DotNode toCheck);
TypeCheckResult analyze(DotSubtractionNode toCheck);
TypeCheckResult analyze(DotSubstractionNode toCheck);
TypeCheckResult analyze(NonCalculationNode toCheck);

View File

@ -9,8 +9,8 @@ import java.util.HashMap;
public class ClassContext {
private final HashMap<String, FieldContext> fields;
private final ArrayList<MethodNode> methods = new ArrayList<>();
private HashMap<String, FieldContext> fields;
private ArrayList<MethodNode> methods = new ArrayList<>();
public ClassContext(ClassNode classNode) {

View File

@ -5,7 +5,7 @@ import java.util.HashMap;
public class Context {
private final HashMap<String, ClassContext> classes;
private HashMap<String, ClassContext> classes;
public Context(ProgramNode programNode) {
classes = new HashMap<>();

View File

@ -6,8 +6,8 @@ import ast.type.type.*;
public class FieldContext {
private final AccessModifierNode accessModifier;
private final ITypeNode type;
private AccessModifierNode accessModifier;
private ITypeNode type;
public FieldContext(FieldNode field) {
accessModifier = field.accessTypeNode;

View File

@ -1,23 +1,23 @@
package semantic;
import ast.type.type.ITypeNode;
public class TypeCheckResult {
private final boolean valid;
private final ITypeNode type;
public TypeCheckResult(boolean valid, ITypeNode type) {
this.valid = valid;
this.type = type;
}
public boolean isValid() {
return valid;
}
public ITypeNode getType() {
return type;
}
package typechecker;
import ast.type.type.ITypeNode;
public class TypeCheckResult {
private boolean valid;
private ITypeNode type;
public TypeCheckResult(boolean valid, ITypeNode type) {
this.valid = valid;
this.type = type;
}
public boolean isValid() {
return valid;
}
public ITypeNode getType() {
return type;
}
}

View File

@ -4,7 +4,7 @@ import bytecode.visitor.ClassVisitor;
import bytecode.visitor.MethodVisitor;
import bytecode.visitor.ProgramVisitor;
import semantic.SemanticVisitor;
import semantic.TypeCheckResult;
import typechecker.TypeCheckResult;
public interface Visitable {
default void accept(ProgramVisitor programVisitor) {

View File

@ -1,3 +0,0 @@
Manifest-Version: 1.0
Main-Class: main.Main

View File

@ -1,63 +1,14 @@
public class CompilerInput {
public int ps;
public char brand;
public int tires;
public int drivenKilometers;
public CompilerInput(int horsePower) {
this.ps = horsePower;
this.tires = 4;
}
public int getTires() {
return this.tires;
}
public boolean isSuperCar() {
if(this.ps > 300) {
return true;
} else {
return false;
}
}
public void tune(int horsePower) {
this.ps = this.ps + horsePower;
}
public void tune() {
this.ps = this.ps + 50;
}
public void driveCircels(int circels) {
for(int i = 0; i < circels; i++) {
this.drivenKilometers = this.drivenKilometers + 5;
}
}
public void isTunable(boolean hasEngine, boolean hasTires) {
if(hasEngine && hasTires) {
this.tune(5);
}
}
public char race() {
int enemyHorsePower = 200;
char win = 'W';
char lose = 'L';
CompilerInput enemy = new CompilerInput(ps);
if(this.ps > enemyHorsePower) {
return win;
} else {
return lose;
}
}
public int refuel(int currentTank, int maxTank){
int tank = currentTank;
do{
tank++;
}while(tank<maxTank);
return tank;
public class Compiler {
public int add(int i, int j) {
return i+j;
}
}
public class Node {
public void main() {
Compiler compiler = new Compiler();
int i = compiler.add(5, 8);
return i;
}
}

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -2,30 +2,44 @@
### IntelliJs play buttons do not work. Run in "src/test" folder with "make" command to run all
### Or run only parts with "make compile-javac", "make clean" etc.
all: compile-javac compile-miniCompiler
all: compile-javac compile-raupenpiler
compile-javac:
javac -d .\resources\output\javac ..\main\resources\input\CompilerInput.java
javac -d .\resources\output\javac .\resources\input\CompilerInput.java
compile-miniCompiler:
compile-raupenpiler:
cd ../.. ; mvn -DskipTests install
cd ../.. ; mvn exec:java -DgenJar=true -DgenClass=true -Dexec.mainClass="main.Main" -Dexec.args="'src/main/resources/input/CompilerInput.java' 'src/main/resources/output'"
cp ..\main\resources\output\CompilerInput.class .\resources\output\miniCompiler
cp ../main/resources/output/CompilerInput.class .java/resources/output/raupenpiler
test: compile-javac compile-raupenpiler test-javac test-raupenpiler
test-javac:
# gleich wie bei raupenpiler, kann ich ohne funktionierenden Compiler nicht testen
test-raupenpiler:
# move the compiled class to the test/main folder
mv ../main/resources/output/CompilerInput.class .java/main/
# compile the test class
javac .java/main.EndToEndTester.java
# run the test class
java .java/main.EndToEndTester
clean:
# clean main output folders
# clean output folders
rm -f ../main/resources/output/*.class
rm -f ../main/resources/output/*.jar
# clean resources output folders
rm -f ./resources/output/javac/*.class
rm -f ./resources/output/miniCompiler/*.class
rm -f ./resources/output/miniCompiler/*.jar
rm -f ./resources/output/raupenpiler/*.class
# clean logs
rm -f ../main/resources/logs/*
rm -f ../main/resources/logs/*.log
# clean test/java/main folders from .class files for End-to-End tests
rm -f ./java/main/*.class
# clean javac output from every folder
rm -f ./resources/input/*/*.class
# clean test results from maven surefire plugin
rm -f ../../target/surefire-reports/*.txt
# clean javac output from combinedFeatureTests
rm -f ./resources/input/combinedFeatureTests/*.class
rm -f ./resources/input/singleFeatureTests/*.class
rm -f ./resources/input/typedAstFeatureTests/*.class

93
src/test/TestSpecs.md Normal file
View File

@ -0,0 +1,93 @@
# Scanner
## Scanner Input
### Beispiel 1: Empty Class
String empty class = "public class Name {}";
### Beispiel 2: Filled Class
String filled class =
"class javaFileInput.Example {" +
"if (x < 5) {" +
"for (int i = 0; i < 10; i++) {" +
"while (true) {" +
"x = 5;" +
"}"
## Scanner Output
CommonTokenStream
### Beispiel 1: Empty Class
Token Type; Token Text
Type gibts nur bei Terminalen, Text bei allen
[null "public", null "class", IDENTIFIER "Name", null "{", null "}", EOF "<EOF>"]
Bsp von Ihm mal:
[TokPublic,TokClass,TokIdentifier "Name",TokLeftBrace,TokRightBrace]
# Parser
## Parser Input
CommonTokenStream
(Scanner Output)
## Parser Output (AST)
(program (classDeclaration (accessType public) class Name { }))
ParseTree
### Beispiel 1: Empty Class
# Semantische Analyse / Typcheck
## Typcheck Input
(Parser Output = AST)
## Typcheck Output
### Beispiel 1: Empty Class
# Bytecodegenerierung
## Bytecodegenerierung Input
(Typcheck Output = vom Typcheck eventuell manipulierter AST)
## Bytecodegenerierung Output
### Beispiel 1: Empty Class
Compiled Classfile
public class javaFileInput.Example {
}
## E2E Tests:
- Testdatei mit Main ausführen/kompilieren
- Testdatei mit "javac -d output .\CompilerInput.java" kompilieren
- -> Dateien mit javap vergleichen
wenn beides erfolgreich
- Ergebnis vom eigenen Compiler mithilfe von main.EndToEndTester ausführen
- (Ergebnis von javac mithilfe von main.EndToEndTester ausführen)
### Andis Tipps:
- cp mitgeben
- makefile
- java -jar pfadtocompiler.jar EmptyClass.java
- mvn package
- javac tester // tester compilen
- java tester // tester ausführen
- -> tester ist in unserem Fall main.EndToEndTester.java
- -> Hab ich alles umgesetzt

View File

@ -1,209 +1,95 @@
package main;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class E2EReflectionsTest {
@Test
public void CharTest() {
runTest("Char");
}
@Test
public void CommentsTest() {
runTest("Comments");
}
@Test
public void ConstructorMethodCallTest() {
runTest("ConstructorMethodCall");
}
@Test
public void ConstructorMethodCallParametersTest() {
runTest("ConstructorMethodCallParameters");
}
@Test
public void ConstructorParameterTest() {
runTest("ConstructorParameter");
}
@Test
public void ConstructorThisDotTest() {
runTest("ConstructorThisDot");
}
@Test
public void DoWhileTest() {
runTest("DoWhile");
}
@Test
public void EmptyClassTest() {
runTest("EmptyClass");
}
@Test
public void EmptyClassWithConstructorTest() {
runTest("EmptyClassWithConstructor");
}
@Test
public void FieldTest() {
runTest("Field");
}
@Test
public void FieldWithAccessModifierTest() {
runTest("FieldWithAccessModifier");
}
@Test
public void ForTest() {
runTest("For");
}
@Test
public void IfTest() {
runTest("If");
}
@Test
public void IfElseTest() {
runTest("IfElse");
}
@Test
public void IfElseIfElseTest() {
runTest("IfElseIfElse");
}
@Test
public void IncrementTest() {
runTest("Increment");
}
@Test
public void MainMethodTest() {
runTest("MainMethod");
}
@Test
public void MultipleClassesTest() {
runTest("MultipleClasses");
}
@Test
public void ThisDotTest() {
runTest("ThisDot");
}
@Test
public void VariableCalculationTest() {
runTest("VariableCalculation");
}
@Test
public void VariableCompareTest() {
runTest("VariableCompare");
}
@Test
public void VoidMethodTest() {
runTest("VoidMethod");
}
@Test
public void WhileTest() {
runTest("While");
}
// Helper method to eliminate redundancy
private void runTest(String fileName) {
public void AllFeaturesClassExampleTest(){
try {
// compile with miniCompiler
Main.main(new String[]{"src/test/resources/input/singleFeatureTests/" + fileName + ".java", "src/test/resources/output/miniCompiler"});
Main.main(new String[]{"src/test/resources/input/combinedFeatureTests/AllFeaturesClassExample.java", "src/test/resources/output/raupenpiler"});
// Get the system Java compiler
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
// Assert that the compiler is available
assertNotNull(javac, "Java Compiler is not available");
// compile with javac
javac.run(null, null, null, "src/test/resources/input/singleFeatureTests/" + fileName + ".java");
moveFile("src/test/resources/input/singleFeatureTests/" + fileName + ".class", "src/test/resources/output/javac/" + fileName + ".class");
javac.run(null, null, null, "src/test/resources/input/combinedFeatureTests/AllFeaturesClassExample.java");
// Load the javac class
Path javacClassPath = Paths.get("src/test/resources/output/javac");
ClassLoader javacClassLoader = new java.net.URLClassLoader(new java.net.URL[]{javacClassPath.toUri().toURL()});
Class<?> javacLoadedClass = javacClassLoader.loadClass(fileName);
// Load the miniCompiler class
Path miniCompilerClassPath = Paths.get("src/test/resources/output/miniCompiler");
ClassLoader miniCompilerClassLoader = new java.net.URLClassLoader(new java.net.URL[]{miniCompilerClassPath.toUri().toURL()});
Class<?> miniCompilerLoadedClass = miniCompilerClassLoader.loadClass(fileName);
Class<?> clazz = Class.forName("src.resources.input.combinedFeatureTests.AllFeaturesClassExample");
ClassLoader classLoader = getClass().getClassLoader();
// Class<?> clazz = classLoader.loadClass("main.AllFeaturesClassExample");
// Class Name
assertEquals(fileName, javacLoadedClass.getName());
assertEquals(fileName, miniCompilerLoadedClass.getName());
assertEquals("main.AllFeaturesClassExample", clazz.getName());
// Constructors
Constructor<?>[] javacConstructors = javacLoadedClass.getDeclaredConstructors();
Constructor<?>[] miniCompilerConstructors = miniCompilerLoadedClass.getDeclaredConstructors();
assertEquals(javacConstructors.length, miniCompilerConstructors.length);
for (Constructor<?> c : javacConstructors) {
for (Constructor<?> miniCompilerConstructor : miniCompilerConstructors) {
assertEquals(c.getParameterCount(), miniCompilerConstructor.getParameterCount());
if (c.getParameterCount() == miniCompilerConstructor.getParameterCount()) {
assertEquals(c.getName(), miniCompilerConstructor.getName());
}
Constructor<?>[] actualConstructors = clazz.getDeclaredConstructors();
assertTrue(actualConstructors.length > 0, "No constructors found");
Constructor<?> expectedConstructor = clazz.getConstructor(int.class, boolean.class, char.class);
boolean constructorFound = false;
for (Constructor<?> constructor : actualConstructors) {
if (constructor.equals(expectedConstructor)) {
constructorFound = true;
break;
}
}
assertTrue(constructorFound, "Expected constructor not found in actual constructors");
// Methods
Method[] javacMethods = javacLoadedClass.getDeclaredMethods();
Method[] miniCompilerMethods = miniCompilerLoadedClass.getDeclaredMethods();
assertEquals(javacMethods.length, miniCompilerMethods.length);
for (int i = 0; i < javacMethods.length; i++) {
assertEquals(javacMethods[i].getName(), miniCompilerMethods[i].getName());
assertEquals(javacMethods[i].getReturnType(), miniCompilerMethods[i].getReturnType());
assertEquals(javacMethods[i].getParameterCount(), miniCompilerMethods[i].getParameterCount());
Method[] actualMethodNames = clazz.getDeclaredMethods();
assertTrue(actualMethodNames.length > 0);
for (Method method : actualMethodNames) {
System.out.println("Method: " + method.getName());
}
// Method Names
String[] expectedMethodNames = {
"controlStructures",
"logicalOperations",
"add",
"subtract",
"multiply",
"divide",
"modulo",
"main"
};
for (Method method : actualMethodNames) {
assertTrue(Arrays.asList(expectedMethodNames).contains(method.getName()));
}
// Fields
Field[] javacLoadedClassDeclaredFields = javacLoadedClass.getDeclaredFields();
Field[] miniCompilerLoadedClassDeclaredFields = miniCompilerLoadedClass.getDeclaredFields();
assertEquals(javacLoadedClassDeclaredFields.length, miniCompilerLoadedClassDeclaredFields.length);
for (Field field : javacLoadedClassDeclaredFields) {
for (Field miniCompilerField : miniCompilerLoadedClassDeclaredFields) {
if (field.getName().equals(miniCompilerField.getName())) {
assertEquals(field.getType(), miniCompilerField.getType());
}
Field[] actualFields = clazz.getDeclaredFields();
assertTrue(actualFields.length > 0, "No fields found");
Field expectedField = clazz.getDeclaredField("c");
assertEquals(expectedField.getType(), char.class);
boolean fieldFound = false;
for (Field field : actualFields) {
if (field.equals(expectedField)) {
fieldFound = true;
break;
}
}
assertTrue(fieldFound, "Expected field not found in actual fields");
} catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) {
e.printStackTrace();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
// Helper method to move file
public static void moveFile(String sourceFilePath, String destinationFilePath) throws IOException {
Path sourcePath = Paths.get(sourceFilePath);
Path destinationPath = Paths.get(destinationFilePath);
Files.move(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING);
}
}
}

View File

@ -0,0 +1,45 @@
package main;
/**
* This class is used to test the output of the compiler.
*
* <p>Im gleichen Ordner wie diese Datei (EndToEndTester.java) muss die selbst kompilierte CompilerInput.class Datei sein.
* <br><strong>Hinweis:</strong> Diese muss man also vom Ordner <code> main/resources/output </code> in diesen Ordner hier (test/java/main) rein kopieren. (bis es eine bessere Lösung gibt -> bin grad in der Make dran das alles hier automatisch zu machen)</p>
*
* <p>Die selbst kompilierte .class Datei wird dann hier drin geladen und eine Instanz von ihr erstellt, es können auch Methoden aufgerufen werden.
* <p>Diese EndToEndTester.java Datei wird dann in <code> \src\test\java> </code> mit <code>javac .\main.EndToEndTester.java</code> kompiliert und mit <code>java main.EndToEndTester</code> ausgeführt.
* Wenn unser Compiler funktioniert, sollten keine Errors kommen (sondern nur die Ausgaben, die wir in der CompilerInput.java Datei gemacht haben,
* oder Methoden, die wir hier aufrufen).</p>
*
* <p><strong>PROBLEM:</strong> Hier kommen Errors, was eigentlich heißt, dass der Compiler nicht funktioniert, der Test sollte eigentlich passen.
* <br><strong>DENN:</strong> Wenn ich statt unserem CompilerInput.class die CompilerInput.class von javac verwende (aus <code> src/test/resources/output/javac </code>), dann funktioniert es.</p>
*/
public class EndToEndTester {
public static void main(String[] args) {
try {
// Try to load the class named "CompilerInput"
Class<?> cls = Class.forName("CompilerInput");
// Print a success message if the class is loaded successfully
System.out.println("Class loaded successfully: " + cls.getName());
// Try to create an instance of the loaded class
Object instance = cls.getDeclaredConstructor().newInstance();
// Print a success message if the instance is created successfully
System.out.println("Instance created: " + instance);
// If the class has a main method, you can invoke it
// cls.getMethod("main", String[].class).invoke(null, (Object) new String[]{});
// If the class has other methods, you can invoke them as well
// Example: cls.getMethod("someMethod").invoke(instance);
} catch (ClassNotFoundException e) {
// Print an error message if the class is not found
System.err.println("Class not found: " + e.getMessage());
} catch (Exception e) {
// Print an error message if any other exception occurs during class loading or instance creation
System.err.println("Error during class loading or execution: " + e.getMessage());
}
}
}

View File

@ -26,69 +26,13 @@ public class InputFilesTest {
// Assert that the compiler is available
assertNotNull(javac, "Java Compiler is not available");
File combinedFeatureTests = new File("src/test/resources/input/combinedFeatureTests");
File endabgabeTests = new File("src/test/resources/input/endabgabeTests");
File singleFeatureSemanticTests = new File("src/test/resources/input/singleFeatureSemanticTests");
File singleFeatureTests = new File("src/test/resources/input/singleFeatureTests");
File typedAstFeatureTests = new File("src/test/resources/input/typedAstFeatureTests");
File finalTest = new File("src/test/resources/input/finalTest");
File folder1 = new File("src/test/resources/input/combinedFeatureTests");
File folder2 = new File("src/test/resources/input/singleFeatureTests");
File folder3 = new File("src/test/resources/input/typedAstFeatureTests");
List<File> files = getJavaFilesFromDirectory(combinedFeatureTests);
// files.addAll(getJavaFilesFromDirectory(endabgabeTests));
// files.addAll(getJavaFilesFromDirectory(singleFeatureSemanticTests));
files.addAll(getJavaFilesFromDirectory(singleFeatureTests));
// files.addAll(getJavaFilesFromDirectory(typedAstFeatureTests));
//files.addAll(getJavaFilesFromDirectory(finalTest));
if (!files.isEmpty()) {
for (File file : files) {
// Try to compile the file and get the result
int result = javac.run(null, null, null, file.getPath());
// Assert that the compilation succeeded (i.e., the result is zero)
assertEquals(0, result, "Expected compilation success for " + file.getName());
}
} else {
System.out.println("No files found in the directories.");
}
}
@Test
public void areCombinedFeatureTestsValid() throws IOException {
// Get the system Java compiler
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
// Assert that the compiler is available
assertNotNull(javac, "Java Compiler is not available");
File combinedFeatureTests = new File("src/test/resources/input/combinedFeatureTests");
List<File> files = getJavaFilesFromDirectory(combinedFeatureTests);
if (!files.isEmpty()) {
for (File file : files) {
// Try to compile the file and get the result
int result = javac.run(null, null, null, file.getPath());
// Assert that the compilation succeeded (i.e., the result is zero)
assertEquals(0, result, "Expected compilation success for " + file.getName());
}
} else {
System.out.println("No files found in the directories.");
}
}
@Test
public void areSingleFeatureTestsActuallyValid() throws IOException {
// Get the system Java compiler
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
// Assert that the compiler is available
assertNotNull(javac, "Java Compiler is not available");
File singleFeatureTests = new File("src/test/resources/input/singleFeatureTests");
List<File> files = getJavaFilesFromDirectory(singleFeatureTests);
List<File> files = getJavaFilesFromDirectory(folder1);
files.addAll(getJavaFilesFromDirectory(folder2));
files.addAll(getJavaFilesFromDirectory(folder3));
if (!files.isEmpty()) {
for (File file : files) {

View File

@ -1,18 +1,28 @@
package main;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import semantic.EndToTypedAstTest;
import semantic.SemanticTest;
import org.junit.jupiter.api.Test;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import java.io.IOException;
import java.nio.file.Paths;
/**
* This class is a test suite that runs all the test classes in the project.
* <p> run: <code> mvn test </code>
* <p> check results in console or <code> target/surefire-reports </code>
* run every test: mvn test
* Nutzen dieser Klasse: Eigentlich nicht vorhanden, in der Main gibts nichts zu testen
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
})
public class MainTest {
// This class remains empty, it is used only as a holder for the above annotations
@Test
void test() {
CharStream codeCharStream = null;
try {
codeCharStream = CharStreams.fromPath(Paths.get("src/main/test/resources/CompilerInput.java"));
Main.compileFile(codeCharStream, "src/main/test/resources/output");
} catch (IOException e) {
System.err.println("Error reading the file: " + e.getMessage());
}
}
}

View File

@ -0,0 +1,145 @@
package main;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import org.antlr.v4.runtime.CharStream;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class ReflectionsTest {
@Test
public void testSimpleJavaLexerClass() throws ClassNotFoundException, NoSuchMethodException {
Class<?> clazz = Class.forName("parser.generated.SimpleJavaLexer");
// Class Name
assertEquals("parser.generated.SimpleJavaLexer", clazz.getName());
// Constructors
Constructor<?>[] actualConstructors = clazz.getDeclaredConstructors();
assertTrue(actualConstructors.length > 0, "No constructors found");
Constructor<?> expectedConstructor = clazz.getConstructor(CharStream.class);
boolean constructorFound = false;
for (Constructor<?> constructor : actualConstructors) {
if (constructor.equals(expectedConstructor)) {
constructorFound = true;
break;
}
}
assertTrue(constructorFound, "Expected constructor not found in actual constructors");
// Methods
Method[] actualMethodNames = clazz.getDeclaredMethods();
assertTrue(actualMethodNames.length > 0);
Arrays.stream(actualMethodNames).forEach(method -> System.out.println("Method: " + method.getName()));
List<String> expectedMethodNames = Arrays.asList(
"getTokenNames",
"getVocabulary",
"getGrammarFileName",
"getRuleNames",
"getSerializedATN",
"getChannelNames",
"getModeNames",
"getATN",
"makeRuleNames",
"makeLiteralNames",
"makeSymbolicNames"
);
for (Method method : actualMethodNames) {
assertTrue(expectedMethodNames.contains(method.getName()));
}
for (String expectedMethodName : expectedMethodNames) {
boolean methodFound = false;
for (Method method : actualMethodNames) {
if (method.getName().equals(expectedMethodName)) {
methodFound = true;
break;
}
}
assertTrue(methodFound, "Expected method " + expectedMethodName + " not found in actual methods");
}
// Fields
Field[] actualFieldNames = clazz.getDeclaredFields();
assertTrue(actualFieldNames.length > 0);
Arrays.stream(actualFieldNames).forEach(field -> System.out.println("Field: " + field.getName()));
List<String> expectedFieldNames = Arrays.asList(
"_decisionToDFA",
"_sharedContextCache",
"channelNames",
"modeNames",
"ruleNames",
"_LITERAL_NAMES",
"_SYMBOLIC_NAMES",
"VOCABULARY",
"tokenNames",
"_serializedATN",
"_ATN"
);
for (Field field : actualFieldNames) {
assertTrue(expectedFieldNames.contains(field.getName()));
}
}
@Test
public void testSimpleJavaParserClass() throws ClassNotFoundException {
Class<?> clazz = Class.forName("parser.generated.SimpleJavaParser");
// Class Name
assertEquals("parser.generated.SimpleJavaParser", clazz.getName());
// Constructors
Constructor<?>[] constructors = clazz.getDeclaredConstructors();
assertTrue(constructors.length > 0);
// Methods
Method[] methods = clazz.getDeclaredMethods();
assertTrue(methods.length > 0);
Arrays.stream(methods).forEach(method -> System.out.println("Method: " + method.getName()));
// Fields
Field[] fields = clazz.getDeclaredFields();
assertTrue(fields.length > 0);
Arrays.stream(fields).forEach(field -> System.out.println("Field: " + field.getName()));
}
@Test
public void testASTBuilderClass() throws ClassNotFoundException {
Class<?> clazz = Class.forName("parser.astBuilder.ASTBuilder");
// Class Name
assertEquals("parser.astBuilder.ASTBuilder", clazz.getName());
// Constructors
Constructor<?>[] constructors = clazz.getDeclaredConstructors();
assertTrue(constructors.length > 0);
// Methods
Method[] methods = clazz.getDeclaredMethods();
assertTrue(methods.length > 0);
Arrays.stream(methods).forEach(method -> System.out.println("Method: " + method.getName()));
// Fields
Field[] fields = clazz.getDeclaredFields();
assertTrue(fields.length > 0);
Arrays.stream(fields).forEach(field -> System.out.println("Field: " + field.getName()));
}
// Similarly, you can add tests for SemanticAnalyzer and ByteCodeGenerator
}

View File

@ -1,34 +1,42 @@
package parser;
import ast.ASTNode;
import ast.ClassNode;
import ast.ProgramNode;
import ast.expressions.IExpressionNode;
import ast.expressions.binaryexpressions.CalculationNode;
import ast.expressions.binaryexpressions.DotNode;
import ast.expressions.binaryexpressions.DotSubtractionNode;
import ast.expressions.binaryexpressions.NonCalculationNode;
import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.expressions.unaryexpressions.UnaryNode;
import ast.members.*;
import ast.members.ConstructorNode;
import ast.members.FieldNode;
import ast.members.MemberNode;
import ast.members.MethodNode;
import ast.parameters.ParameterNode;
import ast.statementexpressions.AssignNode;
import ast.statementexpressions.AssignableNode;
import ast.statementexpressions.NewDeclarationNode;
import ast.statementexpressions.crementexpressions.CrementType;
import ast.statementexpressions.crementexpressions.DecrementNode;
import ast.statementexpressions.crementexpressions.IncrementNode;
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
import ast.statements.*;
import ast.statements.BlockNode;
import ast.statements.IStatementNode;
import ast.statements.ReturnNode;
import ast.type.AccessModifierNode;
import ast.type.EnumValueNode;
import ast.type.ValueNode;
import ast.type.type.BaseType;
import ast.type.type.ReferenceType;
import ast.type.type.ITypeNode;
import ast.type.type.TypeEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import parser.astBuilder.ASTBuilder;
import parser.generated.SimpleJavaLexer;
import parser.generated.SimpleJavaParser;
import java.io.IOException;
import java.lang.reflect.Member;
import static org.assertj.core.api.Assertions.assertThat;
@ -309,357 +317,92 @@ class AstBuilderTest {
}
@Test
@DisplayName("If Test")
public void ifTest() {
BlockNode block = new BlockNode();
block.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "intValue", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "5"))));
@DisplayName("Null Test")
public void nullTest() {
BlockNode blockCon = new BlockNode();
MemberAccessNode memberAccess = new MemberAccessNode(true);
memberAccess.addIdentifier("a");
BlockNode ifBlock = new BlockNode();
ifBlock.addStatement(new DecrementNode(CrementType.SUFFIX, new AssignableNode("intValue")));
block.addStatement(new IfElseNode(new IfNode(new NonCalculationNode(new UnaryNode("intValue"), "==", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "5"))), ifBlock), null));
AssignableNode assignable = new AssignableNode(memberAccess);
block.addStatement(new ReturnNode(null));
blockCon.addStatement(new AssignNode(assignable, new UnaryNode(new ValueNode(EnumValueNode.NULL_VALUE, "null"))));
blockCon.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "Null", blockCon);
ConstructorNode constructor = new ConstructorNode("public", "If", block);
ClassNode class1 = new ClassNode("public", "If");
ClassNode class1 = new ClassNode("public", "Null");
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
class1.addMember(constructor);
ProgramNode expected = new ProgramNode();
expected.addClass(class1);
ASTNode actual = Helper.generateAST(directoryPath + "If.java");
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}
@Test
@DisplayName("If Else Test")
public void ifElseTest() {
BlockNode block = new BlockNode();
block.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "intValue", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "5"))));
BlockNode ifBlock = new BlockNode();
ifBlock.addStatement(new DecrementNode(CrementType.SUFFIX, new AssignableNode("intValue")));
BlockNode elseBlock = new BlockNode();
elseBlock.addStatement(new IncrementNode(CrementType.SUFFIX, new AssignableNode("intValue")));
block.addStatement(new IfElseNode(new IfNode(new NonCalculationNode(new UnaryNode("intValue"), "==", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "5"))), ifBlock), new ElseNode(elseBlock)));
block.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "IfElse", block);
ClassNode class1 = new ClassNode("public", "IfElse");
class1.addMember(constructor);
ProgramNode expected = new ProgramNode();
expected.addClass(class1);
ASTNode actual = Helper.generateAST(directoryPath + "IfElse.java");
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}
@Test
@DisplayName("If Else If ElseTest")
public void ifElseIfElseTest() {
BlockNode block = new BlockNode();
block.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "intValue", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "5"))));
BlockNode ifBlock = new BlockNode();
ifBlock.addStatement(new DecrementNode(CrementType.SUFFIX, new AssignableNode("intValue")));
BlockNode elseBlock = new BlockNode();
elseBlock.addStatement(new IncrementNode(CrementType.SUFFIX, new AssignableNode("intValue")));
IfElseNode ifElseStatement = new IfElseNode(new IfNode(new NonCalculationNode(new UnaryNode("intValue"), "==", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "5"))), ifBlock), new ElseNode(elseBlock));
BlockNode ifElseBlock = new BlockNode();
ifElseBlock.addStatement(new IncrementNode(CrementType.SUFFIX, new AssignableNode("intValue")));
ifElseStatement.addElseIfStatement(new IfNode(new NonCalculationNode(new UnaryNode("intValue"), "==", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "4"))), ifElseBlock));
block.addStatement(ifElseStatement);
block.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "IfElseIfElse", block);
ClassNode class1 = new ClassNode("public", "IfElseIfElse");
class1.addMember(constructor);
ProgramNode expected = new ProgramNode();
expected.addClass(class1);
ASTNode actual = Helper.generateAST(directoryPath + "IfElseIfElse.java");
ASTNode actual = Helper.generateAST(directoryPath + "Null.java");
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}
@Test
@DisplayName("Self Reference Test")
public void selfReferneceTest(){
public void selfReferneceTest() {
ClassNode testClass = Helper.generateEmptyClass("SelfReference");
MemberNode testClassObject = new FieldNode(new AccessModifierNode("public"), new ReferenceType("SelfReference"),"selfReference");
BlockNode testMethod1Block = new BlockNode();
testMethod1Block.addStatement(new ReturnNode(new UnaryNode(new MethodCallNode(null, "testMethod2"))));
MethodNode testMethod1 = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod1", testMethod1Block);
BlockNode testMethod2Block = new BlockNode();
testMethod2Block.addStatement(new ReturnNode(new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE,"1"))));
MethodNode testMethod2 = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod2", testMethod2Block);
BlockNode testMethod3Block = new BlockNode();
testMethod3Block.addStatement(new LocalVariableDeclarationNode(new ReferenceType("SelfReference"),"selfReference1", "=", new UnaryNode(new NewDeclarationNode("SelfReference")))); // Assing einfach "=" ?
MemberAccessNode methodAccess = new MemberAccessNode(false);
TargetNode methodTarget = new TargetNode("selfReference1");
testMethod3Block.addStatement(new ReturnNode(new UnaryNode(new MethodCallNode(methodTarget,"testMethod1"))));
MethodNode testMethod3 = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod3", testMethod3Block);
testClass.addMember(testClassObject);
testClass.addMember(testMethod1);
testClass.addMember(testMethod2);
testClass.addMember(testMethod3);
ProgramNode expected = new ProgramNode();
expected.addClass(testClass);
ASTNode actual = Helper.generateAST(directoryPath + "SelfReference.java");
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}
@Test
@DisplayName("Variable Compare Test")
public void variableCompareTest(){
ClassNode class1 = Helper.generateEmptyClass("VariableCompare");
UnaryNode trueValue = new UnaryNode(new ValueNode(EnumValueNode.BOOLEAN_VALUE,"true"));
UnaryNode falseValue = new UnaryNode(new ValueNode(EnumValueNode.BOOLEAN_VALUE,"false"));
public void variableCompareTest() {
BlockNode trueBlock = new BlockNode();
trueBlock.addStatement(new ReturnNode(trueValue));
MethodNode trueMethod = new MethodNode("public", new BaseType(TypeEnum.BOOL), false, "trueMethod", trueBlock);
BlockNode falseBlock = new BlockNode();
falseBlock.addStatement(new ReturnNode(falseValue));
MethodNode falseMethod = new MethodNode("public", new BaseType(TypeEnum.BOOL), false, "falseMethod", falseBlock);
BlockNode trueAndTrueBlock = new BlockNode();
trueAndTrueBlock.addStatement(new ReturnNode(new NonCalculationNode(trueValue, "&&", trueValue)));
MethodNode trueAndTrueMethod = new MethodNode("public", new BaseType(TypeEnum.BOOL), false, "trueAndTrueMethod", trueAndTrueBlock);
BlockNode trueAndFalseBlock = new BlockNode();
trueAndFalseBlock.addStatement(new ReturnNode(new NonCalculationNode(trueValue, "&&", falseValue)));
MethodNode trueAndFalseMethod = new MethodNode("public", new BaseType(TypeEnum.BOOL), false, "trueAndFalseMethod", trueAndFalseBlock);
BlockNode falseAndFalseBlock = new BlockNode();
falseAndFalseBlock.addStatement(new ReturnNode(new NonCalculationNode(falseValue, "&&", falseValue)));
MethodNode falseAndFalseMethod = new MethodNode("public", new BaseType(TypeEnum.BOOL), false, "falseAndFalseMethod", falseAndFalseBlock);
BlockNode trueOrTrueBlock = new BlockNode();
trueOrTrueBlock.addStatement(new ReturnNode(new NonCalculationNode(trueValue, "||", trueValue)));
MethodNode trueOrFalseMethod = new MethodNode("public", new BaseType(TypeEnum.BOOL), false, "trueOrTrueMethod", trueOrTrueBlock);
BlockNode falseOrFalseBlock = new BlockNode();
falseOrFalseBlock.addStatement(new ReturnNode(new NonCalculationNode(falseValue, "||", falseValue)));
MethodNode falseOrFalseMethod = new MethodNode("public", new BaseType(TypeEnum.BOOL), false, "falseOrFalseMethod", falseOrFalseBlock);
class1.addMember(trueMethod);
class1.addMember(falseMethod);
class1.addMember(trueAndTrueMethod);
class1.addMember(trueAndFalseMethod);
class1.addMember(falseAndFalseMethod);
class1.addMember(trueOrFalseMethod);
class1.addMember(falseOrFalseMethod);
ProgramNode expected = new ProgramNode();
expected.addClass(class1);
ASTNode actual = Helper.generateAST(directoryPath + "VariableCompare.java");
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}
@Test
@DisplayName("Variable Calculation Test")
public void variableCalculationTest(){
ClassNode class1 = Helper.generateEmptyClass("VariableCalculation");
public void variableCalculationTest() {
BlockNode aPlusBBlock = new BlockNode();
aPlusBBlock.addStatement(new ReturnNode(new CalculationNode(new CalculationNode(new DotNode(new DotSubtractionNode("a"))), "+", new DotNode(new DotSubtractionNode("b")))));
MethodNode aPlusBMethod = new MethodNode("public", new BaseType(TypeEnum.INT), false, "aPlusB", aPlusBBlock);
aPlusBMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
aPlusBMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "b"));
BlockNode aMinusBBlock = new BlockNode();
aMinusBBlock.addStatement(new ReturnNode(new CalculationNode(new CalculationNode(new DotNode(new DotSubtractionNode("a"))), "-", new DotNode(new DotSubtractionNode("b")))));
MethodNode aMinusBMethod = new MethodNode("public", new BaseType(TypeEnum.INT), false, "aMinusB", aMinusBBlock);
aMinusBMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
aMinusBMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "b"));
BlockNode aTimeBBlock = new BlockNode();
aTimeBBlock.addStatement(new ReturnNode(new CalculationNode(new DotNode(new DotNode(new DotSubtractionNode("a")), "*", new DotSubtractionNode("b")))));
MethodNode aTimeBMethod = new MethodNode("public", new BaseType(TypeEnum.INT), false, "aTimeB", aTimeBBlock);
aTimeBMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
aTimeBMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "b"));
BlockNode aDivBBlock = new BlockNode();
aDivBBlock.addStatement(new ReturnNode(new CalculationNode(new DotNode(new DotNode(new DotSubtractionNode("a")), "/", new DotSubtractionNode("b")))));
MethodNode aDivBMethod = new MethodNode("public", new BaseType(TypeEnum.INT), false, "aDivB", aDivBBlock);
aDivBMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
aDivBMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "b"));
BlockNode complexCalcBlock = new BlockNode();
complexCalcBlock.addStatement(new ReturnNode(new CalculationNode(null, null, new DotNode(new DotNode(new DotNode(new DotNode(new DotSubtractionNode("a")), "*", new DotSubtractionNode("b")), "/", new DotSubtractionNode(new ValueNode(EnumValueNode.INT_VALUE, "1"))), "*", new DotSubtractionNode(new ValueNode(EnumValueNode.INT_VALUE, "3"))))));
MethodNode complexCalcMethod = new MethodNode("public", new BaseType(TypeEnum.INT), false, "complexCalc", complexCalcBlock);
complexCalcMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
complexCalcMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "b"));
BlockNode aSmallerBBlock = new BlockNode();
aSmallerBBlock.addStatement(new ReturnNode(new NonCalculationNode(new UnaryNode("a"), "<", new UnaryNode("b"))));
MethodNode aSmallerBMethod = new MethodNode("public", new BaseType(TypeEnum.BOOL), false, "aSmallerB", aSmallerBBlock);
aSmallerBMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
aSmallerBMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "b"));
BlockNode aGreaterBBlock = new BlockNode();
aGreaterBBlock.addStatement(new ReturnNode(new NonCalculationNode(new UnaryNode("a"), ">", new UnaryNode("b"))));
MethodNode aGreaterBMethod = new MethodNode("public", new BaseType(TypeEnum.BOOL), false, "aGreaterB", aGreaterBBlock);
aGreaterBMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
aGreaterBMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "b"));
BlockNode aEqualsBBlock = new BlockNode();
aEqualsBBlock.addStatement(new ReturnNode(new NonCalculationNode(new UnaryNode("a"), "==", new UnaryNode("b"))));
MethodNode aEqualsBMethod = new MethodNode("public", new BaseType(TypeEnum.BOOL), false, "aEqualsB", aEqualsBBlock);
aEqualsBMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
aEqualsBMethod.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "b"));
class1.addMember(aPlusBMethod);
class1.addMember(aMinusBMethod);
class1.addMember(aTimeBMethod);
class1.addMember(aDivBMethod);
class1.addMember(complexCalcMethod);
class1.addMember(aSmallerBMethod);
class1.addMember(aGreaterBMethod);
class1.addMember(aEqualsBMethod);
ProgramNode expected = new ProgramNode();
expected.addClass(class1);
ASTNode actual = Helper.generateAST(directoryPath + "VariableCalculation.java");
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}
@Test
@DisplayName("Main Method Test")
public void mainMethodTest(){
ClassNode class1 = Helper.generateEmptyClass("MainMethod");
public void mainMethodTest() {
BlockNode block = new BlockNode();
block.addStatement(new ReturnNode(null));
class1.addMember(new MainMethodNode(block));
ProgramNode expected = new ProgramNode();
expected.addClass(class1);
ASTNode actual = Helper.generateAST(directoryPath + "MainMethod.java");
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}
@Test
@DisplayName("While Test")
public void whileTest(){
NonCalculationNode condition = new NonCalculationNode(new UnaryNode("i"), ">", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "0")));
public void whileTest() {
BlockNode whileBlock = new BlockNode();
whileBlock.addStatement(new DecrementNode(CrementType.SUFFIX, new AssignableNode("i")));
WhileNode whileStatement = new WhileNode(condition, whileBlock);
BlockNode blockCon = new BlockNode();
blockCon.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "i", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "10"))));
blockCon.addStatement(whileStatement);
blockCon.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "While", blockCon);
ClassNode class1 = new ClassNode("public", "While");
class1.addMember(constructor);
ProgramNode expected = new ProgramNode();
expected.addClass(class1);
ASTNode actual = Helper.generateAST(directoryPath + "While.java");
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}
@Test
@DisplayName("Do While Test")
public void doWhileTest(){
NonCalculationNode condition = new NonCalculationNode(new UnaryNode("i"), "<", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "10")));
public void doWhileTest() {
BlockNode whileBlock = new BlockNode();
whileBlock.addStatement(new IncrementNode(CrementType.SUFFIX, new AssignableNode("i")));
WhileNode whileStatement = new WhileNode(condition, whileBlock);
BlockNode blockDoWhile = new BlockNode();
blockDoWhile.addStatement(whileBlock);
blockDoWhile.addStatement(whileStatement);
BlockNode blockCon = new BlockNode();
blockCon.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "i", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "0"))));
blockCon.addStatement(blockDoWhile);
blockCon.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "DoWhile", blockCon);
ClassNode class1 = new ClassNode("public", "DoWhile");
class1.addMember(constructor);
ProgramNode expected = new ProgramNode();
expected.addClass(class1);
ASTNode actual = Helper.generateAST(directoryPath + "DoWhile.java");
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}
@Test
@DisplayName("For Test")
public void forTest(){
LocalVariableDeclarationNode forDeclaration = new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "i", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "0")));
public void forTest() {
AssignableNode assignable = new AssignableNode("i");
IncrementNode increment = new IncrementNode(CrementType.PREFIX, assignable);
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}
LocalVariableDeclarationNode declaration = new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "a", null, null);
BlockNode whileBlock = new BlockNode();
whileBlock.addStatement(declaration);
whileBlock.addStatement(increment);
WhileNode whileStatement = new WhileNode(new NonCalculationNode(new UnaryNode("i"), "<", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "10"))), whileBlock);
BlockNode forStatement = new BlockNode();
forStatement.addStatement(forDeclaration);
forStatement.addStatement(whileStatement);
BlockNode blockCon = new BlockNode();
blockCon.addStatement(forStatement);
blockCon.addStatement(new ReturnNode(null));
ConstructorNode constructor = new ConstructorNode("public", "For", blockCon);
ClassNode class1 = new ClassNode("public", "For");
class1.addMember(constructor);
//Noch nicht speziell Increment nur zum Development Testen per Debug
@Test
@DisplayName("Increment Test")
public void incrementTest() {
ClassNode classNode = Helper.generateEmptyClass("Increment");
classNode.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
ProgramNode expected = new ProgramNode();
expected.addClass(class1);
ASTNode actual = Helper.generateAST(directoryPath + "For.java");
expected.addClass(classNode);
ASTNode actual = Helper.generateAST(directoryPath + "Increment.java");
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
}
}

View File

@ -2,10 +2,12 @@ package parser;
import ast.ASTNode;
import ast.ClassNode;
import ast.ProgramNode;
import ast.members.ConstructorNode;
import ast.members.MemberNode;
import ast.statements.BlockNode;
import ast.statements.ReturnNode;
import ast.type.AccessModifierNode;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
@ -37,7 +39,7 @@ public class Helper {
public static ClassNode generateEmptyClass(String className) {
BlockNode blockNode = new BlockNode();
blockNode.addStatement(new ReturnNode(null));
MemberNode constructor = new ConstructorNode("public", className, blockNode);
MemberNode constructor = new ConstructorNode("public",className, blockNode);
ClassNode classNode = new ClassNode("public", className);
classNode.addMember(constructor);
return classNode;

View File

@ -0,0 +1,138 @@
package parser;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.ParseTree;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import parser.generated.SimpleJavaLexer;
import parser.generated.SimpleJavaParser;
import static org.junit.jupiter.api.Assertions.*;
import java.util.*;
public class ParserTest {
/*
@BeforeEach
public void init() { // noch nicht benötigt
String inputFilePath = "src/main/resources/input/CompilerInput.java";
String outputDirectoryPath = "src/main/resources/output";
}
*/
@Test
public void parserTest() {
// init
CharStream inputCharStream = CharStreams.fromString("public class Name {}");
SimpleJavaLexer lexer = new SimpleJavaLexer(inputCharStream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
tokenStream.fill();
/* Parser -> Parsetree */
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
ParseTree parseTree = parser.program(); // parse the input
//Variante 1 (geht)
String expectedParseTreeAsString = "(program (classDeclaration public class Name { }))";
String actualParseTreeAsString = parseTree.toStringTree(parser);
assertEquals(expectedParseTreeAsString, actualParseTreeAsString);
// Variante 2 (geht nicht)
// - Sollte es gehen und es liegt am Parser? (keine Ahnung) -> Bitte Fehler (actual und expected) durchlesen
// ist die Methode parseStringToTree() korrekt? -> (glaub nicht)
Map<String, Object> expectedTreeStructure = parseStringToTree(expectedParseTreeAsString);
Map<String, Object> actualTreeStructure = buildTreeStructure(parseTree, parser);
// assertEquals(expectedTreeStructure, actualTreeStructure);
}
// Helpers Variante 2.1
public static Map<String, Object> buildTreeStructure(ParseTree tree, Parser parser) {
return buildTree(tree, parser, 0);
}
private static Map<String, Object> buildTree(ParseTree tree, Parser parser, int indent) {
Map<String, Object> node = new HashMap<>();
if (tree instanceof RuleContext) {
int ruleIndex = ((RuleContext) tree).getRuleIndex();
String ruleName = parser.getRuleNames()[ruleIndex];
node.put("rule", ruleName);
} else {
node.put("text", tree.getText());
}
List<Map<String, Object>> children = new ArrayList<>();
for (int i = 0; i < tree.getChildCount(); i++) {
children.add(buildTree(tree.getChild(i), parser, indent + 1));
}
if (!children.isEmpty()) {
node.put("children", children);
}
return node;
}
// Helpers Variante 2.2
public static Map<String, Object> parseStringToTree(String input) {
input = input.trim();
if (input.startsWith("(") && input.endsWith(")")) {
input = input.substring(1, input.length() - 1).trim();
}
return parse(input);
}
private static Map<String, Object> parse(String input) {
Map<String, Object> node = new HashMap<>();
StringBuilder currentToken = new StringBuilder();
List<Map<String, Object>> children = new ArrayList<>();
int depth = 0;
boolean inToken = false;
for (char ch : input.toCharArray()) {
if (ch == '(') {
if (depth == 0) {
if (!currentToken.isEmpty()) {
node.put("node", currentToken.toString().trim());
currentToken.setLength(0);
}
} else {
currentToken.append(ch);
}
depth++;
} else if (ch == ')') {
depth--;
if (depth == 0) {
children.add(parse(currentToken.toString().trim()));
currentToken.setLength(0);
} else {
currentToken.append(ch);
}
} else if (Character.isWhitespace(ch) && depth == 0) {
if (!currentToken.isEmpty()) {
node.put("node", currentToken.toString().trim());
currentToken.setLength(0);
}
} else {
currentToken.append(ch);
}
}
if (!currentToken.isEmpty()) {
node.put("node", currentToken.toString().trim());
}
if (!children.isEmpty()) {
node.put("children", children);
}
return node;
}
}

View File

@ -0,0 +1,45 @@
package parser;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Token;
import org.junit.jupiter.api.Test;
import parser.generated.SimpleJavaLexer;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ScannerTest {
/**
* This test method is used to test the scanner functionality of the SimpleJavaLexer.
* It creates a CharStream from a string representing a simple Java class declaration,
* and uses the SimpleJavaLexer to tokenize this input.
* It then compares the actual tokens and their types produced by the lexer to the expected tokens and their types.
*/
@Test
public void scannerTest() {
// Create a CharStream from a string representing a simple Java class declaration
CharStream inputCharStream = CharStreams.fromString("public class Name {}");
// Use the SimpleJavaLexer to tokenize the input
SimpleJavaLexer lexer = new SimpleJavaLexer(inputCharStream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
tokenStream.fill();
// Prepare the expected results
List<String> expectedTokens = Arrays.asList("public", "class", "Name", "{", "}", "<EOF>");
List<String> expectedTokenTypes = Arrays.asList("AccessModifier", "Class", "Identifier", "OpenCurlyBracket", "ClosedCurlyBracket", "EOF");
List<Token> actualTokens = tokenStream.getTokens();
// Compare the actual tokens and their types to the expected tokens and their types
assertEquals(expectedTokens.size(), actualTokens.size());
for (int i = 0; i < expectedTokens.size(); i++) {
assertEquals(expectedTokens.get(i), actualTokens.get(i).getText());
assertEquals(expectedTokenTypes.get(i), SimpleJavaLexer.VOCABULARY.getSymbolicName(actualTokens.get(i).getType()));
}
}
}

View File

@ -0,0 +1,45 @@
package semantic;
import ast.ProgramNode;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.junit.jupiter.api.Test;
import parser.astBuilder.ASTBuilder;
import parser.generated.SimpleJavaLexer;
import parser.generated.SimpleJavaParser;
import java.io.IOException;
import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class BeginnToTAST {
@Test
public void FieldTests() {
SemanticAnalyzer.clearAnalyzer();
CharStream codeCharStream = null;
try {
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/input/johnsTests/FieldTests.java"));
} catch (IOException e) {
throw new RuntimeException(e);
}
SimpleJavaLexer lexer = new SimpleJavaLexer(codeCharStream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
ParseTree parseTree = parser.program(); // parse the input
/* ------------------------- AST builder -> AST ------------------------- */
ASTBuilder astBuilder = new ASTBuilder();
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
var result = SemanticAnalyzer.generateTast(abstractSyntaxTree);
assertTrue(SemanticAnalyzer.errors.isEmpty());
}
}

View File

@ -26,8 +26,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.jupiter.api.Test;
import semantic.exceptions.*;
import semantic.exceptions.NotDeclaredException;
import static org.junit.jupiter.api.Assertions.*;
@ -154,200 +152,6 @@ public class EndToTypedAstTest {
}
}
/*
@Test
public void notDeclared() {
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/NotDeclared.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof NotDeclaredException));
}*/
@Test
public void typeMismatchTest() {
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/TypeMismatchIntBool.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof TypeMismatchException));
}
@Test
public void parameterAlreadyDecleared() {
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/ParameterAlreadyDecleared.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof AlreadyDeclaredException));
}
@Test
public void fieldAlreadyDecleared(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/FieldAlreadyDecleared.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof AlreadyDeclaredException));
}
@Test
public void typeMismatchRefType(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/TypeMismatchRefType.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof TypeMismatchException));
}
@Test
public void correctRetType(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/CorrectRetType.java");
SemanticAnalyzer.generateTast(tast);
assertTrue(SemanticAnalyzer.errors.isEmpty());
}
@Test
public void retTypeMismatch(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/RetTypeMismatch.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof TypeMismatchException));
}
@Test
public void multipleRetType(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/MultipleRetTypes.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof MultipleReturnTypes));
}
@Test
public void BothTypesMustBeSameGreaterSmallerEqual(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/BothTypesMustBeSame.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof TypeMismatchException));
}
@Test
public void NoSuchType(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/ClassNotDeclared.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof NotDeclaredException));
}
@Test
public void FieldIsNotVisible(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/FieldIsNotVisible.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof NotVisibleException));
}
@Test
public void ChainedMethods(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/ChainedMethods.java");
SemanticAnalyzer.generateTast(tast);
assertTrue(SemanticAnalyzer.errors.isEmpty());
}
@Test
public void VariableCompare(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/VariableCompare.java");
SemanticAnalyzer.generateTast(tast);
assertTrue(SemanticAnalyzer.errors.isEmpty());
}
@Test
public void IfExpressionInt(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/IfExpressionInt.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertInstanceOf(TypeMismatchException.class, SemanticAnalyzer.errors.getFirst());
}
@Test
public void SelectWrongMethodCauseParameter(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/SelectWrongMethodCauseParameter.java");
SemanticAnalyzer.generateTast(tast);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertInstanceOf(TypeMismatchException.class, SemanticAnalyzer.errors.getFirst());
}
@Test
public void SelectRightMethodCauseParameter(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/SelectRightMethodCauseParameter.java");
SemanticAnalyzer.generateTast(tast);
assertTrue(SemanticAnalyzer.errors.isEmpty());
}
@Test
public void VariableCalculation(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/VariableCalculation.java");
SemanticAnalyzer.generateTast(tast);
assertTrue(SemanticAnalyzer.errors.isEmpty());
}
@Test
public void Expression(){
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/Expression.java");
SemanticAnalyzer.generateTast(tast);
assertTrue(SemanticAnalyzer.errors.isEmpty());
}
// ------------------ Helpers ------------------

Some files were not shown because too many files have changed in this diff Show More