Merge remote-tracking branch 'origin/NewParser' into NewParser

# Conflicts:
#	src/main/java/ast/ClassNode.java
#	src/main/java/ast/expressions/AssignableExpressionNode.java
#	src/main/java/ast/expressions/ExpressionNode.java
#	src/main/java/ast/expressions/IExpressionNode.java
#	src/main/java/ast/expressions/binaryexpression/BinaryExpressionNode.java
#	src/main/java/ast/expressions/binaryexpression/CalculationExpressionNode.java
#	src/main/java/ast/expressions/binaryexpression/DotExpressionNode.java
#	src/main/java/ast/expressions/binaryexpression/DotSubstractionExpressionNode.java
#	src/main/java/ast/expressions/binaryexpression/EnumDotOperator.java
#	src/main/java/ast/expressions/binaryexpression/EnumLineOperator.java
#	src/main/java/ast/expressions/binaryexpression/EnumNonCalculationOperator.java
#	src/main/java/ast/expressions/binaryexpression/NonCalculationExpressionNode.java
#	src/main/java/ast/expressions/unaryexpression/MemberAccessNode.java
#	src/main/java/ast/expressions/unaryexpression/NotExpressionNode.java
#	src/main/java/ast/expressions/unaryexpression/UnaryExpressionNode.java
#	src/main/java/ast/members/ConstructorNode.java
#	src/main/java/ast/members/MainMethodNode.java
#	src/main/java/ast/statement/ForStatementNode.java
#	src/main/java/ast/statement/WhileStatementNode.java
#	src/main/java/ast/statement/ifstatement/ElseStatementNode.java
#	src/main/java/ast/statement/ifstatement/IfElseStatementNode.java
#	src/main/java/ast/statement/ifstatement/IfStatementNode.java
#	src/main/java/ast/statement/statementexpression/methodcallstatementnexpression/TargetNode.java
#	src/main/java/ast/statementexpressions/AssignStatementExpressionNode.java
#	src/main/java/ast/statementexpressions/AssignableExpressionNode.java
#	src/main/java/ast/statementexpressions/CrementExpressionStatementExpressionNode.java
#	src/main/java/ast/statementexpressions/IStatementExpressionNode.java
#	src/main/java/ast/statementexpressions/NewDeclarationStatementExpressionNode.java
#	src/main/java/ast/statementexpressions/crementExpression/CrementType.java
#	src/main/java/ast/statementexpressions/crementExpression/DecrementExpressionNode.java
#	src/main/java/ast/statementexpressions/crementExpression/IncrementExpressionNode.java
#	src/main/java/ast/statementexpressions/methodcallstatementnexpression/ChainedMethodNode.java
#	src/main/java/ast/statementexpressions/methodcallstatementnexpression/MethodCallStatementExpressionNode.java
#	src/main/java/ast/statements/BlockStatementNode.java
#	src/main/java/ast/statements/IStatementNode.java
#	src/main/java/ast/statements/LocalVariableDeclarationNode.java
#	src/main/java/ast/statements/ReturnStatementNode.java
#	src/main/java/bytecode/ClassCodeGen.java
#	src/main/java/bytecode/Mapper.java
#	src/main/java/bytecode/MethodCodeGen.java
#	src/main/java/parser/astBuilder/ASTBuilder.java
#	src/main/java/parser/generated/SimpleJava.interp
#	src/main/java/parser/generated/SimpleJava.tokens
#	src/main/java/parser/generated/SimpleJavaBaseListener.java
#	src/main/java/parser/generated/SimpleJavaBaseVisitor.java
#	src/main/java/parser/generated/SimpleJavaLexer.interp
#	src/main/java/parser/generated/SimpleJavaLexer.java
#	src/main/java/parser/generated/SimpleJavaLexer.tokens
#	src/main/java/parser/generated/SimpleJavaListener.java
#	src/main/java/parser/generated/SimpleJavaParser.java
#	src/main/java/parser/generated/SimpleJavaVisitor.java
#	src/main/java/semantic/SemanticVisitor.java
This commit is contained in:
Purplumbi504 2024-06-23 10:58:46 +02:00
commit fcaeb850ba
89 changed files with 2873 additions and 1883 deletions

View File

@ -1,7 +1,7 @@
import oldAst.ASTNode; import ast.ASTNode;
import org.antlr.v4.runtime.*; import org.antlr.v4.runtime.*;
import oldAst.ProgramNode; import ast.ProgramNode;
import bytecode.ByteCodeGenerator; //import bytecode.ByteCodeGenerator;
import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.ParseTree;
@ -9,7 +9,7 @@ import org.antlr.v4.runtime.CommonTokenStream;
import parser.astBuilder.ASTBuilder; import parser.astBuilder.ASTBuilder;
import parser.generated.SimpleJavaLexer; import parser.generated.SimpleJavaLexer;
import parser.generated.SimpleJavaParser; import parser.generated.SimpleJavaParser;
import semantic.SemanticAnalyzer; //import semantic.SemanticAnalyzer;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -60,7 +60,7 @@ public class Main {
/* ------------------------- AST builder -> AST ------------------------- */ /* ------------------------- AST builder -> AST ------------------------- */
ASTBuilder astBuilder = new ASTBuilder(); ASTBuilder astBuilder = new ASTBuilder();
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree); ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
System.out.println(abstractSyntaxTree);
// Printing the AST // Printing the AST
// System.out.println("-------------------- AST builder -> AST --------------------"); // System.out.println("-------------------- AST builder -> AST --------------------");
// // System.out.println("AST: " + ast.toString()); // // System.out.println("AST: " + ast.toString());
@ -70,8 +70,8 @@ public class Main {
/* /*
* ------------------------- Semantic Analyzer -> Tast ------------------------- * ------------------------- Semantic Analyzer -> Tast -------------------------
*/ */
SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer(); //SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer();
ProgramNode typedAst = (ProgramNode) semanticAnalyzer.generateTast(abstractSyntaxTree); //ProgramNode typedAst = (ProgramNode) semanticAnalyzer.generateTast(abstractSyntaxTree);
// Printing the Tast // Printing the Tast
System.out.println("Tast generated"); System.out.println("Tast generated");
@ -80,9 +80,9 @@ public class Main {
* ------------------------- Bytecode Generator -> Bytecode * ------------------------- Bytecode Generator -> Bytecode
* ------------------------- * -------------------------
*/ */
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator(); //ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator();
//byteCodeGenerator.generateByteCode(abstractSyntaxTree); //byteCodeGenerator.generateByteCode(abstractSyntaxTree);
byteCodeGenerator.visit(typedAst); //byteCodeGenerator.visit(typedAst);
System.out.println("Bytecode generated"); System.out.println("Bytecode generated");
} }

View File

@ -1,10 +1,9 @@
package ast; package ast;
import ast.type.AccessModifierNode; import ast.type.AccessModifierNode;
import bytecode.visitor.ClassVisitor; import ast.member.ConstructorNode;
import ast.members.ConstructorNode; import ast.member.MemberNode;
import ast.members.MemberNode; import ast.member.MethodNode;
import ast.members.MethodNode;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
import visitor.Visitable; import visitor.Visitable;
@ -35,7 +34,7 @@ public class ClassNode implements ASTNode, Visitable {
public void ensureConstructor(){ public void ensureConstructor(){
if(!hasConstructor) { if(!hasConstructor) {
ConstructorNode constructor = new ConstructorNode("public", identifier, ); ConstructorNode constructor = new ConstructorNode(new AccessModifierNode("public"), identifier);
members.addFirst(constructor); members.addFirst(constructor);
} }
} }
@ -55,8 +54,4 @@ public class ClassNode implements ASTNode, Visitable {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(ClassVisitor classVisitor) {
classVisitor.visit(this);
}
} }

View File

@ -1,4 +0,0 @@
package ast;
public class IdentifierNode {
}

View File

@ -1,6 +1,5 @@
package ast; package ast;
import bytecode.visitor.ProgramVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
import visitor.Visitable; import visitor.Visitable;
@ -19,9 +18,4 @@ public class ProgramNode implements ASTNode, Visitable {
public TypeCheckResult accept(SemanticVisitor visitor) { public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(ProgramVisitor programVisitor) {
programVisitor.visit(this);
}
} }

View File

@ -1,4 +0,0 @@
package ast.expressions;
public class AssignableExpressionNode {
}

View File

@ -1,4 +0,0 @@
package ast.expressions;
public class ExpressionNode {
}

View File

@ -0,0 +1,11 @@
package ast.expression;
import ast.ASTNode;
import ast.type.type.ITypeNode;
import visitor.Visitable;
public interface IExpressionNode extends ASTNode, Visitable {
ITypeNode getType();
}

View File

@ -0,0 +1,19 @@
package ast.expression.binaryexpression;
import ast.expression.IExpressionNode;
import ast.type.type.*;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class BinaryExpressionNode implements IExpressionNode {
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public ITypeNode getType() {
return null;
}
}

View File

@ -0,0 +1,40 @@
package ast.expression.binaryexpression;
import ast.type.type.*;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class CalculationExpressionNode extends BinaryExpressionNode {
public CalculationExpressionNode calculationExpression;
public EnumLineOperator operator;
public DotExpressionNode dotExpression;
public CalculationExpressionNode(CalculationExpressionNode calculationExpression, String operator, DotExpressionNode dotExpression) {
this.calculationExpression = calculationExpression;
setOperator(operator);
this.dotExpression = dotExpression;
}
public CalculationExpressionNode(DotExpressionNode dotExpression) {
this.dotExpression = dotExpression;
}
private void setOperator(String operator) {
if(operator.equals("+")) {
this.operator = EnumLineOperator.PLUS;
} else if(operator.equals("-")) {
this.operator = EnumLineOperator.MINUS;
}
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public ITypeNode getType() {
return null;
}
}

View File

@ -0,0 +1,42 @@
package ast.expression.binaryexpression;
import ast.type.type.*;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class DotExpressionNode extends BinaryExpressionNode {
public DotExpressionNode dotExpression;
public EnumDotOperator operator;
public DotSubstractionExpressionNode dotSubstractionExpression;
public DotExpressionNode(DotExpressionNode dotExpression, String operator, DotSubstractionExpressionNode dotSubstractionExpression) {
this.dotExpression = dotExpression;
setOperator(operator);
this.dotSubstractionExpression = dotSubstractionExpression;
}
public DotExpressionNode(DotSubstractionExpressionNode dotSubstractionExpression) {
this.dotSubstractionExpression = dotSubstractionExpression;
}
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;
}
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public ITypeNode getType() {
return null;
}
}

View File

@ -0,0 +1,44 @@
package ast.expression.binaryexpression;
import ast.expression.unaryexpression.MemberAccessNode;
import ast.statement.statementexpression.methodcallstatementnexpression.MethodCallStatementExpressionNode;
import ast.type.type.*;
import ast.type.ValueNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class DotSubstractionExpressionNode extends BinaryExpressionNode {
public ValueNode value;
public String identifier;
public MemberAccessNode memberAccess;
public MethodCallStatementExpressionNode methodCall;
public CalculationExpressionNode calculationExpression;
public DotSubstractionExpressionNode(ValueNode value) {
this.value = value;
}
public DotSubstractionExpressionNode(String identifier) {
this.identifier = identifier;
}
public DotSubstractionExpressionNode(MemberAccessNode memberAccess) {
this.memberAccess = memberAccess;
}
public DotSubstractionExpressionNode(MethodCallStatementExpressionNode methodCall, CalculationExpressionNode calculationExpression) {
this.methodCall = methodCall;
this.calculationExpression = calculationExpression;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public ITypeNode getType() {
return null;
}
}

View File

@ -0,0 +1,5 @@
package ast.expression.binaryexpression;
public enum EnumDotOperator {
MULT, DIV, MOD
}

View File

@ -0,0 +1,5 @@
package ast.expression.binaryexpression;
public enum EnumLineOperator {
PLUS, MINUS
}

View File

@ -0,0 +1,5 @@
package ast.expression.binaryexpression;
public enum EnumNonCalculationOperator {
AND, OR, GREATER, LESS, GREATER_EQUAL, LESS_EQUAL, EQUAL, NOT_EQUAL
}

View File

@ -0,0 +1,50 @@
package ast.expression.binaryexpression;
import ast.expression.IExpressionNode;
import ast.expression.unaryexpression.UnaryExpressionNode;
import ast.type.type.*;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class NonCalculationExpressionNode extends BinaryExpressionNode {
public UnaryExpressionNode unaryExpression;
public EnumNonCalculationOperator operator;
public IExpressionNode expression;
public NonCalculationExpressionNode(UnaryExpressionNode unaryExpression, String operator, IExpressionNode expression) {
this.unaryExpression = unaryExpression;
setOperator(operator);
this.expression = expression;
}
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;
}
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public ITypeNode getType() {
return null;
}
}

View File

@ -0,0 +1,20 @@
package ast.expression.unaryexpression;
import ast.ASTNode;
import java.util.ArrayList;
import java.util.List;
public class MemberAccessNode implements ASTNode {
public Boolean thisExpr;
public List<String> identifiers = new ArrayList<>();
public MemberAccessNode(Boolean thisExpr) {
this.thisExpr = thisExpr;
}
public void addIdentifier(String identifier) {
identifiers.add(identifier);
}
}

View File

@ -0,0 +1,13 @@
package ast.expression.unaryexpression;
import ast.ASTNode;
import ast.expression.IExpressionNode;
public class NotExpressionNode implements ASTNode {
public IExpressionNode expression;
public NotExpressionNode(IExpressionNode expression) {
this.expression = expression;
}
}

View File

@ -0,0 +1,64 @@
package ast.expression.unaryexpression;
import ast.expression.IExpressionNode;
import ast.statement.IStatementNode;
import ast.type.type.*;
import ast.type.ValueNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
import java.util.Objects;
public class UnaryExpressionNode implements IExpressionNode {
public String thisExp;
public String identifier;
public MemberAccessNode memberAccess;
public ValueNode value;
public NotExpressionNode notExpression;
public IStatementNode statement;
public IExpressionNode expression;
private ITypeNode type;
public UnaryExpressionNode(String value) {
if(Objects.equals(value, "this")) {
this.thisExp = "this";
} else {
this.identifier = value;
}
}
public UnaryExpressionNode(MemberAccessNode memberAccess) {
this.memberAccess = memberAccess;
}
public UnaryExpressionNode(ValueNode value) {
this.value = value;
}
public UnaryExpressionNode(NotExpressionNode notExpression) {
this.notExpression = notExpression;
}
public UnaryExpressionNode(IStatementNode statement) {
this.statement = statement;
}
public UnaryExpressionNode(IExpressionNode expression) {
this.expression = expression;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
@Override
public ITypeNode getType() {
return type;
}
public void setType(ITypeNode type) {
this.type = type;
}
}

View File

@ -1,21 +1,27 @@
package ast.members; package ast.member;
import ast.statements.BlockStatementNode; import ast.block.BlockNode;
import ast.parameters.ParameterNode; import ast.parameter.ParameterNode;
import ast.type.AccessModifierNode; import ast.type.AccessModifierNode;
import bytecode.visitor.MethodVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
import visitor.Visitable; import visitor.Visitable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ConstructorNode extends MethodNode implements Visitable { public class ConstructorNode extends MethodNode {
public AccessModifierNode accessType; public AccessModifierNode accessType;
public String identifier; public String identifier;
public List<ParameterNode> parameters = new ArrayList<>(); public List<ParameterNode> parameters = new ArrayList<>();
public BlockStatementNode body; public BlockNode body;
public ConstructorNode(String accessType, String identifier, BlockStatementNode body) { public ConstructorNode(AccessModifierNode accessType, String identifier) {
this.accessType = accessType;
this.identifier = identifier;
}
public ConstructorNode(String accessType, String identifier, BlockNode body) {
this.accessType = new AccessModifierNode(accessType); this.accessType = new AccessModifierNode(accessType);
this.identifier = identifier; this.identifier = identifier;
this.body = body; this.body = body;
@ -25,8 +31,4 @@ public class ConstructorNode extends MethodNode implements Visitable {
parameters.add(parameterNode); parameters.add(parameterNode);
} }
@Override
public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this);
}
} }

View File

@ -1,20 +1,17 @@
package ast.members; package ast.members;
import ast.type.AccessModifierNode; import ast.type.AccessModifierNode;
import ast.type.TypeNode; import ast.type.type.ITypeNode;
import bytecode.visitor.ClassVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
import visitor.Visitable; import visitor.Visitable;
public class FieldNode implements MemberNode, Visitable { public class FieldNode implements MemberNode, Visitable {
public AccessModifierNode accessTypeNode; public AccessModifierNode accessTypeNode;
public TypeNode type; public ITypeNode type;
public String identifier; public String identifier;
public FieldNode(){} public FieldNode(AccessModifierNode accessTypeNode, ITypeNode type, String name){
public FieldNode(AccessModifierNode accessTypeNode, TypeNode type, String name){
this.accessTypeNode = accessTypeNode; this.accessTypeNode = accessTypeNode;
this.type = type; this.type = type;
this.identifier = name; this.identifier = name;
@ -25,8 +22,4 @@ public class FieldNode implements MemberNode, Visitable {
return visitor.analyze(this); return visitor.analyze(this);
} }
@Override
public void accept(ClassVisitor classVisitor) {
classVisitor.visit(this);
}
} }

View File

@ -0,0 +1,11 @@
package ast.member;
import ast.block.BlockNode;
public class MainMethodNode extends MethodNode {
public BlockNode block;
public MainMethodNode(BlockNode block) {
this.block = block;
}
}

View File

@ -1,5 +1,9 @@
package ast.members; package ast.members;
import ast.block.BlockNode;
import ast.parameter.ParameterNode;
import ast.type.AccessModifierNode;
import ast.type.type.*;
import bytecode.visitor.MethodVisitor; import bytecode.visitor.MethodVisitor;
import semantic.SemanticVisitor; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
@ -7,46 +11,46 @@ import visitor.Visitable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
public class MethodNode implements MemberNode, Visitable { public class MethodNode implements MemberNode, Visitable {
public AccessModifierNode accessModifier; public AccessModifierNode accesModifier;
public TypeNode type; private ITypeNode type;
public String identifier; public Boolean voidType;
private String identifier;
public List<ParameterNode> parameters = new ArrayList<>();
public BlockNode block;
public ParameterListNode parameters; public MethodNode() {}
public List<StatementNode> statements = new ArrayList<>(); public MethodNode(String accessModifier, ITypeNode type, Boolean voidType, String identifier, BlockNode block){
this.accesModifier = new AccessModifierNode(accessModifier);
public MethodNode(){}
public MethodNode(AccessTypeNode visibility, TypeNode type, String identifier, ParameterListNode parameters,
List<StatementNode> statements){
this.visibility = visibility;
this.type = type; this.type = type;
this.voidType = voidType;
this.identifier = identifier; this.identifier = identifier;
this.parameters = parameters; this.block = block;
this.statements = statements;
} }
public MethodNode(AccessTypeNode visibility, String identifier){ public void addParameter(ParameterNode parameter) {
this.visibility = visibility; this.parameters.add(parameter);
this.identifier = identifier; }
public List<ParameterNode> getParameters() {
return parameters;
} }
public boolean isSame(MethodNode methodNode){ public boolean isSame(MethodNode methodNode){
boolean isSame = false; if (!(Objects.equals(this.identifier, methodNode.getIdentifier())) || type.equals(methodNode.type)
if(methodNode.identifier.equals(identifier)){ || getParameters().size() != methodNode.getParameters().size()) {
if(parameters != null && methodNode.parameters != null){ return false;
if(parameters.parameters.size() == methodNode.parameters.parameters.size()){ }
for(int i = 0; i < parameters.parameters.size(); i++){
if(parameters.parameters.get(i).identifier.equals(methodNode.parameters.parameters.get(i).identifier)){ for (int i = 0; i < this.getParameters().size(); i++) {
isSame = true; if (this.getParameters().get(i).type.equals(methodNode.getParameters().get(i).type)) {
} return false;
}
}
} }
} }
return isSame; return true;
} }
@Override @Override
@ -58,4 +62,21 @@ public class MethodNode implements MemberNode, Visitable {
public void accept(MethodVisitor methodVisitor) { public void accept(MethodVisitor methodVisitor) {
methodVisitor.visit(this); methodVisitor.visit(this);
} }
public String getIdentifier() {
return identifier;
}
public ITypeNode getType() {
return type;
}
public void setType(ITypeNode type) {
this.type = type;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
} }

View File

@ -1,14 +1,23 @@
package ast.parameters; package ast.parameters;
import ast.ASTNode; import ast.ASTNode;
import ast.type.TypeNode; import ast.type.type.*;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
import visitor.Visitable;
public class ParameterNode implements ASTNode { public class ParameterNode implements ASTNode, Visitable {
TypeNode type; public ITypeNode type;
String identifier; public String identifier;
public ParameterNode(TypeNode type, String identifier) { public ParameterNode(ITypeNode type, String identifier) {
this.type = type; this.type = type;
this.identifier = identifier; this.identifier = identifier;
} }
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
} }

View File

@ -0,0 +1,31 @@
package ast.statement;
import ast.ASTNode;
import ast.expression.IExpressionNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class ForStatementNode implements IStatementNode {
public IExpressionNode statementExpressionInit;
public IStatementNode localVariableDeclarationInit;
public IExpressionNode expression;
public IExpressionNode statementExpression;
public ForStatementNode(IExpressionNode statementExpressionInit, IExpressionNode expression, IExpressionNode statementExpression) {
this.statementExpressionInit = statementExpressionInit;
this.expression = expression;
this.statementExpression = statementExpression;
}
public ForStatementNode(IStatementNode localVariableDeclarationInit, IExpressionNode expression, IExpressionNode statementExpression) {
this.localVariableDeclarationInit = localVariableDeclarationInit;
this.expression = expression;
this.statementExpression = statementExpression;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@ -0,0 +1,23 @@
package ast.statement;
import ast.ASTNode;
import ast.block.BlockNode;
import ast.expression.IExpressionNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class WhileStatementNode implements IStatementNode {
public IExpressionNode expression;
public BlockNode block;
public WhileStatementNode(IExpressionNode expression, BlockNode block) {
this.expression = expression;
this.block = block;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@ -0,0 +1,21 @@
package ast.statement.ifstatement;
import ast.ASTNode;
import ast.block.BlockNode;
import ast.statement.IStatementNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class ElseStatementNode implements IStatementNode {
public BlockNode block;
public ElseStatementNode(BlockNode block) {
this.block = block;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@ -0,0 +1,28 @@
package ast.statement.ifstatement;
import ast.ASTNode;
import ast.statement.IStatementNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
import java.util.ArrayList;
import java.util.List;
public class IfElseStatementNode implements IStatementNode {
public IfStatementNode ifStatement;
public List<ElseStatementNode> elseStatements = new ArrayList<>();
public IfElseStatementNode(IfStatementNode ifStatement) {
this.ifStatement = ifStatement;
}
public void addElseStatement(ElseStatementNode elseStatement) {
elseStatements.add(elseStatement);
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@ -0,0 +1,24 @@
package ast.statement.ifstatement;
import ast.ASTNode;
import ast.block.BlockNode;
import ast.expression.IExpressionNode;
import ast.statement.IStatementNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class IfStatementNode implements IStatementNode {
public IExpressionNode expression;
public BlockNode block;
public IfStatementNode(IExpressionNode expression, BlockNode block) {
this.expression = expression;
this.block = block;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@ -0,0 +1,28 @@
package ast.statement.statementexpression.methodcallstatementnexpression;
import ast.ASTNode;
import ast.expression.unaryexpression.MemberAccessNode;
import ast.statement.statementexpression.NewDeclarationStatementExpressionNode;
public class TargetNode implements ASTNode {
public Boolean thisTar;
public MemberAccessNode memberAccess;
public NewDeclarationStatementExpressionNode newDeclaration;
public String identifier;
public TargetNode(Boolean thisTar) {
this.thisTar = thisTar;
}
public TargetNode(MemberAccessNode memberAccess) {
this.memberAccess = memberAccess;
}
public TargetNode(NewDeclarationStatementExpressionNode newDeclaration) {
this.newDeclaration = newDeclaration;
}
public TargetNode(String identifier) {
this.identifier = identifier;
}
}

View File

@ -1,15 +1,21 @@
package ast.statementexpressions; package ast.statement.statementexpression;
import ast.ASTNode; import ast.expression.IExpressionNode;
import ast.expressions.AssignableExpressionNode; import semantic.SemanticVisitor;
import ast.expressions.ExpressionNode; import typechecker.TypeCheckResult;
public class AssignStatementExpressionNode implements ASTNode { public class AssignStatementExpressionNode implements IStatementExpressionNode {
AssignableExpressionNode assignable; public AssignableExpressionNode assignable;
ExpressionNode expression; public IExpressionNode expression;
public AssignStatementExpressionNode(AssignableExpressionNode assignable, ExpressionNode expression) { public AssignStatementExpressionNode(AssignableExpressionNode assignable, IExpressionNode expression) {
this.assignable = assignable; this.assignable = assignable;
this.expression = expression; this.expression = expression;
} }
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
} }

View File

@ -0,0 +1,25 @@
package ast.statement.statementexpression;
import ast.expression.unaryexpression.MemberAccessNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class AssignableExpressionNode implements IStatementExpressionNode {
public String identifier;
public MemberAccessNode memberAccess;
public AssignableExpressionNode(String identifier) {
this.identifier = identifier;
}
public AssignableExpressionNode(MemberAccessNode memberAccess) {
this.memberAccess = memberAccess;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@ -1,20 +0,0 @@
package ast.statementexpressions;
import ast.ASTNode;
import ast.expressions.ExpressionNode;
import java.util.ArrayList;
import java.util.List;
public class CrementExpressionStatementExpressionNode implements ASTNode {
String identifier;
List<ExpressionNode> expressions = new ArrayList<>();
public CrementExpressionStatementExpressionNode(String identifier) {
this.identifier = identifier;
}
public void addExpression(ExpressionNode expression) {
expressions.add(expression);
}
}

View File

@ -0,0 +1,5 @@
package ast.statement.statementexpression;
import ast.statement.IStatementNode;
public interface IStatementExpressionNode extends IStatementNode {}

View File

@ -1,20 +1,28 @@
package ast.statementexpressions; package ast.statement.statementexpression;
import ast.ASTNode; import ast.ASTNode;
import ast.expressions.ExpressionNode; import ast.expression.IExpressionNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class NewDeclarationStatementExpressionNode implements ASTNode { public class NewDeclarationStatementExpressionNode implements IStatementExpressionNode {
String identifier; public String identifier;
List<ExpressionNode> expressions = new ArrayList<>(); public List<IExpressionNode> expressions = new ArrayList<>();
public NewDeclarationStatementExpressionNode(String identifier) { public NewDeclarationStatementExpressionNode(String identifier) {
this.identifier = identifier; this.identifier = identifier;
} }
public void addExpression(ExpressionNode expression) { public void addExpression(IExpressionNode expression) {
expressions.add(expression); expressions.add(expression);
} }
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
} }

View File

@ -0,0 +1,5 @@
package ast.statement.statementexpression.crementExpression;
public enum CrementType {
PREFIX, SUFFIX
}

View File

@ -0,0 +1,22 @@
package ast.statement.statementexpression.crementExpression;
import ast.ASTNode;
import ast.statement.statementexpression.AssignableExpressionNode;
import ast.statement.statementexpression.IStatementExpressionNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class DecrementExpressionNode implements IStatementExpressionNode {
public CrementType crementType;
public AssignableExpressionNode assignableExpression;
public DecrementExpressionNode(CrementType crementType, AssignableExpressionNode assignableExpression) {
this.assignableExpression = assignableExpression;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@ -0,0 +1,22 @@
package ast.statement.statementexpression.crementExpression;
import ast.ASTNode;
import ast.statement.statementexpression.AssignableExpressionNode;
import ast.statement.statementexpression.IStatementExpressionNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class IncrementExpressionNode implements IStatementExpressionNode {
public CrementType crementType;
public AssignableExpressionNode assignableExpression;
public IncrementExpressionNode(CrementType crementType, AssignableExpressionNode assignableExpression) {
this.assignableExpression = assignableExpression;
}
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
}

View File

@ -1,20 +1,20 @@
package ast.statementexpressions.methodcallstatementnexpression; package ast.statement.statementexpression.methodcallstatementnexpression;
import ast.ASTNode; import ast.ASTNode;
import ast.expressions.ExpressionNode; import ast.expression.IExpressionNode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ChainedMethodNode implements ASTNode { public class ChainedMethodNode implements ASTNode {
String identifier; public String identifier;
List<ExpressionNode> expressions = new ArrayList<>(); public List<IExpressionNode> expressions = new ArrayList<>();
public ChainedMethodNode(String identifier) { public ChainedMethodNode(String identifier) {
this.identifier = identifier; this.identifier = identifier;
} }
public void addExpression(ExpressionNode expression) { public void addExpression(IExpressionNode expression) {
expressions.add(expression); expressions.add(expression);
} }
} }

View File

@ -1,16 +1,19 @@
package ast.statementexpressions.methodcallstatementnexpression; package ast.statement.statementexpression.methodcallstatementnexpression;
import ast.ASTNode; import ast.ASTNode;
import ast.expressions.ExpressionNode; import ast.expression.IExpressionNode;
import ast.statement.statementexpression.IStatementExpressionNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class MethodCallStatementExpressionNode implements ASTNode { public class MethodCallStatementExpressionNode implements IStatementExpressionNode {
TargetNode target; public TargetNode target;
List<ChainedMethodNode> chainedMethods = new ArrayList<>(); public List<ChainedMethodNode> chainedMethods = new ArrayList<>();
String identifier; public String identifier;
List<ExpressionNode> expressions = new ArrayList<>(); public List<IExpressionNode> expressions = new ArrayList<>();
public MethodCallStatementExpressionNode(TargetNode target, String identifier) { public MethodCallStatementExpressionNode(TargetNode target, String identifier) {
this.target = target; this.target = target;
@ -21,9 +24,13 @@ public class MethodCallStatementExpressionNode implements ASTNode {
chainedMethods.add(chainedMethode); chainedMethods.add(chainedMethode);
} }
public void addExpression(ExpressionNode expression) { public void addExpression(IExpressionNode expression) {
expressions.add(expression); expressions.add(expression);
} }
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
} }

View File

@ -1,14 +1,29 @@
package ast.statements; package ast.block;
import ast.ASTNode; import ast.ASTNode;
import ast.statement.IStatementNode;
import ast.statement.ReturnStatementNode;
import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
import visitor.Visitable;
import java.beans.Visibility;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class BlockStatementNode extends StatementNode implements ASTNode { public class BlockNode implements ASTNode, Visitable {
public List<StatementNode> statements = new ArrayList<>(); public List<IStatementNode> statements = new ArrayList<>();
public Boolean hasReturnStatement = false;
public void addStatement(StatementNode statement) { public BlockNode() {}
public void addStatement(IStatementNode statement) {
statements.add(statement); statements.add(statement);
} }
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
} }

View File

@ -0,0 +1,7 @@
package ast.statement;
import ast.ASTNode;
import visitor.Visitable;
public interface IStatementNode extends ASTNode, Visitable {
}

View File

@ -1,19 +1,26 @@
package ast.statements; package ast.statement;
import ast.ASTNode; import ast.expression.IExpressionNode;
import ast.expressions.ExpressionNode; import ast.type.type.*;
import ast.type.TypeNode; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class LocalVariableDeclarationNode implements ASTNode { public class LocalVariableDeclarationNode implements IStatementNode {
TypeNode type; public ITypeNode type;
String identifier; public String identifier;
String assign; public String assign;
ExpressionNode expression; public IExpressionNode expression;
public LocalVariableDeclarationNode(TypeNode type, String identifier, String assign, ExpressionNode expression) { public LocalVariableDeclarationNode(ITypeNode type, String identifier, String assign, IExpressionNode expression) {
this.type = type; this.type = type;
this.identifier = identifier; this.identifier = identifier;
this.assign = assign; this.assign = assign;
this.expression = expression; this.expression = expression;
} }
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
} }

View File

@ -1,12 +1,24 @@
package ast.statements; package ast.statement;
import ast.ASTNode; import ast.expression.IExpressionNode;
import ast.expressions.ExpressionNode; import semantic.SemanticVisitor;
import typechecker.TypeCheckResult;
public class ReturnStatementNode implements ASTNode { public class ReturnStatementNode implements IStatementNode {
public ExpressionNode expression; public IExpressionNode expression;
public Boolean voidReturn = false;
public ReturnStatementNode(ExpressionNode expression) { public ReturnStatementNode(IExpressionNode expression) {
this.expression = expression; if(expression != null) {
this.expression = expression;
} else {
voidReturn = true;
}
} }
@Override
public TypeCheckResult accept(SemanticVisitor visitor) {
return visitor.analyze(this);
}
} }

View File

@ -1,7 +1,7 @@
package ast.type; package ast.type;
public class AccessModifierNode { public class AccessModifierNode {
EnumAccessModifierNode accessType; public EnumAccessModifierNode accessType;
public AccessModifierNode(String accessModifier) { public AccessModifierNode(String accessModifier) {
setModifier(accessModifier); setModifier(accessModifier);

View File

@ -1,5 +0,0 @@
package ast.type;
public enum EnumTypeNode {
INT, BOOLEAN, CHAR, IDENTIFIER
}

View File

@ -0,0 +1,5 @@
package ast.type;
public enum EnumValueNode {
INT_VALUE, BOOLEAN_VALUE, CHAR_VALUE, NULL_VALUE
}

View File

@ -1,25 +0,0 @@
package ast.type;
public class TypeNode {
EnumTypeNode type;
public TypeNode(String type) {
setType(type);
}
private void setType(String type) {
switch(type) {
case "int":
this.type = EnumTypeNode.INT;
break;
case "boolean":
this.type = EnumTypeNode.BOOLEAN;
break;
case "char":
this.type = EnumTypeNode.CHAR;
break;
default:
this.type = EnumTypeNode.IDENTIFIER;
}
}
}

View File

@ -0,0 +1,13 @@
package ast.type;
import ast.ASTNode;
public class ValueNode implements ASTNode {
public EnumValueNode valueType;
public String value;
public ValueNode(EnumValueNode valueType, String value) {
this.valueType = valueType;
this.value = value;
}
}

View File

@ -0,0 +1,30 @@
package ast.type.type;
public class BaseType implements ITypeNode {
private TypeEnum typeEnum;
public BaseType(TypeEnum typeEnum) {
this.typeEnum = typeEnum;
}
public TypeEnum getTypeEnum() {
return typeEnum;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BaseType other = (BaseType) obj;
if (typeEnum != other.typeEnum)
return false;
return true;
}
}

View File

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

View File

@ -0,0 +1,33 @@
package ast.type.type;
public class ReferenceType implements ITypeNode{
private String identifier;
public ReferenceType(String identifier) {
this.identifier = identifier;
}
public String getIdentifier() {
return identifier;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ReferenceType other = (ReferenceType) obj;
if (identifier == null) {
if (other.identifier != null)
return false;
} else if (!identifier.equals(other.identifier))
return false;
return true;
}
}

View File

@ -0,0 +1,9 @@
package ast.type.type;
public enum TypeEnum {
VOID,
INT,
CHAR,
BOOL;
}

View File

@ -10,7 +10,7 @@ public class ByteCodeGenerator implements ProgramVisitor {
public void visit(ProgramNode programNode) { public void visit(ProgramNode programNode) {
for (ClassNode classDeclarationNode : programNode.classes) { for (ClassNode classDeclarationNode : programNode.classes) {
ClassCodeGen classCodeGen = new ClassCodeGen(); ClassCodeGen classCodeGen = new ClassCodeGen();
classDeclarationNode.accept(classCodeGen); // classDeclarationNode.accept(classCodeGen);
} }
} }
} }

View File

@ -1,14 +1,13 @@
package bytecode; package bytecode;
import ast.ClassNode; import ast.ClassNode;
import ast.members.FieldNode; import ast.member.FieldNode;
import ast.members.MemberNode; import ast.member.MemberNode;
import ast.members.MethodNode; import ast.member.MethodNode;
import ast.type.BaseTypeNode; import ast.type.type.BaseType;
import bytecode.visitor.ClassVisitor; import bytecode.visitor.ClassVisitor;
import java.io.File; import java.io.File;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -25,8 +24,8 @@ public class ClassCodeGen implements ClassVisitor {
@Override @Override
public void visit(ClassNode classNode) { public void visit(ClassNode classNode) {
classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
classWriter.visit(Opcodes.V1_5, mapper.mapAccessTypeToOpcode(classNode.accessType), classNode.identifier, null, // classWriter.visit(Opcodes.V1_5, mapper.mapAccessTypeToOpcode(classNode.accessType), classNode.identifier, null,
"java/lang/Object", null); // "java/lang/Object", null);
for (MemberNode memberNode : classNode.members) { for (MemberNode memberNode : classNode.members) {
if (memberNode instanceof FieldNode) { if (memberNode instanceof FieldNode) {
@ -45,8 +44,8 @@ public class ClassCodeGen implements ClassVisitor {
@Override @Override
public void visit(FieldNode fieldNode) { public void visit(FieldNode fieldNode) {
if(fieldNode.type instanceof BaseTypeNode baseTypeNode){ if(fieldNode.type instanceof BaseType baseTypeNode){
classWriter.visitField(mapper.mapAccessTypeToOpcode(fieldNode.accessTypeNode), fieldNode.identifier, mapper.getTypeChar(baseTypeNode.enumType), null, null ); // classWriter.visitField(mapper.mapAccessTypeToOpcode(fieldNode.accessTypeNode), fieldNode.identifier, mapper.getTypeChar(baseTypeNode.enumType), null, null );
} }
classWriter.visitEnd(); classWriter.visitEnd();
} }

View File

@ -1,44 +1,41 @@
package bytecode; package bytecode;
import ast.parameters.ParameterNode;
import ast.type.*; import ast.type.*;
import org.objectweb.asm.Opcodes;
import ast.type.BaseTypeNode;
public class Mapper { public class Mapper {
public int mapAccessTypeToOpcode(AccessTypeNode type) { // public int mapAccessTypeToOpcode(AccessModifierNode type) {
switch (type.enumAccessTypeNode) { // switch (type.enumAccessTypeNode) {
case EnumAccessTypeNode.PUBLIC: // case EnumAccessTypeNode.PUBLIC:
return Opcodes.ACC_PUBLIC; // return Opcodes.ACC_PUBLIC;
case EnumAccessTypeNode.PRIVATE: // case EnumAccessTypeNode.PRIVATE:
return Opcodes.ACC_PRIVATE; // return Opcodes.ACC_PRIVATE;
} // }
return 0; // return 0;
} // }
public String generateMethodDescriptor(BaseTypeNode baseTypeNode, ParameterListNode parameterListNode) { // public String generateMethodDescriptor(BaseTypeNode baseTypeNode, ParameterListNode parameterListNode) {
String descriptor = "("; // String descriptor = "(";
for(ParameterNode parameterNode : parameterListNode.parameters) { // for(ParameterNode parameterNode : parameterListNode.parameters) {
descriptor += getTypeChar(EnumTypeNode.INT); // descriptor += getTypeChar(EnumTypeNode.INT);
} // }
descriptor += ")"; // descriptor += ")";
descriptor += getTypeChar(baseTypeNode.enumType); // descriptor += getTypeChar(baseTypeNode.enumType);
return descriptor; // return descriptor;
} // }
public String getTypeChar(EnumTypeNode enumTypeNode) { // public String getTypeChar(TypeEnum enumTypeNode) {
String typeChar = ""; // String typeChar = "";
switch (enumTypeNode) { // switch (enumTypeNode) {
case EnumTypeNode.INT: // case TypeEnum.INT:
typeChar = "I"; // typeChar = "I";
break; // break;
case EnumTypeNode.CHAR: // case TypeEnum.CHAR:
typeChar = "C"; // typeChar = "C";
break; // break;
case EnumTypeNode.BOOLEAN: // case TypeEnum.BOOLEAN:
typeChar = "Z"; // typeChar = "Z";
break; // break;
} // }
return typeChar; // return typeChar;
} // }
} }

View File

@ -1,13 +1,9 @@
package bytecode; package bytecode;
import ast.members.ConstructorNode; import ast.member.ConstructorNode;
import ast.members.MethodNode; import ast.member.MethodNode;
import ast.parameters.ParameterNode;
import ast.type.BaseTypeNode;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -31,12 +27,12 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
@Override @Override
public void visit(ConstructorNode constructorNode) { public void visit(ConstructorNode constructorNode) {
methodVisitor = // methodVisitor =
classWriter.visitMethod(mapper.mapAccessTypeToOpcode(constructorNode.visibility), // classWriter.visitMethod(mapper.mapAccessTypeToOpcode(constructorNode.visibility),
"<init>", // "<init>",
"()V", // "()V",
null, // null,
null); // null);
methodVisitor.visitCode(); methodVisitor.visitCode();
methodVisitor.visitVarInsn(ALOAD, 0); methodVisitor.visitVarInsn(ALOAD, 0);
methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
@ -47,52 +43,52 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
@Override @Override
public void visit(MethodNode methodNode) { public void visit(MethodNode methodNode) {
if (methodNode.type instanceof BaseTypeNode baseTypeNode) { // if (methodNode.type instanceof BaseTypeNode baseTypeNode) {
methodVisitor = classWriter.visitMethod(mapper.mapAccessTypeToOpcode(methodNode.visibility), // methodVisitor = classWriter.visitMethod(mapper.mapAccessTypeToOpcode(methodNode.visibility),
methodNode.identifier, // methodNode.identifier,
mapper.generateMethodDescriptor(baseTypeNode, methodNode.parameters), // mapper.generateMethodDescriptor(baseTypeNode, methodNode.parameters),
null, // null,
null); // null);
methodVisitor.visitCode(); methodVisitor.visitCode();
localVaribales.add("this"); localVaribales.add("this");
for (ParameterNode parameterNode : methodNode.parameters.parameters) { // for (ParameterNode parameterNode : methodNode.parameters.parameters) {
localVaribales.add(parameterNode.identifier); // localVaribales.add(parameterNode.identifier);
} // }
//test(); //test();
methodVisitor.visitMaxs(1, localVaribales.size()); methodVisitor.visitMaxs(1, localVaribales.size());
methodVisitor.visitEnd(); methodVisitor.visitEnd();
} // }
} }
public void test() { // public void test() {
Label start = new Label(); // Label start = new Label();
Label loop = new Label(); // Label loop = new Label();
Label end = new Label(); // Label end = new Label();
methodVisitor.visitLabel(start); // methodVisitor.visitLabel(start);
//methodVisitor.visitVarInsn(Opcodes.ICONST_M1, 99); // //methodVisitor.visitVarInsn(Opcodes.ICONST_M1, 99);
//methodVisitor.visitInsn(Opcodes.ICONST_5); // //methodVisitor.visitInsn(Opcodes.ICONST_5);
methodVisitor.visitLdcInsn(99); // methodVisitor.visitLdcInsn(99);
// methodVisitor.visitInsn(Opcodes.ICONST_0); // // methodVisitor.visitInsn(Opcodes.ICONST_0);
//methodVisitor.visitVarInsn(Opcodes.ILOAD, 2); // //methodVisitor.visitVarInsn(Opcodes.ILOAD, 2);
methodVisitor.visitVarInsn(Opcodes.ISTORE, 1); // methodVisitor.visitVarInsn(Opcodes.ISTORE, 1);
methodVisitor.visitLabel(loop); // methodVisitor.visitLabel(loop);
methodVisitor.visitVarInsn(Opcodes.ILOAD, 1); // methodVisitor.visitVarInsn(Opcodes.ILOAD, 1);
methodVisitor.visitInsn(Opcodes.ICONST_5); // methodVisitor.visitInsn(Opcodes.ICONST_5);
methodVisitor.visitJumpInsn(Opcodes.IF_ICMPGE, end); // methodVisitor.visitJumpInsn(Opcodes.IF_ICMPGE, end);
methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, // methodVisitor.visitFieldInsn(Opcodes.GETSTATIC,
"java/lang/System", "out", // "java/lang/System", "out",
"Ljava/io/PrintStream;"); // "Ljava/io/PrintStream;");
methodVisitor.visitLdcInsn("Bytecode"); // methodVisitor.visitLdcInsn("Bytecode");
methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, // methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
"java/io/PrintStream", "println", // "java/io/PrintStream", "println",
"(Ljava/lang/String;)V", false); // "(Ljava/lang/String;)V", false);
methodVisitor.visitIincInsn(1, 1); // methodVisitor.visitIincInsn(1, 1);
methodVisitor.visitJumpInsn(Opcodes.GOTO, loop); // methodVisitor.visitJumpInsn(Opcodes.GOTO, loop);
methodVisitor.visitLabel(end); // methodVisitor.visitLabel(end);
methodVisitor.visitVarInsn(Opcodes.ILOAD, 1); // methodVisitor.visitVarInsn(Opcodes.ILOAD, 1);
methodVisitor.visitInsn(Opcodes.IRETURN); // methodVisitor.visitInsn(Opcodes.IRETURN);
methodVisitor.visitEnd(); // methodVisitor.visitEnd();
} // }
} }

View File

@ -1,27 +1,35 @@
package parser.astBuilder; package parser.astBuilder;
import ast.*; import ast.*;
import ast.statements.BlockStatementNode; import ast.block.BlockNode;
import ast.expressions.AssignableExpressionNode; import ast.expression.*;
import ast.expressions.ExpressionNode; import ast.expression.binaryexpression.CalculationExpressionNode;
import ast.statements.ElseStatementNode; import ast.expression.binaryexpression.DotExpressionNode;
import ast.statements.IfElseStatementNode; import ast.expression.binaryexpression.DotSubstractionExpressionNode;
import ast.members.ConstructorNode; import ast.expression.binaryexpression.NonCalculationExpressionNode;
import ast.members.MemberNode; import ast.expression.unaryexpression.MemberAccessNode;
import ast.parameters.ParameterNode; import ast.expression.unaryexpression.NotExpressionNode;
import ast.statements.*; import ast.expression.unaryexpression.UnaryExpressionNode;
import ast.statements.IfStatementNode; import ast.member.*;
import ast.statementexpressions.AssignStatementExpressionNode; import ast.statement.ifstatement.ElseStatementNode;
import ast.statementexpressions.CrementExpressionStatementExpressionNode; import ast.statement.ifstatement.IfElseStatementNode;
import ast.statementexpressions.methodcallstatementnexpression.ChainedMethodNode; import ast.parameter.ParameterNode;
import ast.statementexpressions.methodcallstatementnexpression.MethodCallStatementExpressionNode; import ast.statement.*;
import ast.statementexpressions.methodcallstatementnexpression.TargetNode; import ast.statement.ifstatement.IfStatementNode;
import ast.statement.statementexpression.AssignStatementExpressionNode;
import ast.statement.statementexpression.AssignableExpressionNode;
import ast.statement.statementexpression.NewDeclarationStatementExpressionNode;
import ast.statement.statementexpression.crementExpression.CrementType;
import ast.statement.statementexpression.crementExpression.DecrementExpressionNode;
import ast.statement.statementexpression.crementExpression.IncrementExpressionNode;
import ast.statement.statementexpression.methodcallstatementnexpression.ChainedMethodNode;
import ast.statement.statementexpression.methodcallstatementnexpression.MethodCallStatementExpressionNode;
import ast.statement.statementexpression.methodcallstatementnexpression.TargetNode;
import ast.type.*; import ast.type.*;
import ast.type.type.*;
import org.antlr.v4.runtime.tree.TerminalNode;
import parser.generated.*; import parser.generated.*;
import java.util.ArrayList;
import java.util.List;
public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> { public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override @Override
public ASTNode visitProgram(SimpleJavaParser.ProgramContext ctx) { public ASTNode visitProgram(SimpleJavaParser.ProgramContext ctx) {
@ -44,16 +52,42 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override @Override
public ASTNode visitConstructorDeclaration(SimpleJavaParser.ConstructorDeclarationContext ctx) { public ASTNode visitConstructorDeclaration(SimpleJavaParser.ConstructorDeclarationContext ctx) {
ConstructorNode constructorNode = new ConstructorNode(ctx.AccessModifier().getText(), ctx.Identifier().getText(), (BlockStatementNode) visit(ctx.block())); ConstructorNode constructorNode = new ConstructorNode(ctx.AccessModifier().getText(), ctx.Identifier().getText(), (BlockNode) visit(ctx.block()));
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) { for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
constructorNode.addParameter((ParameterNode) visit(parameter)); constructorNode.addParameter((ParameterNode) visit(parameter));
} }
return constructorNode; return constructorNode;
} }
@Override
public ASTNode visitMethodDeclaration(SimpleJavaParser.MethodDeclarationContext ctx) {
if(ctx.MainMethodDeclaration() != null) {
return new MainMethodNode((BlockNode) visit(ctx.block()));
} else {
if(ctx.type() != null) {
MethodNode methodNode = new MethodNode(ctx.AccessModifier().getText(), createTypeNode(ctx.type().getText()), false, ctx.Identifier().getText(), (BlockNode) visit(ctx.block()));
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
methodNode.addParameter((ParameterNode) visit(parameter));
}
return methodNode;
} else {
MethodNode methodNode = new MethodNode(ctx.AccessModifier().getText(), null, true, ctx.Identifier().getText(), (BlockNode) visit(ctx.block()));
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
methodNode.addParameter((ParameterNode) visit(parameter));
}
return methodNode;
}
}
}
@Override
public ASTNode visitFieldDeclaration(SimpleJavaParser.FieldDeclarationContext ctx) {
return new FieldNode(new AccessModifierNode(ctx.AccessModifier().getText()), createTypeNode(ctx.type().getText()), ctx.Identifier().getText());
}
@Override @Override
public ASTNode visitParameter(SimpleJavaParser.ParameterContext ctx) { public ASTNode visitParameter(SimpleJavaParser.ParameterContext ctx) {
return new ParameterNode(new TypeNode(ctx.type().getText()), ctx.Identifier().getText()); return new ParameterNode(createTypeNode(ctx.type().getText()), ctx.Identifier().getText());
} }
@Override @Override
@ -62,8 +96,8 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
return visitReturnStatement(ctx.returnStatement()); return visitReturnStatement(ctx.returnStatement());
} else if(ctx.localVariableDeclaration() != null) { } else if(ctx.localVariableDeclaration() != null) {
return visitLocalVariableDeclaration(ctx.localVariableDeclaration()); return visitLocalVariableDeclaration(ctx.localVariableDeclaration());
} else if(ctx.blockStatement() != null) { } else if(ctx.block() != null) {
return visitBlockStatement(ctx.blockStatement()); return visitBlock(ctx.block());
} else if(ctx.whileStatement() != null) { } else if(ctx.whileStatement() != null) {
return visitWhileStatement(ctx.whileStatement()); return visitWhileStatement(ctx.whileStatement());
} else if(ctx.forStatement() != null) { } else if(ctx.forStatement() != null) {
@ -78,105 +112,58 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override @Override
public ASTNode visitReturnStatement(SimpleJavaParser.ReturnStatementContext ctx) { public ASTNode visitReturnStatement(SimpleJavaParser.ReturnStatementContext ctx) {
return new ReturnStatementNode((ExpressionNode) visit(ctx.expression())); return new ReturnStatementNode((IExpressionNode) visit(ctx.expression()));
} }
@Override @Override
public ASTNode visitLocalVariableDeclaration(SimpleJavaParser.LocalVariableDeclarationContext ctx) { public ASTNode visitLocalVariableDeclaration(SimpleJavaParser.LocalVariableDeclarationContext ctx) {
return new LocalVariableDeclarationNode(new TypeNode(ctx.type().getText()), ctx.Identifier().getText(), ctx.Assign().getText(), (ExpressionNode) visit(ctx.expression())); return new LocalVariableDeclarationNode(createTypeNode(ctx.type().getText()), ctx.Identifier().getText(), ctx.Assign().getText(), (IExpressionNode) visit(ctx.expression()));
} }
@Override @Override
public ASTNode visitBlockStatement(SimpleJavaParser.BlockStatementContext ctx) { public ASTNode visitBlock(SimpleJavaParser.BlockContext ctx) {
BlockStatementNode blockNode = new BlockStatementNode(); BlockNode blockNode = new BlockNode();
for(SimpleJavaParser.StatementContext statement : ctx.statement()) { for(SimpleJavaParser.StatementContext statement : ctx.statement()) {
blockNode.addStatement((StatementNode) visit(statement)); blockNode.addStatement((IStatementNode) visit(statement));
}
if(!blockNode.hasReturnStatement) {
blockNode.addStatement(new ReturnStatementNode(null));
} }
return blockNode; return blockNode;
} }
@Override @Override
public ASTNode visitWhileStatement(SimpleJavaParser.WhileStatementContext ctx) { public ASTNode visitWhileStatement(SimpleJavaParser.WhileStatementContext ctx) {
return new WhileStatementNode((ExpressionNode) visit(ctx.expression()), (BlockStatementNode) visit(ctx.blockStatement())); return new WhileStatementNode((IExpressionNode) visit(ctx.expression()), (BlockNode) visit(ctx.block()));
}
@Override
public ASTNode visitDoWhileStatement(SimpleJavaParser.DoWhileStatementContext ctx) {
ExpressionNode condition = (ExpressionNode) visit(ctx.expression());
BlockStatementNode doBlock = (BlockStatementNode) visit(ctx.blockStatement());
WhileStatementNode whileStatement = new WhileStatementNode(condition, doBlock);
BlockStatementNode resultBlock = new BlockStatementNode();
resultBlock.addStatement(doBlock);
resultBlock.addStatement(whileStatement);
return resultBlock;
} }
@Override @Override
public ASTNode visitForStatement(SimpleJavaParser.ForStatementContext ctx) { public ASTNode visitForStatement(SimpleJavaParser.ForStatementContext ctx) {
if(ctx.statementExpression(0) != null) {
List<StatementNode> statements = new ArrayList<>(); return new ForStatementNode((IExpressionNode) visit(ctx.statementExpression(0)), (IExpressionNode) visit(ctx.expression()), (IExpressionNode) visit(ctx.statementExpression(1)));
} else if(ctx.localVariableDeclaration() != null) {
//init return new ForStatementNode((IStatementNode) visit(ctx.localVariableDeclaration()), (IExpressionNode) visit(ctx.expression()), (IExpressionNode) visit(ctx.statementExpression(1)));
if(ctx.statementExpression(0) != null){
statements.add((StatementNode) visit(ctx.statementExpression(0)));
} else if (ctx.localVariableDeclaration() != null) {
statements.add((StatementNode) visit(ctx.localVariableDeclaration()));
} }
return null;
//condition
ExpressionNode condition = (ExpressionNode) visit(ctx.expression());
//ink
StatementNode increment = null;
if(ctx.statementExpression(1) != null){
increment = (StatementNode) visit(ctx.statementExpression(1));
}
BlockStatementNode forBlock = (BlockStatementNode) visit(ctx.blockStatement());
if(increment != null){
forBlock.addStatement((increment));
}
WhileStatementNode whileStatement = new WhileStatementNode(condition, forBlock);
statements.add(whileStatement);
BlockStatementNode resultBlock = new BlockStatementNode();
for(StatementNode statement : statements) {
resultBlock.addStatement(statement);
}
return resultBlock;
} }
@Override @Override
public ASTNode visitIfElseStatement(SimpleJavaParser.IfElseStatementContext ctx) { public ASTNode visitIfElseStatement(SimpleJavaParser.IfElseStatementContext ctx) {
IfElseStatementNode ifElseStatementNode = new IfElseStatementNode((IfStatementNode) visit(ctx.ifStatement()), IfElseStatementNode ifElseStatementNode = new IfElseStatementNode((IfStatementNode) visit(ctx.ifStatement()));
(ElseStatementNode) visit(ctx.elseStatement())); for(SimpleJavaParser.ElseStatementContext elseStatement : ctx.elseStatement()) {
ifElseStatementNode.addElseStatement((ElseStatementNode) visit(elseStatement));
for (SimpleJavaParser.ElseIfStatementContext elseIfStatement : ctx.elseIfStatement()){
ifElseStatementNode.addElseIfStatement(((IfStatementNode) visit(elseIfStatement)));
} }
return ifElseStatementNode; return ifElseStatementNode;
} }
@Override @Override
public ASTNode visitIfStatement(SimpleJavaParser.IfStatementContext ctx) { public ASTNode visitIfStatement(SimpleJavaParser.IfStatementContext ctx) {
return new IfStatementNode((ExpressionNode) visit(ctx.expression()), (BlockStatementNode) visit(ctx.blockStatement())); return new IfStatementNode((IExpressionNode) visit(ctx.expression()), (BlockNode) visit(ctx.block()));
}
@Override
public ASTNode visitElseIfStatement(SimpleJavaParser.ElseIfStatementContext ctx) {
return new IfStatementNode((ExpressionNode) visit(ctx.expression()), (BlockStatementNode) visit(ctx.blockStatement()));
} }
@Override @Override
public ASTNode visitElseStatement(SimpleJavaParser.ElseStatementContext ctx) { public ASTNode visitElseStatement(SimpleJavaParser.ElseStatementContext ctx) {
return new ElseStatementNode((BlockStatementNode) visit(ctx.blockStatement())); return new ElseStatementNode((BlockNode) visit(ctx.block()));
} }
@Override @Override
@ -195,16 +182,16 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override @Override
public ASTNode visitAssign(SimpleJavaParser.AssignContext ctx) { public ASTNode visitAssign(SimpleJavaParser.AssignContext ctx) {
return new AssignStatementExpressionNode((AssignableExpressionNode) visit(ctx.assignableExpression()), (ExpressionNode) visit(ctx.expression())); return new AssignStatementExpressionNode((AssignableExpressionNode) visit(ctx.assignableExpression()), (IExpressionNode) visit(ctx.expression()));
} }
@Override @Override
public ASTNode visitNewDeclaration(SimpleJavaParser.NewDeclarationContext ctx) { public ASTNode visitNewDeclaration(SimpleJavaParser.NewDeclarationContext ctx) {
CrementExpressionStatementExpressionNode crementExpressionStatementNode = new CrementExpressionStatementExpressionNode(ctx.Identifier().getText()); NewDeclarationStatementExpressionNode newDeclarationStatementExpressionNode = new NewDeclarationStatementExpressionNode(ctx.Identifier().getText());
for(SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) { for(SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) {
crementExpressionStatementNode.addExpression((ExpressionNode) visit(expression)); newDeclarationStatementExpressionNode.addExpression((IExpressionNode) visit(expression));
} }
return crementExpressionStatementNode; return newDeclarationStatementExpressionNode;
} }
@Override @Override
@ -214,22 +201,215 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
methodCallStatementExpressionNode.addChainedMethod((ChainedMethodNode) visit(chainedMethod)); methodCallStatementExpressionNode.addChainedMethod((ChainedMethodNode) visit(chainedMethod));
} }
for(SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) { for(SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) {
methodCallStatementExpressionNode.addExpression((ExpressionNode) visit(expression)); methodCallStatementExpressionNode.addExpression((IExpressionNode) visit(expression));
} }
return methodCallStatementExpressionNode; return methodCallStatementExpressionNode;
} }
@Override @Override
public ASTNode visitTarget(SimpleJavaParser.TargetContext ctx) { public ASTNode visitTarget(SimpleJavaParser.TargetContext ctx) {
if(ctx.This() != null) {
return new TargetNode(true);
} else if(ctx.memberAccess() != null) {
return new TargetNode((MemberAccessNode) visit(ctx.memberAccess()));
} else if(ctx.newDeclaration() != null) {
return new TargetNode((NewDeclarationStatementExpressionNode) visit(ctx.newDeclaration()));
} else if(ctx.Identifier() != null) {
return new TargetNode(ctx.Identifier().getText());
}
return null;
} }
@Override @Override
public ASTNode visitChainedMethod(SimpleJavaParser.ChainedMethodContext ctx) { public ASTNode visitChainedMethod(SimpleJavaParser.ChainedMethodContext ctx) {
ChainedMethodNode chainedMethodNode = new ChainedMethodNode(ctx.Identifier().getText()); ChainedMethodNode chainedMethodNode = new ChainedMethodNode(ctx.Identifier().getText());
for(SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) { for(SimpleJavaParser.ExpressionContext expression : ctx.argumentList().expression()) {
chainedMethodNode.addExpression((ExpressionNode) visit(expression)); chainedMethodNode.addExpression((IExpressionNode) visit(expression));
} }
return chainedMethodNode; return chainedMethodNode;
} }
@Override
public ASTNode visitCrementExpression(SimpleJavaParser.CrementExpressionContext ctx) {
if(ctx.incrementExpression() != null) {
return visitIncrementExpression(ctx.incrementExpression());
} else if(ctx.decrementExpression() != null) {
return visitDecrementExpression(ctx.decrementExpression());
}
return null;
}
@Override
public ASTNode visitIncrementExpression(SimpleJavaParser.IncrementExpressionContext ctx) {
if(ctx.prefixIncrementExpression() != null) {
return visitPrefixIncrementExpression(ctx.prefixIncrementExpression());
} else if(ctx.suffixIncrementExpression() != null) {
return visitSuffixIncrementExpression(ctx.suffixIncrementExpression());
}
return null;
}
@Override
public ASTNode visitPrefixIncrementExpression(SimpleJavaParser.PrefixIncrementExpressionContext ctx) {
return new IncrementExpressionNode(CrementType.PREFIX, (AssignableExpressionNode) visit(ctx.assignableExpression()));
}
@Override
public ASTNode visitSuffixIncrementExpression(SimpleJavaParser.SuffixIncrementExpressionContext ctx) {
return new IncrementExpressionNode(CrementType.SUFFIX, (AssignableExpressionNode) visit(ctx.assignableExpression()));
}
@Override
public ASTNode visitDecrementExpression(SimpleJavaParser.DecrementExpressionContext ctx) {
if(ctx.prefixDecrementExpression() != null) {
return visitPrefixDecrementExpression(ctx.prefixDecrementExpression());
} else if(ctx.suffixDecrementExpression() != null) {
return visitSuffixDecrementExpression(ctx.suffixDecrementExpression());
}
return null;
}
@Override
public ASTNode visitPrefixDecrementExpression(SimpleJavaParser.PrefixDecrementExpressionContext ctx) {
return new DecrementExpressionNode(CrementType.PREFIX, (AssignableExpressionNode) visit(ctx.assignableExpression()));
}
@Override
public ASTNode visitSuffixDecrementExpression(SimpleJavaParser.SuffixDecrementExpressionContext ctx) {
return new DecrementExpressionNode(CrementType.SUFFIX, (AssignableExpressionNode) visit(ctx.assignableExpression()));
}
@Override
public ASTNode visitExpression(SimpleJavaParser.ExpressionContext ctx) {
if(ctx.unaryExpression() != null) {
return visit(ctx.unaryExpression());
} else if(ctx.binaryExpression() != null) {
return visit(ctx.binaryExpression());
}
return null;
}
@Override
public ASTNode visitUnaryExpression(SimpleJavaParser.UnaryExpressionContext ctx) {
if(ctx.This() != null) {
return new UnaryExpressionNode(ctx.This().getText());
} else if(ctx.Identifier() != null) {
return new UnaryExpressionNode(ctx.Identifier().getText());
} else if(ctx.memberAccess() != null) {
return new UnaryExpressionNode((MemberAccessNode) visitMemberAccess(ctx.memberAccess()));
} else if(ctx.value() != null) {
return new UnaryExpressionNode((ValueNode) visitValue(ctx.value()));
} else if(ctx.notExpression() != null) {
return new UnaryExpressionNode((NotExpressionNode) visitNotExpression(ctx.notExpression()));
} else if(ctx.statementExpression() != null) {
return new UnaryExpressionNode((IStatementNode) visitStatementExpression(ctx.statementExpression()));
} else if(ctx.expression() != null) {
return new UnaryExpressionNode((IExpressionNode) visitExpression(ctx.expression()));
}
return null;
}
@Override
public ASTNode visitMemberAccess(SimpleJavaParser.MemberAccessContext ctx) {
MemberAccessNode memberAccessNode;
if(ctx.This() != null) {
memberAccessNode = new MemberAccessNode(true);
} else {
memberAccessNode = new MemberAccessNode(false);
}
for (TerminalNode identifierNode : ctx.Identifier()) {
memberAccessNode.addIdentifier(identifierNode.getText());
}
return memberAccessNode;
}
@Override
public ASTNode visitValue(SimpleJavaParser.ValueContext ctx) {
if(ctx.IntValue() != null) {
return new ValueNode(EnumValueNode.INT_VALUE, ctx.IntValue().getText());
} else if(ctx.BooleanValue() != null) {
return new ValueNode(EnumValueNode.BOOLEAN_VALUE, ctx.BooleanValue().getText());
} else if(ctx.CharValue() != null) {
return new ValueNode(EnumValueNode.CHAR_VALUE, ctx.CharValue().getText());
} else if(ctx.NullValue() != null) {
return new ValueNode(EnumValueNode.NULL_VALUE, ctx.NullValue().getText());
}
return null;
}
@Override
public ASTNode visitNotExpression(SimpleJavaParser.NotExpressionContext ctx) {
return new NotExpressionNode((IExpressionNode) visitExpression(ctx.expression()));
}
@Override
public ASTNode visitBinaryExpression(SimpleJavaParser.BinaryExpressionContext ctx) {
if(ctx.calculationExpression() != null) {
return visit(ctx.calculationExpression());
} else if(ctx.nonCalculationExpression() != null) {
return visit(ctx.nonCalculationExpression());
}
return null;
}
@Override
public ASTNode visitCalculationExpression(SimpleJavaParser.CalculationExpressionContext ctx) {
if(ctx.calculationExpression() != null) {
return new CalculationExpressionNode((CalculationExpressionNode) visit(ctx.calculationExpression()), ctx.LineOperator().getText(), (DotExpressionNode) visit(ctx.dotExpression()));
} else if(ctx.dotExpression() != null) {
return new CalculationExpressionNode((DotExpressionNode) visit(ctx.dotExpression()));
}
return null;
}
@Override
public ASTNode visitDotExpression(SimpleJavaParser.DotExpressionContext ctx) {
if(ctx.dotExpression() != null) {
return new DotExpressionNode((DotExpressionNode) visit(ctx.dotExpression()), ctx.DotOperator().getText(), (DotSubstractionExpressionNode) visit(ctx.dotSubtractionExpression()));
} else if(ctx.dotSubtractionExpression() != null) {
return new DotExpressionNode((DotSubstractionExpressionNode) visit(ctx.dotSubtractionExpression()));
}
return null;
}
@Override
public ASTNode visitDotSubtractionExpression(SimpleJavaParser.DotSubtractionExpressionContext ctx) {
if(ctx.IntValue() != null) {
return new DotSubstractionExpressionNode(new ValueNode(EnumValueNode.INT_VALUE, ctx.IntValue().getText()));
} else if(ctx.Identifier() != null) {
return new DotSubstractionExpressionNode(ctx.Identifier().getText());
} else if(ctx.memberAccess() != null) {
return new DotSubstractionExpressionNode((MemberAccessNode) visit(ctx.memberAccess()));
} else if(ctx.methodCall() != null && ctx.calculationExpression() != null) {
return new DotSubstractionExpressionNode((MethodCallStatementExpressionNode) visit(ctx.methodCall()), (CalculationExpressionNode) visit(ctx.calculationExpression()));
}
return null;
}
@Override
public ASTNode visitNonCalculationExpression(SimpleJavaParser.NonCalculationExpressionContext ctx) {
return new NonCalculationExpressionNode((UnaryExpressionNode) visit(ctx.unaryExpression()), ctx.nonCalculationOperator().getText(), (IExpressionNode) visit(ctx.expression()));
}
@Override
public ASTNode visitAssignableExpression(SimpleJavaParser.AssignableExpressionContext ctx) {
if(ctx.Identifier() != null) {
return new AssignableExpressionNode(ctx.Identifier().getText());
} else if(ctx.memberAccess() != null) {
return new AssignableExpressionNode((MemberAccessNode) visit(ctx.memberAccess()));
}
return null;
}
public ITypeNode createTypeNode(String identifier){
return switch (identifier) {
case "int" -> new BaseType(TypeEnum.INT);
case "boolean" -> new BaseType(TypeEnum.BOOL);
case "char" -> new BaseType(TypeEnum.CHAR);
case "void" -> new BaseType(TypeEnum.VOID);
default -> new ReferenceType(identifier);
};
}
} }

File diff suppressed because one or more lines are too long

View File

@ -35,20 +35,19 @@ Comma=34
Class=35 Class=35
This=36 This=36
While=37 While=37
Do=38 If=38
If=39 Else=39
Else=40 For=40
For=41 Return=41
Return=42 New=42
New=43 CharValue=43
CharValue=44 IntValue=44
IntValue=45 BooleanValue=45
BooleanValue=46 NullValue=46
NullValue=47 Identifier=47
Identifier=48 WS=48
WS=49 InlineComment=49
InlineComment=50 MultilineComment=50
MultilineComment=51
'++'=1 '++'=1
'--'=2 '--'=2
'void'=3 'void'=3
@ -81,10 +80,9 @@ MultilineComment=51
'class'=35 'class'=35
'this'=36 'this'=36
'while'=37 'while'=37
'do'=38 'if'=38
'if'=39 'else'=39
'else'=40 'for'=40
'for'=41 'return'=41
'return'=42 'new'=42
'new'=43 'null'=46
'null'=47

View File

@ -1,4 +1,4 @@
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1 // Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated; package parser.generated;
import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.ParserRuleContext;
@ -137,13 +137,13 @@ public class SimpleJavaBaseListener implements SimpleJavaListener {
* *
* <p>The default implementation does nothing.</p> * <p>The default implementation does nothing.</p>
*/ */
@Override public void enterBlockStatement(SimpleJavaParser.BlockStatementContext ctx) { } @Override public void enterBlock(SimpleJavaParser.BlockContext ctx) { }
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* <p>The default implementation does nothing.</p> * <p>The default implementation does nothing.</p>
*/ */
@Override public void exitBlockStatement(SimpleJavaParser.BlockStatementContext ctx) { } @Override public void exitBlock(SimpleJavaParser.BlockContext ctx) { }
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
@ -180,18 +180,6 @@ public class SimpleJavaBaseListener implements SimpleJavaListener {
* <p>The default implementation does nothing.</p> * <p>The default implementation does nothing.</p>
*/ */
@Override public void exitWhileStatement(SimpleJavaParser.WhileStatementContext ctx) { } @Override public void exitWhileStatement(SimpleJavaParser.WhileStatementContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDoWhileStatement(SimpleJavaParser.DoWhileStatementContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDoWhileStatement(SimpleJavaParser.DoWhileStatementContext ctx) { }
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
@ -228,18 +216,6 @@ public class SimpleJavaBaseListener implements SimpleJavaListener {
* <p>The default implementation does nothing.</p> * <p>The default implementation does nothing.</p>
*/ */
@Override public void exitIfStatement(SimpleJavaParser.IfStatementContext ctx) { } @Override public void exitIfStatement(SimpleJavaParser.IfStatementContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterElseIfStatement(SimpleJavaParser.ElseIfStatementContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitElseIfStatement(SimpleJavaParser.ElseIfStatementContext ctx) { }
/** /**
* {@inheritDoc} * {@inheritDoc}
* *

View File

@ -1,4 +1,4 @@
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1 // Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated; package parser.generated;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
@ -88,7 +88,7 @@ public class SimpleJavaBaseVisitor<T> extends AbstractParseTreeVisitor<T> implem
* <p>The default implementation returns the result of calling * <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p> * {@link #visitChildren} on {@code ctx}.</p>
*/ */
@Override public T visitBlockStatement(SimpleJavaParser.BlockStatementContext ctx) { return visitChildren(ctx); } @Override public T visitBlock(SimpleJavaParser.BlockContext ctx) { return visitChildren(ctx); }
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
@ -110,13 +110,6 @@ public class SimpleJavaBaseVisitor<T> extends AbstractParseTreeVisitor<T> implem
* {@link #visitChildren} on {@code ctx}.</p> * {@link #visitChildren} on {@code ctx}.</p>
*/ */
@Override public T visitWhileStatement(SimpleJavaParser.WhileStatementContext ctx) { return visitChildren(ctx); } @Override public T visitWhileStatement(SimpleJavaParser.WhileStatementContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDoWhileStatement(SimpleJavaParser.DoWhileStatementContext ctx) { return visitChildren(ctx); }
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
@ -138,13 +131,6 @@ public class SimpleJavaBaseVisitor<T> extends AbstractParseTreeVisitor<T> implem
* {@link #visitChildren} on {@code ctx}.</p> * {@link #visitChildren} on {@code ctx}.</p>
*/ */
@Override public T visitIfStatement(SimpleJavaParser.IfStatementContext ctx) { return visitChildren(ctx); } @Override public T visitIfStatement(SimpleJavaParser.IfStatementContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitElseIfStatement(SimpleJavaParser.ElseIfStatementContext ctx) { return visitChildren(ctx); }
/** /**
* {@inheritDoc} * {@inheritDoc}
* *

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1 // Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated; package parser.generated;
import org.antlr.v4.runtime.Lexer; import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream; 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, Less=20, GreaterEqual=21, LessEqual=22, Equal=23, NotEqual=24, Not=25,
And=26, Or=27, Dot=28, OpenRoundBracket=29, ClosedRoundBracket=30, OpenCurlyBracket=31, And=26, Or=27, Dot=28, OpenRoundBracket=29, ClosedRoundBracket=30, OpenCurlyBracket=31,
ClosedCurlyBracket=32, Semicolon=33, Comma=34, Class=35, This=36, While=37, ClosedCurlyBracket=32, Semicolon=33, Comma=34, Class=35, This=36, While=37,
Do=38, If=39, Else=40, For=41, Return=42, New=43, CharValue=44, IntValue=45, If=38, Else=39, For=40, Return=41, New=42, CharValue=43, IntValue=44,
BooleanValue=46, NullValue=47, Identifier=48, WS=49, InlineComment=50, BooleanValue=45, NullValue=46, Identifier=47, WS=48, InlineComment=49,
MultilineComment=51; MultilineComment=50;
public static String[] channelNames = { public static String[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN" "DEFAULT_TOKEN_CHANNEL", "HIDDEN"
}; };
@ -42,9 +42,9 @@ public class SimpleJavaLexer extends Lexer {
"GreaterEqual", "LessEqual", "Equal", "NotEqual", "Not", "And", "Or", "GreaterEqual", "LessEqual", "Equal", "NotEqual", "Not", "And", "Or",
"Dot", "OpenRoundBracket", "ClosedRoundBracket", "OpenCurlyBracket", "Dot", "OpenRoundBracket", "ClosedRoundBracket", "OpenCurlyBracket",
"ClosedCurlyBracket", "Semicolon", "Comma", "Class", "This", "While", "ClosedCurlyBracket", "Semicolon", "Comma", "Class", "This", "While",
"Do", "If", "Else", "For", "Return", "New", "CharValue", "IntValue", "If", "Else", "For", "Return", "New", "CharValue", "IntValue", "BooleanValue",
"BooleanValue", "NullValue", "Alphabetic", "Numeric", "ValidIdentSymbols", "NullValue", "Alphabetic", "Numeric", "ValidIdentSymbols", "Identifier",
"Identifier", "WS", "InlineComment", "MultilineComment" "WS", "InlineComment", "MultilineComment"
}; };
} }
public static final String[] ruleNames = makeRuleNames(); public static final String[] ruleNames = makeRuleNames();
@ -55,8 +55,8 @@ public class SimpleJavaLexer extends Lexer {
"'public static void main(String[] args)'", null, null, null, null, "'='", "'public static void main(String[] args)'", null, null, null, null, "'='",
"'+'", "'-'", "'*'", "'%'", "'/'", "'>'", "'<'", "'>='", "'<='", "'=='", "'+'", "'-'", "'*'", "'%'", "'/'", "'>'", "'<'", "'>='", "'<='", "'=='",
"'!='", "'!'", "'&&'", "'||'", "'.'", "'('", "')'", "'{'", "'}'", "';'", "'!='", "'!'", "'&&'", "'||'", "'.'", "'('", "')'", "'{'", "'}'", "';'",
"','", "'class'", "'this'", "'while'", "'do'", "'if'", "'else'", "'for'", "','", "'class'", "'this'", "'while'", "'if'", "'else'", "'for'", "'return'",
"'return'", "'new'", null, null, null, "'null'" "'new'", null, null, null, "'null'"
}; };
} }
private static final String[] _LITERAL_NAMES = makeLiteralNames(); private static final String[] _LITERAL_NAMES = makeLiteralNames();
@ -68,9 +68,8 @@ public class SimpleJavaLexer extends Lexer {
"Greater", "Less", "GreaterEqual", "LessEqual", "Equal", "NotEqual", "Greater", "Less", "GreaterEqual", "LessEqual", "Equal", "NotEqual",
"Not", "And", "Or", "Dot", "OpenRoundBracket", "ClosedRoundBracket", "Not", "And", "Or", "Dot", "OpenRoundBracket", "ClosedRoundBracket",
"OpenCurlyBracket", "ClosedCurlyBracket", "Semicolon", "Comma", "Class", "OpenCurlyBracket", "ClosedCurlyBracket", "Semicolon", "Comma", "Class",
"This", "While", "Do", "If", "Else", "For", "Return", "New", "CharValue", "This", "While", "If", "Else", "For", "Return", "New", "CharValue", "IntValue",
"IntValue", "BooleanValue", "NullValue", "Identifier", "WS", "InlineComment", "BooleanValue", "NullValue", "Identifier", "WS", "InlineComment", "MultilineComment"
"MultilineComment"
}; };
} }
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
@ -132,7 +131,7 @@ public class SimpleJavaLexer extends Lexer {
public ATN getATN() { return _ATN; } public ATN getATN() { return _ATN; }
public static final String _serializedATN = public static final String _serializedATN =
"\u0004\u00003\u019d\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+ "\u0004\u00002\u0198\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+
"\u0007\u0001\u0002\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004"+ "\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\u0004\u0002\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007"+
"\u0007\u0007\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002\u000b"+ "\u0007\u0007\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002\u000b"+
@ -146,246 +145,244 @@ public class SimpleJavaLexer extends Lexer {
"!\u0002\"\u0007\"\u0002#\u0007#\u0002$\u0007$\u0002%\u0007%\u0002&\u0007"+ "!\u0002\"\u0007\"\u0002#\u0007#\u0002$\u0007$\u0002%\u0007%\u0002&\u0007"+
"&\u0002\'\u0007\'\u0002(\u0007(\u0002)\u0007)\u0002*\u0007*\u0002+\u0007"+ "&\u0002\'\u0007\'\u0002(\u0007(\u0002)\u0007)\u0002*\u0007*\u0002+\u0007"+
"+\u0002,\u0007,\u0002-\u0007-\u0002.\u0007.\u0002/\u0007/\u00020\u0007"+ "+\u0002,\u0007,\u0002-\u0007-\u0002.\u0007.\u0002/\u0007/\u00020\u0007"+
"0\u00021\u00071\u00022\u00072\u00023\u00073\u00024\u00074\u00025\u0007"+ "0\u00021\u00071\u00022\u00072\u00023\u00073\u00024\u00074\u0001\u0000"+
"5\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001\u0001\u0001"+ "\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0002"+
"\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0003"+ "\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0003\u0001\u0003"+
"\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003"+ "\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\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0005"+
"\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0006\u0001\u0006"+ "\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"+
"\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\u00b2\b\u0006\u0001\u0007\u0001\u0007"+ "\u0001\u0006\u0003\u0006\u00b0\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\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\u00de\b\b\u0001\t\u0001\t"+ "\u0001\b\u0001\b\u0001\b\u0003\b\u00dc\b\b\u0001\t\u0001\t\u0003\t\u00e0"+
"\u0003\t\u00e2\b\t\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0003"+ "\b\t\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0001\n\u0003\n\u00e8\b\n"+
"\n\u00ea\b\n\u0001\u000b\u0001\u000b\u0003\u000b\u00ee\b\u000b\u0001\f"+ "\u0001\u000b\u0001\u000b\u0003\u000b\u00ec\b\u000b\u0001\f\u0001\f\u0001"+
"\u0001\f\u0001\r\u0001\r\u0001\u000e\u0001\u000e\u0001\u000f\u0001\u000f"+ "\r\u0001\r\u0001\u000e\u0001\u000e\u0001\u000f\u0001\u000f\u0001\u0010"+
"\u0001\u0010\u0001\u0010\u0001\u0011\u0001\u0011\u0001\u0012\u0001\u0012"+ "\u0001\u0010\u0001\u0011\u0001\u0011\u0001\u0012\u0001\u0012\u0001\u0013"+
"\u0001\u0013\u0001\u0013\u0001\u0014\u0001\u0014\u0001\u0014\u0001\u0015"+ "\u0001\u0013\u0001\u0014\u0001\u0014\u0001\u0014\u0001\u0015\u0001\u0015"+
"\u0001\u0015\u0001\u0015\u0001\u0016\u0001\u0016\u0001\u0016\u0001\u0017"+ "\u0001\u0015\u0001\u0016\u0001\u0016\u0001\u0016\u0001\u0017\u0001\u0017"+
"\u0001\u0017\u0001\u0017\u0001\u0018\u0001\u0018\u0001\u0019\u0001\u0019"+ "\u0001\u0017\u0001\u0018\u0001\u0018\u0001\u0019\u0001\u0019\u0001\u0019"+
"\u0001\u0019\u0001\u001a\u0001\u001a\u0001\u001a\u0001\u001b\u0001\u001b"+ "\u0001\u001a\u0001\u001a\u0001\u001a\u0001\u001b\u0001\u001b\u0001\u001c"+
"\u0001\u001c\u0001\u001c\u0001\u001d\u0001\u001d\u0001\u001e\u0001\u001e"+ "\u0001\u001c\u0001\u001d\u0001\u001d\u0001\u001e\u0001\u001e\u0001\u001f"+
"\u0001\u001f\u0001\u001f\u0001 \u0001 \u0001!\u0001!\u0001\"\u0001\"\u0001"+ "\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)\u0001)\u0001)\u0001)\u0001*\u0001*\u0001"+ "(\u0001(\u0001(\u0001)\u0001)\u0001)\u0001)\u0001*\u0001*\u0005*\u014a"+
"*\u0001*\u0001+\u0001+\u0005+\u014f\b+\n+\f+\u0152\t+\u0001+\u0001+\u0001"+ "\b*\n*\f*\u014d\t*\u0001*\u0001*\u0001+\u0003+\u0152\b+\u0001+\u0004+"+
",\u0003,\u0157\b,\u0001,\u0004,\u015a\b,\u000b,\f,\u015b\u0001-\u0001"+ "\u0155\b+\u000b+\f+\u0156\u0001,\u0001,\u0001,\u0001,\u0001,\u0001,\u0001"+
"-\u0001-\u0001-\u0001-\u0001-\u0001-\u0001-\u0001-\u0003-\u0167\b-\u0001"+ ",\u0001,\u0001,\u0003,\u0162\b,\u0001-\u0001-\u0001-\u0001-\u0001-\u0001"+
".\u0001.\u0001.\u0001.\u0001.\u0001/\u0001/\u00010\u00010\u00011\u0001"+ ".\u0001.\u0001/\u0001/\u00010\u00010\u00010\u00030\u0170\b0\u00011\u0001"+
"1\u00011\u00031\u0175\b1\u00012\u00012\u00052\u0179\b2\n2\f2\u017c\t2"+ "1\u00051\u0174\b1\n1\f1\u0177\t1\u00012\u00042\u017a\b2\u000b2\f2\u017b"+
"\u00013\u00043\u017f\b3\u000b3\f3\u0180\u00013\u00013\u00014\u00014\u0001"+ "\u00012\u00012\u00013\u00013\u00013\u00013\u00053\u0184\b3\n3\f3\u0187"+
"4\u00014\u00054\u0189\b4\n4\f4\u018c\t4\u00014\u00014\u00015\u00015\u0001"+ "\t3\u00013\u00013\u00014\u00014\u00014\u00014\u00054\u018f\b4\n4\f4\u0192"+
"5\u00015\u00055\u0194\b5\n5\f5\u0197\t5\u00015\u00015\u00015\u00015\u0001"+ "\t4\u00014\u00014\u00014\u00014\u00014\u0001\u0190\u00005\u0001\u0001"+
"5\u0001\u0195\u00006\u0001\u0001\u0003\u0002\u0005\u0003\u0007\u0004\t"+ "\u0003\u0002\u0005\u0003\u0007\u0004\t\u0005\u000b\u0006\r\u0007\u000f"+
"\u0005\u000b\u0006\r\u0007\u000f\b\u0011\t\u0013\n\u0015\u000b\u0017\f"+ "\b\u0011\t\u0013\n\u0015\u000b\u0017\f\u0019\r\u001b\u000e\u001d\u000f"+
"\u0019\r\u001b\u000e\u001d\u000f\u001f\u0010!\u0011#\u0012%\u0013\'\u0014"+ "\u001f\u0010!\u0011#\u0012%\u0013\'\u0014)\u0015+\u0016-\u0017/\u0018"+
")\u0015+\u0016-\u0017/\u00181\u00193\u001a5\u001b7\u001c9\u001d;\u001e"+ "1\u00193\u001a5\u001b7\u001c9\u001d;\u001e=\u001f? A!C\"E#G$I%K&M\'O("+
"=\u001f? A!C\"E#G$I%K&M\'O(Q)S*U+W,Y-[.]/_\u0000a\u0000c\u0000e0g1i2k"+ "Q)S*U+W,Y-[.]\u0000_\u0000a\u0000c/e0g1i2\u0001\u0000\u0005\u0002\u0000"+
"3\u0001\u0000\u0005\u0002\u0000\n\n\r\r\u0002\u0000AZaz\u0001\u000009"+ "\n\n\r\r\u0002\u0000AZaz\u0001\u000009\u0002\u0000$$__\u0003\u0000\t\n"+
"\u0002\u0000$$__\u0003\u0000\t\n\r\r \u01af\u0000\u0001\u0001\u0000\u0000"+ "\r\r \u01aa\u0000\u0001\u0001\u0000\u0000\u0000\u0000\u0003\u0001\u0000"+
"\u0000\u0000\u0003\u0001\u0000\u0000\u0000\u0000\u0005\u0001\u0000\u0000"+ "\u0000\u0000\u0000\u0005\u0001\u0000\u0000\u0000\u0000\u0007\u0001\u0000"+
"\u0000\u0000\u0007\u0001\u0000\u0000\u0000\u0000\t\u0001\u0000\u0000\u0000"+ "\u0000\u0000\u0000\t\u0001\u0000\u0000\u0000\u0000\u000b\u0001\u0000\u0000"+
"\u0000\u000b\u0001\u0000\u0000\u0000\u0000\r\u0001\u0000\u0000\u0000\u0000"+ "\u0000\u0000\r\u0001\u0000\u0000\u0000\u0000\u000f\u0001\u0000\u0000\u0000"+
"\u000f\u0001\u0000\u0000\u0000\u0000\u0011\u0001\u0000\u0000\u0000\u0000"+ "\u0000\u0011\u0001\u0000\u0000\u0000\u0000\u0013\u0001\u0000\u0000\u0000"+
"\u0013\u0001\u0000\u0000\u0000\u0000\u0015\u0001\u0000\u0000\u0000\u0000"+ "\u0000\u0015\u0001\u0000\u0000\u0000\u0000\u0017\u0001\u0000\u0000\u0000"+
"\u0017\u0001\u0000\u0000\u0000\u0000\u0019\u0001\u0000\u0000\u0000\u0000"+ "\u0000\u0019\u0001\u0000\u0000\u0000\u0000\u001b\u0001\u0000\u0000\u0000"+
"\u001b\u0001\u0000\u0000\u0000\u0000\u001d\u0001\u0000\u0000\u0000\u0000"+ "\u0000\u001d\u0001\u0000\u0000\u0000\u0000\u001f\u0001\u0000\u0000\u0000"+
"\u001f\u0001\u0000\u0000\u0000\u0000!\u0001\u0000\u0000\u0000\u0000#\u0001"+ "\u0000!\u0001\u0000\u0000\u0000\u0000#\u0001\u0000\u0000\u0000\u0000%"+
"\u0000\u0000\u0000\u0000%\u0001\u0000\u0000\u0000\u0000\'\u0001\u0000"+ "\u0001\u0000\u0000\u0000\u0000\'\u0001\u0000\u0000\u0000\u0000)\u0001"+
"\u0000\u0000\u0000)\u0001\u0000\u0000\u0000\u0000+\u0001\u0000\u0000\u0000"+ "\u0000\u0000\u0000\u0000+\u0001\u0000\u0000\u0000\u0000-\u0001\u0000\u0000"+
"\u0000-\u0001\u0000\u0000\u0000\u0000/\u0001\u0000\u0000\u0000\u00001"+ "\u0000\u0000/\u0001\u0000\u0000\u0000\u00001\u0001\u0000\u0000\u0000\u0000"+
"\u0001\u0000\u0000\u0000\u00003\u0001\u0000\u0000\u0000\u00005\u0001\u0000"+ "3\u0001\u0000\u0000\u0000\u00005\u0001\u0000\u0000\u0000\u00007\u0001"+
"\u0000\u0000\u00007\u0001\u0000\u0000\u0000\u00009\u0001\u0000\u0000\u0000"+ "\u0000\u0000\u0000\u00009\u0001\u0000\u0000\u0000\u0000;\u0001\u0000\u0000"+
"\u0000;\u0001\u0000\u0000\u0000\u0000=\u0001\u0000\u0000\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"+ "A\u0001\u0000\u0000\u0000\u0000C\u0001\u0000\u0000\u0000\u0000E\u0001"+
"\u0000\u0000\u0000E\u0001\u0000\u0000\u0000\u0000G\u0001\u0000\u0000\u0000"+ "\u0000\u0000\u0000\u0000G\u0001\u0000\u0000\u0000\u0000I\u0001\u0000\u0000"+
"\u0000I\u0001\u0000\u0000\u0000\u0000K\u0001\u0000\u0000\u0000\u0000M"+ "\u0000\u0000K\u0001\u0000\u0000\u0000\u0000M\u0001\u0000\u0000\u0000\u0000"+
"\u0001\u0000\u0000\u0000\u0000O\u0001\u0000\u0000\u0000\u0000Q\u0001\u0000"+ "O\u0001\u0000\u0000\u0000\u0000Q\u0001\u0000\u0000\u0000\u0000S\u0001"+
"\u0000\u0000\u0000S\u0001\u0000\u0000\u0000\u0000U\u0001\u0000\u0000\u0000"+ "\u0000\u0000\u0000\u0000U\u0001\u0000\u0000\u0000\u0000W\u0001\u0000\u0000"+
"\u0000W\u0001\u0000\u0000\u0000\u0000Y\u0001\u0000\u0000\u0000\u0000["+ "\u0000\u0000Y\u0001\u0000\u0000\u0000\u0000[\u0001\u0000\u0000\u0000\u0000"+
"\u0001\u0000\u0000\u0000\u0000]\u0001\u0000\u0000\u0000\u0000e\u0001\u0000"+ "c\u0001\u0000\u0000\u0000\u0000e\u0001\u0000\u0000\u0000\u0000g\u0001"+
"\u0000\u0000\u0000g\u0001\u0000\u0000\u0000\u0000i\u0001\u0000\u0000\u0000"+ "\u0000\u0000\u0000\u0000i\u0001\u0000\u0000\u0000\u0001k\u0001\u0000\u0000"+
"\u0000k\u0001\u0000\u0000\u0000\u0001m\u0001\u0000\u0000\u0000\u0003p"+ "\u0000\u0003n\u0001\u0000\u0000\u0000\u0005q\u0001\u0000\u0000\u0000\u0007"+
"\u0001\u0000\u0000\u0000\u0005s\u0001\u0000\u0000\u0000\u0007x\u0001\u0000"+ "v\u0001\u0000\u0000\u0000\t~\u0001\u0000\u0000\u0000\u000b\u0083\u0001"+
"\u0000\u0000\t\u0080\u0001\u0000\u0000\u0000\u000b\u0085\u0001\u0000\u0000"+ "\u0000\u0000\u0000\r\u00af\u0001\u0000\u0000\u0000\u000f\u00b1\u0001\u0000"+
"\u0000\r\u00b1\u0001\u0000\u0000\u0000\u000f\u00b3\u0001\u0000\u0000\u0000"+ "\u0000\u0000\u0011\u00db\u0001\u0000\u0000\u0000\u0013\u00df\u0001\u0000"+
"\u0011\u00dd\u0001\u0000\u0000\u0000\u0013\u00e1\u0001\u0000\u0000\u0000"+ "\u0000\u0000\u0015\u00e7\u0001\u0000\u0000\u0000\u0017\u00eb\u0001\u0000"+
"\u0015\u00e9\u0001\u0000\u0000\u0000\u0017\u00ed\u0001\u0000\u0000\u0000"+ "\u0000\u0000\u0019\u00ed\u0001\u0000\u0000\u0000\u001b\u00ef\u0001\u0000"+
"\u0019\u00ef\u0001\u0000\u0000\u0000\u001b\u00f1\u0001\u0000\u0000\u0000"+ "\u0000\u0000\u001d\u00f1\u0001\u0000\u0000\u0000\u001f\u00f3\u0001\u0000"+
"\u001d\u00f3\u0001\u0000\u0000\u0000\u001f\u00f5\u0001\u0000\u0000\u0000"+ "\u0000\u0000!\u00f5\u0001\u0000\u0000\u0000#\u00f7\u0001\u0000\u0000\u0000"+
"!\u00f7\u0001\u0000\u0000\u0000#\u00f9\u0001\u0000\u0000\u0000%\u00fb"+ "%\u00f9\u0001\u0000\u0000\u0000\'\u00fb\u0001\u0000\u0000\u0000)\u00fd"+
"\u0001\u0000\u0000\u0000\'\u00fd\u0001\u0000\u0000\u0000)\u00ff\u0001"+ "\u0001\u0000\u0000\u0000+\u0100\u0001\u0000\u0000\u0000-\u0103\u0001\u0000"+
"\u0000\u0000\u0000+\u0102\u0001\u0000\u0000\u0000-\u0105\u0001\u0000\u0000"+ "\u0000\u0000/\u0106\u0001\u0000\u0000\u00001\u0109\u0001\u0000\u0000\u0000"+
"\u0000/\u0108\u0001\u0000\u0000\u00001\u010b\u0001\u0000\u0000\u00003"+ "3\u010b\u0001\u0000\u0000\u00005\u010e\u0001\u0000\u0000\u00007\u0111"+
"\u010d\u0001\u0000\u0000\u00005\u0110\u0001\u0000\u0000\u00007\u0113\u0001"+ "\u0001\u0000\u0000\u00009\u0113\u0001\u0000\u0000\u0000;\u0115\u0001\u0000"+
"\u0000\u0000\u00009\u0115\u0001\u0000\u0000\u0000;\u0117\u0001\u0000\u0000"+ "\u0000\u0000=\u0117\u0001\u0000\u0000\u0000?\u0119\u0001\u0000\u0000\u0000"+
"\u0000=\u0119\u0001\u0000\u0000\u0000?\u011b\u0001\u0000\u0000\u0000A"+ "A\u011b\u0001\u0000\u0000\u0000C\u011d\u0001\u0000\u0000\u0000E\u011f"+
"\u011d\u0001\u0000\u0000\u0000C\u011f\u0001\u0000\u0000\u0000E\u0121\u0001"+ "\u0001\u0000\u0000\u0000G\u0125\u0001\u0000\u0000\u0000I\u012a\u0001\u0000"+
"\u0000\u0000\u0000G\u0127\u0001\u0000\u0000\u0000I\u012c\u0001\u0000\u0000"+ "\u0000\u0000K\u0130\u0001\u0000\u0000\u0000M\u0133\u0001\u0000\u0000\u0000"+
"\u0000K\u0132\u0001\u0000\u0000\u0000M\u0135\u0001\u0000\u0000\u0000O"+ "O\u0138\u0001\u0000\u0000\u0000Q\u013c\u0001\u0000\u0000\u0000S\u0143"+
"\u0138\u0001\u0000\u0000\u0000Q\u013d\u0001\u0000\u0000\u0000S\u0141\u0001"+ "\u0001\u0000\u0000\u0000U\u0147\u0001\u0000\u0000\u0000W\u0151\u0001\u0000"+
"\u0000\u0000\u0000U\u0148\u0001\u0000\u0000\u0000W\u014c\u0001\u0000\u0000"+ "\u0000\u0000Y\u0161\u0001\u0000\u0000\u0000[\u0163\u0001\u0000\u0000\u0000"+
"\u0000Y\u0156\u0001\u0000\u0000\u0000[\u0166\u0001\u0000\u0000\u0000]"+ "]\u0168\u0001\u0000\u0000\u0000_\u016a\u0001\u0000\u0000\u0000a\u016f"+
"\u0168\u0001\u0000\u0000\u0000_\u016d\u0001\u0000\u0000\u0000a\u016f\u0001"+ "\u0001\u0000\u0000\u0000c\u0171\u0001\u0000\u0000\u0000e\u0179\u0001\u0000"+
"\u0000\u0000\u0000c\u0174\u0001\u0000\u0000\u0000e\u0176\u0001\u0000\u0000"+ "\u0000\u0000g\u017f\u0001\u0000\u0000\u0000i\u018a\u0001\u0000\u0000\u0000"+
"\u0000g\u017e\u0001\u0000\u0000\u0000i\u0184\u0001\u0000\u0000\u0000k"+ "kl\u0005+\u0000\u0000lm\u0005+\u0000\u0000m\u0002\u0001\u0000\u0000\u0000"+
"\u018f\u0001\u0000\u0000\u0000mn\u0005+\u0000\u0000no\u0005+\u0000\u0000"+ "no\u0005-\u0000\u0000op\u0005-\u0000\u0000p\u0004\u0001\u0000\u0000\u0000"+
"o\u0002\u0001\u0000\u0000\u0000pq\u0005-\u0000\u0000qr\u0005-\u0000\u0000"+ "qr\u0005v\u0000\u0000rs\u0005o\u0000\u0000st\u0005i\u0000\u0000tu\u0005"+
"r\u0004\u0001\u0000\u0000\u0000st\u0005v\u0000\u0000tu\u0005o\u0000\u0000"+ "d\u0000\u0000u\u0006\u0001\u0000\u0000\u0000vw\u0005b\u0000\u0000wx\u0005"+
"uv\u0005i\u0000\u0000vw\u0005d\u0000\u0000w\u0006\u0001\u0000\u0000\u0000"+ "o\u0000\u0000xy\u0005o\u0000\u0000yz\u0005l\u0000\u0000z{\u0005e\u0000"+
"xy\u0005b\u0000\u0000yz\u0005o\u0000\u0000z{\u0005o\u0000\u0000{|\u0005"+ "\u0000{|\u0005a\u0000\u0000|}\u0005n\u0000\u0000}\b\u0001\u0000\u0000"+
"l\u0000\u0000|}\u0005e\u0000\u0000}~\u0005a\u0000\u0000~\u007f\u0005n"+ "\u0000~\u007f\u0005c\u0000\u0000\u007f\u0080\u0005h\u0000\u0000\u0080"+
"\u0000\u0000\u007f\b\u0001\u0000\u0000\u0000\u0080\u0081\u0005c\u0000"+ "\u0081\u0005a\u0000\u0000\u0081\u0082\u0005r\u0000\u0000\u0082\n\u0001"+
"\u0000\u0081\u0082\u0005h\u0000\u0000\u0082\u0083\u0005a\u0000\u0000\u0083"+ "\u0000\u0000\u0000\u0083\u0084\u0005i\u0000\u0000\u0084\u0085\u0005n\u0000"+
"\u0084\u0005r\u0000\u0000\u0084\n\u0001\u0000\u0000\u0000\u0085\u0086"+ "\u0000\u0085\u0086\u0005t\u0000\u0000\u0086\f\u0001\u0000\u0000\u0000"+
"\u0005i\u0000\u0000\u0086\u0087\u0005n\u0000\u0000\u0087\u0088\u0005t"+ "\u0087\u0088\u0005p\u0000\u0000\u0088\u0089\u0005u\u0000\u0000\u0089\u008a"+
"\u0000\u0000\u0088\f\u0001\u0000\u0000\u0000\u0089\u008a\u0005p\u0000"+ "\u0005b\u0000\u0000\u008a\u008b\u0005l\u0000\u0000\u008b\u008c\u0005i"+
"\u0000\u008a\u008b\u0005u\u0000\u0000\u008b\u008c\u0005b\u0000\u0000\u008c"+ "\u0000\u0000\u008c\u00b0\u0005c\u0000\u0000\u008d\u008e\u0005p\u0000\u0000"+
"\u008d\u0005l\u0000\u0000\u008d\u008e\u0005i\u0000\u0000\u008e\u00b2\u0005"+ "\u008e\u008f\u0005r\u0000\u0000\u008f\u0090\u0005i\u0000\u0000\u0090\u0091"+
"c\u0000\u0000\u008f\u0090\u0005p\u0000\u0000\u0090\u0091\u0005r\u0000"+ "\u0005v\u0000\u0000\u0091\u0092\u0005a\u0000\u0000\u0092\u0093\u0005t"+
"\u0000\u0091\u0092\u0005i\u0000\u0000\u0092\u0093\u0005v\u0000\u0000\u0093"+ "\u0000\u0000\u0093\u00b0\u0005e\u0000\u0000\u0094\u0095\u0005p\u0000\u0000"+
"\u0094\u0005a\u0000\u0000\u0094\u0095\u0005t\u0000\u0000\u0095\u00b2\u0005"+ "\u0095\u0096\u0005u\u0000\u0000\u0096\u0097\u0005b\u0000\u0000\u0097\u0098"+
"e\u0000\u0000\u0096\u0097\u0005p\u0000\u0000\u0097\u0098\u0005u\u0000"+ "\u0005l\u0000\u0000\u0098\u0099\u0005i\u0000\u0000\u0099\u009a\u0005c"+
"\u0000\u0098\u0099\u0005b\u0000\u0000\u0099\u009a\u0005l\u0000\u0000\u009a"+ "\u0000\u0000\u009a\u009b\u0005 \u0000\u0000\u009b\u009c\u0005s\u0000\u0000"+
"\u009b\u0005i\u0000\u0000\u009b\u009c\u0005c\u0000\u0000\u009c\u009d\u0005"+ "\u009c\u009d\u0005t\u0000\u0000\u009d\u009e\u0005a\u0000\u0000\u009e\u009f"+
" \u0000\u0000\u009d\u009e\u0005s\u0000\u0000\u009e\u009f\u0005t\u0000"+ "\u0005t\u0000\u0000\u009f\u00a0\u0005i\u0000\u0000\u00a0\u00b0\u0005c"+
"\u0000\u009f\u00a0\u0005a\u0000\u0000\u00a0\u00a1\u0005t\u0000\u0000\u00a1"+ "\u0000\u0000\u00a1\u00a2\u0005p\u0000\u0000\u00a2\u00a3\u0005r\u0000\u0000"+
"\u00a2\u0005i\u0000\u0000\u00a2\u00b2\u0005c\u0000\u0000\u00a3\u00a4\u0005"+ "\u00a3\u00a4\u0005i\u0000\u0000\u00a4\u00a5\u0005v\u0000\u0000\u00a5\u00a6"+
"p\u0000\u0000\u00a4\u00a5\u0005r\u0000\u0000\u00a5\u00a6\u0005i\u0000"+ "\u0005a\u0000\u0000\u00a6\u00a7\u0005t\u0000\u0000\u00a7\u00a8\u0005e"+
"\u0000\u00a6\u00a7\u0005v\u0000\u0000\u00a7\u00a8\u0005a\u0000\u0000\u00a8"+ "\u0000\u0000\u00a8\u00a9\u0005 \u0000\u0000\u00a9\u00aa\u0005s\u0000\u0000"+
"\u00a9\u0005t\u0000\u0000\u00a9\u00aa\u0005e\u0000\u0000\u00aa\u00ab\u0005"+ "\u00aa\u00ab\u0005t\u0000\u0000\u00ab\u00ac\u0005a\u0000\u0000\u00ac\u00ad"+
" \u0000\u0000\u00ab\u00ac\u0005s\u0000\u0000\u00ac\u00ad\u0005t\u0000"+ "\u0005t\u0000\u0000\u00ad\u00ae\u0005i\u0000\u0000\u00ae\u00b0\u0005c"+
"\u0000\u00ad\u00ae\u0005a\u0000\u0000\u00ae\u00af\u0005t\u0000\u0000\u00af"+ "\u0000\u0000\u00af\u0087\u0001\u0000\u0000\u0000\u00af\u008d\u0001\u0000"+
"\u00b0\u0005i\u0000\u0000\u00b0\u00b2\u0005c\u0000\u0000\u00b1\u0089\u0001"+ "\u0000\u0000\u00af\u0094\u0001\u0000\u0000\u0000\u00af\u00a1\u0001\u0000"+
"\u0000\u0000\u0000\u00b1\u008f\u0001\u0000\u0000\u0000\u00b1\u0096\u0001"+ "\u0000\u0000\u00b0\u000e\u0001\u0000\u0000\u0000\u00b1\u00b2\u0005p\u0000"+
"\u0000\u0000\u0000\u00b1\u00a3\u0001\u0000\u0000\u0000\u00b2\u000e\u0001"+ "\u0000\u00b2\u00b3\u0005u\u0000\u0000\u00b3\u00b4\u0005b\u0000\u0000\u00b4"+
"\u0000\u0000\u0000\u00b3\u00b4\u0005p\u0000\u0000\u00b4\u00b5\u0005u\u0000"+ "\u00b5\u0005l\u0000\u0000\u00b5\u00b6\u0005i\u0000\u0000\u00b6\u00b7\u0005"+
"\u0000\u00b5\u00b6\u0005b\u0000\u0000\u00b6\u00b7\u0005l\u0000\u0000\u00b7"+ "c\u0000\u0000\u00b7\u00b8\u0005 \u0000\u0000\u00b8\u00b9\u0005s\u0000"+
"\u00b8\u0005i\u0000\u0000\u00b8\u00b9\u0005c\u0000\u0000\u00b9\u00ba\u0005"+ "\u0000\u00b9\u00ba\u0005t\u0000\u0000\u00ba\u00bb\u0005a\u0000\u0000\u00bb"+
" \u0000\u0000\u00ba\u00bb\u0005s\u0000\u0000\u00bb\u00bc\u0005t\u0000"+ "\u00bc\u0005t\u0000\u0000\u00bc\u00bd\u0005i\u0000\u0000\u00bd\u00be\u0005"+
"\u0000\u00bc\u00bd\u0005a\u0000\u0000\u00bd\u00be\u0005t\u0000\u0000\u00be"+ "c\u0000\u0000\u00be\u00bf\u0005 \u0000\u0000\u00bf\u00c0\u0005v\u0000"+
"\u00bf\u0005i\u0000\u0000\u00bf\u00c0\u0005c\u0000\u0000\u00c0\u00c1\u0005"+ "\u0000\u00c0\u00c1\u0005o\u0000\u0000\u00c1\u00c2\u0005i\u0000\u0000\u00c2"+
" \u0000\u0000\u00c1\u00c2\u0005v\u0000\u0000\u00c2\u00c3\u0005o\u0000"+ "\u00c3\u0005d\u0000\u0000\u00c3\u00c4\u0005 \u0000\u0000\u00c4\u00c5\u0005"+
"\u0000\u00c3\u00c4\u0005i\u0000\u0000\u00c4\u00c5\u0005d\u0000\u0000\u00c5"+ "m\u0000\u0000\u00c5\u00c6\u0005a\u0000\u0000\u00c6\u00c7\u0005i\u0000"+
"\u00c6\u0005 \u0000\u0000\u00c6\u00c7\u0005m\u0000\u0000\u00c7\u00c8\u0005"+ "\u0000\u00c7\u00c8\u0005n\u0000\u0000\u00c8\u00c9\u0005(\u0000\u0000\u00c9"+
"a\u0000\u0000\u00c8\u00c9\u0005i\u0000\u0000\u00c9\u00ca\u0005n\u0000"+ "\u00ca\u0005S\u0000\u0000\u00ca\u00cb\u0005t\u0000\u0000\u00cb\u00cc\u0005"+
"\u0000\u00ca\u00cb\u0005(\u0000\u0000\u00cb\u00cc\u0005S\u0000\u0000\u00cc"+ "r\u0000\u0000\u00cc\u00cd\u0005i\u0000\u0000\u00cd\u00ce\u0005n\u0000"+
"\u00cd\u0005t\u0000\u0000\u00cd\u00ce\u0005r\u0000\u0000\u00ce\u00cf\u0005"+ "\u0000\u00ce\u00cf\u0005g\u0000\u0000\u00cf\u00d0\u0005[\u0000\u0000\u00d0"+
"i\u0000\u0000\u00cf\u00d0\u0005n\u0000\u0000\u00d0\u00d1\u0005g\u0000"+ "\u00d1\u0005]\u0000\u0000\u00d1\u00d2\u0005 \u0000\u0000\u00d2\u00d3\u0005"+
"\u0000\u00d1\u00d2\u0005[\u0000\u0000\u00d2\u00d3\u0005]\u0000\u0000\u00d3"+ "a\u0000\u0000\u00d3\u00d4\u0005r\u0000\u0000\u00d4\u00d5\u0005g\u0000"+
"\u00d4\u0005 \u0000\u0000\u00d4\u00d5\u0005a\u0000\u0000\u00d5\u00d6\u0005"+ "\u0000\u00d5\u00d6\u0005s\u0000\u0000\u00d6\u00d7\u0005)\u0000\u0000\u00d7"+
"r\u0000\u0000\u00d6\u00d7\u0005g\u0000\u0000\u00d7\u00d8\u0005s\u0000"+ "\u0010\u0001\u0000\u0000\u0000\u00d8\u00dc\u0003\u001f\u000f\u0000\u00d9"+
"\u0000\u00d8\u00d9\u0005)\u0000\u0000\u00d9\u0010\u0001\u0000\u0000\u0000"+ "\u00dc\u0003#\u0011\u0000\u00da\u00dc\u0003!\u0010\u0000\u00db\u00d8\u0001"+
"\u00da\u00de\u0003\u001f\u000f\u0000\u00db\u00de\u0003#\u0011\u0000\u00dc"+ "\u0000\u0000\u0000\u00db\u00d9\u0001\u0000\u0000\u0000\u00db\u00da\u0001"+
"\u00de\u0003!\u0010\u0000\u00dd\u00da\u0001\u0000\u0000\u0000\u00dd\u00db"+ "\u0000\u0000\u0000\u00dc\u0012\u0001\u0000\u0000\u0000\u00dd\u00e0\u0003"+
"\u0001\u0000\u0000\u0000\u00dd\u00dc\u0001\u0000\u0000\u0000\u00de\u0012"+ "\u001b\r\u0000\u00de\u00e0\u0003\u001d\u000e\u0000\u00df\u00dd\u0001\u0000"+
"\u0001\u0000\u0000\u0000\u00df\u00e2\u0003\u001b\r\u0000\u00e0\u00e2\u0003"+ "\u0000\u0000\u00df\u00de\u0001\u0000\u0000\u0000\u00e0\u0014\u0001\u0000"+
"\u001d\u000e\u0000\u00e1\u00df\u0001\u0000\u0000\u0000\u00e1\u00e0\u0001"+ "\u0000\u0000\u00e1\u00e8\u0003%\u0012\u0000\u00e2\u00e8\u0003\'\u0013"+
"\u0000\u0000\u0000\u00e2\u0014\u0001\u0000\u0000\u0000\u00e3\u00ea\u0003"+ "\u0000\u00e3\u00e8\u0003)\u0014\u0000\u00e4\u00e8\u0003+\u0015\u0000\u00e5"+
"%\u0012\u0000\u00e4\u00ea\u0003\'\u0013\u0000\u00e5\u00ea\u0003)\u0014"+ "\u00e8\u0003-\u0016\u0000\u00e6\u00e8\u0003/\u0017\u0000\u00e7\u00e1\u0001"+
"\u0000\u00e6\u00ea\u0003+\u0015\u0000\u00e7\u00ea\u0003-\u0016\u0000\u00e8"+ "\u0000\u0000\u0000\u00e7\u00e2\u0001\u0000\u0000\u0000\u00e7\u00e3\u0001"+
"\u00ea\u0003/\u0017\u0000\u00e9\u00e3\u0001\u0000\u0000\u0000\u00e9\u00e4"+ "\u0000\u0000\u0000\u00e7\u00e4\u0001\u0000\u0000\u0000\u00e7\u00e5\u0001"+
"\u0001\u0000\u0000\u0000\u00e9\u00e5\u0001\u0000\u0000\u0000\u00e9\u00e6"+ "\u0000\u0000\u0000\u00e7\u00e6\u0001\u0000\u0000\u0000\u00e8\u0016\u0001"+
"\u0001\u0000\u0000\u0000\u00e9\u00e7\u0001\u0000\u0000\u0000\u00e9\u00e8"+ "\u0000\u0000\u0000\u00e9\u00ec\u00033\u0019\u0000\u00ea\u00ec\u00035\u001a"+
"\u0001\u0000\u0000\u0000\u00ea\u0016\u0001\u0000\u0000\u0000\u00eb\u00ee"+ "\u0000\u00eb\u00e9\u0001\u0000\u0000\u0000\u00eb\u00ea\u0001\u0000\u0000"+
"\u00033\u0019\u0000\u00ec\u00ee\u00035\u001a\u0000\u00ed\u00eb\u0001\u0000"+ "\u0000\u00ec\u0018\u0001\u0000\u0000\u0000\u00ed\u00ee\u0005=\u0000\u0000"+
"\u0000\u0000\u00ed\u00ec\u0001\u0000\u0000\u0000\u00ee\u0018\u0001\u0000"+ "\u00ee\u001a\u0001\u0000\u0000\u0000\u00ef\u00f0\u0005+\u0000\u0000\u00f0"+
"\u0000\u0000\u00ef\u00f0\u0005=\u0000\u0000\u00f0\u001a\u0001\u0000\u0000"+ "\u001c\u0001\u0000\u0000\u0000\u00f1\u00f2\u0005-\u0000\u0000\u00f2\u001e"+
"\u0000\u00f1\u00f2\u0005+\u0000\u0000\u00f2\u001c\u0001\u0000\u0000\u0000"+ "\u0001\u0000\u0000\u0000\u00f3\u00f4\u0005*\u0000\u0000\u00f4 \u0001\u0000"+
"\u00f3\u00f4\u0005-\u0000\u0000\u00f4\u001e\u0001\u0000\u0000\u0000\u00f5"+ "\u0000\u0000\u00f5\u00f6\u0005%\u0000\u0000\u00f6\"\u0001\u0000\u0000"+
"\u00f6\u0005*\u0000\u0000\u00f6 \u0001\u0000\u0000\u0000\u00f7\u00f8\u0005"+ "\u0000\u00f7\u00f8\u0005/\u0000\u0000\u00f8$\u0001\u0000\u0000\u0000\u00f9"+
"%\u0000\u0000\u00f8\"\u0001\u0000\u0000\u0000\u00f9\u00fa\u0005/\u0000"+ "\u00fa\u0005>\u0000\u0000\u00fa&\u0001\u0000\u0000\u0000\u00fb\u00fc\u0005"+
"\u0000\u00fa$\u0001\u0000\u0000\u0000\u00fb\u00fc\u0005>\u0000\u0000\u00fc"+ "<\u0000\u0000\u00fc(\u0001\u0000\u0000\u0000\u00fd\u00fe\u0005>\u0000"+
"&\u0001\u0000\u0000\u0000\u00fd\u00fe\u0005<\u0000\u0000\u00fe(\u0001"+ "\u0000\u00fe\u00ff\u0005=\u0000\u0000\u00ff*\u0001\u0000\u0000\u0000\u0100"+
"\u0000\u0000\u0000\u00ff\u0100\u0005>\u0000\u0000\u0100\u0101\u0005=\u0000"+ "\u0101\u0005<\u0000\u0000\u0101\u0102\u0005=\u0000\u0000\u0102,\u0001"+
"\u0000\u0101*\u0001\u0000\u0000\u0000\u0102\u0103\u0005<\u0000\u0000\u0103"+ "\u0000\u0000\u0000\u0103\u0104\u0005=\u0000\u0000\u0104\u0105\u0005=\u0000"+
"\u0104\u0005=\u0000\u0000\u0104,\u0001\u0000\u0000\u0000\u0105\u0106\u0005"+ "\u0000\u0105.\u0001\u0000\u0000\u0000\u0106\u0107\u0005!\u0000\u0000\u0107"+
"=\u0000\u0000\u0106\u0107\u0005=\u0000\u0000\u0107.\u0001\u0000\u0000"+ "\u0108\u0005=\u0000\u0000\u01080\u0001\u0000\u0000\u0000\u0109\u010a\u0005"+
"\u0000\u0108\u0109\u0005!\u0000\u0000\u0109\u010a\u0005=\u0000\u0000\u010a"+ "!\u0000\u0000\u010a2\u0001\u0000\u0000\u0000\u010b\u010c\u0005&\u0000"+
"0\u0001\u0000\u0000\u0000\u010b\u010c\u0005!\u0000\u0000\u010c2\u0001"+ "\u0000\u010c\u010d\u0005&\u0000\u0000\u010d4\u0001\u0000\u0000\u0000\u010e"+
"\u0000\u0000\u0000\u010d\u010e\u0005&\u0000\u0000\u010e\u010f\u0005&\u0000"+ "\u010f\u0005|\u0000\u0000\u010f\u0110\u0005|\u0000\u0000\u01106\u0001"+
"\u0000\u010f4\u0001\u0000\u0000\u0000\u0110\u0111\u0005|\u0000\u0000\u0111"+ "\u0000\u0000\u0000\u0111\u0112\u0005.\u0000\u0000\u01128\u0001\u0000\u0000"+
"\u0112\u0005|\u0000\u0000\u01126\u0001\u0000\u0000\u0000\u0113\u0114\u0005"+ "\u0000\u0113\u0114\u0005(\u0000\u0000\u0114:\u0001\u0000\u0000\u0000\u0115"+
".\u0000\u0000\u01148\u0001\u0000\u0000\u0000\u0115\u0116\u0005(\u0000"+ "\u0116\u0005)\u0000\u0000\u0116<\u0001\u0000\u0000\u0000\u0117\u0118\u0005"+
"\u0000\u0116:\u0001\u0000\u0000\u0000\u0117\u0118\u0005)\u0000\u0000\u0118"+ "{\u0000\u0000\u0118>\u0001\u0000\u0000\u0000\u0119\u011a\u0005}\u0000"+
"<\u0001\u0000\u0000\u0000\u0119\u011a\u0005{\u0000\u0000\u011a>\u0001"+ "\u0000\u011a@\u0001\u0000\u0000\u0000\u011b\u011c\u0005;\u0000\u0000\u011c"+
"\u0000\u0000\u0000\u011b\u011c\u0005}\u0000\u0000\u011c@\u0001\u0000\u0000"+ "B\u0001\u0000\u0000\u0000\u011d\u011e\u0005,\u0000\u0000\u011eD\u0001"+
"\u0000\u011d\u011e\u0005;\u0000\u0000\u011eB\u0001\u0000\u0000\u0000\u011f"+ "\u0000\u0000\u0000\u011f\u0120\u0005c\u0000\u0000\u0120\u0121\u0005l\u0000"+
"\u0120\u0005,\u0000\u0000\u0120D\u0001\u0000\u0000\u0000\u0121\u0122\u0005"+ "\u0000\u0121\u0122\u0005a\u0000\u0000\u0122\u0123\u0005s\u0000\u0000\u0123"+
"c\u0000\u0000\u0122\u0123\u0005l\u0000\u0000\u0123\u0124\u0005a\u0000"+ "\u0124\u0005s\u0000\u0000\u0124F\u0001\u0000\u0000\u0000\u0125\u0126\u0005"+
"\u0000\u0124\u0125\u0005s\u0000\u0000\u0125\u0126\u0005s\u0000\u0000\u0126"+ "t\u0000\u0000\u0126\u0127\u0005h\u0000\u0000\u0127\u0128\u0005i\u0000"+
"F\u0001\u0000\u0000\u0000\u0127\u0128\u0005t\u0000\u0000\u0128\u0129\u0005"+ "\u0000\u0128\u0129\u0005s\u0000\u0000\u0129H\u0001\u0000\u0000\u0000\u012a"+
"h\u0000\u0000\u0129\u012a\u0005i\u0000\u0000\u012a\u012b\u0005s\u0000"+ "\u012b\u0005w\u0000\u0000\u012b\u012c\u0005h\u0000\u0000\u012c\u012d\u0005"+
"\u0000\u012bH\u0001\u0000\u0000\u0000\u012c\u012d\u0005w\u0000\u0000\u012d"+ "i\u0000\u0000\u012d\u012e\u0005l\u0000\u0000\u012e\u012f\u0005e\u0000"+
"\u012e\u0005h\u0000\u0000\u012e\u012f\u0005i\u0000\u0000\u012f\u0130\u0005"+ "\u0000\u012fJ\u0001\u0000\u0000\u0000\u0130\u0131\u0005i\u0000\u0000\u0131"+
"l\u0000\u0000\u0130\u0131\u0005e\u0000\u0000\u0131J\u0001\u0000\u0000"+ "\u0132\u0005f\u0000\u0000\u0132L\u0001\u0000\u0000\u0000\u0133\u0134\u0005"+
"\u0000\u0132\u0133\u0005d\u0000\u0000\u0133\u0134\u0005o\u0000\u0000\u0134"+ "e\u0000\u0000\u0134\u0135\u0005l\u0000\u0000\u0135\u0136\u0005s\u0000"+
"L\u0001\u0000\u0000\u0000\u0135\u0136\u0005i\u0000\u0000\u0136\u0137\u0005"+ "\u0000\u0136\u0137\u0005e\u0000\u0000\u0137N\u0001\u0000\u0000\u0000\u0138"+
"f\u0000\u0000\u0137N\u0001\u0000\u0000\u0000\u0138\u0139\u0005e\u0000"+ "\u0139\u0005f\u0000\u0000\u0139\u013a\u0005o\u0000\u0000\u013a\u013b\u0005"+
"\u0000\u0139\u013a\u0005l\u0000\u0000\u013a\u013b\u0005s\u0000\u0000\u013b"+ "r\u0000\u0000\u013bP\u0001\u0000\u0000\u0000\u013c\u013d\u0005r\u0000"+
"\u013c\u0005e\u0000\u0000\u013cP\u0001\u0000\u0000\u0000\u013d\u013e\u0005"+ "\u0000\u013d\u013e\u0005e\u0000\u0000\u013e\u013f\u0005t\u0000\u0000\u013f"+
"f\u0000\u0000\u013e\u013f\u0005o\u0000\u0000\u013f\u0140\u0005r\u0000"+ "\u0140\u0005u\u0000\u0000\u0140\u0141\u0005r\u0000\u0000\u0141\u0142\u0005"+
"\u0000\u0140R\u0001\u0000\u0000\u0000\u0141\u0142\u0005r\u0000\u0000\u0142"+ "n\u0000\u0000\u0142R\u0001\u0000\u0000\u0000\u0143\u0144\u0005n\u0000"+
"\u0143\u0005e\u0000\u0000\u0143\u0144\u0005t\u0000\u0000\u0144\u0145\u0005"+ "\u0000\u0144\u0145\u0005e\u0000\u0000\u0145\u0146\u0005w\u0000\u0000\u0146"+
"u\u0000\u0000\u0145\u0146\u0005r\u0000\u0000\u0146\u0147\u0005n\u0000"+ "T\u0001\u0000\u0000\u0000\u0147\u014b\u0005\'\u0000\u0000\u0148\u014a"+
"\u0000\u0147T\u0001\u0000\u0000\u0000\u0148\u0149\u0005n\u0000\u0000\u0149"+ "\b\u0000\u0000\u0000\u0149\u0148\u0001\u0000\u0000\u0000\u014a\u014d\u0001"+
"\u014a\u0005e\u0000\u0000\u014a\u014b\u0005w\u0000\u0000\u014bV\u0001"+ "\u0000\u0000\u0000\u014b\u0149\u0001\u0000\u0000\u0000\u014b\u014c\u0001"+
"\u0000\u0000\u0000\u014c\u0150\u0005\'\u0000\u0000\u014d\u014f\b\u0000"+ "\u0000\u0000\u0000\u014c\u014e\u0001\u0000\u0000\u0000\u014d\u014b\u0001"+
"\u0000\u0000\u014e\u014d\u0001\u0000\u0000\u0000\u014f\u0152\u0001\u0000"+ "\u0000\u0000\u0000\u014e\u014f\u0005\'\u0000\u0000\u014fV\u0001\u0000"+
"\u0000\u0000\u0150\u014e\u0001\u0000\u0000\u0000\u0150\u0151\u0001\u0000"+ "\u0000\u0000\u0150\u0152\u0003\u001d\u000e\u0000\u0151\u0150\u0001\u0000"+
"\u0000\u0000\u0151\u0153\u0001\u0000\u0000\u0000\u0152\u0150\u0001\u0000"+ "\u0000\u0000\u0151\u0152\u0001\u0000\u0000\u0000\u0152\u0154\u0001\u0000"+
"\u0000\u0000\u0153\u0154\u0005\'\u0000\u0000\u0154X\u0001\u0000\u0000"+ "\u0000\u0000\u0153\u0155\u0003_/\u0000\u0154\u0153\u0001\u0000\u0000\u0000"+
"\u0000\u0155\u0157\u0003\u001d\u000e\u0000\u0156\u0155\u0001\u0000\u0000"+ "\u0155\u0156\u0001\u0000\u0000\u0000\u0156\u0154\u0001\u0000\u0000\u0000"+
"\u0000\u0156\u0157\u0001\u0000\u0000\u0000\u0157\u0159\u0001\u0000\u0000"+ "\u0156\u0157\u0001\u0000\u0000\u0000\u0157X\u0001\u0000\u0000\u0000\u0158"+
"\u0000\u0158\u015a\u0003a0\u0000\u0159\u0158\u0001\u0000\u0000\u0000\u015a"+ "\u0159\u0005t\u0000\u0000\u0159\u015a\u0005r\u0000\u0000\u015a\u015b\u0005"+
"\u015b\u0001\u0000\u0000\u0000\u015b\u0159\u0001\u0000\u0000\u0000\u015b"+ "u\u0000\u0000\u015b\u0162\u0005e\u0000\u0000\u015c\u015d\u0005f\u0000"+
"\u015c\u0001\u0000\u0000\u0000\u015cZ\u0001\u0000\u0000\u0000\u015d\u015e"+ "\u0000\u015d\u015e\u0005a\u0000\u0000\u015e\u015f\u0005l\u0000\u0000\u015f"+
"\u0005t\u0000\u0000\u015e\u015f\u0005r\u0000\u0000\u015f\u0160\u0005u"+ "\u0160\u0005s\u0000\u0000\u0160\u0162\u0005e\u0000\u0000\u0161\u0158\u0001"+
"\u0000\u0000\u0160\u0167\u0005e\u0000\u0000\u0161\u0162\u0005f\u0000\u0000"+ "\u0000\u0000\u0000\u0161\u015c\u0001\u0000\u0000\u0000\u0162Z\u0001\u0000"+
"\u0162\u0163\u0005a\u0000\u0000\u0163\u0164\u0005l\u0000\u0000\u0164\u0165"+ "\u0000\u0000\u0163\u0164\u0005n\u0000\u0000\u0164\u0165\u0005u\u0000\u0000"+
"\u0005s\u0000\u0000\u0165\u0167\u0005e\u0000\u0000\u0166\u015d\u0001\u0000"+ "\u0165\u0166\u0005l\u0000\u0000\u0166\u0167\u0005l\u0000\u0000\u0167\\"+
"\u0000\u0000\u0166\u0161\u0001\u0000\u0000\u0000\u0167\\\u0001\u0000\u0000"+ "\u0001\u0000\u0000\u0000\u0168\u0169\u0007\u0001\u0000\u0000\u0169^\u0001"+
"\u0000\u0168\u0169\u0005n\u0000\u0000\u0169\u016a\u0005u\u0000\u0000\u016a"+ "\u0000\u0000\u0000\u016a\u016b\u0007\u0002\u0000\u0000\u016b`\u0001\u0000"+
"\u016b\u0005l\u0000\u0000\u016b\u016c\u0005l\u0000\u0000\u016c^\u0001"+ "\u0000\u0000\u016c\u0170\u0003].\u0000\u016d\u0170\u0003_/\u0000\u016e"+
"\u0000\u0000\u0000\u016d\u016e\u0007\u0001\u0000\u0000\u016e`\u0001\u0000"+ "\u0170\u0007\u0003\u0000\u0000\u016f\u016c\u0001\u0000\u0000\u0000\u016f"+
"\u0000\u0000\u016f\u0170\u0007\u0002\u0000\u0000\u0170b\u0001\u0000\u0000"+ "\u016d\u0001\u0000\u0000\u0000\u016f\u016e\u0001\u0000\u0000\u0000\u0170"+
"\u0000\u0171\u0175\u0003_/\u0000\u0172\u0175\u0003a0\u0000\u0173\u0175"+ "b\u0001\u0000\u0000\u0000\u0171\u0175\u0003].\u0000\u0172\u0174\u0003"+
"\u0007\u0003\u0000\u0000\u0174\u0171\u0001\u0000\u0000\u0000\u0174\u0172"+ "a0\u0000\u0173\u0172\u0001\u0000\u0000\u0000\u0174\u0177\u0001\u0000\u0000"+
"\u0001\u0000\u0000\u0000\u0174\u0173\u0001\u0000\u0000\u0000\u0175d\u0001"+ "\u0000\u0175\u0173\u0001\u0000\u0000\u0000\u0175\u0176\u0001\u0000\u0000"+
"\u0000\u0000\u0000\u0176\u017a\u0003_/\u0000\u0177\u0179\u0003c1\u0000"+ "\u0000\u0176d\u0001\u0000\u0000\u0000\u0177\u0175\u0001\u0000\u0000\u0000"+
"\u0178\u0177\u0001\u0000\u0000\u0000\u0179\u017c\u0001\u0000\u0000\u0000"+ "\u0178\u017a\u0007\u0004\u0000\u0000\u0179\u0178\u0001\u0000\u0000\u0000"+
"\u017a\u0178\u0001\u0000\u0000\u0000\u017a\u017b\u0001\u0000\u0000\u0000"+ "\u017a\u017b\u0001\u0000\u0000\u0000\u017b\u0179\u0001\u0000\u0000\u0000"+
"\u017bf\u0001\u0000\u0000\u0000\u017c\u017a\u0001\u0000\u0000\u0000\u017d"+ "\u017b\u017c\u0001\u0000\u0000\u0000\u017c\u017d\u0001\u0000\u0000\u0000"+
"\u017f\u0007\u0004\u0000\u0000\u017e\u017d\u0001\u0000\u0000\u0000\u017f"+ "\u017d\u017e\u00062\u0000\u0000\u017ef\u0001\u0000\u0000\u0000\u017f\u0180"+
"\u0180\u0001\u0000\u0000\u0000\u0180\u017e\u0001\u0000\u0000\u0000\u0180"+ "\u0005/\u0000\u0000\u0180\u0181\u0005/\u0000\u0000\u0181\u0185\u0001\u0000"+
"\u0181\u0001\u0000\u0000\u0000\u0181\u0182\u0001\u0000\u0000\u0000\u0182"+ "\u0000\u0000\u0182\u0184\b\u0000\u0000\u0000\u0183\u0182\u0001\u0000\u0000"+
"\u0183\u00063\u0000\u0000\u0183h\u0001\u0000\u0000\u0000\u0184\u0185\u0005"+ "\u0000\u0184\u0187\u0001\u0000\u0000\u0000\u0185\u0183\u0001\u0000\u0000"+
"/\u0000\u0000\u0185\u0186\u0005/\u0000\u0000\u0186\u018a\u0001\u0000\u0000"+ "\u0000\u0185\u0186\u0001\u0000\u0000\u0000\u0186\u0188\u0001\u0000\u0000"+
"\u0000\u0187\u0189\b\u0000\u0000\u0000\u0188\u0187\u0001\u0000\u0000\u0000"+ "\u0000\u0187\u0185\u0001\u0000\u0000\u0000\u0188\u0189\u00063\u0000\u0000"+
"\u0189\u018c\u0001\u0000\u0000\u0000\u018a\u0188\u0001\u0000\u0000\u0000"+ "\u0189h\u0001\u0000\u0000\u0000\u018a\u018b\u0005/\u0000\u0000\u018b\u018c"+
"\u018a\u018b\u0001\u0000\u0000\u0000\u018b\u018d\u0001\u0000\u0000\u0000"+ "\u0005*\u0000\u0000\u018c\u0190\u0001\u0000\u0000\u0000\u018d\u018f\t"+
"\u018c\u018a\u0001\u0000\u0000\u0000\u018d\u018e\u00064\u0000\u0000\u018e"+ "\u0000\u0000\u0000\u018e\u018d\u0001\u0000\u0000\u0000\u018f\u0192\u0001"+
"j\u0001\u0000\u0000\u0000\u018f\u0190\u0005/\u0000\u0000\u0190\u0191\u0005"+ "\u0000\u0000\u0000\u0190\u0191\u0001\u0000\u0000\u0000\u0190\u018e\u0001"+
"*\u0000\u0000\u0191\u0195\u0001\u0000\u0000\u0000\u0192\u0194\t\u0000"+ "\u0000\u0000\u0000\u0191\u0193\u0001\u0000\u0000\u0000\u0192\u0190\u0001"+
"\u0000\u0000\u0193\u0192\u0001\u0000\u0000\u0000\u0194\u0197\u0001\u0000"+ "\u0000\u0000\u0000\u0193\u0194\u0005*\u0000\u0000\u0194\u0195\u0005/\u0000"+
"\u0000\u0000\u0195\u0196\u0001\u0000\u0000\u0000\u0195\u0193\u0001\u0000"+ "\u0000\u0195\u0196\u0001\u0000\u0000\u0000\u0196\u0197\u00064\u0000\u0000"+
"\u0000\u0000\u0196\u0198\u0001\u0000\u0000\u0000\u0197\u0195\u0001\u0000"+ "\u0197j\u0001\u0000\u0000\u0000\u000f\u0000\u00af\u00db\u00df\u00e7\u00eb"+
"\u0000\u0000\u0198\u0199\u0005*\u0000\u0000\u0199\u019a\u0005/\u0000\u0000"+ "\u014b\u0151\u0156\u0161\u016f\u0175\u017b\u0185\u0190\u0001\u0006\u0000"+
"\u019a\u019b\u0001\u0000\u0000\u0000\u019b\u019c\u00065\u0000\u0000\u019c"+ "\u0000";
"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 = public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray()); new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static { static {

View File

@ -35,20 +35,19 @@ Comma=34
Class=35 Class=35
This=36 This=36
While=37 While=37
Do=38 If=38
If=39 Else=39
Else=40 For=40
For=41 Return=41
Return=42 New=42
New=43 CharValue=43
CharValue=44 IntValue=44
IntValue=45 BooleanValue=45
BooleanValue=46 NullValue=46
NullValue=47 Identifier=47
Identifier=48 WS=48
WS=49 InlineComment=49
InlineComment=50 MultilineComment=50
MultilineComment=51
'++'=1 '++'=1
'--'=2 '--'=2
'void'=3 'void'=3
@ -81,10 +80,9 @@ MultilineComment=51
'class'=35 'class'=35
'this'=36 'this'=36
'while'=37 'while'=37
'do'=38 'if'=38
'if'=39 'else'=39
'else'=40 'for'=40
'for'=41 'return'=41
'return'=42 'new'=42
'new'=43 'null'=46
'null'=47

View File

@ -1,4 +1,4 @@
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1 // Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated; package parser.generated;
import org.antlr.v4.runtime.tree.ParseTreeListener; import org.antlr.v4.runtime.tree.ParseTreeListener;
@ -108,15 +108,15 @@ public interface SimpleJavaListener extends ParseTreeListener {
*/ */
void exitStatement(SimpleJavaParser.StatementContext ctx); void exitStatement(SimpleJavaParser.StatementContext ctx);
/** /**
* Enter a parse tree produced by {@link SimpleJavaParser#blockStatement}. * Enter a parse tree produced by {@link SimpleJavaParser#block}.
* @param ctx the parse tree * @param ctx the parse tree
*/ */
void enterBlockStatement(SimpleJavaParser.BlockStatementContext ctx); void enterBlock(SimpleJavaParser.BlockContext ctx);
/** /**
* Exit a parse tree produced by {@link SimpleJavaParser#blockStatement}. * Exit a parse tree produced by {@link SimpleJavaParser#block}.
* @param ctx the parse tree * @param ctx the parse tree
*/ */
void exitBlockStatement(SimpleJavaParser.BlockStatementContext ctx); void exitBlock(SimpleJavaParser.BlockContext ctx);
/** /**
* Enter a parse tree produced by {@link SimpleJavaParser#returnStatement}. * Enter a parse tree produced by {@link SimpleJavaParser#returnStatement}.
* @param ctx the parse tree * @param ctx the parse tree
@ -147,16 +147,6 @@ public interface SimpleJavaListener extends ParseTreeListener {
* @param ctx the parse tree * @param ctx the parse tree
*/ */
void exitWhileStatement(SimpleJavaParser.WhileStatementContext ctx); void exitWhileStatement(SimpleJavaParser.WhileStatementContext ctx);
/**
* Enter a parse tree produced by {@link SimpleJavaParser#doWhileStatement}.
* @param ctx the parse tree
*/
void enterDoWhileStatement(SimpleJavaParser.DoWhileStatementContext ctx);
/**
* Exit a parse tree produced by {@link SimpleJavaParser#doWhileStatement}.
* @param ctx the parse tree
*/
void exitDoWhileStatement(SimpleJavaParser.DoWhileStatementContext ctx);
/** /**
* Enter a parse tree produced by {@link SimpleJavaParser#forStatement}. * Enter a parse tree produced by {@link SimpleJavaParser#forStatement}.
* @param ctx the parse tree * @param ctx the parse tree
@ -187,16 +177,6 @@ public interface SimpleJavaListener extends ParseTreeListener {
* @param ctx the parse tree * @param ctx the parse tree
*/ */
void exitIfStatement(SimpleJavaParser.IfStatementContext ctx); void exitIfStatement(SimpleJavaParser.IfStatementContext ctx);
/**
* Enter a parse tree produced by {@link SimpleJavaParser#elseIfStatement}.
* @param ctx the parse tree
*/
void enterElseIfStatement(SimpleJavaParser.ElseIfStatementContext ctx);
/**
* Exit a parse tree produced by {@link SimpleJavaParser#elseIfStatement}.
* @param ctx the parse tree
*/
void exitElseIfStatement(SimpleJavaParser.ElseIfStatementContext ctx);
/** /**
* Enter a parse tree produced by {@link SimpleJavaParser#elseStatement}. * Enter a parse tree produced by {@link SimpleJavaParser#elseStatement}.
* @param ctx the parse tree * @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/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1 // Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
package parser.generated; package parser.generated;
import org.antlr.v4.runtime.tree.ParseTreeVisitor; import org.antlr.v4.runtime.tree.ParseTreeVisitor;
@ -71,11 +71,11 @@ public interface SimpleJavaVisitor<T> extends ParseTreeVisitor<T> {
*/ */
T visitStatement(SimpleJavaParser.StatementContext ctx); T visitStatement(SimpleJavaParser.StatementContext ctx);
/** /**
* Visit a parse tree produced by {@link SimpleJavaParser#blockStatement}. * Visit a parse tree produced by {@link SimpleJavaParser#block}.
* @param ctx the parse tree * @param ctx the parse tree
* @return the visitor result * @return the visitor result
*/ */
T visitBlockStatement(SimpleJavaParser.BlockStatementContext ctx); T visitBlock(SimpleJavaParser.BlockContext ctx);
/** /**
* Visit a parse tree produced by {@link SimpleJavaParser#returnStatement}. * Visit a parse tree produced by {@link SimpleJavaParser#returnStatement}.
* @param ctx the parse tree * @param ctx the parse tree
@ -94,12 +94,6 @@ public interface SimpleJavaVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result * @return the visitor result
*/ */
T visitWhileStatement(SimpleJavaParser.WhileStatementContext ctx); T visitWhileStatement(SimpleJavaParser.WhileStatementContext ctx);
/**
* Visit a parse tree produced by {@link SimpleJavaParser#doWhileStatement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDoWhileStatement(SimpleJavaParser.DoWhileStatementContext ctx);
/** /**
* Visit a parse tree produced by {@link SimpleJavaParser#forStatement}. * Visit a parse tree produced by {@link SimpleJavaParser#forStatement}.
* @param ctx the parse tree * @param ctx the parse tree
@ -118,12 +112,6 @@ public interface SimpleJavaVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result * @return the visitor result
*/ */
T visitIfStatement(SimpleJavaParser.IfStatementContext ctx); T visitIfStatement(SimpleJavaParser.IfStatementContext ctx);
/**
* Visit a parse tree produced by {@link SimpleJavaParser#elseIfStatement}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitElseIfStatement(SimpleJavaParser.ElseIfStatementContext ctx);
/** /**
* Visit a parse tree produced by {@link SimpleJavaParser#elseStatement}. * Visit a parse tree produced by {@link SimpleJavaParser#elseStatement}.
* @param ctx the parse tree * @param ctx the parse tree

View File

@ -1,27 +1,35 @@
package semantic; package semantic;
import oldAst.type.TypeNode; import ast.type.type.*;
import semantic.exeptions.AlreadyDeclearedException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Stack; import java.util.Stack;
public class Scope { public class Scope {
private Stack<HashMap<String, TypeNode>> localVars; private Stack<HashMap<String, ITypeNode>> localVars;
public Scope() { public Scope() {
localVars = new Stack<HashMap<String, TypeNode>>(); localVars = new Stack<HashMap<String, ITypeNode>>();
} }
public void addLocalVar(String name, TypeNode type) { public void addLocalVar(String name, ITypeNode type) {
if (this.contains(name)) { if (this.contains(name)) {
throw new RuntimeException("Variable " + name + " already exists in this scope"); throw new AlreadyDeclearedException("Variable " + name + " already exists in this scope");
} }
localVars.peek().put(name, type); localVars.peek().put(name, type);
} }
public ITypeNode getLocalVar(String name) {
for (HashMap<String, ITypeNode> map : localVars) {
return map.get(name);
}
return null;
}
public boolean contains(String name) { public boolean contains(String name) {
for (HashMap<String, TypeNode> map : localVars) { for (HashMap<String, ITypeNode> map : localVars) {
if (map.containsKey(name)) { if (map.containsKey(name)) {
return true; return true;
} }
@ -30,7 +38,7 @@ public class Scope {
} }
public void pushScope() { public void pushScope() {
localVars.push(new HashMap<String, TypeNode>()); localVars.push(new HashMap<String, ITypeNode>());
} }
public void popScope() { public void popScope() {

View File

@ -1,40 +1,44 @@
package semantic; package semantic;
import oldAst.*;
import oldAst.expression.*;
import oldAst.member.FieldNode;
import oldAst.member.MemberNode;
import oldAst.member.MethodNode;
import oldAst.parameter.ParameterListNode;
import oldAst.parameter.ParameterNode;
import oldAst.statement.*;
import oldAst.type.ReferenceTypeNode;
import oldAst.expression.This;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import oldAst.type.BaseTypeNode; import ast.*;
import oldAst.type.TypeNode; import ast.block.BlockNode;
import ast.expression.IExpressionNode;
import ast.expression.binaryexpression.*;
import ast.expression.unaryexpression.UnaryExpressionNode;
import ast.member.*;
import ast.parameter.ParameterNode;
import ast.statement.*;
import ast.statement.ifstatement.ElseStatementNode;
import ast.statement.ifstatement.IfElseStatementNode;
import ast.statement.ifstatement.IfStatementNode;
import ast.statement.statementexpression.AssignStatementExpressionNode;
import ast.statement.statementexpression.AssignableExpressionNode;
import ast.statement.statementexpression.NewDeclarationStatementExpressionNode;
import ast.statement.statementexpression.crementExpression.DecrementExpressionNode;
import ast.statement.statementexpression.crementExpression.IncrementExpressionNode;
import ast.statement.statementexpression.methodcallstatementnexpression.MethodCallStatementExpressionNode;
import ast.type.type.*;
import semantic.context.Context; import semantic.context.Context;
import semantic.exeptions.AlreadyDeclearedException; import semantic.exeptions.*;
import semantic.exeptions.NotDeclearedException;
import semantic.exeptions.TypeMismatchException;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
public class SemanticAnalyzer implements SemanticVisitor { public class SemanticAnalyzer implements SemanticVisitor {
private static HashMap<String, TypeNode> currentFields = new HashMap<>(); private static HashMap<String, ITypeNode> currentFields = new HashMap<>();
public static ArrayList<Exception> errors = new ArrayList<>(); public static ArrayList<Exception> errors = new ArrayList<>();
private Context context; private static Context context;
private static Scope currentScope; private static Scope currentScope;
private static ClassNode currentClass; private static ClassNode currentClass;
private static ITypeNode currentNullType;
private ITypeNode currentMethodReturnType;
public static ASTNode generateTast(ASTNode node) { public static ASTNode generateTast(ASTNode node) {
SemanticAnalyzer semanticCheck = new SemanticAnalyzer(); SemanticAnalyzer semanticCheck = new SemanticAnalyzer();
@ -50,7 +54,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
return null; return null;
} }
public static void clearAnalyzier(){ public static void clearAnalyzer() {
currentFields.clear(); currentFields.clear();
errors.clear(); errors.clear();
currentScope = null; currentScope = null;
@ -87,13 +91,10 @@ public class SemanticAnalyzer implements SemanticVisitor {
valid = valid && result.isValid(); valid = valid && result.isValid();
} else if (memberNode instanceof MethodNode methodNode) { } else if (memberNode instanceof MethodNode methodNode) {
//Methods //Methods
for(MethodNode methode : currentClass.getMethods()){ for (MethodNode methode : currentClass.getMethods()) {
if(methode.equals(methodNode)) if (methode.equals(methodNode))
break; break;
if(methode.isSame(methodNode)){
errors.add(new AlreadyDeclearedException("This method has already been declared"));
valid = false;
}
} }
var result = methodNode.accept(this); var result = methodNode.accept(this);
valid = valid && result.isValid(); valid = valid && result.isValid();
@ -106,38 +107,59 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override @Override
public TypeCheckResult analyze(MethodNode methodNode) { public TypeCheckResult analyze(MethodNode methodNode) {
var valid = true; if (methodNode instanceof ConstructorNode) {
return new TypeCheckResult(true, new BaseType(TypeEnum.VOID));
} else {
currentScope.pushScope(); var valid = true;
//Parameter for (var otherMethod : currentClass.getMethods()) {
ParameterListNode parameterListNode = methodNode.parameters; if (Objects.equals(otherMethod, methodNode))
if (parameterListNode != null) { break;
List<ParameterNode> parameters = parameterListNode.parameters; if (otherMethod.isSame(methodNode)) {
for (ParameterNode parameter : parameters) { errors.add(new AlreadyDeclearedException(
if (currentScope.contains(parameter.identifier)) { "Method " + methodNode.getIdentifier() + " is already defined in class "
errors.add(new AlreadyDeclearedException("Duplicated Parameter " + parameter.identifier)); + currentClass.identifier));
return new TypeCheckResult(false, null); valid = false;
} else {
currentScope.addLocalVar(parameter.identifier, parameter.type);
} }
} }
}
//Statements currentScope.pushScope();
List<StatementNode> statements = methodNode.statements; for (var parameter : methodNode.getParameters()) {
for (StatementNode statement : statements) { var result = parameter.accept(this);
if (statement instanceof AssignmentStatementNode assignmentStatementNode) {
var result = assignmentStatementNode.accept(this);
valid = valid && result.isValid();
} else if (statement instanceof VariableDeclarationStatementNode variableDeclarationStatementNode) {
var result = variableDeclarationStatementNode.accept(this);
valid = valid && result.isValid(); valid = valid && result.isValid();
try {
currentScope.addLocalVar(parameter.identifier, parameter.type);
} catch (AlreadyDeclearedException e) {
errors.add(new AlreadyDeclearedException(parameter.identifier));
}
} }
} // Check if this method is already declared
currentScope.popScope(); currentMethodReturnType = methodNode.getType();
return new TypeCheckResult(valid, null); currentNullType = currentMethodReturnType; // Solange nicht in einem Assign oder Methoden-Aufruf dieser Typ
ITypeNode resultType = new BaseType(TypeEnum.VOID);
// gesetzt ist, ist dieser der Rückgabewert der Methode
var result = methodNode.block.accept(this);
valid = valid && result.isValid();
currentScope.popScope();
resultType = result.getType();
if (resultType == null) {
resultType = new BaseType(TypeEnum.VOID);
}
if (!resultType.equals(methodNode.getType())) {
errors.add(new TypeMismatchException("Method-Declaration " + methodNode.getIdentifier() + " with type "
+ methodNode.getType() + " has at least one Mismatching return Type:"));
valid = false;
}
return new TypeCheckResult(valid, resultType);
}
} }
@Override @Override
@ -151,80 +173,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
return new TypeCheckResult(true, null); return new TypeCheckResult(true, null);
} }
@Override
public TypeCheckResult analyze(AssignmentStatementNode assignmentStatementNode) {
boolean valid = true;
ExpressionNode expressionNodeLeft = assignmentStatementNode.expressionLeft;
var resultLeft = expressionNodeLeft.accept(this);
valid = valid && resultLeft.isValid();
ExpressionNode expressionNodeRight = assignmentStatementNode.expressionRight;
var resultRight = expressionNodeRight.accept(this);
valid = valid && resultRight.isValid();
if(Objects.equals(resultLeft.getType(), resultRight.getType())){
System.out.println("SAME TYPE");
} else {
errors.add(new TypeMismatchException("Type mismatch"));
valid = false;
}
return new TypeCheckResult(valid, null);
}
@Override
public TypeCheckResult analyze(BinaryExpressionNode toCheck) {
boolean valid = true;
ExpressionNode left = toCheck.left;
var resultLeft = left.accept(this);
ExpressionNode right = toCheck.right;
var resultRight = right.accept(this);
switch (toCheck.operator) {
case ASSIGNMENT:
if(Objects.equals(resultRight.getType(), resultLeft.getType())){
System.out.println("Correct Type");
} else {
valid = false;
errors.add(new TypeMismatchException("Type Mismatch " + resultLeft.getType() + " and " + resultRight.getType()));
}
break;
case DOT:
return new TypeCheckResult(true, resultRight.getType());
default:
throw new RuntimeException("Unexpected operator: " + toCheck.operator);
}
return new TypeCheckResult(valid, null);
}
@Override
public TypeCheckResult analyze(IdentifierExpressionNode toCheck) {
if(toCheck.name == "this"){
return new TypeCheckResult(true, null);
} else if (currentFields.get(toCheck.name) == null) {
errors.add(new AlreadyDeclearedException("Not declared " + toCheck.name + " in this scope"));
return new TypeCheckResult(false, null);
} else {
return new TypeCheckResult(false, currentFields.get(toCheck.name));
}
}
@Override
public TypeCheckResult analyze(UnaryExpressionNode toCheck) {
return null;
}
@Override
public TypeCheckResult analyze(VariableDeclarationStatementNode toCheck) {
if (currentScope.contains(toCheck.identifier)) {
errors.add(new AlreadyDeclearedException("Already declared " + toCheck.identifier + " in this scope"));
return new TypeCheckResult(false, null);
} else {
currentScope.addLocalVar(toCheck.identifier, toCheck.type);
}
return new TypeCheckResult(true, null);
}
@Override @Override
public TypeCheckResult analyze(IfStatementNode toCheck) { public TypeCheckResult analyze(IfStatementNode toCheck) {
return null; return null;
@ -232,7 +180,9 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override @Override
public TypeCheckResult analyze(ReturnStatementNode toCheck) { public TypeCheckResult analyze(ReturnStatementNode toCheck) {
return null;
var result = toCheck.expression.accept(this);
return new TypeCheckResult(true, result.getType());
} }
@Override @Override
@ -241,39 +191,175 @@ public class SemanticAnalyzer implements SemanticVisitor {
} }
@Override @Override
public TypeCheckResult analyze(LiteralNode toCheck) { public TypeCheckResult analyze(ParameterNode toCheck) {
return new TypeCheckResult(true, toCheck.getType());
return new TypeCheckResult(true, null);
} }
@Override @Override
public TypeCheckResult analyze(InstVar toCheck) { public TypeCheckResult analyze(BlockNode blockNode) {
boolean valid = true; ITypeNode blockReturnType = null;
for (IStatementNode statementNode : blockNode.statements) {
var result = toCheck.expression.accept(this); var result = statementNode.accept(this);
if(result.getType() != null){
if(result.getType() instanceof BaseTypeNode){ if(blockReturnType == null){
throw new RuntimeException("BaseType has no Methods or Fields"); blockReturnType = result.getType();
} else { } else {
//Get typ of Field errors.add(new MultipleReturnTypes("There are multiple Return types"));
}
var type = (ReferenceTypeNode)result.getType();
var classContext = context.getClass(type.getIdentifier());
if(classContext == null){
errors.add(new NotDeclearedException("Not declared " + type.getIdentifier() + " in this scope"));
return new TypeCheckResult(false, null);
} else {
var field = classContext.getField(toCheck.identifier);
return new TypeCheckResult(valid, field.getType());
} }
} }
return new TypeCheckResult(true, blockReturnType);
}
@Override
public TypeCheckResult analyze(AssignableExpressionNode toCheck) {
return new TypeCheckResult(true, currentFields.get(toCheck.identifier));
} }
@Override @Override
public TypeCheckResult analyze(This toCheck) { public TypeCheckResult analyze(ElseStatementNode toCheck) {
return new TypeCheckResult(true, toCheck.getType()); return null;
}
@Override
public TypeCheckResult analyze(ForStatementNode toCheck) {
return null;
}
@Override
public TypeCheckResult analyze(AssignStatementExpressionNode toCheck) {
AssignableExpressionNode assignable = toCheck.assignable;
var oldNullType = currentNullType;
currentNullType = currentFields.get(toCheck.assignable.identifier);
IExpressionNode rExpression = toCheck.expression;
currentNullType = oldNullType;
var valid = true;
// This check currently handles things like :
/**
* private int i;
* void foo(int i){
* i = i;
* }
*/
if (assignable.equals(rExpression)) {
errors.add(new TypeMismatchException("Cannot assign to self"));
valid = false;
}
var lResult = assignable.accept(this);
currentNullType = lResult.getType();
var rResult = rExpression.accept(this);
if (!Objects.equals(currentScope.getLocalVar(toCheck.assignable.identifier), rExpression.getType())) {
errors.add(new TypeMismatchException(
"Mismatch types in Assign-Statement: cannot convert from \"" + lResult.getType() + "\" to \""
+ rResult.getType() + "\""));
valid = false;
}
// else {
// toCheck.setType(assignable.getType());
// }
valid = valid && lResult.isValid() && rResult.isValid();
currentNullType = null;
return new TypeCheckResult(valid, null); // return type is null to get the return type sufficently
}
@Override
public TypeCheckResult analyze(DecrementExpressionNode toCheck) {
return null;
}
@Override
public TypeCheckResult analyze(IfElseStatementNode toCheck) {
return null;
}
@Override
public TypeCheckResult analyze(MethodCallStatementExpressionNode toCheck) {
return null;
}
@Override
public TypeCheckResult analyze(LocalVariableDeclarationNode localVarDecl) {
var valid = true;
if (localVarDecl.expression != null) {
TypeCheckResult result = localVarDecl.expression.accept(this);
var resultType = localVarDecl.expression.getType();
valid = result.isValid() && valid;
if (!Objects.equals(resultType, localVarDecl.type)) {
errors.add(new TypeMismatchException(
"Type mismatch: cannot convert from " + resultType + " to " + localVarDecl.type));
valid = false;
}
}
try {
currentScope.addLocalVar(localVarDecl.identifier, localVarDecl.type);
} catch (AlreadyDefinedException e) {
errors.add(new AlreadyDefinedException(e.getMessage()));
valid = false;
}
return new TypeCheckResult(valid, null);
}
@Override
public TypeCheckResult analyze(NewDeclarationStatementExpressionNode toCheck) {
return null;
}
@Override
public TypeCheckResult analyze(IncrementExpressionNode toCheck) {
return null;
}
@Override
public TypeCheckResult analyze(BinaryExpressionNode toCheck) {
return null;
}
@Override
public TypeCheckResult analyze(CalculationExpressionNode calcNode) {
if (calcNode.calculationExpression != null) {
calcNode.calculationExpression.accept(this);
}
return null;
}
@Override
public TypeCheckResult analyze(DotExpressionNode toCheck) {
return null;
}
@Override
public TypeCheckResult analyze(DotSubstractionExpressionNode toCheck) {
return null;
}
@Override
public TypeCheckResult analyze(NonCalculationExpressionNode toCheck) {
return null;
}
@Override
public TypeCheckResult analyze(UnaryExpressionNode unary) {
var valid = true;
if (currentScope.contains(unary.identifier)) {
return new TypeCheckResult(valid, currentScope.getLocalVar(unary.identifier));
} else if(currentFields.get(unary.identifier) != null) {
return new TypeCheckResult(valid, currentFields.get(unary.identifier));
} else {
errors.add(new NotDeclearedException("Var is not Decleared"));
}
return new TypeCheckResult(valid, null);
} }
} }

View File

@ -1,18 +1,20 @@
package semantic; package semantic;
import ast.ClassNode; import ast.*;
import ast.expressions.LiteralNode; import ast.block.BlockNode;
import ast.ProgramNode; import ast.expression.binaryexpression.*;
import ast.expressions.BinaryExpressionNode; import ast.expression.unaryexpression.UnaryExpressionNode;
import ast.expressions.IdentifierExpressionNode; import ast.member.*;
import ast.expressions.InstVar; import ast.parameter.ParameterNode;
import ast.expressions.UnaryExpressionNode; import ast.statement.*;
import ast.members.FieldNode; import ast.statement.ifstatement.*;
import ast.members.MethodNode; import ast.statement.statementexpression.AssignStatementExpressionNode;
import ast.statements.*; import ast.statement.statementexpression.AssignableExpressionNode;
import ast.expressions.This; import ast.statement.statementexpression.NewDeclarationStatementExpressionNode;
import ast.statements.IfStatementNode; import ast.statement.statementexpression.crementExpression.DecrementExpressionNode;
import ast.statement.statementexpression.crementExpression.IncrementExpressionNode;
import ast.statement.statementexpression.methodcallstatementnexpression.MethodCallStatementExpressionNode;
import typechecker.TypeCheckResult; import typechecker.TypeCheckResult;
public interface SemanticVisitor { public interface SemanticVisitor {
@ -25,25 +27,46 @@ public interface SemanticVisitor {
TypeCheckResult analyze(FieldNode toCheck); TypeCheckResult analyze(FieldNode toCheck);
TypeCheckResult analyze(AssignmentStatementNode toCheck);
TypeCheckResult analyze(BinaryExpressionNode toCheck);
TypeCheckResult analyze(IdentifierExpressionNode toCheck);
TypeCheckResult analyze(UnaryExpressionNode toCheck);
TypeCheckResult analyze(VariableDeclarationStatementNode toCheck);
TypeCheckResult analyze(IfStatementNode toCheck); TypeCheckResult analyze(IfStatementNode toCheck);
TypeCheckResult analyze(ReturnStatementNode toCheck); TypeCheckResult analyze(ReturnStatementNode toCheck);
TypeCheckResult analyze(WhileStatementNode toCheck); TypeCheckResult analyze(WhileStatementNode toCheck);
TypeCheckResult analyze(LiteralNode toCheck); TypeCheckResult analyze(ParameterNode toCheck);
TypeCheckResult analyze(InstVar toCheck); TypeCheckResult analyze(BlockNode toCheck);
TypeCheckResult analyze(AssignableExpressionNode toCheck);
TypeCheckResult analyze(ElseStatementNode toCheck);
TypeCheckResult analyze(ForStatementNode toCheck);
TypeCheckResult analyze(AssignStatementExpressionNode toCheck);
TypeCheckResult analyze(DecrementExpressionNode toCheck);
TypeCheckResult analyze(IfElseStatementNode toCheck);
TypeCheckResult analyze(MethodCallStatementExpressionNode toCheck);
TypeCheckResult analyze(LocalVariableDeclarationNode toCheck);
TypeCheckResult analyze(NewDeclarationStatementExpressionNode toCheck);
TypeCheckResult analyze(IncrementExpressionNode toCheck);
TypeCheckResult analyze(BinaryExpressionNode toCheck);
TypeCheckResult analyze(CalculationExpressionNode toCheck);
TypeCheckResult analyze(DotExpressionNode toCheck);
TypeCheckResult analyze(DotSubstractionExpressionNode toCheck);
TypeCheckResult analyze(NonCalculationExpressionNode toCheck);
TypeCheckResult analyze(UnaryExpressionNode toCheck);
TypeCheckResult analyze(This toCheck);
} }

View File

@ -1,7 +1,7 @@
package semantic.context; package semantic.context;
import oldAst.ClassNode; import ast.ClassNode;
import oldAst.member.FieldNode; import ast.member.FieldNode;
import java.util.HashMap; import java.util.HashMap;
public class ClassContext { public class ClassContext {

View File

@ -1,6 +1,6 @@
package semantic.context; package semantic.context;
import oldAst.ProgramNode; import ast.ProgramNode;
import java.util.HashMap; import java.util.HashMap;
public class Context { public class Context {

View File

@ -1,20 +1,20 @@
package semantic.context; package semantic.context;
import oldAst.member.FieldNode; import ast.member.FieldNode;
import oldAst.type.AccessTypeNode; import ast.type.*;
import oldAst.type.TypeNode; import ast.type.type.*;
public class FieldContext { public class FieldContext {
private AccessTypeNode accessModifier; private AccessModifierNode accessModifier;
private TypeNode type; private ITypeNode type;
public FieldContext(FieldNode field) { public FieldContext(FieldNode field) {
accessModifier = field.accessTypeNode; accessModifier = field.accessTypeNode;
type = field.type; type = field.type;
} }
public TypeNode getType() { public ITypeNode getType() {
return type; return type;
} }

View File

@ -0,0 +1,9 @@
package semantic.exeptions;
public class AlreadyDefinedException extends RuntimeException {
public AlreadyDefinedException(String message) {
super(message);
}
}

View File

@ -0,0 +1,9 @@
package semantic.exeptions;
public class MultipleReturnTypes extends RuntimeException {
public MultipleReturnTypes(String message) {
super(message);
}
}

View File

@ -1,14 +1,14 @@
package typechecker; package typechecker;
import oldAst.type.TypeNode; import ast.type.type.ITypeNode;
public class TypeCheckResult { public class TypeCheckResult {
private boolean valid; private boolean valid;
private TypeNode type; private ITypeNode type;
public TypeCheckResult(boolean valid, TypeNode type) { public TypeCheckResult(boolean valid, ITypeNode type) {
this.valid = valid; this.valid = valid;
this.type = type; this.type = type;
} }
@ -17,7 +17,7 @@ public class TypeCheckResult {
return valid; return valid;
} }
public TypeNode getType() { public ITypeNode getType() {
return type; return type;
} }
} }

View File

@ -11,8 +11,7 @@ public class Example {
public class Test { public class Test {
public static int testMethod(char x, int a){ public static int testMethod(char x, int a){
x = x + a;
return x;
} }
} }

View File

@ -0,0 +1,257 @@
package semantic;
import ast.ASTNode;
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.BeforeEach;
import org.junit.jupiter.api.Test;
import parser.astBuilder.ASTBuilder;
import parser.generated.SimpleJavaLexer;
import parser.generated.SimpleJavaParser;
import semantic.exeptions.AlreadyDeclearedException;
import semantic.exeptions.MultipleReturnTypes;
import semantic.exeptions.NotDeclearedException;
import semantic.exeptions.TypeMismatchException;
import java.io.IOException;
import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.*;
public class EndToTAST {
@BeforeEach
public void setup(){
SemanticAnalyzer.clearAnalyzer();
}
@Test
public void CorrectTest(){
CharStream codeCharStream = null;
try {
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/CorrectTest.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);
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
assertEquals(SemanticAnalyzer.errors.size(), 0);
assertNotNull(tast);
}
@Test
public void notDecleared() {
CharStream codeCharStream = null;
try {
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/NotDecleared.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);
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertInstanceOf(NotDeclearedException.class, SemanticAnalyzer.errors.getFirst());
}
@Test
public void typeMismatch(){
CharStream codeCharStream = null;
try {
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/TypeMismatchIntBool.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();
ASTBuilder astBuilder = new ASTBuilder();
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertInstanceOf(TypeMismatchException.class, SemanticAnalyzer.errors.getFirst());
}
@Test
public void parameterAlreadyDecleared(){
CharStream codeCharStream = null;
try {
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/ParameterAlreadyDecleared.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();
ASTBuilder astBuilder = new ASTBuilder();
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertInstanceOf(AlreadyDeclearedException.class, SemanticAnalyzer.errors.getFirst());
}
@Test
public void fieldAlreadyDecleared(){
CharStream codeCharStream = null;
try {
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/FieldAlreadyDecleared.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();
ASTBuilder astBuilder = new ASTBuilder();
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertInstanceOf(AlreadyDeclearedException.class, SemanticAnalyzer.errors.getFirst());
}
@Test
public void typeMismatchRefType(){
CharStream codeCharStream = null;
try {
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/TypeMismatchRefType.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();
ASTBuilder astBuilder = new ASTBuilder();
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertInstanceOf(TypeMismatchException.class, SemanticAnalyzer.errors.getFirst());
}
@Test
public void correctRetType(){
CharStream codeCharStream = null;
try {
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/CorrectRetType.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();
ASTBuilder astBuilder = new ASTBuilder();
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
assertTrue(SemanticAnalyzer.errors.isEmpty());
}
@Test
public void retTypeMismatch(){
CharStream codeCharStream = null;
try {
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/retTypeMismatch.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();
ASTBuilder astBuilder = new ASTBuilder();
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertInstanceOf(TypeMismatchException.class, SemanticAnalyzer.errors.getFirst());
}
@Test
public void multipleRetType(){
CharStream codeCharStream = null;
try {
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/MultipleRetTypes.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();
ASTBuilder astBuilder = new ASTBuilder();
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
assertFalse(SemanticAnalyzer.errors.isEmpty());
assertInstanceOf(MultipleReturnTypes.class, SemanticAnalyzer.errors.getFirst());
}
}

View File

@ -1,76 +1,103 @@
package semantic; package semantic;
import oldAst.ClassNode; import ast.*;
import oldAst.expression.LiteralNode; import ast.block.BlockNode;
import oldAst.ProgramNode; import ast.member.FieldNode;
import oldAst.expression.*; import ast.member.MethodNode;
import oldAst.member.FieldNode; import ast.parameter.ParameterNode;
import oldAst.member.MemberNode; import ast.type.AccessModifierNode;
import oldAst.member.MethodNode; import ast.type.type.*;
import oldAst.parameter.ParameterListNode;
import oldAst.parameter.ParameterNode;
import oldAst.statement.AssignmentStatementNode;
import oldAst.statement.StatementNode;
import oldAst.type.*;
import java.util.ArrayList;
import java.util.List;
public class Mocker { public class Mocker {
public static ProgramNode mockCorrectProgrammNode(){ public static ASTNode mockTwoSameFields(){
ProgramNode p = new ProgramNode();
ProgramNode programNode = new ProgramNode(); ClassNode c = new ClassNode();
List<ClassNode> classList = new ArrayList<ClassNode>(); c.identifier = "testClass";
AccessTypeNode accessTypeNode = new AccessTypeNode(EnumAccessTypeNode.PUBLIC);
ClassNode classNode = new ClassNode(accessTypeNode, "testClass");
MemberNode memberNode1 = new FieldNode(accessTypeNode, new BaseTypeNode(EnumTypeNode.INT), "testVar1"); FieldNode f1 = new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a");
classNode.members.add(memberNode1);
MemberNode memberNode2 = new FieldNode(accessTypeNode, new BaseTypeNode(EnumTypeNode.INT), "objectVar"); c.members.add(f1);
classNode.members.add(memberNode2);
List<ParameterNode> parameterNodeList = new ArrayList<ParameterNode>(); FieldNode f2 = new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a");
ParameterNode parameterNode1 = new ParameterNode(new BaseTypeNode(EnumTypeNode.INT), "param1");
parameterNodeList.add(parameterNode1);
ParameterListNode parameterListNode = new ParameterListNode(parameterNodeList);
List<StatementNode> statementNodeList = new ArrayList<StatementNode>(); c.members.add(f2);
ExpressionNode expressionNodeLeft = new InstVar(new This("testClass"), "objectVar");
LiteralNode expressionNodeRight = new LiteralNode();
expressionNodeRight.setType(new BaseTypeNode(EnumTypeNode.INT));
StatementNode statementNode1 = new AssignmentStatementNode(expressionNodeLeft, expressionNodeRight);
statementNodeList.add(statementNode1);
MemberNode memberNode3 = new MethodNode(accessTypeNode, new BaseTypeNode(EnumTypeNode.INT), "testVar2",parameterListNode, statementNodeList );
classNode.members.add(memberNode3);
classList.add(classNode);
programNode.classes = classList;
return programNode;
p.classes.add(c);
return p;
} }
public static ProgramNode mockFieldNodeAlreadyDeclaredProgrammNode(){ public static ASTNode mockSimpleMethod(){
ProgramNode programNode = new ProgramNode(); ProgramNode p = new ProgramNode();
List<ClassNode> classList = new ArrayList<ClassNode>();
AccessTypeNode accessTypeNode = new AccessTypeNode(EnumAccessTypeNode.PUBLIC);
ClassNode classNode = new ClassNode(accessTypeNode, "testClass");
MemberNode memberNode1 = new FieldNode(accessTypeNode, new BaseTypeNode(EnumTypeNode.INT), "testVar"); ClassNode c = new ClassNode();
classNode.members.add(memberNode1);
MemberNode memberNode2 = new FieldNode(accessTypeNode, new BaseTypeNode(EnumTypeNode.INT), "testVar"); MethodNode methodNode = new MethodNode();
classNode.members.add(memberNode2);
classList.add(classNode); //Parameter
programNode.classes = classList; ParameterNode parameterNode = new ParameterNode(new BaseType(TypeEnum.INT), "a");
return programNode; methodNode.addParameter(parameterNode);
//Statements
//Block
methodNode.block = new BlockNode();
c.members.add(methodNode);
p.classes.add(c);
return p;
} }
public static ASTNode mockTwoSameMethods(){
ProgramNode p = new ProgramNode();
ClassNode c = new ClassNode();
MethodNode methodNode = new MethodNode();
methodNode.block = new BlockNode();
methodNode.setType(new BaseType(TypeEnum.INT));
methodNode.setIdentifier("testMethod");
c.members.add(methodNode);
MethodNode methodNode1 = new MethodNode();
methodNode1.block = new BlockNode();
methodNode1.setType(new BaseType(TypeEnum.INT));
methodNode1.setIdentifier("testMethod");
c.members.add(methodNode1);
p.classes.add(c);
return p;
}
public static ASTNode mockTwoDifferentMethods(){
ProgramNode p = new ProgramNode();
ClassNode c = new ClassNode();
MethodNode methodNode = new MethodNode();
methodNode.block = new BlockNode();
methodNode.setIdentifier("testMethod");
c.members.add(methodNode);
MethodNode methodNode1 = new MethodNode();
methodNode1.block = new BlockNode();
methodNode1.setIdentifier("testMethod1");
c.members.add(methodNode1);
p.classes.add(c);
return p;
}
} }

View File

@ -1,162 +1,63 @@
package semantic; package semantic;
import ast.ASTNode;
import oldAst.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import semantic.exeptions.AlreadyDeclearedException; import semantic.exeptions.AlreadyDeclearedException;
import semantic.exeptions.TypeMismatchException;
import java.io.File; import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SemanticTest { public class SemanticTest {
@BeforeEach
public void init() {
SemanticAnalyzer.clearAnalyzier();
}
@Test @Test
public void alreadyDeclaredLocalFieldVar() { public void twoFieldsSameName() {
//Arrange ASTNode ast = Mocker.mockTwoSameFields();
ProgramNode programNode = Mocker.mockFieldNodeAlreadyDeclaredProgrammNode(); SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer();
ASTNode tast = semanticAnalyzer.generateTast(ast);
//Act assertEquals(semanticAnalyzer.errors.size(), 1);
assertInstanceOf(AlreadyDeclearedException.class, semanticAnalyzer.errors.getFirst());
ASTNode typedAst = SemanticAnalyzer.generateTast(programNode); assertNull(tast);
//Assert
assertEquals(1, SemanticAnalyzer.errors.size());
assertEquals(true, SemanticAnalyzer.errors.get(0) instanceof AlreadyDeclearedException);
assertEquals(null, typedAst);
} }
@Test @Test
public void alreadyDecleared() { public void simpleMethod(){
//Arrange ASTNode ast = Mocker.mockSimpleMethod();
ProgramNode programNode = Mocker.mockFieldNodeAlreadyDeclaredProgrammNode(); SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer();
ASTNode tast = semanticAnalyzer.generateTast(ast);
//Act assertEquals(semanticAnalyzer.errors.size(), 0);
assertNotNull(tast);
ASTNode typedAst = SemanticAnalyzer.generateTast(programNode);
//Assert
assertEquals(1, SemanticAnalyzer.errors.size());
assertInstanceOf(AlreadyDeclearedException.class, SemanticAnalyzer.errors.getFirst());
assertNull(typedAst);
} }
@Test @Test
public void shouldWorkWithNoError() { public void twoSameMethods(){
ASTNode ast = Mocker.mockTwoSameMethods();
//Arrange SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer();
ASTNode tast = semanticAnalyzer.generateTast(ast);
ProgramNode programNode = Mocker.mockCorrectProgrammNode();
//Act
ASTNode typedAst = SemanticAnalyzer.generateTast(programNode);
//Assert
assertEquals(0, SemanticAnalyzer.errors.size());
assertEquals(programNode, typedAst);
assertEquals(1, semanticAnalyzer.errors.size());
assertInstanceOf(AlreadyDeclearedException.class, semanticAnalyzer.errors.getFirst());
assertNull(tast);
} }
@Test @Test
public void refTypeCorrect() { public void twoDifferentMethods(){
ASTNode ast = Mocker.mockTwoDifferentMethods();
//Arrange SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer();
ASTNode tast = semanticAnalyzer.generateTast(ast);
ObjectMapper objectMapper = new ObjectMapper();
ProgramNode programNode = null;
try{
programNode = objectMapper.readValue(new File("src/test/resources/semantic/correctRefType.json"), ProgramNode.class);
} catch (Exception e) {
e.printStackTrace();
}
//Act
ASTNode typedAst = SemanticAnalyzer.generateTast(programNode);
//Assert
assertEquals(0, SemanticAnalyzer.errors.size());
assertEquals(programNode, typedAst);
}
@Test
public void jsonWriteTest() {
ObjectMapper objectMapper = new ObjectMapper();
//Arrange
ProgramNode programNode = Mocker.mockCorrectProgrammNode();
try{
objectMapper.writeValue(new File("src/test/resources/semantic/test.json"), programNode);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void jsonReadTest() {
ObjectMapper objectMapper = new ObjectMapper();
ProgramNode programNode1 = null;
try{
programNode1 = objectMapper.readValue(new File("src/test/resources/semantic/test.json"), ProgramNode.class);
} catch (Exception e) {
e.printStackTrace();
}
ProgramNode programNode2 = Mocker.mockCorrectProgrammNode();
}
@Test
public void typeMismatch() {
//Arrange
ObjectMapper objectMapper = new ObjectMapper();
ProgramNode programNode = null;
try{
programNode = objectMapper.readValue(new File("src/test/resources/semantic/refTypeMismatch.json"), ProgramNode.class);
} catch (Exception e) {
e.printStackTrace();
}
//Act
ASTNode typedAst = SemanticAnalyzer.generateTast(programNode);
//Assert
assertEquals(1, SemanticAnalyzer.errors.size());
assertInstanceOf(TypeMismatchException.class, SemanticAnalyzer.errors.getFirst());
assertNull(typedAst);
assertEquals(semanticAnalyzer.errors.size(), 0);
assertNotNull(tast);
} }
} }

View File

@ -0,0 +1,7 @@
public class Example {
public static int testMethod(int x){
return x;
}
}

View File

@ -0,0 +1,11 @@
public class Example {
public int a;
public static int testMethod(int b){
a = b;
return a;
}
}

View File

@ -0,0 +1,10 @@
public class Example {
public int a;
public int a;
public static int testMethod(char a){
}
}

View File

@ -0,0 +1,8 @@
public class Example {
public static int testMethod(int x, char c){
return x;
return c;
}
}

View File

@ -0,0 +1,6 @@
public class Test {
public static int testMethod(int x){
int a = b;
return x;
}
}

View File

@ -0,0 +1,7 @@
public class Example {
public static int testMethod(char a, int a){
}
}

View File

@ -0,0 +1,10 @@
public class Test {
public boolean b;
public static int testMethod(int a){
b = a;
}
}

View File

@ -0,0 +1,16 @@
public class Test {
public static int testMethod(ExampleA exampleA, ExampleB exampleB){
exampleA = exampleB;
}
}
public class ExampleA{
public int a;
}
public class ExampleB{
public int a;
}

View File

@ -0,0 +1,7 @@
public class Example {
public static int testMethod(char x){
return x;
}
}