├── Phase 2 ├── src │ └── main │ │ ├── ast │ │ ├── type │ │ │ ├── Type.java │ │ │ ├── complexType │ │ │ │ ├── CandleType.java │ │ │ │ ├── OrderType.java │ │ │ │ ├── TradeType.java │ │ │ │ └── ExceptionType.java │ │ │ └── primitiveType │ │ │ │ ├── BoolType.java │ │ │ │ ├── IntType.java │ │ │ │ ├── VoidType.java │ │ │ │ ├── DoubleType.java │ │ │ │ ├── FloatType.java │ │ │ │ └── StringType.java │ │ └── node │ │ │ ├── declaration │ │ │ ├── Declaration.java │ │ │ ├── OnInitDeclaration.java │ │ │ ├── OnStartDeclaration.java │ │ │ ├── MainDeclaration.java │ │ │ ├── VarDeclaration.java │ │ │ ├── GlobalVarDeclaration.java │ │ │ └── FunctionDeclaration.java │ │ │ ├── expression │ │ │ ├── operators │ │ │ │ ├── UnaryOperator.java │ │ │ │ └── BinaryOperator.java │ │ │ ├── values │ │ │ │ ├── Value.java │ │ │ │ ├── FloatValue.java │ │ │ │ ├── BoolValue.java │ │ │ │ ├── IntValue.java │ │ │ │ ├── StringValue.java │ │ │ │ └── TradeValue.java │ │ │ ├── Expression.java │ │ │ ├── Identifier.java │ │ │ ├── ArrayIdentifier.java │ │ │ ├── VarAccess.java │ │ │ ├── FunctionCall.java │ │ │ ├── UnaryExpression.java │ │ │ ├── BinaryExpression.java │ │ │ └── MethodCall.java │ │ │ ├── statement │ │ │ ├── Statement.java │ │ │ ├── ContinueBreakStmt.java │ │ │ ├── ExpressionStmt.java │ │ │ ├── ReturnStmt.java │ │ │ ├── ThrowStmt.java │ │ │ ├── AssignStmt.java │ │ │ ├── WhileStmt.java │ │ │ ├── TryCatchStmt.java │ │ │ ├── IfElseStmt.java │ │ │ └── ForStmt.java │ │ │ ├── Node.java │ │ │ └── Program.java │ │ ├── compileError │ │ ├── CompileError.java │ │ └── name │ │ │ ├── MethodRedefinition.java │ │ │ ├── VariableRedefinition.java │ │ │ ├── IrregularDefenition.java │ │ │ ├── GlobalVariableRedefinition.java │ │ │ ├── PrimitiveFunctionRedefinition.java │ │ │ └── FunctionVariableConflict.java │ │ ├── symbolTable │ │ ├── itemException │ │ │ ├── ItemAlreadyExistsException.java │ │ │ └── ItemNotFoundException.java │ │ ├── symbolTableItems │ │ │ ├── SymbolTableItem.java │ │ │ ├── MainItem.java │ │ │ ├── VariableItem.java │ │ │ ├── OnInitItem.java │ │ │ ├── OnStartItem.java │ │ │ └── FunctionItem.java │ │ ├── Stack.java │ │ └── SymbolTable.java │ │ ├── UTL.java │ │ ├── visitor │ │ ├── IVisitor.java │ │ └── Visitor.java │ │ └── grammar │ │ └── .antlr │ │ ├── UTL.tokens │ │ └── UTLLexer.tokens └── description │ └── PLC_Phase2.pdf ├── Phase 3 ├── src │ ├── main │ │ ├── ast │ │ │ ├── type │ │ │ │ ├── Type.java │ │ │ │ ├── complexType │ │ │ │ │ ├── CandleType.java │ │ │ │ │ ├── OrderType.java │ │ │ │ │ ├── TradeType.java │ │ │ │ │ └── ExceptionType.java │ │ │ │ ├── primitiveType │ │ │ │ │ ├── BoolType.java │ │ │ │ │ ├── IntType.java │ │ │ │ │ ├── VoidType.java │ │ │ │ │ ├── FloatType.java │ │ │ │ │ └── StringType.java │ │ │ │ └── NoType.java │ │ │ └── node │ │ │ │ ├── statement │ │ │ │ ├── Statement.java │ │ │ │ ├── ContinueBreakStmt.java │ │ │ │ ├── ExpressionStmt.java │ │ │ │ ├── ReturnStmt.java │ │ │ │ ├── ThrowStmt.java │ │ │ │ ├── AssignStmt.java │ │ │ │ ├── WhileStmt.java │ │ │ │ ├── TryCatchStmt.java │ │ │ │ ├── IfElseStmt.java │ │ │ │ └── ForStmt.java │ │ │ │ ├── declaration │ │ │ │ ├── Declaration.java │ │ │ │ ├── MainDeclaration.java │ │ │ │ ├── OnInitDeclaration.java │ │ │ │ ├── OnStartDeclaration.java │ │ │ │ ├── VarDeclaration.java │ │ │ │ └── FunctionDeclaration.java │ │ │ │ ├── expression │ │ │ │ ├── operators │ │ │ │ │ ├── UnaryOperator.java │ │ │ │ │ └── BinaryOperator.java │ │ │ │ ├── values │ │ │ │ │ ├── Value.java │ │ │ │ │ ├── BoolValue.java │ │ │ │ │ ├── FloatValue.java │ │ │ │ │ ├── IntValue.java │ │ │ │ │ ├── StringValue.java │ │ │ │ │ └── TradeValue.java │ │ │ │ ├── Expression.java │ │ │ │ ├── Identifier.java │ │ │ │ ├── ArrayIdentifier.java │ │ │ │ ├── VarAccess.java │ │ │ │ ├── FunctionCall.java │ │ │ │ ├── UnaryExpression.java │ │ │ │ ├── MethodCall.java │ │ │ │ └── BinaryExpression.java │ │ │ │ ├── Node.java │ │ │ │ └── Program.java │ │ ├── compileError │ │ │ ├── CompileError.java │ │ │ ├── type │ │ │ │ ├── ConditionTypeNotBool.java │ │ │ │ └── UnsupportedOperandType.java │ │ │ └── name │ │ │ │ ├── MethodRedefinition.java │ │ │ │ ├── VariableRedefinition.java │ │ │ │ ├── GlobalVariableRedefinition.java │ │ │ │ ├── PrimitiveFunctionRedefinition.java │ │ │ │ └── FunctionVariableConflict.java │ │ ├── symbolTable │ │ │ ├── itemException │ │ │ │ ├── ItemAlreadyExistsException.java │ │ │ │ └── ItemNotFoundException.java │ │ │ ├── symbolTableItems │ │ │ │ ├── SymbolTableItem.java │ │ │ │ ├── MainItem.java │ │ │ │ ├── OnInitItem.java │ │ │ │ ├── VariableItem.java │ │ │ │ ├── OnStartItem.java │ │ │ │ └── FunctionItem.java │ │ │ ├── Stack.java │ │ │ └── SymbolTable.java │ │ ├── UTL.java │ │ └── visitor │ │ │ ├── IVisitor.java │ │ │ ├── Visitor.java │ │ │ └── nameAnalyzer │ │ │ └── NameAnalyzer.java │ └── parsers │ │ ├── UTL.tokens │ │ └── UTLLexer.tokens └── description │ └── PLC_Phase3.pdf ├── Phase 4 ├── src │ ├── main │ │ ├── ast │ │ │ ├── type │ │ │ │ ├── Type.java │ │ │ │ ├── complexType │ │ │ │ │ ├── CandleType.java │ │ │ │ │ ├── OrderType.java │ │ │ │ │ ├── TradeType.java │ │ │ │ │ └── ExceptionType.java │ │ │ │ ├── primitiveType │ │ │ │ │ ├── BoolType.java │ │ │ │ │ ├── IntType.java │ │ │ │ │ ├── NullType.java │ │ │ │ │ ├── VoidType.java │ │ │ │ │ ├── FloatType.java │ │ │ │ │ └── StringType.java │ │ │ │ └── NoType.java │ │ │ └── node │ │ │ │ ├── statement │ │ │ │ ├── Statement.java │ │ │ │ ├── ContinueBreakStmt.java │ │ │ │ ├── ExpressionStmt.java │ │ │ │ ├── ReturnStmt.java │ │ │ │ ├── ThrowStmt.java │ │ │ │ ├── AssignStmt.java │ │ │ │ ├── WhileStmt.java │ │ │ │ ├── TryCatchStmt.java │ │ │ │ ├── IfElseStmt.java │ │ │ │ └── ForStmt.java │ │ │ │ ├── declaration │ │ │ │ ├── Declaration.java │ │ │ │ ├── MainDeclaration.java │ │ │ │ ├── OnInitDeclaration.java │ │ │ │ ├── OnStartDeclaration.java │ │ │ │ ├── VarDeclaration.java │ │ │ │ └── FunctionDeclaration.java │ │ │ │ ├── expression │ │ │ │ ├── operators │ │ │ │ │ ├── UnaryOperator.java │ │ │ │ │ └── BinaryOperator.java │ │ │ │ ├── values │ │ │ │ │ ├── Value.java │ │ │ │ │ ├── NullValue.java │ │ │ │ │ ├── BoolValue.java │ │ │ │ │ ├── FloatValue.java │ │ │ │ │ ├── IntValue.java │ │ │ │ │ ├── StringValue.java │ │ │ │ │ └── TradeValue.java │ │ │ │ ├── Expression.java │ │ │ │ ├── Identifier.java │ │ │ │ ├── ArrayIdentifier.java │ │ │ │ ├── VarAccess.java │ │ │ │ ├── FunctionCall.java │ │ │ │ ├── UnaryExpression.java │ │ │ │ ├── MethodCall.java │ │ │ │ └── BinaryExpression.java │ │ │ │ ├── Node.java │ │ │ │ └── Program.java │ │ ├── compileError │ │ │ ├── CompileError.java │ │ │ ├── type │ │ │ │ ├── ConditionTypeNotBool.java │ │ │ │ └── UnsupportedOperandType.java │ │ │ └── name │ │ │ │ ├── MethodRedefinition.java │ │ │ │ ├── VariableRedefinition.java │ │ │ │ ├── GlobalVariableRedefinition.java │ │ │ │ ├── PrimitiveFunctionRedefinition.java │ │ │ │ └── FunctionVariableConflict.java │ │ ├── symbolTable │ │ │ ├── itemException │ │ │ │ ├── ItemAlreadyExistsException.java │ │ │ │ └── ItemNotFoundException.java │ │ │ ├── symbolTableItems │ │ │ │ ├── SymbolTableItem.java │ │ │ │ ├── MainItem.java │ │ │ │ ├── OnInitItem.java │ │ │ │ ├── VariableItem.java │ │ │ │ ├── OnStartItem.java │ │ │ │ └── FunctionItem.java │ │ │ ├── Stack.java │ │ │ └── SymbolTable.java │ │ ├── sample │ │ │ ├── input.utl │ │ │ └── output.j │ │ ├── UTL.java │ │ └── visitor │ │ │ ├── IVisitor.java │ │ │ ├── Visitor.java │ │ │ └── nameAnalyzer │ │ │ └── NameAnalyzer.java │ └── parsers │ │ ├── UTL.tokens │ │ └── UTLLexer.tokens └── description │ └── PLC_Phase4.pdf ├── Phase 1 └── description │ └── PLC_Phase1.pdf └── UTL-Documentation └── UT Trading Language Documentation.pdf /Phase 2/src/main/ast/type/Type.java: -------------------------------------------------------------------------------- 1 | package main.ast.type; 2 | 3 | import main.ast.node.Node; 4 | 5 | public abstract class Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/type/Type.java: -------------------------------------------------------------------------------- 1 | package main.ast.type; 2 | 3 | import main.ast.node.Node; 4 | 5 | public abstract class Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/type/Type.java: -------------------------------------------------------------------------------- 1 | package main.ast.type; 2 | 3 | import main.ast.node.Node; 4 | 5 | public abstract class Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 1/description/PLC_Phase1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmd-nemati/Compiler-Course-Projects-F2023/HEAD/Phase 1/description/PLC_Phase1.pdf -------------------------------------------------------------------------------- /Phase 2/description/PLC_Phase2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmd-nemati/Compiler-Course-Projects-F2023/HEAD/Phase 2/description/PLC_Phase2.pdf -------------------------------------------------------------------------------- /Phase 3/description/PLC_Phase3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmd-nemati/Compiler-Course-Projects-F2023/HEAD/Phase 3/description/PLC_Phase3.pdf -------------------------------------------------------------------------------- /Phase 4/description/PLC_Phase4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmd-nemati/Compiler-Course-Projects-F2023/HEAD/Phase 4/description/PLC_Phase4.pdf -------------------------------------------------------------------------------- /Phase 2/src/main/compileError/CompileError.java: -------------------------------------------------------------------------------- 1 | package main.compileError; 2 | 3 | public abstract class CompileError{ 4 | public abstract String getMessage(); 5 | } 6 | -------------------------------------------------------------------------------- /Phase 3/src/main/compileError/CompileError.java: -------------------------------------------------------------------------------- 1 | package main.compileError; 2 | 3 | public abstract class CompileError{ 4 | public abstract String getMessage(); 5 | } 6 | -------------------------------------------------------------------------------- /Phase 4/src/main/compileError/CompileError.java: -------------------------------------------------------------------------------- 1 | package main.compileError; 2 | 3 | public abstract class CompileError{ 4 | public abstract String getMessage(); 5 | } 6 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/type/complexType/CandleType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.complexType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class CandleType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/type/complexType/OrderType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.complexType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class OrderType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/type/complexType/TradeType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.complexType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class TradeType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/type/primitiveType/BoolType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class BoolType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/type/primitiveType/IntType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class IntType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/type/primitiveType/VoidType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class VoidType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/type/complexType/CandleType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.complexType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class CandleType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/type/complexType/OrderType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.complexType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class OrderType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/type/complexType/TradeType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.complexType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class TradeType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/type/primitiveType/BoolType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class BoolType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/type/primitiveType/IntType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class IntType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/type/primitiveType/VoidType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class VoidType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/type/complexType/CandleType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.complexType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class CandleType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/type/complexType/OrderType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.complexType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class OrderType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/type/complexType/TradeType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.complexType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class TradeType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/type/primitiveType/BoolType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class BoolType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/type/primitiveType/IntType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class IntType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/type/primitiveType/NullType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class NullType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/type/primitiveType/VoidType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class VoidType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/type/complexType/ExceptionType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.complexType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class ExceptionType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/type/primitiveType/DoubleType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class DoubleType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/type/primitiveType/FloatType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class FloatType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/type/primitiveType/StringType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class StringType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 2/src/main/symbolTable/itemException/ItemAlreadyExistsException.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.itemException; 2 | 3 | public class ItemAlreadyExistsException extends Exception { 4 | } -------------------------------------------------------------------------------- /Phase 2/src/main/symbolTable/itemException/ItemNotFoundException.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.itemException; 2 | 3 | 4 | public class ItemNotFoundException extends Exception { 5 | } 6 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/statement/Statement.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.Node; 4 | 5 | public abstract class Statement extends Node { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/type/complexType/ExceptionType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.complexType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class ExceptionType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/type/primitiveType/FloatType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class FloatType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/type/primitiveType/StringType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class StringType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 3/src/main/symbolTable/itemException/ItemAlreadyExistsException.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.itemException; 2 | 3 | public class ItemAlreadyExistsException extends Exception { 4 | } -------------------------------------------------------------------------------- /Phase 3/src/main/symbolTable/itemException/ItemNotFoundException.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.itemException; 2 | 3 | 4 | public class ItemNotFoundException extends Exception { 5 | } 6 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/statement/Statement.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.Node; 4 | 5 | public abstract class Statement extends Node { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/type/complexType/ExceptionType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.complexType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class ExceptionType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/type/primitiveType/FloatType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class FloatType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/type/primitiveType/StringType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type.primitiveType; 2 | 3 | import main.ast.type.Type; 4 | 5 | public class StringType extends Type { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 4/src/main/symbolTable/itemException/ItemAlreadyExistsException.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.itemException; 2 | 3 | public class ItemAlreadyExistsException extends Exception { 4 | } -------------------------------------------------------------------------------- /Phase 4/src/main/symbolTable/itemException/ItemNotFoundException.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.itemException; 2 | 3 | 4 | public class ItemNotFoundException extends Exception { 5 | } 6 | -------------------------------------------------------------------------------- /UTL-Documentation/UT Trading Language Documentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmd-nemati/Compiler-Course-Projects-F2023/HEAD/UTL-Documentation/UT Trading Language Documentation.pdf -------------------------------------------------------------------------------- /Phase 3/src/main/ast/type/NoType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type; 2 | 3 | public class NoType extends Type { 4 | @Override 5 | public String toString() { 6 | return "noType"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/type/NoType.java: -------------------------------------------------------------------------------- 1 | package main.ast.type; 2 | 3 | public class NoType extends Type { 4 | @Override 5 | public String toString() { 6 | return "noType"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/declaration/Declaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.statement.Statement; 4 | 5 | public abstract class Declaration extends Statement { 6 | } 7 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/declaration/Declaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.statement.Statement; 4 | import main.ast.type.Type; 5 | 6 | public abstract class Declaration extends Statement { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/declaration/Declaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.statement.Statement; 4 | import main.ast.type.Type; 5 | 6 | public abstract class Declaration extends Statement { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/operators/UnaryOperator.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.operators; 2 | 3 | public enum UnaryOperator { 4 | BIT_NOT , // ~ 5 | MINUS , // - 6 | NOT, // ! 7 | INC , // ++ 8 | DEC , // -- 9 | } 10 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/operators/UnaryOperator.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.operators; 2 | 3 | public enum UnaryOperator { 4 | BIT_NOT , // ~ 5 | MINUS , // - 6 | NOT, // ! 7 | INC , // ++ 8 | DEC , // -- 9 | } 10 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/operators/UnaryOperator.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.operators; 2 | 3 | public enum UnaryOperator { 4 | BIT_NOT , // ~ 5 | MINUS , // - 6 | NOT, // ! 7 | INC , // ++ 8 | DEC , // -- 9 | } 10 | -------------------------------------------------------------------------------- /Phase 2/src/main/symbolTable/symbolTableItems/SymbolTableItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | public abstract class SymbolTableItem { 4 | protected String name; 5 | 6 | public SymbolTableItem() { 7 | } 8 | 9 | public abstract String getKey(); 10 | } -------------------------------------------------------------------------------- /Phase 3/src/main/symbolTable/symbolTableItems/SymbolTableItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | public abstract class SymbolTableItem { 4 | protected String name; 5 | 6 | public SymbolTableItem() { 7 | } 8 | 9 | public abstract String getKey(); 10 | } -------------------------------------------------------------------------------- /Phase 4/src/main/symbolTable/symbolTableItems/SymbolTableItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | public abstract class SymbolTableItem { 4 | protected String name; 5 | 6 | public SymbolTableItem() { 7 | } 8 | 9 | public abstract String getKey(); 10 | } -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/values/Value.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.ast.type.Type; 4 | import main.ast.node.expression.Expression; 5 | 6 | public abstract class Value extends Expression { 7 | protected Type type; 8 | 9 | public Type getType() { 10 | return type; 11 | } 12 | 13 | public void setType(Type type) { 14 | this.type = type; 15 | } 16 | } -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/values/Value.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.ast.type.Type; 4 | import main.ast.node.expression.Expression; 5 | 6 | public abstract class Value extends Expression { 7 | protected Type type; 8 | 9 | public Type getType() { 10 | return type; 11 | } 12 | 13 | public void setType(Type type) { 14 | this.type = type; 15 | } 16 | } -------------------------------------------------------------------------------- /Phase 3/src/main/compileError/type/ConditionTypeNotBool.java: -------------------------------------------------------------------------------- 1 | package main.compileError.type; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class ConditionTypeNotBool extends CompileError { 6 | int line; 7 | public ConditionTypeNotBool(int line){ 8 | this.line = line; 9 | } 10 | public String getMessage(){ 11 | return "Line:" + line + ":Condition must be bool"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/values/Value.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.ast.type.Type; 4 | import main.ast.node.expression.Expression; 5 | 6 | public abstract class Value extends Expression { 7 | protected Type type; 8 | 9 | public Type getType() { 10 | return type; 11 | } 12 | 13 | public void setType(Type type) { 14 | this.type = type; 15 | } 16 | } -------------------------------------------------------------------------------- /Phase 4/src/main/compileError/type/ConditionTypeNotBool.java: -------------------------------------------------------------------------------- 1 | package main.compileError.type; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class ConditionTypeNotBool extends CompileError { 6 | int line; 7 | public ConditionTypeNotBool(int line){ 8 | this.line = line; 9 | } 10 | public String getMessage(){ 11 | return "Line:" + line + ":Condition must be bool"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/statement/Statement.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.Node; 4 | import main.ast.node.expression.Identifier; 5 | 6 | public abstract class Statement extends Node { 7 | private Identifier identifier; 8 | 9 | public void setIdentifier(Identifier identifier) { this.identifier = identifier; } 10 | 11 | public Identifier getIdentifier() { return this.identifier; } 12 | } 13 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/Expression.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.ast.type.Type; 4 | import main.ast.node.Node; 5 | import main.ast.node.statement.Statement; 6 | 7 | public abstract class Expression extends Node{ 8 | private Type type; 9 | 10 | public Type getType() { 11 | return type; 12 | } 13 | 14 | public void setType(Type type) { 15 | this.type = type; 16 | } 17 | } -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/Expression.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.ast.type.Type; 4 | import main.ast.node.Node; 5 | import main.ast.node.statement.Statement; 6 | 7 | public abstract class Expression extends Node{ 8 | private Type type; 9 | 10 | public Type getType() { 11 | return type; 12 | } 13 | 14 | public void setType(Type type) { 15 | this.type = type; 16 | } 17 | } -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/Expression.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.ast.type.Type; 4 | import main.ast.node.Node; 5 | import main.ast.node.statement.Statement; 6 | 7 | public abstract class Expression extends Node{ 8 | private Type type; 9 | 10 | public Type getType() { 11 | return type; 12 | } 13 | 14 | public void setType(Type type) { 15 | this.type = type; 16 | } 17 | } -------------------------------------------------------------------------------- /Phase 2/src/main/compileError/name/MethodRedefinition.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class MethodRedefinition extends CompileError { 6 | int line; 7 | String name; 8 | public MethodRedefinition(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line:" + line + ":Redefinition of method " + name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/Node.java: -------------------------------------------------------------------------------- 1 | package main.ast.node; 2 | 3 | import main.visitor.IVisitor; 4 | import main.visitor.Visitor; 5 | 6 | public abstract class Node { 7 | 8 | private int line; 9 | 10 | public void setLine(int line_num) { 11 | this.line = line_num; 12 | } 13 | 14 | public int getLine() { 15 | return this.line; 16 | } 17 | 18 | public abstract String toString(); 19 | 20 | public abstract T accept(IVisitor visitor); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Phase 3/src/main/compileError/name/MethodRedefinition.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class MethodRedefinition extends CompileError { 6 | int line; 7 | String name; 8 | public MethodRedefinition(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line:" + line + ":Redefinition of method " + name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/Node.java: -------------------------------------------------------------------------------- 1 | package main.ast.node; 2 | 3 | import main.visitor.IVisitor; 4 | import main.visitor.Visitor; 5 | 6 | public abstract class Node { 7 | 8 | private int line; 9 | 10 | public void setLine(int line_num) { 11 | this.line = line_num; 12 | } 13 | 14 | public int getLine() { 15 | return this.line; 16 | } 17 | 18 | public abstract String toString(); 19 | 20 | public abstract T accept(IVisitor visitor); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Phase 4/src/main/compileError/name/MethodRedefinition.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class MethodRedefinition extends CompileError { 6 | int line; 7 | String name; 8 | public MethodRedefinition(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line:" + line + ":Redefinition of method " + name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 2/src/main/compileError/name/VariableRedefinition.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class VariableRedefinition extends CompileError { 6 | int line; 7 | String name; 8 | public VariableRedefinition(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line:" + line + ":Redefinition of variable " + name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 3/src/main/compileError/name/VariableRedefinition.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class VariableRedefinition extends CompileError { 6 | int line; 7 | String name; 8 | public VariableRedefinition(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line:" + line + ":Redefinition of variable " + name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 4/src/main/compileError/name/VariableRedefinition.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class VariableRedefinition extends CompileError { 6 | int line; 7 | String name; 8 | public VariableRedefinition(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line:" + line + ":Redefinition of variable " + name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 2/src/main/compileError/name/IrregularDefenition.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class IrregularDefenition extends CompileError { 6 | int line; 7 | String name; 8 | public IrregularDefenition(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line " + line + ": Irregular definition of variable " + name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 3/src/main/compileError/type/UnsupportedOperandType.java: -------------------------------------------------------------------------------- 1 | package main.compileError.type; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class UnsupportedOperandType extends CompileError { 6 | int line; 7 | String name; 8 | public UnsupportedOperandType(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | public String getMessage(){ 13 | return "Line:" + line + ":Unsupported operand type for operator " + name; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Phase 4/src/main/compileError/type/UnsupportedOperandType.java: -------------------------------------------------------------------------------- 1 | package main.compileError.type; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class UnsupportedOperandType extends CompileError { 6 | int line; 7 | String name; 8 | public UnsupportedOperandType(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | public String getMessage(){ 13 | return "Line:" + line + ":Unsupported operand type for operator " + name; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Phase 2/src/main/compileError/name/GlobalVariableRedefinition.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class GlobalVariableRedefinition extends CompileError { 6 | int line; 7 | String name; 8 | public GlobalVariableRedefinition(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line " + line + ": Redefinition of global variable " + name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 3/src/main/compileError/name/GlobalVariableRedefinition.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class GlobalVariableRedefinition extends CompileError { 6 | int line; 7 | String name; 8 | public GlobalVariableRedefinition(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line:" + line + ":Redefinition of global variable " + name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 4/src/main/compileError/name/GlobalVariableRedefinition.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class GlobalVariableRedefinition extends CompileError { 6 | int line; 7 | String name; 8 | public GlobalVariableRedefinition(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line:" + line + ":Redefinition of global variable " + name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 2/src/main/compileError/name/PrimitiveFunctionRedefinition.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class PrimitiveFunctionRedefinition extends CompileError { 6 | int line; 7 | String name; 8 | public PrimitiveFunctionRedefinition(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line:" + line + ":Redefinition of primitive function:" + name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 3/src/main/compileError/name/PrimitiveFunctionRedefinition.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class PrimitiveFunctionRedefinition extends CompileError { 6 | int line; 7 | String name; 8 | public PrimitiveFunctionRedefinition(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line:" + line + ":Redefinition of primitive function:" + name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 4/src/main/compileError/name/PrimitiveFunctionRedefinition.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class PrimitiveFunctionRedefinition extends CompileError { 6 | int line; 7 | String name; 8 | public PrimitiveFunctionRedefinition(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line:" + line + ":Redefinition of primitive function:" + name; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 2/src/main/compileError/name/FunctionVariableConflict.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class FunctionVariableConflict extends CompileError { 6 | int line; 7 | String name; 8 | public FunctionVariableConflict(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line:" + line + ":Name of variable " + name + " conflicts with the function’s name"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 3/src/main/compileError/name/FunctionVariableConflict.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class FunctionVariableConflict extends CompileError { 6 | int line; 7 | String name; 8 | public FunctionVariableConflict(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line:" + line + ":Name of variable " + name + " conflicts with the function's name"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 4/src/main/compileError/name/FunctionVariableConflict.java: -------------------------------------------------------------------------------- 1 | package main.compileError.name; 2 | 3 | import main.compileError.CompileError; 4 | 5 | public class FunctionVariableConflict extends CompileError { 6 | int line; 7 | String name; 8 | public FunctionVariableConflict(int line, String name){ 9 | this.line = line; 10 | this.name = name; 11 | } 12 | 13 | public String getMessage(){ 14 | return "Line:" + line + ":Name of variable " + name + " conflicts with the function's name"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Phase 2/src/main/symbolTable/Stack.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable; 2 | 3 | import java.util.ArrayList; 4 | 5 | class Stack { 6 | private int top; 7 | private ArrayList elements; 8 | 9 | public Stack() { 10 | top = -1; 11 | elements = new ArrayList(); 12 | } 13 | 14 | public void push(E pushValue) { 15 | elements.add(pushValue); 16 | ++top; 17 | } 18 | 19 | public E pop() { 20 | if (top == -1) 21 | return null; 22 | --top; 23 | E e = elements.get(top + 1); 24 | elements.remove(top + 1); 25 | return e; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Phase 3/src/main/symbolTable/Stack.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable; 2 | 3 | import java.util.ArrayList; 4 | 5 | class Stack { 6 | private int top; 7 | private ArrayList elements; 8 | 9 | public Stack() { 10 | top = -1; 11 | elements = new ArrayList(); 12 | } 13 | 14 | public void push(E pushValue) { 15 | elements.add(pushValue); 16 | ++top; 17 | } 18 | 19 | public E pop() { 20 | if (top == -1) 21 | return null; 22 | --top; 23 | E e = elements.get(top + 1); 24 | elements.remove(top + 1); 25 | return e; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Phase 4/src/main/symbolTable/Stack.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable; 2 | 3 | import java.util.ArrayList; 4 | 5 | class Stack { 6 | private int top; 7 | private ArrayList elements; 8 | 9 | public Stack() { 10 | top = -1; 11 | elements = new ArrayList(); 12 | } 13 | 14 | public void push(E pushValue) { 15 | elements.add(pushValue); 16 | ++top; 17 | } 18 | 19 | public E pop() { 20 | if (top == -1) 21 | return null; 22 | --top; 23 | E e = elements.get(top + 1); 24 | elements.remove(top + 1); 25 | return e; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/Node.java: -------------------------------------------------------------------------------- 1 | package main.ast.node; 2 | 3 | import main.visitor.IVisitor; 4 | import main.ast.type.*; 5 | import main.visitor.Visitor; 6 | 7 | public abstract class Node { 8 | 9 | private int line; 10 | private Type type; 11 | 12 | public void setType(Type type) { this.type = type; }; 13 | 14 | public Type getType() { return null; }; 15 | 16 | public void setLine(int line_num) { 17 | this.line = line_num; 18 | } 19 | 20 | public int getLine() { 21 | return this.line; 22 | } 23 | 24 | public abstract T accept(IVisitor visitor); 25 | } 26 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/statement/ContinueBreakStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class ContinueBreakStmt extends Statement { 6 | private String token; 7 | 8 | public ContinueBreakStmt(String token) { 9 | this.token = token; 10 | } 11 | 12 | public String getToken() { 13 | return token; 14 | } 15 | 16 | public void setToken(String token) { 17 | this.token = token; 18 | } 19 | 20 | @Override 21 | public T accept(IVisitor visitor) { 22 | return visitor.visit(this); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/Identifier.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | import main.visitor.Visitor; 5 | 6 | public class Identifier extends Expression { 7 | private String name; 8 | 9 | public Identifier(String name) { 10 | this.name = name; 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public void setName(String name) { 18 | this.name = name; 19 | } 20 | 21 | @Override 22 | public T accept(IVisitor visitor) { 23 | return visitor.visit(this); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/values/FloatValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class FloatValue extends Value { 6 | private float constant; 7 | 8 | public FloatValue(float constant) { 9 | this.constant = constant; 10 | } 11 | 12 | public float getConstant() { 13 | return constant; 14 | } 15 | 16 | public void setConstant(float constant) { 17 | this.constant = constant; 18 | } 19 | 20 | @Override 21 | public T accept(IVisitor visitor) { 22 | return visitor.visit(this); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/operators/BinaryOperator.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.operators; 2 | 3 | public enum BinaryOperator { 4 | PLUS , // + 5 | MINUS , // - 6 | MULT , // * 7 | DIV , // / 8 | MOD , // % 9 | AND , // && 10 | OR, // || 11 | BIT_AND , // & 12 | BIT_OR , // | 13 | BIT_XOR , // ^ 14 | L_SHIFT , // << 15 | R_SHIFT , // >> 16 | LT , // < 17 | GT , // > 18 | EQ , // == 19 | NEQ , // != 20 | ASSIGN , // = 21 | ADD_ASSIGN, // += 22 | SUB_ASSIGN, // -= 23 | MUL_ASSIGN, // *= 24 | DIV_ASSIGN, // /= 25 | MOD_ASSIGN, // %= 26 | } 27 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/values/BoolValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class BoolValue extends Value { 6 | private boolean constant; 7 | 8 | public BoolValue(boolean constant) { 9 | this.constant = constant; 10 | } 11 | 12 | public boolean getConstant() { 13 | return constant; 14 | } 15 | 16 | public void setConstant(boolean constant) { 17 | this.constant = constant; 18 | } 19 | 20 | @Override 21 | public T accept(IVisitor visitor) { 22 | return visitor.visit(this); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/operators/BinaryOperator.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.operators; 2 | 3 | public enum BinaryOperator { 4 | PLUS , // + 5 | MINUS , // - 6 | MULT , // * 7 | DIV , // / 8 | MOD , // % 9 | AND , // && 10 | OR, // || 11 | BIT_AND , // & 12 | BIT_OR , // | 13 | BIT_XOR , // ^ 14 | L_SHIFT , // << 15 | R_SHIFT , // >> 16 | LT , // < 17 | GT , // > 18 | EQ , // == 19 | NEQ , // != 20 | ASSIGN , // = 21 | ADD_ASSIGN, // += 22 | SUB_ASSIGN, // -= 23 | MUL_ASSIGN, // *= 24 | DIV_ASSIGN, // /= 25 | MOD_ASSIGN, // %= 26 | } 27 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/operators/BinaryOperator.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.operators; 2 | 3 | public enum BinaryOperator { 4 | PLUS , // + 5 | MINUS , // - 6 | MULT , // * 7 | DIV , // / 8 | MOD , // % 9 | AND , // && 10 | OR, // || 11 | BIT_AND , // & 12 | BIT_OR , // | 13 | BIT_XOR , // ^ 14 | L_SHIFT , // << 15 | R_SHIFT , // >> 16 | LT , // < 17 | GT , // > 18 | EQ , // == 19 | NEQ , // != 20 | ASSIGN , // = 21 | ADD_ASSIGN, // += 22 | SUB_ASSIGN, // -= 23 | MUL_ASSIGN, // *= 24 | DIV_ASSIGN, // /= 25 | MOD_ASSIGN, // %= 26 | } 27 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/ArrayIdentifier.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class ArrayIdentifier extends Identifier { 6 | private Expression index; 7 | 8 | public ArrayIdentifier(String name, Expression index) { 9 | super(name); 10 | this.index = index; 11 | } 12 | 13 | public Expression getIndex() { 14 | return index; 15 | } 16 | 17 | public void setIndex(Expression index) { 18 | this.index = index; 19 | } 20 | 21 | @Override 22 | public T accept(IVisitor visitor) { 23 | return visitor.visit(this); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/values/IntValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.ast.type.Type; 4 | import main.visitor.IVisitor; 5 | import main.visitor.Visitor; 6 | 7 | public class IntValue extends Value { 8 | private int constant; 9 | 10 | public IntValue(int constant) { 11 | this.constant = constant; 12 | } 13 | 14 | public int getConstant() { 15 | return constant; 16 | } 17 | 18 | public void setConstant(int constant) { 19 | this.constant = constant; 20 | } 21 | 22 | @Override 23 | public T accept(IVisitor visitor) { 24 | return visitor.visit(this); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/values/StringValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.ast.type.Type; 4 | import main.visitor.IVisitor; 5 | import main.visitor.Visitor; 6 | 7 | public class StringValue extends Value { 8 | private String constant; 9 | 10 | public StringValue(String constant) { 11 | this.constant = constant; 12 | } 13 | 14 | public String getConstant() { 15 | return constant; 16 | } 17 | 18 | public void setConstant(String constant) { 19 | this.constant = constant; 20 | } 21 | 22 | @Override 23 | public T accept(IVisitor visitor) { 24 | return visitor.visit(this); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/values/TradeValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.ast.type.Type; 4 | import main.visitor.IVisitor; 5 | import main.visitor.Visitor; 6 | 7 | public class TradeValue extends Value { 8 | private String constant; 9 | 10 | public TradeValue(String constant) { 11 | this.constant = constant; 12 | } 13 | 14 | public String getConstant() { 15 | return constant; 16 | } 17 | 18 | public void setConstant(String constant) { 19 | this.constant = constant; 20 | } 21 | 22 | @Override 23 | public T accept(IVisitor visitor) { 24 | return visitor.visit(this); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/Identifier.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | import main.visitor.Visitor; 5 | 6 | public class Identifier extends Expression { 7 | protected String name; 8 | 9 | public Identifier(String name) { 10 | this.name = name; 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public void setName(String name) { 18 | this.name = name; 19 | } 20 | 21 | @Override 22 | public String toString() {return "Identifier " + name;} 23 | @Override 24 | public T accept(IVisitor visitor) { 25 | return visitor.visit(this); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/Identifier.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | import main.visitor.Visitor; 5 | 6 | public class Identifier extends Expression { 7 | protected String name; 8 | 9 | public Identifier(String name) { 10 | this.name = name; 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public void setName(String name) { 18 | this.name = name; 19 | } 20 | 21 | @Override 22 | public String toString() {return "Identifier " + name;} 23 | @Override 24 | public T accept(IVisitor visitor) { 25 | return visitor.visit(this); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/statement/ExpressionStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | public class ExpressionStmt extends Statement { 7 | private Expression expression; 8 | 9 | public ExpressionStmt(Expression expression) { 10 | this.expression = expression; 11 | } 12 | 13 | public Expression getExpression() { 14 | return expression; 15 | } 16 | 17 | public void setExpression(Expression expression) { 18 | this.expression = expression; 19 | } 20 | 21 | @Override 22 | public T accept(IVisitor visitor) { 23 | return visitor.visit(this); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/statement/ReturnStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | public class ReturnStmt extends Statement { 7 | private Expression returnedExpr; 8 | 9 | public ReturnStmt(Expression returnedExpr) { 10 | this.returnedExpr = returnedExpr; 11 | } 12 | 13 | public Expression getReturnedExpr() { 14 | return returnedExpr; 15 | } 16 | 17 | public void setReturnedExpr(Expression returnedExpr) { 18 | this.returnedExpr = returnedExpr; 19 | } 20 | 21 | @Override 22 | public T accept(IVisitor visitor) { 23 | return visitor.visit(this); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/values/NullValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class NullValue extends Value { 6 | private int constant; 7 | 8 | public NullValue() { 9 | this.constant = Integer.parseInt(null); 10 | } 11 | 12 | public Object getConstant() { 13 | return null; 14 | } 15 | 16 | // public void setConstant(boolean constant) { 17 | // this.constant = constant; 18 | // } 19 | 20 | @Override 21 | public String toString(){ 22 | return "NullValue"; 23 | 24 | } 25 | @Override 26 | public T accept(IVisitor visitor) { 27 | return visitor.visit(this); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/values/BoolValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class BoolValue extends Value { 6 | private boolean constant; 7 | 8 | public BoolValue(boolean constant) { 9 | this.constant = constant; 10 | } 11 | 12 | public boolean getConstant() { 13 | return constant; 14 | } 15 | 16 | public void setConstant(boolean constant) { 17 | this.constant = constant; 18 | } 19 | 20 | @Override 21 | public String toString(){ 22 | return "BoolValue"; 23 | 24 | } 25 | @Override 26 | public T accept(IVisitor visitor) { 27 | return visitor.visit(this); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/values/FloatValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class FloatValue extends Value { 6 | private float constant; 7 | 8 | public FloatValue(float constant) { 9 | this.constant = constant; 10 | } 11 | 12 | public float getConstant() { 13 | return constant; 14 | } 15 | 16 | public void setConstant(float constant) { 17 | this.constant = constant; 18 | } 19 | 20 | @Override 21 | public String toString(){ 22 | return "FloatValue"; 23 | 24 | } 25 | 26 | @Override 27 | public T accept(IVisitor visitor) { 28 | return visitor.visit(this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/statement/ContinueBreakStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class ContinueBreakStmt extends Statement { 6 | private String token; 7 | 8 | public ContinueBreakStmt(String token) { 9 | this.token = token; 10 | } 11 | 12 | public String getToken() { 13 | return token; 14 | } 15 | 16 | public void setToken(String token) { 17 | this.token = token; 18 | } 19 | 20 | 21 | @Override 22 | public String toString() { 23 | return "ContinueBreakStmt " + token; 24 | } 25 | 26 | @Override 27 | public T accept(IVisitor visitor) { 28 | return visitor.visit(this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/values/BoolValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class BoolValue extends Value { 6 | private boolean constant; 7 | 8 | public BoolValue(boolean constant) { 9 | this.constant = constant; 10 | } 11 | 12 | public boolean getConstant() { 13 | return constant; 14 | } 15 | 16 | public void setConstant(boolean constant) { 17 | this.constant = constant; 18 | } 19 | 20 | @Override 21 | public String toString(){ 22 | return "BoolValue"; 23 | 24 | } 25 | @Override 26 | public T accept(IVisitor visitor) { 27 | return visitor.visit(this); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/values/FloatValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class FloatValue extends Value { 6 | private float constant; 7 | 8 | public FloatValue(float constant) { 9 | this.constant = constant; 10 | } 11 | 12 | public float getConstant() { 13 | return constant; 14 | } 15 | 16 | public void setConstant(float constant) { 17 | this.constant = constant; 18 | } 19 | 20 | @Override 21 | public String toString(){ 22 | return "FloatValue"; 23 | 24 | } 25 | 26 | @Override 27 | public T accept(IVisitor visitor) { 28 | return visitor.visit(this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/statement/ContinueBreakStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class ContinueBreakStmt extends Statement { 6 | private String token; 7 | 8 | public ContinueBreakStmt(String token) { 9 | this.token = token; 10 | } 11 | 12 | public String getToken() { 13 | return token; 14 | } 15 | 16 | public void setToken(String token) { 17 | this.token = token; 18 | } 19 | 20 | 21 | @Override 22 | public String toString() { 23 | return "ContinueBreakStmt " + token; 24 | } 25 | 26 | @Override 27 | public T accept(IVisitor visitor) { 28 | return visitor.visit(this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/ArrayIdentifier.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class ArrayIdentifier extends Identifier { 6 | private Expression index; 7 | 8 | public ArrayIdentifier(String name, Expression index) { 9 | super(name); 10 | this.index = index; 11 | } 12 | 13 | public Expression getIndex() { 14 | return index; 15 | } 16 | 17 | public void setIndex(Expression index) { 18 | this.index = index; 19 | } 20 | 21 | 22 | @Override 23 | public String toString() {return "ArrayIdentifier " + name;} 24 | @Override 25 | public T accept(IVisitor visitor) { 26 | return visitor.visit(this); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/ArrayIdentifier.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class ArrayIdentifier extends Identifier { 6 | private Expression index; 7 | 8 | public ArrayIdentifier(String name, Expression index) { 9 | super(name); 10 | this.index = index; 11 | } 12 | 13 | public Expression getIndex() { 14 | return index; 15 | } 16 | 17 | public void setIndex(Expression index) { 18 | this.index = index; 19 | } 20 | 21 | 22 | @Override 23 | public String toString() {return "ArrayIdentifier " + name;} 24 | @Override 25 | public T accept(IVisitor visitor) { 26 | return visitor.visit(this); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/statement/ThrowStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | public class ThrowStmt extends Statement { 7 | private Expression throwedExpression; 8 | 9 | public ThrowStmt(Expression throwedExpression) { 10 | this.throwedExpression = throwedExpression; 11 | } 12 | 13 | public Expression getReturnedExpr() { 14 | return throwedExpression; 15 | } 16 | 17 | public void setReturnedExpr(Expression throwedExpression) { 18 | this.throwedExpression = throwedExpression; 19 | } 20 | 21 | @Override 22 | public T accept(IVisitor visitor) { 23 | return visitor.visit(this); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/statement/ExpressionStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | public class ExpressionStmt extends Statement { 7 | private Expression expression; 8 | 9 | public ExpressionStmt(Expression expression) { 10 | this.expression = expression; 11 | } 12 | 13 | public Expression getExpression() { 14 | return expression; 15 | } 16 | 17 | public void setExpression(Expression expression) { 18 | this.expression = expression; 19 | } 20 | 21 | public String toString(){return "ExpressionStmt";} 22 | @Override 23 | public T accept(IVisitor visitor) { 24 | return visitor.visit(this); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/statement/ExpressionStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | public class ExpressionStmt extends Statement { 7 | private Expression expression; 8 | 9 | public ExpressionStmt(Expression expression) { 10 | this.expression = expression; 11 | } 12 | 13 | public Expression getExpression() { 14 | return expression; 15 | } 16 | 17 | public void setExpression(Expression expression) { 18 | this.expression = expression; 19 | } 20 | 21 | public String toString(){return "ExpressionStmt";} 22 | @Override 23 | public T accept(IVisitor visitor) { 24 | return visitor.visit(this); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/values/IntValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.ast.type.Type; 4 | import main.visitor.IVisitor; 5 | import main.visitor.Visitor; 6 | 7 | public class IntValue extends Value { 8 | private int constant; 9 | 10 | public IntValue(int constant) { 11 | this.constant = constant; 12 | } 13 | 14 | public int getConstant() { 15 | return constant; 16 | } 17 | 18 | public void setConstant(int constant) { 19 | this.constant = constant; 20 | } 21 | 22 | @Override 23 | public String toString(){ 24 | return "IntValue"; 25 | 26 | } 27 | @Override 28 | public T accept(IVisitor visitor) { 29 | return visitor.visit(this); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/values/IntValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.ast.type.Type; 4 | import main.visitor.IVisitor; 5 | import main.visitor.Visitor; 6 | 7 | public class IntValue extends Value { 8 | private int constant; 9 | 10 | public IntValue(int constant) { 11 | this.constant = constant; 12 | } 13 | 14 | public int getConstant() { 15 | return constant; 16 | } 17 | 18 | public void setConstant(int constant) { 19 | this.constant = constant; 20 | } 21 | 22 | @Override 23 | public String toString(){ 24 | return "IntValue"; 25 | 26 | } 27 | @Override 28 | public T accept(IVisitor visitor) { 29 | return visitor.visit(this); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/values/StringValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.ast.type.Type; 4 | import main.visitor.IVisitor; 5 | import main.visitor.Visitor; 6 | 7 | public class StringValue extends Value { 8 | private String constant; 9 | 10 | public StringValue(String constant) { 11 | this.constant = constant; 12 | } 13 | 14 | public String getConstant() { 15 | return constant; 16 | } 17 | 18 | public void setConstant(String constant) { 19 | this.constant = constant; 20 | } 21 | 22 | @Override 23 | public String toString(){ 24 | return "StringValue"; 25 | } 26 | 27 | @Override 28 | public T accept(IVisitor visitor) { 29 | return visitor.visit(this); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/values/StringValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.ast.type.Type; 4 | import main.visitor.IVisitor; 5 | import main.visitor.Visitor; 6 | 7 | public class StringValue extends Value { 8 | private String constant; 9 | 10 | public StringValue(String constant) { 11 | this.constant = constant; 12 | } 13 | 14 | public String getConstant() { 15 | return constant; 16 | } 17 | 18 | public void setConstant(String constant) { 19 | this.constant = constant; 20 | } 21 | 22 | @Override 23 | public String toString(){ 24 | return "StringValue"; 25 | } 26 | 27 | @Override 28 | public T accept(IVisitor visitor) { 29 | return visitor.visit(this); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/values/TradeValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.ast.type.Type; 4 | import main.visitor.IVisitor; 5 | import main.visitor.Visitor; 6 | 7 | public class TradeValue extends Value { 8 | private String constant; 9 | 10 | public TradeValue(String constant) { 11 | this.constant = constant; 12 | } 13 | 14 | public String getConstant() { 15 | return constant; 16 | } 17 | 18 | public void setConstant(String constant) { 19 | this.constant = constant; 20 | } 21 | 22 | @Override 23 | public String toString(){ 24 | return "TradeValue " + constant; 25 | } 26 | 27 | @Override 28 | public T accept(IVisitor visitor) { 29 | return visitor.visit(this); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/values/TradeValue.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression.values; 2 | 3 | import main.ast.type.Type; 4 | import main.visitor.IVisitor; 5 | import main.visitor.Visitor; 6 | 7 | public class TradeValue extends Value { 8 | private String constant; 9 | 10 | public TradeValue(String constant) { 11 | this.constant = constant; 12 | } 13 | 14 | public String getConstant() { 15 | return constant; 16 | } 17 | 18 | public void setConstant(String constant) { 19 | this.constant = constant; 20 | } 21 | 22 | @Override 23 | public String toString(){ 24 | return "TradeValue " + constant; 25 | } 26 | 27 | @Override 28 | public T accept(IVisitor visitor) { 29 | return visitor.visit(this); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/statement/ReturnStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | public class ReturnStmt extends Statement { 7 | private Expression returnedExpr; 8 | 9 | public ReturnStmt(Expression returnedExpr) { 10 | this.returnedExpr = returnedExpr; 11 | } 12 | 13 | public Expression getReturnedExpr() { 14 | return returnedExpr; 15 | } 16 | 17 | public void setReturnedExpr(Expression returnedExpr) { 18 | this.returnedExpr = returnedExpr; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "ReturnStmt"; 24 | } 25 | 26 | @Override 27 | public T accept(IVisitor visitor) { 28 | return visitor.visit(this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/statement/ReturnStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | public class ReturnStmt extends Statement { 7 | private Expression returnedExpr; 8 | 9 | public ReturnStmt(Expression returnedExpr) { 10 | this.returnedExpr = returnedExpr; 11 | } 12 | 13 | public Expression getReturnedExpr() { 14 | return returnedExpr; 15 | } 16 | 17 | public void setReturnedExpr(Expression returnedExpr) { 18 | this.returnedExpr = returnedExpr; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "ReturnStmt"; 24 | } 25 | 26 | @Override 27 | public T accept(IVisitor visitor) { 28 | return visitor.visit(this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/statement/ThrowStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | public class ThrowStmt extends Statement { 7 | private Expression throwedExpression; 8 | 9 | public ThrowStmt(Expression throwedExpression) { 10 | this.throwedExpression = throwedExpression; 11 | } 12 | 13 | public Expression getReturnedExpr() { 14 | return throwedExpression; 15 | } 16 | 17 | public void setReturnedExpr(Expression throwedExpression) { 18 | this.throwedExpression = throwedExpression; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "ThrowStmt"; 24 | } 25 | 26 | @Override 27 | public T accept(IVisitor visitor) { 28 | return visitor.visit(this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/statement/ThrowStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | public class ThrowStmt extends Statement { 7 | private Expression throwedExpression; 8 | 9 | public ThrowStmt(Expression throwedExpression) { 10 | this.throwedExpression = throwedExpression; 11 | } 12 | 13 | public Expression getReturnedExpr() { 14 | return throwedExpression; 15 | } 16 | 17 | public void setReturnedExpr(Expression throwedExpression) { 18 | this.throwedExpression = throwedExpression; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "ThrowStmt"; 24 | } 25 | 26 | @Override 27 | public T accept(IVisitor visitor) { 28 | return visitor.visit(this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/declaration/MainDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import java.util.ArrayList; 4 | 5 | import main.ast.node.statement.Statement; 6 | import main.visitor.IVisitor; 7 | 8 | public class MainDeclaration extends Declaration { 9 | private ArrayList body = new ArrayList<>(); 10 | 11 | public MainDeclaration() { 12 | } 13 | 14 | public ArrayList getBody() { 15 | return body; 16 | } 17 | 18 | public void setBody(ArrayList body) { 19 | this.body = body; 20 | } 21 | 22 | public void addStatement(Statement statement) { 23 | this.body.add(statement); 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return "MainDeclaration"; 29 | } 30 | 31 | @Override 32 | public T accept(IVisitor visitor) { 33 | return visitor.visit(this); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/declaration/MainDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import java.util.ArrayList; 4 | 5 | import main.ast.node.statement.Statement; 6 | import main.visitor.IVisitor; 7 | 8 | public class MainDeclaration extends Declaration { 9 | private ArrayList body = new ArrayList<>(); 10 | 11 | public MainDeclaration() { 12 | } 13 | 14 | public ArrayList getBody() { 15 | return body; 16 | } 17 | 18 | public void setBody(ArrayList body) { 19 | this.body = body; 20 | } 21 | 22 | public void addStatement(Statement statement) { 23 | this.body.add(statement); 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return "MainDeclaration"; 29 | } 30 | 31 | @Override 32 | public T accept(IVisitor visitor) { 33 | return visitor.visit(this); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Phase 4/src/main/sample/input.utl: -------------------------------------------------------------------------------- 1 | int balance; 2 | int tick_counts = 0; 3 | 4 | void OnInit(Trade t1) { 5 | Order o3 = Order(SELL, 100, 100, 10); 6 | } 7 | 8 | void OnInit(Trade t3) { 9 | Order o1 = Order(BUY, 200, 50, 5); 10 | Order o2 = Order(SELL, 100, 100, 10); 11 | } 12 | 13 | void OnStart (Trade t1) throw Exception 14 | { 15 | float low = t1.Bid; 16 | float high = t1.Ask; 17 | 18 | //linear regression algorithm 19 | float Stoploss = 100; 20 | float TakeProfit = 250; 21 | float amount = 20; 22 | Order o1 = Order(BUY, Stoploss, TakeProfit, amount); 23 | float profit_ratio = TakeProfit/amount; 24 | } 25 | 26 | void OnStart(Trade t3) //throws 27 | { 28 | GetCandle(100); 29 | } 30 | 31 | void Main() 32 | { 33 | string username = "admin"; 34 | Connect(username, "password"); 35 | Trade t1 = Observe("USDETH"); 36 | int d = t1.Digits; 37 | Trade t3 = Observe("IRRETH"); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/VarAccess.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class VarAccess extends Expression { 6 | private Expression instance; 7 | private Identifier variableName; 8 | 9 | public VarAccess(Expression instance, Identifier variableName) { 10 | this.instance = instance; 11 | this.variableName = variableName; 12 | } 13 | 14 | public Expression getInstance() { 15 | return instance; 16 | } 17 | 18 | public void setInstance(Expression instance) { 19 | this.instance = instance; 20 | } 21 | 22 | public Identifier getVariable() { 23 | return variableName; 24 | } 25 | 26 | public void setVariable(Identifier variableName) { 27 | this.variableName = variableName; 28 | } 29 | 30 | @Override 31 | public T accept(IVisitor visitor) { 32 | return visitor.visit(this); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/statement/AssignStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.visitor.IVisitor; 4 | import main.visitor.Visitor; 5 | import main.ast.node.expression.Expression; 6 | 7 | // Line -> '=' 8 | public class AssignStmt extends Statement { 9 | private Expression lValue; 10 | private Expression rValue; 11 | 12 | public AssignStmt(Expression lValue, Expression rValue) { 13 | this.lValue = lValue; 14 | this.rValue = rValue; 15 | } 16 | 17 | public Expression getLValue() { 18 | return lValue; 19 | } 20 | 21 | public void setLValue(Expression lValue) { 22 | this.lValue = lValue; 23 | } 24 | 25 | public Expression getRValue() { 26 | return rValue; 27 | } 28 | 29 | public void setRValue(Expression rValue) { 30 | this.rValue = rValue; 31 | } 32 | 33 | @Override 34 | public T accept(IVisitor visitor) { 35 | return visitor.visit(this); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/statement/AssignStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | public class AssignStmt extends Statement { 7 | private Expression lValue; 8 | private Expression rValue; 9 | 10 | public AssignStmt(Expression lValue, Expression rValue) { 11 | this.lValue = lValue; 12 | this.rValue = rValue; 13 | } 14 | 15 | public Expression getLValue() { 16 | return lValue; 17 | } 18 | 19 | public void setLValue(Expression lValue) { 20 | this.lValue = lValue; 21 | } 22 | 23 | public Expression getRValue() { 24 | return rValue; 25 | } 26 | 27 | public void setRValue(Expression rValue) { 28 | this.rValue = rValue; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "AssignStmt"; 34 | } 35 | 36 | @Override 37 | public T accept(IVisitor visitor) { 38 | return visitor.visit(this); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/statement/AssignStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | public class AssignStmt extends Statement { 7 | private Expression lValue; 8 | private Expression rValue; 9 | 10 | public AssignStmt(Expression lValue, Expression rValue) { 11 | this.lValue = lValue; 12 | this.rValue = rValue; 13 | } 14 | 15 | public Expression getLValue() { 16 | return lValue; 17 | } 18 | 19 | public void setLValue(Expression lValue) { 20 | this.lValue = lValue; 21 | } 22 | 23 | public Expression getRValue() { 24 | return rValue; 25 | } 26 | 27 | public void setRValue(Expression rValue) { 28 | this.rValue = rValue; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "AssignStmt"; 34 | } 35 | 36 | @Override 37 | public T accept(IVisitor visitor) { 38 | return visitor.visit(this); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/VarAccess.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class VarAccess extends Expression { 6 | private Expression instance; 7 | private Identifier variableName; 8 | 9 | public VarAccess(Expression instance, Identifier variableName) { 10 | this.instance = instance; 11 | this.variableName = variableName; 12 | } 13 | 14 | public Expression getInstance() { 15 | return instance; 16 | } 17 | 18 | public void setInstance(Expression instance) { 19 | this.instance = instance; 20 | } 21 | 22 | public Identifier getVariable() { 23 | return variableName; 24 | } 25 | 26 | public void setVariable(Identifier variableName) { 27 | this.variableName = variableName; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return "VarAccess"; 33 | } 34 | 35 | @Override 36 | public T accept(IVisitor visitor) { 37 | return visitor.visit(this); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/VarAccess.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | public class VarAccess extends Expression { 6 | private Expression instance; 7 | private Identifier variableName; 8 | 9 | public VarAccess(Expression instance, Identifier variableName) { 10 | this.instance = instance; 11 | this.variableName = variableName; 12 | } 13 | 14 | public Expression getInstance() { 15 | return instance; 16 | } 17 | 18 | public void setInstance(Expression instance) { 19 | this.instance = instance; 20 | } 21 | 22 | public Identifier getVariable() { 23 | return variableName; 24 | } 25 | 26 | public void setVariable(Identifier variableName) { 27 | this.variableName = variableName; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return "VarAccess"; 33 | } 34 | 35 | @Override 36 | public T accept(IVisitor visitor) { 37 | return visitor.visit(this); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/FunctionCall.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class FunctionCall extends Expression { 8 | private Identifier functionName; 9 | private ArrayList args = new ArrayList<>(); 10 | 11 | public FunctionCall(Identifier functionName) { 12 | this.functionName = functionName; 13 | } 14 | 15 | public Identifier getFunctionName() { 16 | return functionName; 17 | } 18 | 19 | public void setFunctionName(Identifier functionName) { 20 | this.functionName = functionName; 21 | } 22 | 23 | public void setArgs(ArrayList args) { 24 | this.args = args; 25 | } 26 | 27 | public ArrayList getArgs() { 28 | return args; 29 | } 30 | 31 | public void addArg(Expression arg) { 32 | this.args.add(arg); 33 | } 34 | 35 | @Override 36 | public T accept(IVisitor visitor) { 37 | return visitor.visit(this); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/statement/WhileStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | import java.util.ArrayList; 7 | 8 | // Line -> IF 9 | public class WhileStmt extends Statement { 10 | private Expression condition; 11 | private ArrayList body = new ArrayList<>(); 12 | 13 | public WhileStmt(Expression condition) { 14 | this.condition = condition; 15 | } 16 | 17 | public Expression getCondition() { 18 | return condition; 19 | } 20 | 21 | public void setCondition(Expression condition) { 22 | this.condition = condition; 23 | } 24 | 25 | public ArrayList getBody() { 26 | return body; 27 | } 28 | 29 | public void setBody(ArrayList body) { 30 | this.body = body; 31 | } 32 | 33 | public void addBody(Statement statement) { 34 | this.body.add(statement); 35 | } 36 | 37 | @Override 38 | public T accept(IVisitor visitor) { 39 | return visitor.visit(this); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/declaration/OnInitDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.expression.Identifier; 4 | import main.ast.node.statement.Statement; 5 | import main.visitor.IVisitor; 6 | 7 | import java.util.ArrayList; 8 | 9 | public class OnInitDeclaration extends Declaration { 10 | private Identifier tradeName; 11 | private ArrayList body = new ArrayList<>(); 12 | 13 | public OnInitDeclaration() { 14 | } 15 | 16 | public Identifier getTradeName() { 17 | return tradeName; 18 | } 19 | 20 | public void setTradeName(Identifier tradeName) { 21 | this.tradeName = tradeName; 22 | } 23 | 24 | public ArrayList getBody() { 25 | return body; 26 | } 27 | 28 | public void setBody(ArrayList body) { 29 | this.body = body; 30 | } 31 | 32 | public void addStatement(Statement statement) { 33 | this.body.add(statement); 34 | } 35 | 36 | @Override 37 | public T accept(IVisitor visitor) { 38 | return visitor.visit(this); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/UnaryExpression.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.ast.node.expression.operators.UnaryOperator; 4 | import main.visitor.IVisitor; 5 | import main.visitor.Visitor; 6 | 7 | //Line -> operator 8 | public class UnaryExpression extends Expression { 9 | 10 | private UnaryOperator unaryOperator; 11 | private Expression operand; 12 | 13 | public UnaryExpression(UnaryOperator unaryOperator, Expression operand) { 14 | this.unaryOperator = unaryOperator; 15 | this.operand = operand; 16 | } 17 | 18 | public Expression getOperand() { 19 | return operand; 20 | } 21 | 22 | public void setOperand(Expression operand) { 23 | this.operand = operand; 24 | } 25 | 26 | public UnaryOperator getUnaryOperator() { 27 | return unaryOperator; 28 | } 29 | 30 | public void setUnaryOperator(UnaryOperator unaryOperator) { 31 | this.unaryOperator = unaryOperator; 32 | } 33 | 34 | @Override 35 | public T accept(IVisitor visitor) { 36 | return visitor.visit(this); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/declaration/OnStartDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.expression.Identifier; 4 | import main.ast.node.statement.Statement; 5 | import main.visitor.IVisitor; 6 | 7 | import java.util.ArrayList; 8 | 9 | public class OnStartDeclaration extends Declaration { 10 | private Identifier tradeName; 11 | private ArrayList body = new ArrayList<>(); 12 | 13 | public OnStartDeclaration(Identifier name){ 14 | this.tradeName = name; 15 | } 16 | 17 | public Identifier getTradeName() { 18 | return tradeName; 19 | } 20 | 21 | public void setTradeName(Identifier tradeName) { 22 | this.tradeName = tradeName; 23 | } 24 | 25 | public ArrayList getBody() { 26 | return body; 27 | } 28 | 29 | public void setBody(ArrayList body) { 30 | this.body = body; 31 | } 32 | 33 | public void addStatement(Statement statement) { 34 | this.body.add(statement); 35 | } 36 | 37 | @Override 38 | public T accept(IVisitor visitor) { 39 | return visitor.visit(this); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Phase 3/src/main/UTL.java: -------------------------------------------------------------------------------- 1 | package main; 2 | 3 | import main.ast.node.Program; 4 | import main.compileError.CompileError; 5 | import main.visitor.astPrinter.ASTPrinter; 6 | import main.visitor.nameAnalyzer.NameAnalyzer; 7 | import main.visitor.typeAnalyzer.TypeAnalyzer; 8 | import org.antlr.v4.runtime.*; 9 | import parsers.*; 10 | 11 | import java.io.IOException; 12 | 13 | public class UTL { 14 | public static void main(String[] args) throws IOException { 15 | CharStream reader = CharStreams.fromFileName(args[0]); 16 | UTLLexer lexer = new UTLLexer(reader); 17 | CommonTokenStream tokens = new CommonTokenStream(lexer); 18 | UTLParser parser = new UTLParser(tokens); 19 | Program program = parser.program().pro; 20 | NameAnalyzer nameAnalyzer = new NameAnalyzer(); 21 | nameAnalyzer.visit(program); 22 | TypeAnalyzer typeAnalyzer = new TypeAnalyzer(); 23 | typeAnalyzer.visit(program); 24 | if (!typeAnalyzer.typeErrors.isEmpty()){ 25 | for(CompileError compileError: typeAnalyzer.typeErrors) 26 | System.out.println(compileError.getMessage()); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/FunctionCall.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class FunctionCall extends Expression { 8 | private Identifier functionName; 9 | private ArrayList args = new ArrayList<>(); 10 | 11 | public FunctionCall(Identifier functionName) { 12 | this.functionName = functionName; 13 | } 14 | 15 | public Identifier getFunctionName() { 16 | return functionName; 17 | } 18 | 19 | public void setFunctionName(Identifier functionName) { 20 | this.functionName = functionName; 21 | } 22 | 23 | public void setArgs(ArrayList args) { 24 | this.args = args; 25 | } 26 | 27 | public ArrayList getArgs() { 28 | return args; 29 | } 30 | 31 | public void addArg(Expression arg) { 32 | this.args.add(arg); 33 | } 34 | 35 | @Override 36 | public String toString(){ 37 | return "FunctionCall"; 38 | } 39 | 40 | @Override 41 | public T accept(IVisitor visitor) { 42 | return visitor.visit(this); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/FunctionCall.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class FunctionCall extends Expression { 8 | private Identifier functionName; 9 | private ArrayList args = new ArrayList<>(); 10 | 11 | public FunctionCall(Identifier functionName) { 12 | this.functionName = functionName; 13 | } 14 | 15 | public Identifier getFunctionName() { 16 | return functionName; 17 | } 18 | 19 | public void setFunctionName(Identifier functionName) { 20 | this.functionName = functionName; 21 | } 22 | 23 | public void setArgs(ArrayList args) { 24 | this.args = args; 25 | } 26 | 27 | public ArrayList getArgs() { 28 | return args; 29 | } 30 | 31 | public void addArg(Expression arg) { 32 | this.args.add(arg); 33 | } 34 | 35 | @Override 36 | public String toString(){ 37 | return "FunctionCall"; 38 | } 39 | 40 | @Override 41 | public T accept(IVisitor visitor) { 42 | return visitor.visit(this); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/statement/WhileStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class WhileStmt extends Statement { 9 | private Expression condition; 10 | private ArrayList body = new ArrayList<>(); 11 | 12 | public WhileStmt(Expression condition) { 13 | this.condition = condition; 14 | } 15 | 16 | public Expression getCondition() { 17 | return condition; 18 | } 19 | 20 | public void setCondition(Expression condition) { 21 | this.condition = condition; 22 | } 23 | 24 | public ArrayList getBody() { 25 | return body; 26 | } 27 | 28 | public void setBody(ArrayList body) { 29 | this.body = body; 30 | } 31 | 32 | public void addBody(Statement statement) { 33 | this.body.add(statement); 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "WhileStmt"; 39 | } 40 | 41 | @Override 42 | public T accept(IVisitor visitor) { 43 | return visitor.visit(this); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/statement/WhileStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class WhileStmt extends Statement { 9 | private Expression condition; 10 | private ArrayList body = new ArrayList<>(); 11 | 12 | public WhileStmt(Expression condition) { 13 | this.condition = condition; 14 | } 15 | 16 | public Expression getCondition() { 17 | return condition; 18 | } 19 | 20 | public void setCondition(Expression condition) { 21 | this.condition = condition; 22 | } 23 | 24 | public ArrayList getBody() { 25 | return body; 26 | } 27 | 28 | public void setBody(ArrayList body) { 29 | this.body = body; 30 | } 31 | 32 | public void addBody(Statement statement) { 33 | this.body.add(statement); 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "WhileStmt"; 39 | } 40 | 41 | @Override 42 | public T accept(IVisitor visitor) { 43 | return visitor.visit(this); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/declaration/OnInitDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.expression.Identifier; 4 | import main.ast.node.statement.Statement; 5 | import main.visitor.IVisitor; 6 | 7 | import java.util.ArrayList; 8 | 9 | public class OnInitDeclaration extends Declaration { 10 | private Identifier tradeName; 11 | private ArrayList body = new ArrayList<>(); 12 | 13 | public OnInitDeclaration() { 14 | } 15 | 16 | public Identifier getTradeName() { 17 | return tradeName; 18 | } 19 | 20 | public void setTradeName(Identifier tradeName) { 21 | this.tradeName = tradeName; 22 | } 23 | 24 | public ArrayList getBody() { 25 | return body; 26 | } 27 | 28 | public void setBody(ArrayList body) { 29 | this.body = body; 30 | } 31 | 32 | public void addStatement(Statement statement) { 33 | this.body.add(statement); 34 | } 35 | 36 | public String toString() { 37 | return "OnInitDeclaration"; 38 | } 39 | 40 | @Override 41 | public T accept(IVisitor visitor) { 42 | return visitor.visit(this); 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/declaration/OnInitDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.expression.Identifier; 4 | import main.ast.node.statement.Statement; 5 | import main.visitor.IVisitor; 6 | 7 | import java.util.ArrayList; 8 | 9 | public class OnInitDeclaration extends Declaration { 10 | private Identifier tradeName; 11 | private ArrayList body = new ArrayList<>(); 12 | 13 | public OnInitDeclaration() { 14 | } 15 | 16 | public Identifier getTradeName() { 17 | return tradeName; 18 | } 19 | 20 | public void setTradeName(Identifier tradeName) { 21 | this.tradeName = tradeName; 22 | } 23 | 24 | public ArrayList getBody() { 25 | return body; 26 | } 27 | 28 | public void setBody(ArrayList body) { 29 | this.body = body; 30 | } 31 | 32 | public void addStatement(Statement statement) { 33 | this.body.add(statement); 34 | } 35 | 36 | public String toString() { 37 | return "OnInitDeclaration"; 38 | } 39 | 40 | @Override 41 | public T accept(IVisitor visitor) { 42 | return visitor.visit(this); 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /Phase 2/src/main/UTL.java: -------------------------------------------------------------------------------- 1 | package main; 2 | 3 | import main.ast.node.Program; 4 | import main.compileError.CompileError; 5 | import main.visitor.astPrinter.ASTPrinter; 6 | import main.visitor.nameAnalyzer.NameAnalyzer; 7 | import org.antlr.v4.runtime.*; 8 | import main.grammar.UTLLexer; 9 | import main.grammar.UTLParser; 10 | 11 | import java.io.IOException; 12 | 13 | public class UTL { 14 | public static void main(String[] args) throws IOException { 15 | CharStream reader = CharStreams.fromFileName(args[0]); 16 | UTLLexer lexer = new UTLLexer(reader); 17 | CommonTokenStream tokens = new CommonTokenStream(lexer); 18 | UTLParser parser = new UTLParser(tokens); 19 | Program program = parser.program().pro; 20 | 21 | NameAnalyzer nameAnalyzer = new NameAnalyzer(); 22 | nameAnalyzer.visit(program); 23 | // if (!nameAnalyzer.nameErrors.isEmpty()) { 24 | // for(CompileError compileError: nameAnalyzer.nameErrors) 25 | // System.out.println(compileError.getMessage()); 26 | // } 27 | // else { 28 | ASTPrinter astPrinter = new ASTPrinter(); 29 | astPrinter.visit(program); 30 | // } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/declaration/OnStartDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.expression.Identifier; 4 | import main.ast.node.statement.Statement; 5 | import main.visitor.IVisitor; 6 | 7 | import java.util.ArrayList; 8 | 9 | public class OnStartDeclaration extends Declaration { 10 | private Identifier tradeName; 11 | private ArrayList body = new ArrayList<>(); 12 | 13 | public OnStartDeclaration(Identifier name) { 14 | } 15 | 16 | 17 | public Identifier getTradeName() { 18 | return tradeName; 19 | } 20 | 21 | public void setTradeName(Identifier tradeName) { 22 | this.tradeName = tradeName; 23 | } 24 | 25 | public ArrayList getBody() { 26 | return body; 27 | } 28 | 29 | public void setBody(ArrayList body) { 30 | this.body = body; 31 | } 32 | 33 | public void addStatement(Statement statement) { 34 | this.body.add(statement); 35 | } 36 | 37 | public String toString() { 38 | return "OnStartDeclaration"; 39 | } 40 | 41 | @Override 42 | public T accept(IVisitor visitor) { 43 | return visitor.visit(this); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/declaration/OnStartDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.expression.Identifier; 4 | import main.ast.node.statement.Statement; 5 | import main.visitor.IVisitor; 6 | 7 | import java.util.ArrayList; 8 | 9 | public class OnStartDeclaration extends Declaration { 10 | private Identifier tradeName; 11 | private ArrayList body = new ArrayList<>(); 12 | 13 | public OnStartDeclaration(Identifier name) { 14 | } 15 | 16 | 17 | public Identifier getTradeName() { 18 | return tradeName; 19 | } 20 | 21 | public void setTradeName(Identifier tradeName) { 22 | this.tradeName = tradeName; 23 | } 24 | 25 | public ArrayList getBody() { 26 | return body; 27 | } 28 | 29 | public void setBody(ArrayList body) { 30 | this.body = body; 31 | } 32 | 33 | public void addStatement(Statement statement) { 34 | this.body.add(statement); 35 | } 36 | 37 | public String toString() { 38 | return "OnStartDeclaration"; 39 | } 40 | 41 | @Override 42 | public T accept(IVisitor visitor) { 43 | return visitor.visit(this); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/UnaryExpression.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.ast.node.expression.operators.UnaryOperator; 4 | import main.visitor.IVisitor; 5 | import main.visitor.Visitor; 6 | 7 | public class UnaryExpression extends Expression { 8 | 9 | private UnaryOperator unaryOperator; 10 | private Expression operand; 11 | 12 | public UnaryExpression(UnaryOperator unaryOperator, Expression operand) { 13 | this.unaryOperator = unaryOperator; 14 | this.operand = operand; 15 | } 16 | 17 | public Expression getOperand() { 18 | return operand; 19 | } 20 | 21 | public void setOperand(Expression operand) { 22 | this.operand = operand; 23 | } 24 | 25 | public UnaryOperator getUnaryOperator() { 26 | return unaryOperator; 27 | } 28 | 29 | public void setUnaryOperator(UnaryOperator unaryOperator) { 30 | this.unaryOperator = unaryOperator; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "UnaryExpression " + unaryOperator.name(); 36 | } 37 | 38 | @Override 39 | public T accept(IVisitor visitor) { 40 | return visitor.visit(this); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/UnaryExpression.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.ast.node.expression.operators.UnaryOperator; 4 | import main.visitor.IVisitor; 5 | import main.visitor.Visitor; 6 | 7 | public class UnaryExpression extends Expression { 8 | 9 | private UnaryOperator unaryOperator; 10 | private Expression operand; 11 | 12 | public UnaryExpression(UnaryOperator unaryOperator, Expression operand) { 13 | this.unaryOperator = unaryOperator; 14 | this.operand = operand; 15 | } 16 | 17 | public Expression getOperand() { 18 | return operand; 19 | } 20 | 21 | public void setOperand(Expression operand) { 22 | this.operand = operand; 23 | } 24 | 25 | public UnaryOperator getUnaryOperator() { 26 | return unaryOperator; 27 | } 28 | 29 | public void setUnaryOperator(UnaryOperator unaryOperator) { 30 | this.unaryOperator = unaryOperator; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "UnaryExpression " + unaryOperator.name(); 36 | } 37 | 38 | @Override 39 | public T accept(IVisitor visitor) { 40 | return visitor.visit(this); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/statement/TryCatchStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class TryCatchStmt extends Statement { 9 | private ArrayList thenBody = new ArrayList<>(); 10 | private ArrayList elseBody = new ArrayList<>(); 11 | 12 | public TryCatchStmt() { 13 | 14 | } 15 | 16 | public ArrayList getThenBody() { 17 | return thenBody; 18 | } 19 | public void setThenBody(ArrayList thenBody) { 20 | this.thenBody = thenBody; 21 | } 22 | 23 | public ArrayList getElseBody() { 24 | return elseBody; 25 | } 26 | public void setElseBody(ArrayList elseBody) { 27 | this.elseBody = elseBody; 28 | } 29 | 30 | public void addThenStatement(Statement statement) { 31 | this.thenBody.add(statement); 32 | } 33 | 34 | public void addElseStatement(Statement statement) { 35 | this.elseBody.add(statement); 36 | } 37 | 38 | @Override 39 | public T accept(IVisitor visitor) { 40 | return visitor.visit(this); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Phase 3/src/main/symbolTable/symbolTableItems/MainItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.MainDeclaration; 4 | import main.ast.node.declaration.OnInitDeclaration; 5 | import main.symbolTable.SymbolTable; 6 | 7 | public class MainItem extends SymbolTableItem { 8 | 9 | protected SymbolTable mainSymbolTable; 10 | protected MainDeclaration mainDeclaration; 11 | public static final String START_KEY = "Main_"; 12 | 13 | public MainItem(MainDeclaration mainDeclaration) 14 | { 15 | this.mainDeclaration = mainDeclaration; 16 | } 17 | 18 | public void setMainSymbolTable(SymbolTable mainSymbolTable) 19 | { 20 | this.mainSymbolTable = mainSymbolTable; 21 | } 22 | 23 | public SymbolTable getMainSymbolTable() 24 | { 25 | return mainSymbolTable; 26 | } 27 | 28 | 29 | public void setDeclaration(MainDeclaration mainDeclaration) 30 | { 31 | this.mainDeclaration = mainDeclaration; 32 | } 33 | 34 | public MainDeclaration getDeclaration() 35 | { 36 | return mainDeclaration; 37 | } 38 | 39 | @Override 40 | public String getKey() 41 | { 42 | return MainItem.START_KEY + "main"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Phase 4/src/main/symbolTable/symbolTableItems/MainItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.MainDeclaration; 4 | import main.ast.node.declaration.OnInitDeclaration; 5 | import main.symbolTable.SymbolTable; 6 | 7 | public class MainItem extends SymbolTableItem { 8 | 9 | protected SymbolTable mainSymbolTable; 10 | protected MainDeclaration mainDeclaration; 11 | public static final String START_KEY = "Main_"; 12 | 13 | public MainItem(MainDeclaration mainDeclaration) 14 | { 15 | this.mainDeclaration = mainDeclaration; 16 | } 17 | 18 | public void setMainSymbolTable(SymbolTable mainSymbolTable) 19 | { 20 | this.mainSymbolTable = mainSymbolTable; 21 | } 22 | 23 | public SymbolTable getMainSymbolTable() 24 | { 25 | return mainSymbolTable; 26 | } 27 | 28 | 29 | public void setDeclaration(MainDeclaration mainDeclaration) 30 | { 31 | this.mainDeclaration = mainDeclaration; 32 | } 33 | 34 | public MainDeclaration getDeclaration() 35 | { 36 | return mainDeclaration; 37 | } 38 | 39 | @Override 40 | public String getKey() 41 | { 42 | return MainItem.START_KEY + "main"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/declaration/MainDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import java.util.ArrayList; 4 | 5 | import main.ast.node.statement.Statement; 6 | import main.visitor.IVisitor; 7 | 8 | public class MainDeclaration extends Declaration { 9 | private ArrayList mainTrades = new ArrayList<>(); 10 | private ArrayList body = new ArrayList<>(); 11 | 12 | public MainDeclaration(){ 13 | } 14 | 15 | public ArrayList getMainTrades(){ 16 | return this.mainTrades; 17 | } 18 | 19 | public void setMainTrades(ArrayList mainTrades) { 20 | this.mainTrades = mainTrades; 21 | } 22 | 23 | public void addTradeInstantiation(VarDeclaration tradeInstantiation) { 24 | mainTrades.add(tradeInstantiation); 25 | } 26 | 27 | 28 | public ArrayList getBody() { 29 | return body; 30 | } 31 | 32 | public void setBody(ArrayList body) { 33 | this.body = body; 34 | } 35 | 36 | public void addStatement(Statement statement) { 37 | this.body.add(statement); 38 | } 39 | 40 | @Override 41 | public T accept(IVisitor visitor) { 42 | return visitor.visit(this); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/statement/TryCatchStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class TryCatchStmt extends Statement { 8 | private ArrayList tryBlock = new ArrayList<>(); 9 | private ArrayList catchBlock = new ArrayList<>(); 10 | 11 | public TryCatchStmt() { 12 | } 13 | 14 | 15 | public ArrayList getTryBlock() { 16 | return tryBlock; 17 | } 18 | 19 | public void setTryBlock(ArrayList tryBlock) { 20 | this.tryBlock = tryBlock; 21 | } 22 | 23 | public ArrayList getCatchBlock() { 24 | return catchBlock; 25 | } 26 | 27 | public void setCatchBlock(ArrayList catchBlock) { 28 | this.catchBlock = catchBlock; 29 | } 30 | 31 | public void addThenStatement(Statement statement) { 32 | this.tryBlock.add(statement); 33 | } 34 | 35 | public void addElseStatement(Statement statement) { 36 | this.catchBlock.add(statement); 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "TryCatchStmt"; 42 | } 43 | 44 | @Override 45 | public T accept(IVisitor visitor) { 46 | return visitor.visit(this); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/statement/TryCatchStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class TryCatchStmt extends Statement { 8 | private ArrayList tryBlock = new ArrayList<>(); 9 | private ArrayList catchBlock = new ArrayList<>(); 10 | 11 | public TryCatchStmt() { 12 | } 13 | 14 | 15 | public ArrayList getTryBlock() { 16 | return tryBlock; 17 | } 18 | 19 | public void setTryBlock(ArrayList tryBlock) { 20 | this.tryBlock = tryBlock; 21 | } 22 | 23 | public ArrayList getCatchBlock() { 24 | return catchBlock; 25 | } 26 | 27 | public void setCatchBlock(ArrayList catchBlock) { 28 | this.catchBlock = catchBlock; 29 | } 30 | 31 | public void addThenStatement(Statement statement) { 32 | this.tryBlock.add(statement); 33 | } 34 | 35 | public void addElseStatement(Statement statement) { 36 | this.catchBlock.add(statement); 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "TryCatchStmt"; 42 | } 43 | 44 | @Override 45 | public T accept(IVisitor visitor) { 46 | return visitor.visit(this); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Phase 4/src/main/UTL.java: -------------------------------------------------------------------------------- 1 | package main; 2 | 3 | import main.ast.node.Program; 4 | import main.compileError.CompileError; 5 | import main.visitor.astPrinter.ASTPrinter; 6 | import main.visitor.codeGenerator.CodeGenerator; 7 | import main.visitor.nameAnalyzer.NameAnalyzer; 8 | import main.visitor.typeAnalyzer.TypeAnalyzer; 9 | import org.antlr.v4.runtime.*; 10 | import parsers.*; 11 | 12 | import java.io.IOException; 13 | 14 | public class UTL { 15 | public static void main(String[] args) throws IOException { 16 | CharStream reader = CharStreams.fromFileName(args[0]); 17 | UTLLexer lexer = new UTLLexer(reader); 18 | CommonTokenStream tokens = new CommonTokenStream(lexer); 19 | UTLParser parser = new UTLParser(tokens); 20 | Program program = parser.program().pro; 21 | NameAnalyzer nameAnalyzer = new NameAnalyzer(); 22 | nameAnalyzer.visit(program); 23 | TypeAnalyzer typeAnalyzer = new TypeAnalyzer(); 24 | typeAnalyzer.visit(program); 25 | if (!typeAnalyzer.typeErrors.isEmpty()){ 26 | for(CompileError compileError: typeAnalyzer.typeErrors) 27 | System.out.println(compileError.getMessage()); 28 | } 29 | CodeGenerator codeGenerator = new CodeGenerator(program); 30 | codeGenerator.visit(program); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/BinaryExpression.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | import main.visitor.Visitor; 5 | import main.ast.node.expression.operators.BinaryOperator; 6 | 7 | //Line -> operator 8 | public class BinaryExpression extends Expression { 9 | 10 | private Expression left; 11 | private Expression right; 12 | private BinaryOperator binaryOperator; 13 | 14 | public BinaryExpression(Expression left, Expression right, BinaryOperator binaryOperator) { 15 | this.left = left; 16 | this.right = right; 17 | this.binaryOperator = binaryOperator; 18 | } 19 | 20 | public Expression getLeft() { 21 | return left; 22 | } 23 | 24 | public void setLeft(Expression left) { 25 | this.left = left; 26 | } 27 | 28 | public Expression getRight() { 29 | return right; 30 | } 31 | 32 | public void setRight(Expression right) { 33 | this.right = right; 34 | } 35 | 36 | public BinaryOperator getBinaryOperator() { 37 | return binaryOperator; 38 | } 39 | 40 | public void setBinaryOperator(BinaryOperator binaryOperator) { 41 | this.binaryOperator = binaryOperator; 42 | } 43 | 44 | @Override 45 | public T accept(IVisitor visitor) { 46 | return visitor.visit(this); 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/expression/MethodCall.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | import java.util.ArrayList; 6 | //.open(); 7 | 8 | public class MethodCall extends Expression { 9 | private Expression instance; 10 | private Identifier functionName; 11 | private ArrayList args = new ArrayList<>(); 12 | 13 | public MethodCall(Expression instance, Identifier functionName) { 14 | this.instance = instance; 15 | this.functionName = functionName; 16 | } 17 | 18 | public Expression getInstance() { 19 | return instance; 20 | } 21 | 22 | public void setInstance(Expression instance) { 23 | this.instance = instance; 24 | } 25 | 26 | public Identifier getFunctionName() { 27 | return functionName; 28 | } 29 | 30 | public void setFunctionName(Identifier functionName) { 31 | this.functionName = functionName; 32 | } 33 | 34 | public void setArgs(ArrayList args) { 35 | this.args = args; 36 | } 37 | 38 | public ArrayList getArgs() { 39 | return args; 40 | } 41 | 42 | public void addArg(Expression arg) { 43 | this.args.add(arg); 44 | } 45 | 46 | @Override 47 | public T accept(IVisitor visitor) { 48 | return visitor.visit(this); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/declaration/VarDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.ast.node.expression.Identifier; 5 | import main.ast.type.Type; 6 | import main.visitor.IVisitor; 7 | 8 | public class VarDeclaration extends Declaration { 9 | private Type type; 10 | private Identifier identifier; 11 | private int length = 0; // > 0 means array 12 | private Expression value = null; 13 | 14 | public VarDeclaration() { 15 | } 16 | 17 | public Identifier getIdentifier() { 18 | return identifier; 19 | } 20 | 21 | public void setIdentifier(Identifier identifier) { 22 | this.identifier = identifier; 23 | } 24 | 25 | @Override 26 | public Type getType() { 27 | return type; 28 | } 29 | @Override 30 | public void setType(Type type) { 31 | this.type = type; 32 | } 33 | 34 | public int getLength() { 35 | return this.length; 36 | } 37 | 38 | public void setLength(int length) { 39 | this.length = length; 40 | } 41 | 42 | public boolean isArray() { 43 | return this.length > 0; 44 | } 45 | 46 | public Expression getValue() { return this.value; } 47 | 48 | public void setValue(Expression value) { this.value = value; } 49 | 50 | @Override 51 | public T accept(IVisitor visitor) { 52 | return visitor.visit(this); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Phase 2/src/main/symbolTable/symbolTableItems/MainItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.OnInitDeclaration; 4 | import main.symbolTable.SymbolTable; 5 | 6 | public class MainItem extends SymbolTableItem { 7 | 8 | protected SymbolTable mainSymbolTable; 9 | protected OnInitDeclaration onInitDeclaration; 10 | public static final String START_KEY = "Main_"; 11 | 12 | public MainItem(OnInitDeclaration onInitDeclaration) 13 | { 14 | this.name = onInitDeclaration.getTradeName().getName(); 15 | this.onInitDeclaration = onInitDeclaration; 16 | } 17 | 18 | public void setMainSymbolTable(SymbolTable mainSymbolTable) 19 | { 20 | this.mainSymbolTable = mainSymbolTable; 21 | } 22 | 23 | public SymbolTable getMainSymbolTable() 24 | { 25 | return mainSymbolTable; 26 | } 27 | 28 | public void setName(String name) 29 | { 30 | this.name = name; 31 | this.onInitDeclaration.getTradeName().setName(name); 32 | } 33 | 34 | public void setActorDeclaration(OnInitDeclaration onInitDeclaration) 35 | { 36 | this.onInitDeclaration = onInitDeclaration; 37 | } 38 | 39 | public OnInitDeclaration getActorDeclaration() 40 | { 41 | return onInitDeclaration; 42 | } 43 | 44 | @Override 45 | public String getKey() 46 | { 47 | return MainItem.START_KEY + this.name; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/MethodCall.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class MethodCall extends Expression { 8 | private Expression instance; 9 | private Identifier functionName; 10 | private ArrayList args = new ArrayList<>(); 11 | 12 | public MethodCall(Expression instance, Identifier functionName) { 13 | this.instance = instance; 14 | this.functionName = functionName; 15 | } 16 | 17 | public Expression getInstance() { 18 | return instance; 19 | } 20 | 21 | public void setInstance(Expression instance) { 22 | this.instance = instance; 23 | } 24 | 25 | public Identifier getFunctionName() { 26 | return functionName; 27 | } 28 | 29 | public void setFunctionName(Identifier functionName) { 30 | this.functionName = functionName; 31 | } 32 | 33 | public void setArgs(ArrayList args) { 34 | this.args = args; 35 | } 36 | 37 | public ArrayList getArgs() { 38 | return args; 39 | } 40 | 41 | public void addArg(Expression arg) { 42 | this.args.add(arg); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "MethodCall"; 48 | } 49 | 50 | @Override 51 | public T accept(IVisitor visitor) { 52 | return visitor.visit(this); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/MethodCall.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class MethodCall extends Expression { 8 | private Expression instance; 9 | private Identifier functionName; 10 | private ArrayList args = new ArrayList<>(); 11 | 12 | public MethodCall(Expression instance, Identifier functionName) { 13 | this.instance = instance; 14 | this.functionName = functionName; 15 | } 16 | 17 | public Expression getInstance() { 18 | return instance; 19 | } 20 | 21 | public void setInstance(Expression instance) { 22 | this.instance = instance; 23 | } 24 | 25 | public Identifier getFunctionName() { 26 | return functionName; 27 | } 28 | 29 | public void setFunctionName(Identifier functionName) { 30 | this.functionName = functionName; 31 | } 32 | 33 | public void setArgs(ArrayList args) { 34 | this.args = args; 35 | } 36 | 37 | public ArrayList getArgs() { 38 | return args; 39 | } 40 | 41 | public void addArg(Expression arg) { 42 | this.args.add(arg); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "MethodCall"; 48 | } 49 | 50 | @Override 51 | public T accept(IVisitor visitor) { 52 | return visitor.visit(this); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/expression/BinaryExpression.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | import main.visitor.Visitor; 5 | import main.ast.node.expression.operators.BinaryOperator; 6 | 7 | public class BinaryExpression extends Expression { 8 | 9 | private Expression left; 10 | private Expression right; 11 | private BinaryOperator binaryOperator; 12 | 13 | public BinaryExpression(Expression left, Expression right, BinaryOperator binaryOperator) { 14 | this.left = left; 15 | this.right = right; 16 | this.binaryOperator = binaryOperator; 17 | } 18 | 19 | public Expression getLeft() { 20 | return left; 21 | } 22 | 23 | public void setLeft(Expression left) { 24 | this.left = left; 25 | } 26 | 27 | public Expression getRight() { 28 | return right; 29 | } 30 | 31 | public void setRight(Expression right) { 32 | this.right = right; 33 | } 34 | 35 | public BinaryOperator getBinaryOperator() { 36 | return binaryOperator; 37 | } 38 | 39 | public void setBinaryOperator(BinaryOperator binaryOperator) { 40 | this.binaryOperator = binaryOperator; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "BinaryExpression " + binaryOperator.name(); 46 | } 47 | @Override 48 | public T accept(IVisitor visitor) { 49 | return visitor.visit(this); 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/expression/BinaryExpression.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.expression; 2 | 3 | import main.visitor.IVisitor; 4 | import main.visitor.Visitor; 5 | import main.ast.node.expression.operators.BinaryOperator; 6 | 7 | public class BinaryExpression extends Expression { 8 | 9 | private Expression left; 10 | private Expression right; 11 | private BinaryOperator binaryOperator; 12 | 13 | public BinaryExpression(Expression left, Expression right, BinaryOperator binaryOperator) { 14 | this.left = left; 15 | this.right = right; 16 | this.binaryOperator = binaryOperator; 17 | } 18 | 19 | public Expression getLeft() { 20 | return left; 21 | } 22 | 23 | public void setLeft(Expression left) { 24 | this.left = left; 25 | } 26 | 27 | public Expression getRight() { 28 | return right; 29 | } 30 | 31 | public void setRight(Expression right) { 32 | this.right = right; 33 | } 34 | 35 | public BinaryOperator getBinaryOperator() { 36 | return binaryOperator; 37 | } 38 | 39 | public void setBinaryOperator(BinaryOperator binaryOperator) { 40 | this.binaryOperator = binaryOperator; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "BinaryExpression " + binaryOperator.name(); 46 | } 47 | @Override 48 | public T accept(IVisitor visitor) { 49 | return visitor.visit(this); 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /Phase 3/src/main/symbolTable/symbolTableItems/OnInitItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.OnInitDeclaration; 4 | import main.symbolTable.SymbolTable; 5 | 6 | public class OnInitItem extends SymbolTableItem { 7 | 8 | protected SymbolTable onInitSymbolTable; 9 | protected OnInitDeclaration onInitDeclaration; 10 | public static final String START_KEY = "OnInit_"; 11 | 12 | public OnInitItem(OnInitDeclaration onInitDeclaration) 13 | { 14 | this.name = onInitDeclaration.getTradeName().getName(); 15 | this.onInitDeclaration = onInitDeclaration; 16 | } 17 | 18 | public void setOnInitSymbolTable(SymbolTable onInitSymbolTable) 19 | { 20 | this.onInitSymbolTable = onInitSymbolTable; 21 | } 22 | 23 | public SymbolTable getOnInitSymbolTable() 24 | { 25 | return onInitSymbolTable; 26 | } 27 | 28 | public void setName(String name) 29 | { 30 | this.name = name; 31 | this.onInitDeclaration.getTradeName().setName(name); 32 | } 33 | 34 | public void setActorDeclaration(OnInitDeclaration onInitDeclaration) 35 | { 36 | this.onInitDeclaration = onInitDeclaration; 37 | } 38 | 39 | public OnInitDeclaration getDeclaration() 40 | { 41 | return onInitDeclaration; 42 | } 43 | 44 | @Override 45 | public String getKey() 46 | { 47 | return OnInitItem.START_KEY + this.name; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Phase 4/src/main/symbolTable/symbolTableItems/OnInitItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.OnInitDeclaration; 4 | import main.symbolTable.SymbolTable; 5 | 6 | public class OnInitItem extends SymbolTableItem { 7 | 8 | protected SymbolTable onInitSymbolTable; 9 | protected OnInitDeclaration onInitDeclaration; 10 | public static final String START_KEY = "OnInit_"; 11 | 12 | public OnInitItem(OnInitDeclaration onInitDeclaration) 13 | { 14 | this.name = onInitDeclaration.getTradeName().getName(); 15 | this.onInitDeclaration = onInitDeclaration; 16 | } 17 | 18 | public void setOnInitSymbolTable(SymbolTable onInitSymbolTable) 19 | { 20 | this.onInitSymbolTable = onInitSymbolTable; 21 | } 22 | 23 | public SymbolTable getOnInitSymbolTable() 24 | { 25 | return onInitSymbolTable; 26 | } 27 | 28 | public void setName(String name) 29 | { 30 | this.name = name; 31 | this.onInitDeclaration.getTradeName().setName(name); 32 | } 33 | 34 | public void setActorDeclaration(OnInitDeclaration onInitDeclaration) 35 | { 36 | this.onInitDeclaration = onInitDeclaration; 37 | } 38 | 39 | public OnInitDeclaration getDeclaration() 40 | { 41 | return onInitDeclaration; 42 | } 43 | 44 | @Override 45 | public String getKey() 46 | { 47 | return OnInitItem.START_KEY + this.name; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Phase 2/src/main/symbolTable/SymbolTable.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable; 2 | 3 | import main.symbolTable.itemException.*; 4 | import main.symbolTable.symbolTableItems.SymbolTableItem; 5 | 6 | import java.util.HashMap; 7 | 8 | public class SymbolTable { 9 | 10 | // Static members region 11 | public static SymbolTable top; 12 | public static SymbolTable root; 13 | private static Stack stack = new Stack(); 14 | public static void push(SymbolTable symbolTable) { 15 | if(top != null) 16 | stack.push(top); 17 | top = symbolTable; 18 | } 19 | 20 | public static void pop() { 21 | top = stack.pop(); 22 | } 23 | 24 | public SymbolTable pre; 25 | public String name; 26 | private HashMap items; 27 | 28 | 29 | public SymbolTable() { 30 | this(null, ""); 31 | } 32 | 33 | public SymbolTable(SymbolTable pre, String name) { 34 | this.pre = pre; 35 | this.items = new HashMap<>(); 36 | this.name = name; 37 | } 38 | 39 | public void put(SymbolTableItem item) throws ItemAlreadyExistsException { 40 | if(items.containsKey(item.getKey())) 41 | throw new ItemAlreadyExistsException(); 42 | items.put(item.getKey(), item); 43 | } 44 | 45 | public SymbolTableItem get(String key) throws ItemNotFoundException { 46 | SymbolTableItem item = items.get(key); 47 | if(item == null && pre != null) 48 | return pre.get(key); 49 | else if(item == null) 50 | throw new ItemNotFoundException(); 51 | else 52 | return item; 53 | } 54 | } -------------------------------------------------------------------------------- /Phase 3/src/main/symbolTable/SymbolTable.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable; 2 | 3 | import main.symbolTable.itemException.*; 4 | import main.symbolTable.symbolTableItems.SymbolTableItem; 5 | 6 | import java.util.HashMap; 7 | 8 | public class SymbolTable { 9 | 10 | // Static members region 11 | public static SymbolTable top; 12 | public static SymbolTable root; 13 | private static Stack stack = new Stack(); 14 | public static void push(SymbolTable symbolTable) { 15 | if(top != null) 16 | stack.push(top); 17 | top = symbolTable; 18 | } 19 | 20 | public static void pop() { 21 | top = stack.pop(); 22 | } 23 | 24 | public SymbolTable pre; 25 | public String name; 26 | private HashMap items; 27 | 28 | 29 | public SymbolTable() { 30 | this(null, ""); 31 | } 32 | 33 | public SymbolTable(SymbolTable pre, String name) { 34 | this.pre = pre; 35 | this.items = new HashMap<>(); 36 | this.name = name; 37 | } 38 | 39 | public void put(SymbolTableItem item) throws ItemAlreadyExistsException { 40 | if(items.containsKey(item.getKey())) 41 | throw new ItemAlreadyExistsException(); 42 | items.put(item.getKey(), item); 43 | } 44 | 45 | public SymbolTableItem get(String key) throws ItemNotFoundException { 46 | SymbolTableItem item = items.get(key); 47 | if(item == null && pre != null) 48 | return pre.get(key); 49 | else if(item == null) 50 | throw new ItemNotFoundException(); 51 | else 52 | return item; 53 | } 54 | } -------------------------------------------------------------------------------- /Phase 4/src/main/symbolTable/SymbolTable.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable; 2 | 3 | import main.symbolTable.itemException.*; 4 | import main.symbolTable.symbolTableItems.SymbolTableItem; 5 | 6 | import java.util.HashMap; 7 | 8 | public class SymbolTable { 9 | 10 | // Static members region 11 | public static SymbolTable top; 12 | public static SymbolTable root; 13 | private static Stack stack = new Stack(); 14 | public static void push(SymbolTable symbolTable) { 15 | if(top != null) 16 | stack.push(top); 17 | top = symbolTable; 18 | } 19 | 20 | public static void pop() { 21 | top = stack.pop(); 22 | } 23 | 24 | public SymbolTable pre; 25 | public String name; 26 | private HashMap items; 27 | 28 | 29 | public SymbolTable() { 30 | this(null, ""); 31 | } 32 | 33 | public SymbolTable(SymbolTable pre, String name) { 34 | this.pre = pre; 35 | this.items = new HashMap<>(); 36 | this.name = name; 37 | } 38 | 39 | public void put(SymbolTableItem item) throws ItemAlreadyExistsException { 40 | if(items.containsKey(item.getKey())) 41 | throw new ItemAlreadyExistsException(); 42 | items.put(item.getKey(), item); 43 | } 44 | 45 | public SymbolTableItem get(String key) throws ItemNotFoundException { 46 | SymbolTableItem item = items.get(key); 47 | if(item == null && pre != null) 48 | return pre.get(key); 49 | else if(item == null) 50 | throw new ItemNotFoundException(); 51 | else 52 | return item; 53 | } 54 | } -------------------------------------------------------------------------------- /Phase 2/src/main/symbolTable/symbolTableItems/VariableItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.VarDeclaration; 4 | import main.ast.type.Type; 5 | 6 | public class VariableItem extends SymbolTableItem { 7 | 8 | protected Type type; 9 | protected VarDeclaration varDeclaration; 10 | public static final String START_KEY = "Variable_"; 11 | 12 | public VariableItem(String name, Type type) { 13 | this.name = name; 14 | this.type = type; 15 | } 16 | 17 | public VariableItem(VarDeclaration varDeclaration) 18 | { 19 | this.name = varDeclaration.getIdentifier().getName(); 20 | this.type = varDeclaration.getType(); 21 | this.varDeclaration = varDeclaration; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) 29 | { 30 | this.name = name; 31 | varDeclaration.getIdentifier().setName(name); 32 | } 33 | 34 | public Type getType() { 35 | return type; 36 | } 37 | 38 | public void setType(Type type) { 39 | this.type = type; 40 | } 41 | 42 | public VarDeclaration getVarDeclaration() 43 | { 44 | return varDeclaration; 45 | } 46 | 47 | public void setVarDeclaration(VarDeclaration varDeclaration) 48 | { 49 | this.varDeclaration = varDeclaration; 50 | } 51 | 52 | @Override 53 | public String getKey() { 54 | return VariableItem.START_KEY + this.name; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Phase 3/src/main/symbolTable/symbolTableItems/VariableItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.VarDeclaration; 4 | import main.ast.type.Type; 5 | 6 | public class VariableItem extends SymbolTableItem { 7 | 8 | protected Type type; 9 | protected VarDeclaration varDeclaration; 10 | public static final String START_KEY = "Variable_"; 11 | 12 | public VariableItem(String name, Type type) { 13 | this.name = name; 14 | this.type = type; 15 | } 16 | 17 | public VariableItem(VarDeclaration varDeclaration) 18 | { 19 | this.name = varDeclaration.getIdentifier().getName(); 20 | this.type = varDeclaration.getType(); 21 | this.varDeclaration = varDeclaration; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) 29 | { 30 | this.name = name; 31 | varDeclaration.getIdentifier().setName(name); 32 | } 33 | 34 | public Type getType() { 35 | return type; 36 | } 37 | 38 | public void setType(Type type) { 39 | this.type = type; 40 | } 41 | 42 | public VarDeclaration getVarDeclaration() 43 | { 44 | return varDeclaration; 45 | } 46 | 47 | public void setVarDeclaration(VarDeclaration varDeclaration) 48 | { 49 | this.varDeclaration = varDeclaration; 50 | } 51 | 52 | @Override 53 | public String getKey() { 54 | return VariableItem.START_KEY + this.name; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Phase 4/src/main/symbolTable/symbolTableItems/VariableItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.VarDeclaration; 4 | import main.ast.type.Type; 5 | 6 | public class VariableItem extends SymbolTableItem { 7 | 8 | protected Type type; 9 | protected VarDeclaration varDeclaration; 10 | public static final String START_KEY = "Variable_"; 11 | 12 | public VariableItem(String name, Type type) { 13 | this.name = name; 14 | this.type = type; 15 | } 16 | 17 | public VariableItem(VarDeclaration varDeclaration) 18 | { 19 | this.name = varDeclaration.getIdentifier().getName(); 20 | this.type = varDeclaration.getType(); 21 | this.varDeclaration = varDeclaration; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) 29 | { 30 | this.name = name; 31 | varDeclaration.getIdentifier().setName(name); 32 | } 33 | 34 | public Type getType() { 35 | return type; 36 | } 37 | 38 | public void setType(Type type) { 39 | this.type = type; 40 | } 41 | 42 | public VarDeclaration getVarDeclaration() 43 | { 44 | return varDeclaration; 45 | } 46 | 47 | public void setVarDeclaration(VarDeclaration varDeclaration) 48 | { 49 | this.varDeclaration = varDeclaration; 50 | } 51 | 52 | @Override 53 | public String getKey() { 54 | return VariableItem.START_KEY + this.name; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/statement/IfElseStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.visitor.IVisitor; 4 | import main.ast.node.expression.Expression; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class IfElseStmt extends Statement { 9 | private Expression condition; 10 | private ArrayList thenBody = new ArrayList<>(); 11 | private ArrayList elseBody = new ArrayList<>(); 12 | 13 | public IfElseStmt(Expression condition) { 14 | this.condition = condition; 15 | } 16 | 17 | public Expression getCondition() { 18 | return condition; 19 | } 20 | public void setCondition(Expression condition) { 21 | this.condition = condition; 22 | } 23 | 24 | public ArrayList getThenBody() { 25 | return thenBody; 26 | } 27 | public void setThenBody(ArrayList thenBody) { 28 | this.thenBody = thenBody; 29 | } 30 | 31 | public ArrayList getElseBody() { 32 | return elseBody; 33 | } 34 | public void setElseBody(ArrayList elseBody) { 35 | this.elseBody = elseBody; 36 | } 37 | 38 | public void addThenStatement(Statement statement) { 39 | this.thenBody.add(statement); 40 | } 41 | 42 | public void addElseStatement(Statement statement) { 43 | this.elseBody.add(statement); 44 | } 45 | 46 | @Override 47 | public T accept(IVisitor visitor) { 48 | return visitor.visit(this); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Phase 2/src/main/symbolTable/symbolTableItems/OnInitItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.OnInitDeclaration; 4 | import main.symbolTable.SymbolTable; 5 | 6 | public class OnInitItem extends SymbolTableItem { 7 | 8 | protected SymbolTable onInitSymbolTable; 9 | protected OnInitDeclaration onInitDeclaration; 10 | public static final String START_KEY = "OnInit_"; 11 | 12 | public OnInitItem(OnInitDeclaration onInitDeclaration) 13 | { 14 | this.name = onInitDeclaration.getTradeName().getName(); 15 | this.onInitDeclaration = onInitDeclaration; 16 | } 17 | 18 | public void setOnInitSymbolTable(SymbolTable onInitSymbolTable) 19 | { 20 | this.onInitSymbolTable = onInitSymbolTable; 21 | } 22 | 23 | public SymbolTable getOnInitSymbolTable() 24 | { 25 | return onInitSymbolTable; 26 | } 27 | 28 | public void setName(String name) 29 | { 30 | this.name = name; 31 | this.onInitDeclaration.getTradeName().setName(name); 32 | } 33 | public String getName() { 34 | return name; 35 | } 36 | public void setOnInitDeclaration(OnInitDeclaration onInitDeclaration) 37 | { 38 | this.onInitDeclaration = onInitDeclaration; 39 | } 40 | 41 | public OnInitDeclaration getOnInitDeclaration() 42 | { 43 | return onInitDeclaration; 44 | } 45 | 46 | @Override 47 | public String getKey() 48 | { 49 | return OnInitItem.START_KEY + this.name; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Phase 2/src/main/symbolTable/symbolTableItems/OnStartItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.OnStartDeclaration; 4 | import main.symbolTable.SymbolTable; 5 | 6 | public class OnStartItem extends SymbolTableItem { 7 | 8 | protected SymbolTable onStartSymbolTable; 9 | protected OnStartDeclaration onStartDeclaration; 10 | public static final String START_KEY = "OnStart_"; 11 | 12 | public OnStartItem(OnStartDeclaration onStartDeclaration) 13 | { 14 | this.name = onStartDeclaration.getTradeName().getName(); 15 | this.onStartDeclaration = onStartDeclaration; 16 | } 17 | 18 | public void setOnStartSymbolTable(SymbolTable onStartSymbolTable) 19 | { 20 | this.onStartSymbolTable = onStartSymbolTable; 21 | } 22 | 23 | public SymbolTable getOnStartSymbolTable() 24 | { 25 | return onStartSymbolTable; 26 | } 27 | 28 | public void setName(String name) 29 | { 30 | this.name = name; 31 | this.onStartDeclaration.getTradeName().setName(name); 32 | } 33 | public String getName() { 34 | return name; 35 | } 36 | public void setStartDeclaration(OnStartDeclaration onStartDeclaration) 37 | { 38 | this.onStartDeclaration = onStartDeclaration; 39 | } 40 | 41 | public OnStartDeclaration getStartDeclaration() 42 | { 43 | return onStartDeclaration; 44 | } 45 | 46 | @Override 47 | public String getKey() 48 | { 49 | return OnStartItem.START_KEY + this.name; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Phase 3/src/main/symbolTable/symbolTableItems/OnStartItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.OnInitDeclaration; 4 | import main.ast.node.declaration.OnStartDeclaration; 5 | import main.symbolTable.SymbolTable; 6 | 7 | public class OnStartItem extends SymbolTableItem { 8 | 9 | protected SymbolTable onStartSymbolTable; 10 | protected OnStartDeclaration onStartDeclaration; 11 | public static final String START_KEY = "OnStart_"; 12 | 13 | public OnStartItem(OnStartDeclaration onStartDeclaration) 14 | { 15 | this.name = onStartDeclaration.getTradeName().getName(); 16 | this.onStartDeclaration = onStartDeclaration; 17 | } 18 | 19 | public void setOnStartSymbolTable(SymbolTable onStartSymbolTable) 20 | { 21 | this.onStartSymbolTable = onStartSymbolTable; 22 | } 23 | 24 | public SymbolTable getOnStartSymbolTable() 25 | { 26 | return onStartSymbolTable; 27 | } 28 | 29 | public void setName(String name) 30 | { 31 | this.name = name; 32 | this.onStartDeclaration.getTradeName().setName(name); 33 | } 34 | 35 | public void setDeclaration(OnStartDeclaration onStartDeclaration) 36 | { 37 | this.onStartDeclaration = onStartDeclaration; 38 | } 39 | 40 | public OnStartDeclaration getDeclaration() 41 | { 42 | return onStartDeclaration; 43 | } 44 | 45 | @Override 46 | public String getKey() 47 | { 48 | return OnStartItem.START_KEY + this.name; 49 | } 50 | } 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Phase 4/src/main/symbolTable/symbolTableItems/OnStartItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.OnInitDeclaration; 4 | import main.ast.node.declaration.OnStartDeclaration; 5 | import main.symbolTable.SymbolTable; 6 | 7 | public class OnStartItem extends SymbolTableItem { 8 | 9 | protected SymbolTable onStartSymbolTable; 10 | protected OnStartDeclaration onStartDeclaration; 11 | public static final String START_KEY = "OnStart_"; 12 | 13 | public OnStartItem(OnStartDeclaration onStartDeclaration) 14 | { 15 | this.name = onStartDeclaration.getTradeName().getName(); 16 | this.onStartDeclaration = onStartDeclaration; 17 | } 18 | 19 | public void setOnStartSymbolTable(SymbolTable onStartSymbolTable) 20 | { 21 | this.onStartSymbolTable = onStartSymbolTable; 22 | } 23 | 24 | public SymbolTable getOnStartSymbolTable() 25 | { 26 | return onStartSymbolTable; 27 | } 28 | 29 | public void setName(String name) 30 | { 31 | this.name = name; 32 | this.onStartDeclaration.getTradeName().setName(name); 33 | } 34 | 35 | public void setDeclaration(OnStartDeclaration onStartDeclaration) 36 | { 37 | this.onStartDeclaration = onStartDeclaration; 38 | } 39 | 40 | public OnStartDeclaration getDeclaration() 41 | { 42 | return onStartDeclaration; 43 | } 44 | 45 | @Override 46 | public String getKey() 47 | { 48 | return OnStartItem.START_KEY + this.name; 49 | } 50 | } 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/declaration/VarDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.ast.node.expression.Identifier; 5 | import main.ast.type.Type; 6 | import main.visitor.IVisitor; 7 | 8 | public class VarDeclaration extends Declaration { 9 | private Type type; 10 | 11 | private Expression rValue; 12 | private Identifier identifier; 13 | private int length = 0; // > 0 means array 14 | 15 | public VarDeclaration() { 16 | } 17 | 18 | public Expression getRValue() { 19 | return rValue; 20 | } 21 | 22 | public void setRValue(Expression expression) { 23 | this.rValue = expression; 24 | } 25 | 26 | public Identifier getIdentifier() { 27 | return identifier; 28 | } 29 | 30 | public void setIdentifier(Identifier identifier) { 31 | this.identifier = identifier; 32 | } 33 | 34 | public Type getType() { 35 | return type; 36 | } 37 | 38 | public void setType(Type type) { 39 | this.type = type; 40 | } 41 | 42 | public int getLength() { 43 | return this.length; 44 | } 45 | 46 | public void setLength(int length) { 47 | this.length = length; 48 | } 49 | 50 | public boolean isArray() { 51 | return this.length > 0; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "VarDeclaration " + this.identifier.getName(); 57 | } 58 | 59 | @Override 60 | public T accept(IVisitor visitor) { 61 | return visitor.visit(this); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/declaration/VarDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.ast.node.expression.Identifier; 5 | import main.ast.type.Type; 6 | import main.visitor.IVisitor; 7 | 8 | public class VarDeclaration extends Declaration { 9 | private Type type; 10 | 11 | private Expression rValue; 12 | private Identifier identifier; 13 | private int length = 0; // > 0 means array 14 | 15 | public VarDeclaration() { 16 | } 17 | 18 | public Expression getRValue() { 19 | return rValue; 20 | } 21 | 22 | public void setRValue(Expression expression) { 23 | this.rValue = expression; 24 | } 25 | 26 | public Identifier getIdentifier() { 27 | return identifier; 28 | } 29 | 30 | public void setIdentifier(Identifier identifier) { 31 | this.identifier = identifier; 32 | } 33 | 34 | public Type getType() { 35 | return type; 36 | } 37 | 38 | public void setType(Type type) { 39 | this.type = type; 40 | } 41 | 42 | public int getLength() { 43 | return this.length; 44 | } 45 | 46 | public void setLength(int length) { 47 | this.length = length; 48 | } 49 | 50 | public boolean isArray() { 51 | return this.length > 0; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "VarDeclaration " + this.identifier.getName(); 57 | } 58 | 59 | @Override 60 | public T accept(IVisitor visitor) { 61 | return visitor.visit(this); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Phase 3/src/main/visitor/IVisitor.java: -------------------------------------------------------------------------------- 1 | package main.visitor; 2 | 3 | import main.ast.node.Program; 4 | import main.ast.node.declaration.*; 5 | import main.ast.node.expression.*; 6 | import main.ast.node.expression.values.*; 7 | import main.ast.node.statement.*; 8 | 9 | public interface IVisitor { 10 | T visit(Program program); 11 | 12 | T visit(MainDeclaration mainDeclarationActors); 13 | 14 | T visit(OnInitDeclaration onInitDeclaration); 15 | 16 | T visit(OnStartDeclaration onStartDeclaration); 17 | 18 | T visit(FunctionDeclaration functionDeclaration); 19 | 20 | T visit(VarDeclaration varDeclaration); 21 | 22 | T visit(UnaryExpression unaryExpression); 23 | 24 | T visit(BinaryExpression binaryExpression); 25 | 26 | T visit(VarAccess varAccess); 27 | 28 | T visit(Identifier identifier); 29 | 30 | T visit(ArrayIdentifier arrayIdentifier); 31 | 32 | T visit(IntValue value); 33 | 34 | T visit(TradeValue value); 35 | T visit(StringValue value); 36 | 37 | T visit(BoolValue boolValue); 38 | 39 | T visit(FloatValue floatValue); 40 | 41 | T visit(FunctionCall functionCall); 42 | 43 | T visit(MethodCall methodCall); 44 | 45 | T visit(IfElseStmt conditional); 46 | 47 | T visit(AssignStmt assignStmt); 48 | 49 | T visit(ForStmt forStmt); 50 | 51 | T visit(WhileStmt whileStmt); 52 | 53 | T visit(ContinueBreakStmt continueBreakStmt); 54 | 55 | T visit(ExpressionStmt expressionStmt); 56 | 57 | T visit(ReturnStmt returnStmt); 58 | 59 | T visit(ThrowStmt throwStmt); 60 | 61 | T visit(TryCatchStmt tryCatchStmt); 62 | } 63 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/statement/IfElseStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.visitor.IVisitor; 4 | import main.ast.node.expression.Expression; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class IfElseStmt extends Statement { 9 | private Expression condition; 10 | private ArrayList thenBody = new ArrayList<>(); 11 | private ArrayList elseBody = new ArrayList<>(); 12 | 13 | public IfElseStmt(Expression condition) { 14 | this.condition = condition; 15 | } 16 | 17 | public Expression getCondition() { 18 | return condition; 19 | } 20 | 21 | public void setCondition(Expression condition) { 22 | this.condition = condition; 23 | } 24 | 25 | public ArrayList getThenBody() { 26 | return thenBody; 27 | } 28 | 29 | public void setThenBody(ArrayList thenBody) { 30 | this.thenBody = thenBody; 31 | } 32 | 33 | public ArrayList getElseBody() { 34 | return elseBody; 35 | } 36 | 37 | public void setElseBody(ArrayList elseBody) { 38 | this.elseBody = elseBody; 39 | } 40 | 41 | public void addThenStatement(Statement statement) { 42 | this.thenBody.add(statement); 43 | } 44 | 45 | public void addElseStatement(Statement statement) { 46 | this.elseBody.add(statement); 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "IfElseStmt"; 52 | } 53 | 54 | @Override 55 | public T accept(IVisitor visitor) { 56 | return visitor.visit(this); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/statement/IfElseStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.visitor.IVisitor; 4 | import main.ast.node.expression.Expression; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class IfElseStmt extends Statement { 9 | private Expression condition; 10 | private ArrayList thenBody = new ArrayList<>(); 11 | private ArrayList elseBody = new ArrayList<>(); 12 | 13 | public IfElseStmt(Expression condition) { 14 | this.condition = condition; 15 | } 16 | 17 | public Expression getCondition() { 18 | return condition; 19 | } 20 | 21 | public void setCondition(Expression condition) { 22 | this.condition = condition; 23 | } 24 | 25 | public ArrayList getThenBody() { 26 | return thenBody; 27 | } 28 | 29 | public void setThenBody(ArrayList thenBody) { 30 | this.thenBody = thenBody; 31 | } 32 | 33 | public ArrayList getElseBody() { 34 | return elseBody; 35 | } 36 | 37 | public void setElseBody(ArrayList elseBody) { 38 | this.elseBody = elseBody; 39 | } 40 | 41 | public void addThenStatement(Statement statement) { 42 | this.thenBody.add(statement); 43 | } 44 | 45 | public void addElseStatement(Statement statement) { 46 | this.elseBody.add(statement); 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "IfElseStmt"; 52 | } 53 | 54 | @Override 55 | public T accept(IVisitor visitor) { 56 | return visitor.visit(this); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/declaration/GlobalVarDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.ast.node.expression.Identifier; 5 | import main.ast.node.declaration.VarDeclaration; 6 | import main.ast.type.Type; 7 | import main.visitor.IVisitor; 8 | 9 | public class GlobalVarDeclaration extends Declaration { 10 | private Type type; 11 | private Identifier identifier; 12 | private int length = 0; // > 0 means array 13 | private Expression value = null; 14 | 15 | public GlobalVarDeclaration() { 16 | } 17 | 18 | public Identifier getIdentifier() { 19 | return identifier; 20 | } 21 | 22 | public void setIdentifier(Identifier identifier) { 23 | this.identifier = identifier; 24 | } 25 | 26 | @Override 27 | public Type getType() { 28 | return type; 29 | } 30 | @Override 31 | public void setType(Type type) { 32 | this.type = type; 33 | } 34 | 35 | public int getLength() { 36 | return this.length; 37 | } 38 | 39 | public void setLength(int length) { 40 | this.length = length; 41 | } 42 | 43 | public boolean isArray() { 44 | return this.length > 0; 45 | } 46 | 47 | public Expression getValue() { return this.value; } 48 | 49 | public void setValue(Expression value) { this.value = value; } 50 | 51 | @Override 52 | public String toString() { VarDeclaration a = new VarDeclaration(); return a.getClass().getSimpleName(); } 53 | 54 | @Override 55 | public T accept(IVisitor visitor) { 56 | return visitor.visit(this); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Phase 4/src/main/visitor/IVisitor.java: -------------------------------------------------------------------------------- 1 | package main.visitor; 2 | 3 | import main.ast.node.Program; 4 | import main.ast.node.declaration.*; 5 | import main.ast.node.expression.*; 6 | import main.ast.node.expression.values.*; 7 | import main.ast.node.statement.*; 8 | 9 | public interface IVisitor { 10 | T visit(Program program); 11 | 12 | T visit(MainDeclaration mainDeclarationActors); 13 | 14 | T visit(OnInitDeclaration onInitDeclaration); 15 | 16 | T visit(OnStartDeclaration onStartDeclaration); 17 | 18 | T visit(FunctionDeclaration functionDeclaration); 19 | 20 | T visit(VarDeclaration varDeclaration); 21 | 22 | T visit(UnaryExpression unaryExpression); 23 | 24 | T visit(BinaryExpression binaryExpression); 25 | 26 | T visit(VarAccess varAccess); 27 | 28 | T visit(Identifier identifier); 29 | 30 | T visit(ArrayIdentifier arrayIdentifier); 31 | 32 | T visit(IntValue value); 33 | 34 | T visit(TradeValue value); 35 | T visit(StringValue value); 36 | 37 | T visit(NullValue value); 38 | 39 | T visit(BoolValue boolValue); 40 | 41 | T visit(FloatValue floatValue); 42 | 43 | T visit(FunctionCall functionCall); 44 | 45 | T visit(MethodCall methodCall); 46 | 47 | T visit(IfElseStmt conditional); 48 | 49 | T visit(AssignStmt assignStmt); 50 | 51 | T visit(ForStmt forStmt); 52 | 53 | T visit(WhileStmt whileStmt); 54 | 55 | T visit(ContinueBreakStmt continueBreakStmt); 56 | 57 | T visit(ExpressionStmt expressionStmt); 58 | 59 | T visit(ReturnStmt returnStmt); 60 | 61 | T visit(ThrowStmt throwStmt); 62 | 63 | T visit(TryCatchStmt tryCatchStmt); 64 | } 65 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/declaration/FunctionDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.expression.Identifier; 4 | import main.ast.node.statement.Statement; 5 | import main.ast.type.Type; 6 | import main.visitor.IVisitor; 7 | 8 | import java.util.ArrayList; 9 | 10 | public class FunctionDeclaration extends Declaration { 11 | private Type returnType; 12 | private Identifier name; 13 | private ArrayList args = new ArrayList<>(); 14 | private ArrayList body = new ArrayList<>(); 15 | 16 | public FunctionDeclaration() { 17 | } 18 | 19 | 20 | public Identifier getName() { 21 | return name; 22 | } 23 | 24 | public Type getReturnType() { 25 | return returnType; 26 | } 27 | 28 | public ArrayList getArgs() { 29 | return args; 30 | } 31 | 32 | public void setArgs(ArrayList args) { 33 | this.args = args; 34 | } 35 | 36 | public ArrayList getBody() { 37 | return body; 38 | } 39 | 40 | public void setBody(ArrayList body) { 41 | this.body = body; 42 | } 43 | 44 | public void addStatement(Statement statement) { 45 | this.body.add(statement); 46 | } 47 | 48 | public void addArg(VarDeclaration arg) { 49 | this.args.add(arg); 50 | } 51 | 52 | public void setName(Identifier name) { 53 | this.name = name; 54 | } 55 | 56 | public void setReturnType(Type returnType) { 57 | this.returnType = returnType; 58 | } 59 | 60 | @Override 61 | public T accept(IVisitor visitor) { 62 | return visitor.visit(this); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/statement/ForStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | import java.util.ArrayList; 7 | 8 | // Line -> IF 9 | public class ForStmt extends Statement { 10 | private ArrayList init = new ArrayList<>(); 11 | private Expression condition; 12 | private ArrayList update = new ArrayList<>(); 13 | private ArrayList body = new ArrayList<>(); 14 | 15 | public ForStmt() {} 16 | 17 | public ArrayList getInit() { 18 | return init; 19 | } 20 | 21 | public void setInit(ArrayList init) { 22 | this.init = init; 23 | } 24 | 25 | public void addInit(Statement statement) { 26 | this.init.add(statement); 27 | } 28 | 29 | public Expression getCondition() { 30 | return condition; 31 | } 32 | 33 | public void setCondition(Expression condition) { 34 | this.condition = condition; 35 | } 36 | 37 | public ArrayList getUpdate() { 38 | return update; 39 | } 40 | 41 | public void setUpdate(ArrayList update) { 42 | this.update = update; 43 | } 44 | 45 | public void addUpdate(Expression expression) { 46 | this.update.add(expression); 47 | } 48 | 49 | public ArrayList getBody() { 50 | return body; 51 | } 52 | 53 | public void setBody(ArrayList body) { 54 | this.body = body; 55 | } 56 | 57 | public void addBody(Statement statement) { 58 | this.body.add(statement); 59 | } 60 | 61 | @Override 62 | public T accept(IVisitor visitor) { 63 | return visitor.visit(this); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/declaration/FunctionDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.expression.Identifier; 4 | import main.ast.node.statement.Statement; 5 | import main.ast.type.Type; 6 | import main.visitor.IVisitor; 7 | 8 | import java.util.ArrayList; 9 | 10 | public class FunctionDeclaration extends Declaration { 11 | private Type returnType; 12 | private Identifier name; 13 | private ArrayList args = new ArrayList<>(); 14 | private ArrayList body = new ArrayList<>(); 15 | 16 | public FunctionDeclaration() { 17 | } 18 | 19 | public Identifier getName() { 20 | return name; 21 | } 22 | 23 | public Type getReturnType() { 24 | return returnType; 25 | } 26 | 27 | public ArrayList getArgs() { 28 | return args; 29 | } 30 | 31 | public void setArgs(ArrayList args) { 32 | this.args = args; 33 | } 34 | 35 | public ArrayList getBody() { 36 | return body; 37 | } 38 | 39 | public void setBody(ArrayList body) { 40 | this.body = body; 41 | } 42 | 43 | public void addStatement(Statement statement) { 44 | this.body.add(statement); 45 | } 46 | 47 | public void addArg(VarDeclaration arg) { 48 | this.args.add(arg); 49 | } 50 | 51 | public void setName(Identifier name) { 52 | this.name = name; 53 | } 54 | 55 | public void setReturnType(Type returnType) { 56 | this.returnType = returnType; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "FunctionDeclaration"; 62 | } 63 | 64 | @Override 65 | public T accept(IVisitor visitor) { 66 | return visitor.visit(this); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/declaration/FunctionDeclaration.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.declaration; 2 | 3 | import main.ast.node.expression.Identifier; 4 | import main.ast.node.statement.Statement; 5 | import main.ast.type.Type; 6 | import main.visitor.IVisitor; 7 | 8 | import java.util.ArrayList; 9 | 10 | public class FunctionDeclaration extends Declaration { 11 | private Type returnType; 12 | private Identifier name; 13 | private ArrayList args = new ArrayList<>(); 14 | private ArrayList body = new ArrayList<>(); 15 | 16 | public FunctionDeclaration() { 17 | } 18 | 19 | public Identifier getName() { 20 | return name; 21 | } 22 | 23 | public Type getReturnType() { 24 | return returnType; 25 | } 26 | 27 | public ArrayList getArgs() { 28 | return args; 29 | } 30 | 31 | public void setArgs(ArrayList args) { 32 | this.args = args; 33 | } 34 | 35 | public ArrayList getBody() { 36 | return body; 37 | } 38 | 39 | public void setBody(ArrayList body) { 40 | this.body = body; 41 | } 42 | 43 | public void addStatement(Statement statement) { 44 | this.body.add(statement); 45 | } 46 | 47 | public void addArg(VarDeclaration arg) { 48 | this.args.add(arg); 49 | } 50 | 51 | public void setName(Identifier name) { 52 | this.name = name; 53 | } 54 | 55 | public void setReturnType(Type returnType) { 56 | this.returnType = returnType; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "FunctionDeclaration"; 62 | } 63 | 64 | @Override 65 | public T accept(IVisitor visitor) { 66 | return visitor.visit(this); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/statement/ForStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class ForStmt extends Statement { 9 | private ArrayList init = new ArrayList<>(); 10 | private Expression condition; 11 | private ArrayList update = new ArrayList<>(); 12 | private ArrayList body = new ArrayList<>(); 13 | 14 | public ForStmt() { 15 | } 16 | 17 | public ArrayList getInit() { 18 | return init; 19 | } 20 | 21 | public void setInit(ArrayList init) { 22 | this.init = init; 23 | } 24 | 25 | public void addInit(Statement statement) { 26 | this.init.add(statement); 27 | } 28 | 29 | public Expression getCondition() { 30 | return condition; 31 | } 32 | 33 | public void setCondition(Expression condition) { 34 | this.condition = condition; 35 | } 36 | 37 | public ArrayList getUpdate() { 38 | return update; 39 | } 40 | 41 | public void setUpdate(ArrayList update) { 42 | this.update = update; 43 | } 44 | 45 | public void addUpdate(Expression update) { 46 | this.update.add(update); 47 | } 48 | 49 | public ArrayList getBody() { 50 | return body; 51 | } 52 | 53 | public void setBody(ArrayList body) { 54 | this.body = body; 55 | } 56 | 57 | public void addBody(Statement statement) { 58 | this.body.add(statement); 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "ForStmt"; 64 | } 65 | 66 | @Override 67 | public T accept(IVisitor visitor) { 68 | return visitor.visit(this); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/statement/ForStmt.java: -------------------------------------------------------------------------------- 1 | package main.ast.node.statement; 2 | 3 | import main.ast.node.expression.Expression; 4 | import main.visitor.IVisitor; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class ForStmt extends Statement { 9 | private ArrayList init = new ArrayList<>(); 10 | private Expression condition; 11 | private ArrayList update = new ArrayList<>(); 12 | private ArrayList body = new ArrayList<>(); 13 | 14 | public ForStmt() { 15 | } 16 | 17 | public ArrayList getInit() { 18 | return init; 19 | } 20 | 21 | public void setInit(ArrayList init) { 22 | this.init = init; 23 | } 24 | 25 | public void addInit(Statement statement) { 26 | this.init.add(statement); 27 | } 28 | 29 | public Expression getCondition() { 30 | return condition; 31 | } 32 | 33 | public void setCondition(Expression condition) { 34 | this.condition = condition; 35 | } 36 | 37 | public ArrayList getUpdate() { 38 | return update; 39 | } 40 | 41 | public void setUpdate(ArrayList update) { 42 | this.update = update; 43 | } 44 | 45 | public void addUpdate(Expression update) { 46 | this.update.add(update); 47 | } 48 | 49 | public ArrayList getBody() { 50 | return body; 51 | } 52 | 53 | public void setBody(ArrayList body) { 54 | this.body = body; 55 | } 56 | 57 | public void addBody(Statement statement) { 58 | this.body.add(statement); 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "ForStmt"; 64 | } 65 | 66 | @Override 67 | public T accept(IVisitor visitor) { 68 | return visitor.visit(this); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Phase 2/src/main/visitor/IVisitor.java: -------------------------------------------------------------------------------- 1 | package main.visitor; 2 | 3 | import main.ast.node.Program; 4 | import main.ast.node.declaration.*; 5 | import main.ast.node.expression.*; 6 | import main.ast.node.expression.values.BoolValue; 7 | import main.ast.node.expression.values.FloatValue; 8 | import main.ast.node.expression.values.IntValue; 9 | import main.ast.node.expression.values.StringValue; 10 | import main.ast.node.expression.values.TradeValue; 11 | import main.ast.node.statement.*; 12 | 13 | public interface IVisitor { 14 | T visit(Program program); 15 | 16 | T visit(MainDeclaration mainDeclarationActors); 17 | 18 | T visit(OnInitDeclaration onInitDeclaration); 19 | 20 | T visit(OnStartDeclaration onStartDeclaration); 21 | 22 | T visit(FunctionDeclaration functionDeclaration); 23 | 24 | T visit(VarDeclaration varDeclaration); 25 | 26 | T visit(GlobalVarDeclaration globalVarDeclaration); 27 | 28 | T visit(UnaryExpression unaryExpression); 29 | 30 | T visit(BinaryExpression binaryExpression); 31 | 32 | T visit(VarAccess varAccess); 33 | 34 | T visit(Identifier identifier); 35 | 36 | T visit(ArrayIdentifier arrayIdentifier); 37 | 38 | T visit(IntValue value); 39 | 40 | T visit(StringValue value); 41 | 42 | T visit(BoolValue boolValue); 43 | 44 | T visit(FloatValue floatValue); 45 | 46 | T visit(TradeValue tradeValue); 47 | 48 | T visit(FunctionCall functionCall); 49 | 50 | T visit(MethodCall methodCall); 51 | 52 | T visit(IfElseStmt conditional); 53 | 54 | T visit(AssignStmt assignStmt); 55 | 56 | T visit(ForStmt forStmt); 57 | 58 | T visit(WhileStmt whileStmt); 59 | 60 | T visit(ContinueBreakStmt continueBreakStmt); 61 | 62 | T visit(ExpressionStmt expressionStmt); 63 | 64 | T visit(ReturnStmt returnStmt); 65 | 66 | T visit(ThrowStmt throwStmt); 67 | 68 | T visit(TryCatchStmt tryCatchStmt); 69 | } 70 | -------------------------------------------------------------------------------- /Phase 2/src/main/symbolTable/symbolTableItems/FunctionItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.FunctionDeclaration; 4 | import main.ast.node.declaration.VarDeclaration; 5 | import main.ast.type.Type; 6 | import main.symbolTable.SymbolTable; 7 | 8 | import java.util.ArrayList; 9 | 10 | public class FunctionItem extends SymbolTableItem { 11 | 12 | protected ArrayList argTypes = new ArrayList<>(); 13 | protected SymbolTable handlerSymbolTable; 14 | protected FunctionDeclaration functionDeclaration; 15 | public static final String START_KEY = "Function_"; 16 | 17 | public FunctionItem(String name, ArrayList argTypes) { 18 | this.name = name; 19 | this.argTypes = argTypes; 20 | } 21 | 22 | public FunctionItem(FunctionDeclaration functionDeclaration) { 23 | this.name = functionDeclaration.getName().getName(); 24 | this.argTypes = new ArrayList<>(); 25 | for (VarDeclaration arg : functionDeclaration.getArgs()) 26 | argTypes.add(arg.getType()); 27 | this.functionDeclaration = functionDeclaration; 28 | } 29 | 30 | public void setHandlerSymbolTable(SymbolTable symbolTable) { 31 | this.handlerSymbolTable = symbolTable; 32 | } 33 | 34 | public SymbolTable getHandlerSymbolTable() { 35 | return this.handlerSymbolTable; 36 | } 37 | 38 | public void setFunctionDeclaration(FunctionDeclaration functionDeclaration) { 39 | this.functionDeclaration = functionDeclaration; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | functionDeclaration.getName().setName(name); 49 | } 50 | 51 | public FunctionDeclaration getFunctionDeclaration() { 52 | return functionDeclaration; 53 | } 54 | 55 | @Override 56 | public String getKey() { 57 | return FunctionItem.START_KEY + this.name; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Phase 3/src/main/symbolTable/symbolTableItems/FunctionItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.FunctionDeclaration; 4 | import main.ast.node.declaration.VarDeclaration; 5 | import main.ast.type.Type; 6 | import main.symbolTable.SymbolTable; 7 | 8 | import java.util.ArrayList; 9 | 10 | public class FunctionItem extends SymbolTableItem { 11 | 12 | protected ArrayList argTypes = new ArrayList<>(); 13 | protected SymbolTable functionSymbolTable; 14 | protected FunctionDeclaration functionDeclaration; 15 | public static final String START_KEY = "Function_"; 16 | 17 | public FunctionItem(String name, ArrayList argTypes) { 18 | this.name = name; 19 | this.argTypes = argTypes; 20 | } 21 | 22 | public FunctionItem(FunctionDeclaration functionDeclaration) { 23 | this.name = functionDeclaration.getName().getName(); 24 | this.argTypes = new ArrayList<>(); 25 | for (VarDeclaration arg : functionDeclaration.getArgs()) 26 | argTypes.add(arg.getType()); 27 | this.functionDeclaration = functionDeclaration; 28 | } 29 | 30 | public void setFunctionSymbolTable(SymbolTable symbolTable) { 31 | this.functionSymbolTable = symbolTable; 32 | } 33 | 34 | public SymbolTable getFunctionSymbolTable() { 35 | return this.functionSymbolTable; 36 | } 37 | 38 | public void setFunctionDeclaration(FunctionDeclaration functionDeclaration) { 39 | this.functionDeclaration = functionDeclaration; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | functionDeclaration.getName().setName(name); 49 | } 50 | 51 | public FunctionDeclaration getFunctionDeclaration() { 52 | return functionDeclaration; 53 | } 54 | 55 | @Override 56 | public String getKey() { 57 | return FunctionItem.START_KEY + this.name; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Phase 4/src/main/symbolTable/symbolTableItems/FunctionItem.java: -------------------------------------------------------------------------------- 1 | package main.symbolTable.symbolTableItems; 2 | 3 | import main.ast.node.declaration.FunctionDeclaration; 4 | import main.ast.node.declaration.VarDeclaration; 5 | import main.ast.type.Type; 6 | import main.symbolTable.SymbolTable; 7 | 8 | import java.util.ArrayList; 9 | 10 | public class FunctionItem extends SymbolTableItem { 11 | 12 | protected ArrayList argTypes = new ArrayList<>(); 13 | protected SymbolTable functionSymbolTable; 14 | protected FunctionDeclaration functionDeclaration; 15 | public static final String START_KEY = "Function_"; 16 | 17 | public FunctionItem(String name, ArrayList argTypes) { 18 | this.name = name; 19 | this.argTypes = argTypes; 20 | } 21 | 22 | public FunctionItem(FunctionDeclaration functionDeclaration) { 23 | this.name = functionDeclaration.getName().getName(); 24 | this.argTypes = new ArrayList<>(); 25 | for (VarDeclaration arg : functionDeclaration.getArgs()) 26 | argTypes.add(arg.getType()); 27 | this.functionDeclaration = functionDeclaration; 28 | } 29 | 30 | public void setFunctionSymbolTable(SymbolTable symbolTable) { 31 | this.functionSymbolTable = symbolTable; 32 | } 33 | 34 | public SymbolTable getFunctionSymbolTable() { 35 | return this.functionSymbolTable; 36 | } 37 | 38 | public void setFunctionDeclaration(FunctionDeclaration functionDeclaration) { 39 | this.functionDeclaration = functionDeclaration; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | functionDeclaration.getName().setName(name); 49 | } 50 | 51 | public FunctionDeclaration getFunctionDeclaration() { 52 | return functionDeclaration; 53 | } 54 | 55 | @Override 56 | public String getKey() { 57 | return FunctionItem.START_KEY + this.name; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Phase 3/src/parsers/UTL.tokens: -------------------------------------------------------------------------------- 1 | SPACES=1 2 | SEMICOLON=2 3 | COMMA=3 4 | COLON=4 5 | DOT=5 6 | LPAREN=6 7 | RPAREN=7 8 | LBRACE=8 9 | RBRACE=9 10 | LBRACK=10 11 | RBRACK=11 12 | PLUS=12 13 | MINUS=13 14 | MULT=14 15 | DIV=15 16 | MOD=16 17 | AND=17 18 | OR=18 19 | NOT=19 20 | BIT_AND=20 21 | BIT_OR=21 22 | BIT_XOR=22 23 | L_SHIFT=23 24 | R_SHIFT=24 25 | BIT_NOT=25 26 | LT=26 27 | GT=27 28 | EQ=28 29 | NEQ=29 30 | INC=30 31 | DEC=31 32 | ASSIGN=32 33 | ADD_ASSIGN=33 34 | SUB_ASSIGN=34 35 | MUL_ASSIGN=35 36 | DIV_ASSIGN=36 37 | MOD_ASSIGN=37 38 | TRY=38 39 | THROW=39 40 | CATCH=40 41 | IF=41 42 | ELSE=42 43 | FOR=43 44 | WHILE=44 45 | BREAK=45 46 | CONTINUE=46 47 | RETURN=47 48 | MAIN=48 49 | ONINIT=49 50 | ONSTART=50 51 | FLOAT=51 52 | STRING=52 53 | BOOL=53 54 | VOID=54 55 | INT=55 56 | BUY=56 57 | SELL=57 58 | ASK=58 59 | BID=59 60 | TIME=60 61 | HIGH=61 62 | LOW=62 63 | DIGITS=63 64 | VOLUME=64 65 | TYPE=65 66 | TEXT=66 67 | OPEN=67 68 | CLOSE=68 69 | TRADE=69 70 | ORDER=70 71 | CANDLE=71 72 | EXCEPTION=72 73 | REFRESH_RATE=73 74 | GET_CANDLE=74 75 | TERMINATE=75 76 | CONNECT=76 77 | OBSERVE=77 78 | PRINT=78 79 | ID=79 80 | INT_LITERAL=80 81 | FLOAT_LITERAL=81 82 | STRING_LITERAL=82 83 | COMMENT=83 84 | ';'=2 85 | ','=3 86 | ':'=4 87 | '.'=5 88 | '('=6 89 | ')'=7 90 | '{'=8 91 | '}'=9 92 | '['=10 93 | ']'=11 94 | '+'=12 95 | '-'=13 96 | '*'=14 97 | '/'=15 98 | '%'=16 99 | '&&'=17 100 | '||'=18 101 | '!'=19 102 | '&'=20 103 | '|'=21 104 | '^'=22 105 | '<<'=23 106 | '>>'=24 107 | '~'=25 108 | '<'=26 109 | '>'=27 110 | '=='=28 111 | '!='=29 112 | '++'=30 113 | '--'=31 114 | '='=32 115 | '+='=33 116 | '-='=34 117 | '*='=35 118 | '/='=36 119 | '%='=37 120 | 'try'=38 121 | 'throw'=39 122 | 'catch'=40 123 | 'if'=41 124 | 'else'=42 125 | 'for'=43 126 | 'while'=44 127 | 'break'=45 128 | 'continue'=46 129 | 'return'=47 130 | 'Main'=48 131 | 'OnInit'=49 132 | 'OnStart'=50 133 | 'float'=51 134 | 'string'=52 135 | 'bool'=53 136 | 'void'=54 137 | 'int'=55 138 | 'BUY'=56 139 | 'SELL'=57 140 | 'Ask'=58 141 | 'Bid'=59 142 | 'Time'=60 143 | 'High'=61 144 | 'Low'=62 145 | 'Digits'=63 146 | 'Volume'=64 147 | 'Type'=65 148 | 'Text'=66 149 | 'Open'=67 150 | 'Close'=68 151 | 'Trade'=69 152 | 'Order'=70 153 | 'Candle'=71 154 | 'Exception'=72 155 | 'RefreshRate'=73 156 | 'GetCandle'=74 157 | 'Terminate'=75 158 | 'Connect'=76 159 | 'Observe'=77 160 | 'Print'=78 161 | -------------------------------------------------------------------------------- /Phase 4/src/parsers/UTL.tokens: -------------------------------------------------------------------------------- 1 | SPACES=1 2 | SEMICOLON=2 3 | COMMA=3 4 | COLON=4 5 | DOT=5 6 | LPAREN=6 7 | RPAREN=7 8 | LBRACE=8 9 | RBRACE=9 10 | LBRACK=10 11 | RBRACK=11 12 | PLUS=12 13 | MINUS=13 14 | MULT=14 15 | DIV=15 16 | MOD=16 17 | AND=17 18 | OR=18 19 | NOT=19 20 | BIT_AND=20 21 | BIT_OR=21 22 | BIT_XOR=22 23 | L_SHIFT=23 24 | R_SHIFT=24 25 | BIT_NOT=25 26 | LT=26 27 | GT=27 28 | EQ=28 29 | NEQ=29 30 | INC=30 31 | DEC=31 32 | ASSIGN=32 33 | ADD_ASSIGN=33 34 | SUB_ASSIGN=34 35 | MUL_ASSIGN=35 36 | DIV_ASSIGN=36 37 | MOD_ASSIGN=37 38 | TRY=38 39 | THROW=39 40 | CATCH=40 41 | IF=41 42 | ELSE=42 43 | FOR=43 44 | WHILE=44 45 | BREAK=45 46 | CONTINUE=46 47 | RETURN=47 48 | MAIN=48 49 | ONINIT=49 50 | ONSTART=50 51 | FLOAT=51 52 | STRING=52 53 | BOOL=53 54 | VOID=54 55 | INT=55 56 | BUY=56 57 | SELL=57 58 | ASK=58 59 | BID=59 60 | TIME=60 61 | HIGH=61 62 | LOW=62 63 | DIGITS=63 64 | VOLUME=64 65 | TYPE=65 66 | TEXT=66 67 | OPEN=67 68 | CLOSE=68 69 | TRADE=69 70 | ORDER=70 71 | CANDLE=71 72 | EXCEPTION=72 73 | REFRESH_RATE=73 74 | GET_CANDLE=74 75 | TERMINATE=75 76 | CONNECT=76 77 | OBSERVE=77 78 | PRINT=78 79 | ID=79 80 | INT_LITERAL=80 81 | FLOAT_LITERAL=81 82 | STRING_LITERAL=82 83 | COMMENT=83 84 | ';'=2 85 | ','=3 86 | ':'=4 87 | '.'=5 88 | '('=6 89 | ')'=7 90 | '{'=8 91 | '}'=9 92 | '['=10 93 | ']'=11 94 | '+'=12 95 | '-'=13 96 | '*'=14 97 | '/'=15 98 | '%'=16 99 | '&&'=17 100 | '||'=18 101 | '!'=19 102 | '&'=20 103 | '|'=21 104 | '^'=22 105 | '<<'=23 106 | '>>'=24 107 | '~'=25 108 | '<'=26 109 | '>'=27 110 | '=='=28 111 | '!='=29 112 | '++'=30 113 | '--'=31 114 | '='=32 115 | '+='=33 116 | '-='=34 117 | '*='=35 118 | '/='=36 119 | '%='=37 120 | 'try'=38 121 | 'throw'=39 122 | 'catch'=40 123 | 'if'=41 124 | 'else'=42 125 | 'for'=43 126 | 'while'=44 127 | 'break'=45 128 | 'continue'=46 129 | 'return'=47 130 | 'Main'=48 131 | 'OnInit'=49 132 | 'OnStart'=50 133 | 'float'=51 134 | 'string'=52 135 | 'bool'=53 136 | 'void'=54 137 | 'int'=55 138 | 'BUY'=56 139 | 'SELL'=57 140 | 'Ask'=58 141 | 'Bid'=59 142 | 'Time'=60 143 | 'High'=61 144 | 'Low'=62 145 | 'Digits'=63 146 | 'Volume'=64 147 | 'Type'=65 148 | 'Text'=66 149 | 'Open'=67 150 | 'Close'=68 151 | 'Trade'=69 152 | 'Order'=70 153 | 'Candle'=71 154 | 'Exception'=72 155 | 'RefreshRate'=73 156 | 'GetCandle'=74 157 | 'Terminate'=75 158 | 'Connect'=76 159 | 'Observe'=77 160 | 'Print'=78 161 | -------------------------------------------------------------------------------- /Phase 3/src/parsers/UTLLexer.tokens: -------------------------------------------------------------------------------- 1 | SPACES=1 2 | SEMICOLON=2 3 | COMMA=3 4 | COLON=4 5 | DOT=5 6 | LPAREN=6 7 | RPAREN=7 8 | LBRACE=8 9 | RBRACE=9 10 | LBRACK=10 11 | RBRACK=11 12 | PLUS=12 13 | MINUS=13 14 | MULT=14 15 | DIV=15 16 | MOD=16 17 | AND=17 18 | OR=18 19 | NOT=19 20 | BIT_AND=20 21 | BIT_OR=21 22 | BIT_XOR=22 23 | L_SHIFT=23 24 | R_SHIFT=24 25 | BIT_NOT=25 26 | LT=26 27 | GT=27 28 | EQ=28 29 | NEQ=29 30 | INC=30 31 | DEC=31 32 | ASSIGN=32 33 | ADD_ASSIGN=33 34 | SUB_ASSIGN=34 35 | MUL_ASSIGN=35 36 | DIV_ASSIGN=36 37 | MOD_ASSIGN=37 38 | TRY=38 39 | THROW=39 40 | CATCH=40 41 | IF=41 42 | ELSE=42 43 | FOR=43 44 | WHILE=44 45 | BREAK=45 46 | CONTINUE=46 47 | RETURN=47 48 | MAIN=48 49 | ONINIT=49 50 | ONSTART=50 51 | FLOAT=51 52 | STRING=52 53 | BOOL=53 54 | VOID=54 55 | INT=55 56 | BUY=56 57 | SELL=57 58 | ASK=58 59 | BID=59 60 | TIME=60 61 | HIGH=61 62 | LOW=62 63 | DIGITS=63 64 | VOLUME=64 65 | TYPE=65 66 | TEXT=66 67 | OPEN=67 68 | CLOSE=68 69 | TRADE=69 70 | ORDER=70 71 | CANDLE=71 72 | EXCEPTION=72 73 | REFRESH_RATE=73 74 | GET_CANDLE=74 75 | TERMINATE=75 76 | CONNECT=76 77 | OBSERVE=77 78 | PRINT=78 79 | ID=79 80 | INT_LITERAL=80 81 | FLOAT_LITERAL=81 82 | STRING_LITERAL=82 83 | COMMENT=83 84 | ';'=2 85 | ','=3 86 | ':'=4 87 | '.'=5 88 | '('=6 89 | ')'=7 90 | '{'=8 91 | '}'=9 92 | '['=10 93 | ']'=11 94 | '+'=12 95 | '-'=13 96 | '*'=14 97 | '/'=15 98 | '%'=16 99 | '&&'=17 100 | '||'=18 101 | '!'=19 102 | '&'=20 103 | '|'=21 104 | '^'=22 105 | '<<'=23 106 | '>>'=24 107 | '~'=25 108 | '<'=26 109 | '>'=27 110 | '=='=28 111 | '!='=29 112 | '++'=30 113 | '--'=31 114 | '='=32 115 | '+='=33 116 | '-='=34 117 | '*='=35 118 | '/='=36 119 | '%='=37 120 | 'try'=38 121 | 'throw'=39 122 | 'catch'=40 123 | 'if'=41 124 | 'else'=42 125 | 'for'=43 126 | 'while'=44 127 | 'break'=45 128 | 'continue'=46 129 | 'return'=47 130 | 'Main'=48 131 | 'OnInit'=49 132 | 'OnStart'=50 133 | 'float'=51 134 | 'string'=52 135 | 'bool'=53 136 | 'void'=54 137 | 'int'=55 138 | 'BUY'=56 139 | 'SELL'=57 140 | 'Ask'=58 141 | 'Bid'=59 142 | 'Time'=60 143 | 'High'=61 144 | 'Low'=62 145 | 'Digits'=63 146 | 'Volume'=64 147 | 'Type'=65 148 | 'Text'=66 149 | 'Open'=67 150 | 'Close'=68 151 | 'Trade'=69 152 | 'Order'=70 153 | 'Candle'=71 154 | 'Exception'=72 155 | 'RefreshRate'=73 156 | 'GetCandle'=74 157 | 'Terminate'=75 158 | 'Connect'=76 159 | 'Observe'=77 160 | 'Print'=78 161 | -------------------------------------------------------------------------------- /Phase 4/src/parsers/UTLLexer.tokens: -------------------------------------------------------------------------------- 1 | SPACES=1 2 | SEMICOLON=2 3 | COMMA=3 4 | COLON=4 5 | DOT=5 6 | LPAREN=6 7 | RPAREN=7 8 | LBRACE=8 9 | RBRACE=9 10 | LBRACK=10 11 | RBRACK=11 12 | PLUS=12 13 | MINUS=13 14 | MULT=14 15 | DIV=15 16 | MOD=16 17 | AND=17 18 | OR=18 19 | NOT=19 20 | BIT_AND=20 21 | BIT_OR=21 22 | BIT_XOR=22 23 | L_SHIFT=23 24 | R_SHIFT=24 25 | BIT_NOT=25 26 | LT=26 27 | GT=27 28 | EQ=28 29 | NEQ=29 30 | INC=30 31 | DEC=31 32 | ASSIGN=32 33 | ADD_ASSIGN=33 34 | SUB_ASSIGN=34 35 | MUL_ASSIGN=35 36 | DIV_ASSIGN=36 37 | MOD_ASSIGN=37 38 | TRY=38 39 | THROW=39 40 | CATCH=40 41 | IF=41 42 | ELSE=42 43 | FOR=43 44 | WHILE=44 45 | BREAK=45 46 | CONTINUE=46 47 | RETURN=47 48 | MAIN=48 49 | ONINIT=49 50 | ONSTART=50 51 | FLOAT=51 52 | STRING=52 53 | BOOL=53 54 | VOID=54 55 | INT=55 56 | BUY=56 57 | SELL=57 58 | ASK=58 59 | BID=59 60 | TIME=60 61 | HIGH=61 62 | LOW=62 63 | DIGITS=63 64 | VOLUME=64 65 | TYPE=65 66 | TEXT=66 67 | OPEN=67 68 | CLOSE=68 69 | TRADE=69 70 | ORDER=70 71 | CANDLE=71 72 | EXCEPTION=72 73 | REFRESH_RATE=73 74 | GET_CANDLE=74 75 | TERMINATE=75 76 | CONNECT=76 77 | OBSERVE=77 78 | PRINT=78 79 | ID=79 80 | INT_LITERAL=80 81 | FLOAT_LITERAL=81 82 | STRING_LITERAL=82 83 | COMMENT=83 84 | ';'=2 85 | ','=3 86 | ':'=4 87 | '.'=5 88 | '('=6 89 | ')'=7 90 | '{'=8 91 | '}'=9 92 | '['=10 93 | ']'=11 94 | '+'=12 95 | '-'=13 96 | '*'=14 97 | '/'=15 98 | '%'=16 99 | '&&'=17 100 | '||'=18 101 | '!'=19 102 | '&'=20 103 | '|'=21 104 | '^'=22 105 | '<<'=23 106 | '>>'=24 107 | '~'=25 108 | '<'=26 109 | '>'=27 110 | '=='=28 111 | '!='=29 112 | '++'=30 113 | '--'=31 114 | '='=32 115 | '+='=33 116 | '-='=34 117 | '*='=35 118 | '/='=36 119 | '%='=37 120 | 'try'=38 121 | 'throw'=39 122 | 'catch'=40 123 | 'if'=41 124 | 'else'=42 125 | 'for'=43 126 | 'while'=44 127 | 'break'=45 128 | 'continue'=46 129 | 'return'=47 130 | 'Main'=48 131 | 'OnInit'=49 132 | 'OnStart'=50 133 | 'float'=51 134 | 'string'=52 135 | 'bool'=53 136 | 'void'=54 137 | 'int'=55 138 | 'BUY'=56 139 | 'SELL'=57 140 | 'Ask'=58 141 | 'Bid'=59 142 | 'Time'=60 143 | 'High'=61 144 | 'Low'=62 145 | 'Digits'=63 146 | 'Volume'=64 147 | 'Type'=65 148 | 'Text'=66 149 | 'Open'=67 150 | 'Close'=68 151 | 'Trade'=69 152 | 'Order'=70 153 | 'Candle'=71 154 | 'Exception'=72 155 | 'RefreshRate'=73 156 | 'GetCandle'=74 157 | 'Terminate'=75 158 | 'Connect'=76 159 | 'Observe'=77 160 | 'Print'=78 161 | -------------------------------------------------------------------------------- /Phase 3/src/main/ast/node/Program.java: -------------------------------------------------------------------------------- 1 | package main.ast.node; 2 | 3 | import main.ast.node.declaration.*; 4 | import main.visitor.IVisitor; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class Program extends Node { 9 | private ArrayList vars = new ArrayList<>(); 10 | private ArrayList inits = new ArrayList<>(); 11 | private ArrayList starts = new ArrayList<>(); 12 | private ArrayList functions = new ArrayList<>(); 13 | private MainDeclaration programMainDeclaration; 14 | 15 | public MainDeclaration getMain() { 16 | return this.programMainDeclaration; 17 | } 18 | 19 | public void setMain(MainDeclaration mainDeclarationActors) { 20 | this.programMainDeclaration = mainDeclarationActors; 21 | } 22 | 23 | public ArrayList getVars() { 24 | return vars; 25 | } 26 | 27 | public void setVars(ArrayList vars) { 28 | this.vars = vars; 29 | } 30 | 31 | public ArrayList getInits() { 32 | return inits; 33 | } 34 | 35 | public void setInits(ArrayList inits) { 36 | this.inits = inits; 37 | } 38 | 39 | public ArrayList getStarts() { 40 | return starts; 41 | } 42 | 43 | public void setStarts(ArrayList starts) { 44 | this.starts = starts; 45 | } 46 | 47 | public ArrayList getFunctions() { 48 | return functions; 49 | } 50 | 51 | public void setFunctions(ArrayList functions) { 52 | this.functions = functions; 53 | } 54 | 55 | public void addVar(VarDeclaration varDeclaration) { 56 | this.vars.add(varDeclaration); 57 | } 58 | 59 | public void addInit(OnInitDeclaration onInitDeclaration) { 60 | this.inits.add(onInitDeclaration); 61 | } 62 | 63 | public void addStart(OnStartDeclaration onStartDeclaration) { 64 | this.starts.add(onStartDeclaration); 65 | } 66 | 67 | public void addFunction(FunctionDeclaration functionDeclaration) { 68 | this.functions.add(functionDeclaration); 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return "Program"; 74 | } 75 | 76 | @Override 77 | public T accept(IVisitor visitor) { 78 | return visitor.visit(this); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Phase 4/src/main/ast/node/Program.java: -------------------------------------------------------------------------------- 1 | package main.ast.node; 2 | 3 | import main.ast.node.declaration.*; 4 | import main.visitor.IVisitor; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class Program extends Node { 9 | private ArrayList vars = new ArrayList<>(); 10 | private ArrayList inits = new ArrayList<>(); 11 | private ArrayList starts = new ArrayList<>(); 12 | private ArrayList functions = new ArrayList<>(); 13 | private MainDeclaration programMainDeclaration; 14 | 15 | public MainDeclaration getMain() { 16 | return this.programMainDeclaration; 17 | } 18 | 19 | public void setMain(MainDeclaration mainDeclarationActors) { 20 | this.programMainDeclaration = mainDeclarationActors; 21 | } 22 | 23 | public ArrayList getVars() { 24 | return vars; 25 | } 26 | 27 | public void setVars(ArrayList vars) { 28 | this.vars = vars; 29 | } 30 | 31 | public ArrayList getInits() { 32 | return inits; 33 | } 34 | 35 | public void setInits(ArrayList inits) { 36 | this.inits = inits; 37 | } 38 | 39 | public ArrayList getStarts() { 40 | return starts; 41 | } 42 | 43 | public void setStarts(ArrayList starts) { 44 | this.starts = starts; 45 | } 46 | 47 | public ArrayList getFunctions() { 48 | return functions; 49 | } 50 | 51 | public void setFunctions(ArrayList functions) { 52 | this.functions = functions; 53 | } 54 | 55 | public void addVar(VarDeclaration varDeclaration) { 56 | this.vars.add(varDeclaration); 57 | } 58 | 59 | public void addInit(OnInitDeclaration onInitDeclaration) { 60 | this.inits.add(onInitDeclaration); 61 | } 62 | 63 | public void addStart(OnStartDeclaration onStartDeclaration) { 64 | this.starts.add(onStartDeclaration); 65 | } 66 | 67 | public void addFunction(FunctionDeclaration functionDeclaration) { 68 | this.functions.add(functionDeclaration); 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return "Program"; 74 | } 75 | 76 | @Override 77 | public T accept(IVisitor visitor) { 78 | return visitor.visit(this); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Phase 2/src/main/grammar/.antlr/UTL.tokens: -------------------------------------------------------------------------------- 1 | SPACES=1 2 | SEMICOLON=2 3 | COMMA=3 4 | COLON=4 5 | DOT=5 6 | LPAREN=6 7 | RPAREN=7 8 | LBRACE=8 9 | RBRACE=9 10 | LBRACK=10 11 | RBRACK=11 12 | PLUS=12 13 | MINUS=13 14 | MULT=14 15 | DIV=15 16 | MOD=16 17 | AND=17 18 | OR=18 19 | NOT=19 20 | BIT_AND=20 21 | BIT_OR=21 22 | BIT_XOR=22 23 | L_SHIFT=23 24 | R_SHIFT=24 25 | BIT_NOT=25 26 | LT=26 27 | GT=27 28 | EQ=28 29 | NEQ=29 30 | INC=30 31 | DEC=31 32 | ASSIGN=32 33 | ADD_ASSIGN=33 34 | SUB_ASSIGN=34 35 | MUL_ASSIGN=35 36 | DIV_ASSIGN=36 37 | MOD_ASSIGN=37 38 | TRY=38 39 | THROW=39 40 | CATCH=40 41 | IF=41 42 | ELSE=42 43 | FOR=43 44 | WHILE=44 45 | BREAK=45 46 | CONTINUE=46 47 | RETURN=47 48 | MAIN=48 49 | ONINIT=49 50 | ONSTART=50 51 | FLOAT=51 52 | DOUBLE=52 53 | STRING=53 54 | BOOL=54 55 | VOID=55 56 | INT=56 57 | BUY=57 58 | SELL=58 59 | ASK=59 60 | BID=60 61 | TIME=61 62 | HIGH=62 63 | LOW=63 64 | DIGITS=64 65 | VOLUME=65 66 | TYPE=66 67 | TEXT=67 68 | OPEN=68 69 | CLOSE=69 70 | TRADE=70 71 | ORDER=71 72 | CANDLE=72 73 | EXCEPTION=73 74 | REFRESH_RATE=74 75 | GET_CANDLE=75 76 | TERMINATE=76 77 | CONNECT=77 78 | OBSERVE=78 79 | PRINT=79 80 | ID=80 81 | INT_LITERAL=81 82 | FLOAT_LITERAL=82 83 | STRING_LITERAL=83 84 | BOOL_LITERAL=84 85 | COMMENT=85 86 | ';'=2 87 | ','=3 88 | ':'=4 89 | '.'=5 90 | '('=6 91 | ')'=7 92 | '{'=8 93 | '}'=9 94 | '['=10 95 | ']'=11 96 | '+'=12 97 | '-'=13 98 | '*'=14 99 | '/'=15 100 | '%'=16 101 | '&&'=17 102 | '||'=18 103 | '!'=19 104 | '&'=20 105 | '|'=21 106 | '^'=22 107 | '<<'=23 108 | '>>'=24 109 | '~'=25 110 | '<'=26 111 | '>'=27 112 | '=='=28 113 | '!='=29 114 | '++'=30 115 | '--'=31 116 | '='=32 117 | '+='=33 118 | '-='=34 119 | '*='=35 120 | '/='=36 121 | '%='=37 122 | 'try'=38 123 | 'throw'=39 124 | 'catch'=40 125 | 'if'=41 126 | 'else'=42 127 | 'for'=43 128 | 'while'=44 129 | 'break'=45 130 | 'continue'=46 131 | 'return'=47 132 | 'Main'=48 133 | 'OnInit'=49 134 | 'OnStart'=50 135 | 'float'=51 136 | 'double'=52 137 | 'string'=53 138 | 'bool'=54 139 | 'void'=55 140 | 'int'=56 141 | 'BUY'=57 142 | 'SELL'=58 143 | 'Ask'=59 144 | 'Bid'=60 145 | 'Time'=61 146 | 'High'=62 147 | 'Low'=63 148 | 'Digits'=64 149 | 'Volume'=65 150 | 'Type'=66 151 | 'Text'=67 152 | 'Open'=68 153 | 'Close'=69 154 | 'Trade'=70 155 | 'Order'=71 156 | 'Candle'=72 157 | 'Exception'=73 158 | 'RefreshRate'=74 159 | 'GetCandle'=75 160 | 'Terminate'=76 161 | 'Connect'=77 162 | 'Observe'=78 163 | 'Print'=79 164 | -------------------------------------------------------------------------------- /Phase 2/src/main/grammar/.antlr/UTLLexer.tokens: -------------------------------------------------------------------------------- 1 | SPACES=1 2 | SEMICOLON=2 3 | COMMA=3 4 | COLON=4 5 | DOT=5 6 | LPAREN=6 7 | RPAREN=7 8 | LBRACE=8 9 | RBRACE=9 10 | LBRACK=10 11 | RBRACK=11 12 | PLUS=12 13 | MINUS=13 14 | MULT=14 15 | DIV=15 16 | MOD=16 17 | AND=17 18 | OR=18 19 | NOT=19 20 | BIT_AND=20 21 | BIT_OR=21 22 | BIT_XOR=22 23 | L_SHIFT=23 24 | R_SHIFT=24 25 | BIT_NOT=25 26 | LT=26 27 | GT=27 28 | EQ=28 29 | NEQ=29 30 | INC=30 31 | DEC=31 32 | ASSIGN=32 33 | ADD_ASSIGN=33 34 | SUB_ASSIGN=34 35 | MUL_ASSIGN=35 36 | DIV_ASSIGN=36 37 | MOD_ASSIGN=37 38 | TRY=38 39 | THROW=39 40 | CATCH=40 41 | IF=41 42 | ELSE=42 43 | FOR=43 44 | WHILE=44 45 | BREAK=45 46 | CONTINUE=46 47 | RETURN=47 48 | MAIN=48 49 | ONINIT=49 50 | ONSTART=50 51 | FLOAT=51 52 | DOUBLE=52 53 | STRING=53 54 | BOOL=54 55 | VOID=55 56 | INT=56 57 | BUY=57 58 | SELL=58 59 | ASK=59 60 | BID=60 61 | TIME=61 62 | HIGH=62 63 | LOW=63 64 | DIGITS=64 65 | VOLUME=65 66 | TYPE=66 67 | TEXT=67 68 | OPEN=68 69 | CLOSE=69 70 | TRADE=70 71 | ORDER=71 72 | CANDLE=72 73 | EXCEPTION=73 74 | REFRESH_RATE=74 75 | GET_CANDLE=75 76 | TERMINATE=76 77 | CONNECT=77 78 | OBSERVE=78 79 | PRINT=79 80 | ID=80 81 | INT_LITERAL=81 82 | FLOAT_LITERAL=82 83 | STRING_LITERAL=83 84 | BOOL_LITERAL=84 85 | COMMENT=85 86 | ';'=2 87 | ','=3 88 | ':'=4 89 | '.'=5 90 | '('=6 91 | ')'=7 92 | '{'=8 93 | '}'=9 94 | '['=10 95 | ']'=11 96 | '+'=12 97 | '-'=13 98 | '*'=14 99 | '/'=15 100 | '%'=16 101 | '&&'=17 102 | '||'=18 103 | '!'=19 104 | '&'=20 105 | '|'=21 106 | '^'=22 107 | '<<'=23 108 | '>>'=24 109 | '~'=25 110 | '<'=26 111 | '>'=27 112 | '=='=28 113 | '!='=29 114 | '++'=30 115 | '--'=31 116 | '='=32 117 | '+='=33 118 | '-='=34 119 | '*='=35 120 | '/='=36 121 | '%='=37 122 | 'try'=38 123 | 'throw'=39 124 | 'catch'=40 125 | 'if'=41 126 | 'else'=42 127 | 'for'=43 128 | 'while'=44 129 | 'break'=45 130 | 'continue'=46 131 | 'return'=47 132 | 'Main'=48 133 | 'OnInit'=49 134 | 'OnStart'=50 135 | 'float'=51 136 | 'double'=52 137 | 'string'=53 138 | 'bool'=54 139 | 'void'=55 140 | 'int'=56 141 | 'BUY'=57 142 | 'SELL'=58 143 | 'Ask'=59 144 | 'Bid'=60 145 | 'Time'=61 146 | 'High'=62 147 | 'Low'=63 148 | 'Digits'=64 149 | 'Volume'=65 150 | 'Type'=66 151 | 'Text'=67 152 | 'Open'=68 153 | 'Close'=69 154 | 'Trade'=70 155 | 'Order'=71 156 | 'Candle'=72 157 | 'Exception'=73 158 | 'RefreshRate'=74 159 | 'GetCandle'=75 160 | 'Terminate'=76 161 | 'Connect'=77 162 | 'Observe'=78 163 | 'Print'=79 164 | -------------------------------------------------------------------------------- /Phase 4/src/main/sample/output.j: -------------------------------------------------------------------------------- 1 | .class public UTL 2 | .super java/lang/Object 3 | 4 | .field public balance I 5 | .field public tick_counts I 6 | 7 | .method public ()V 8 | aload_0 9 | invokespecial java/lang/Object/()V 10 | return 11 | .end method 12 | 13 | .method public OnInit(LTrade;)V 14 | .limit stack 128 15 | .limit locals 128 16 | new Order 17 | dup 18 | ldc "SELL" 19 | bipush 100 20 | bipush 100 21 | bipush 10 22 | invokespecial Order/(Ljava/lang/String;III)V 23 | astore 2 24 | return 25 | .end method 26 | 27 | .method public OnInit(LTrade;)V 28 | .limit stack 128 29 | .limit locals 128 30 | new Order 31 | dup 32 | ldc "BUY" 33 | bipush 200 34 | bipush 50 35 | bipush 5 36 | invokespecial Order/(Ljava/lang/String;III)V 37 | astore 2 38 | new Order 39 | dup 40 | ldc "SELL" 41 | bipush 100 42 | bipush 100 43 | bipush 10 44 | invokespecial Order/(Ljava/lang/String;III)V 45 | astore 3 46 | return 47 | .end method 48 | 49 | .method public OnStart(LTrade;)V 50 | .limit stack 128 51 | .limit locals 128 52 | aload 1 53 | invokevirtual LTrade/getBid()F 54 | fstore 2 55 | 56 | aload 1 57 | invokevirtual LTrade/getAsk()D 58 | fstore 3 59 | 60 | bipush 100 61 | fstore 4 62 | 63 | bipush 250 64 | fstore 5 65 | 66 | bipush 20 67 | fstore 6 68 | 69 | new Order 70 | dup 71 | ldc "BUY" 72 | fload 4 73 | fload 5 74 | fload 6 75 | invokespecial Order/(Ljava/lang/String;III)V 76 | astore 7 77 | 78 | fload 5 79 | fload 6 80 | idiv 81 | fstore 8 82 | 83 | return 84 | .end method 85 | 86 | .method public OnStart(LTrade;)V 87 | .limit stack 128 88 | .limit locals 128 89 | bipush 100 90 | invokevirtual LYourClass/GetCandle(I)V 91 | return 92 | .end method 93 | 94 | .method public static Main([Ljava/lang/String;)V 95 | .limit stack 128 96 | .limit locals 128 97 | ldc "admin" 98 | astore 1 99 | 100 | aload 1 101 | ldc "password" 102 | invokestatic LYourClass/Connect(Ljava/lang/String;Ljava/lang/String;)V 103 | ldc "USDETH" 104 | invokestatic LYourClass/Observe(Ljava/lang/String;)LTrade; 105 | astore 2 106 | 107 | aload 2 108 | invokevirtual LTrade/getDigits()I 109 | istore 3 110 | 111 | aload 2 112 | invokevirtual LTrade/getDigits()I 113 | astore 3 114 | 115 | ldc "IRRETH" 116 | invokestatic LYourClass/Observe(Ljava/lang/String;)LTrade; 117 | astore 4 118 | 119 | return 120 | .end method 121 | 122 | -------------------------------------------------------------------------------- /Phase 2/src/main/ast/node/Program.java: -------------------------------------------------------------------------------- 1 | package main.ast.node; 2 | 3 | import main.ast.node.declaration.*; 4 | import main.visitor.IVisitor; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class Program extends Node{ 9 | private ArrayList vars = new ArrayList<>(); 10 | private ArrayList globalVars = new ArrayList<>(); 11 | private ArrayList inits = new ArrayList<>(); 12 | private ArrayList starts = new ArrayList<>(); 13 | private ArrayList functions = new ArrayList<>(); 14 | private MainDeclaration programMainDeclaration; 15 | 16 | public MainDeclaration getMain() { 17 | return this.programMainDeclaration; 18 | } 19 | 20 | public void setMain(MainDeclaration mainDeclarationActors) { 21 | this.programMainDeclaration = mainDeclarationActors; 22 | } 23 | 24 | public ArrayList getVars() { 25 | return vars; 26 | } 27 | 28 | public ArrayList getGlobalVars() { return globalVars; } 29 | 30 | public void setVars(ArrayList vars) { 31 | this.vars = vars; 32 | } 33 | 34 | public void setGlobalVars(ArrayList globalVars) { 35 | this.globalVars = globalVars; 36 | } 37 | 38 | public ArrayList getInits() { 39 | return inits; 40 | } 41 | 42 | public void setInits(ArrayList inits) { 43 | this.inits = inits; 44 | } 45 | 46 | public ArrayList getStarts() { 47 | return starts; 48 | } 49 | 50 | public void setStarts(ArrayList starts) { 51 | this.starts = starts; 52 | } 53 | 54 | public ArrayList getFunctions() { 55 | return functions; 56 | } 57 | 58 | public void setFunctions(ArrayList functions) { 59 | this.functions = functions; 60 | } 61 | 62 | public void addVar(VarDeclaration varDeclaration) { 63 | this.vars.add(varDeclaration); 64 | } 65 | 66 | public void addGlobalVar(GlobalVarDeclaration globalVarDeclaration) { 67 | this.globalVars.add(globalVarDeclaration); 68 | } 69 | 70 | public void addInit(OnInitDeclaration onInitDeclaration) { 71 | this.inits.add(onInitDeclaration); 72 | } 73 | 74 | public void addStart(OnStartDeclaration onStartDeclaration) { 75 | this.starts.add(onStartDeclaration); 76 | } 77 | 78 | public void addFunction(FunctionDeclaration functionDeclaration) { 79 | this.functions.add(functionDeclaration); 80 | } 81 | 82 | @Override 83 | public T accept(IVisitor visitor) { 84 | return visitor.visit(this); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Phase 3/src/main/visitor/Visitor.java: -------------------------------------------------------------------------------- 1 | package main.visitor; 2 | 3 | import main.ast.node.Program; 4 | import main.ast.node.declaration.*; 5 | import main.ast.node.expression.*; 6 | import main.ast.node.expression.values.*; 7 | import main.ast.node.statement.*; 8 | 9 | public class Visitor implements IVisitor { 10 | 11 | @Override 12 | public T visit(Program program) { 13 | return null; 14 | } 15 | 16 | @Override 17 | public T visit(OnInitDeclaration onInitDeclaration) { 18 | return null; 19 | } 20 | 21 | @Override 22 | public T visit(OnStartDeclaration onStartDeclaration) { 23 | return null; 24 | } 25 | 26 | @Override 27 | public T visit(FunctionDeclaration functionDeclaration) { 28 | return null; 29 | } 30 | 31 | @Override 32 | public T visit(VarDeclaration varDeclaration) { 33 | return null; 34 | } 35 | 36 | @Override 37 | public T visit(MainDeclaration mainDeclarationActors) { 38 | return null; 39 | } 40 | 41 | @Override 42 | public T visit(UnaryExpression unaryExpression) { 43 | return null; 44 | } 45 | 46 | @Override 47 | public T visit(BinaryExpression binaryExpression) { 48 | return null; 49 | } 50 | 51 | @Override 52 | public T visit(VarAccess varAccess) { 53 | return null; 54 | } 55 | 56 | @Override 57 | public T visit(Identifier identifier) { 58 | return null; 59 | } 60 | 61 | @Override 62 | public T visit(ArrayIdentifier arrayIdentifier) { 63 | return null; 64 | } 65 | 66 | @Override 67 | public T visit(IntValue value) { 68 | return null; 69 | } 70 | 71 | @Override 72 | public T visit(StringValue value) { 73 | return null; 74 | } 75 | 76 | @Override 77 | public T visit(BoolValue boolValue) { 78 | return null; 79 | } 80 | 81 | @Override 82 | public T visit(FloatValue floatValue) { 83 | return null; 84 | } 85 | 86 | @Override 87 | public T visit(TradeValue tradeValue) { 88 | return null; 89 | } 90 | 91 | @Override 92 | public T visit(IfElseStmt conditional) { 93 | return null; 94 | } 95 | 96 | @Override 97 | public T visit(FunctionCall functionCall) { 98 | return null; 99 | } 100 | 101 | @Override 102 | public T visit(MethodCall methodCall) { 103 | return null; 104 | } 105 | 106 | @Override 107 | public T visit(AssignStmt assignStmt) { 108 | return null; 109 | } 110 | 111 | @Override 112 | public T visit(ForStmt forStmt) { 113 | return null; 114 | } 115 | 116 | @Override 117 | public T visit(WhileStmt whileStmt) { 118 | return null; 119 | } 120 | 121 | @Override 122 | public T visit(ContinueBreakStmt continueBreakStmt) { 123 | return null; 124 | } 125 | 126 | @Override 127 | public T visit(ExpressionStmt expressionStmt) { 128 | return null; 129 | } 130 | 131 | @Override 132 | public T visit(ReturnStmt returnStmt) { 133 | return null; 134 | } 135 | 136 | @Override 137 | public T visit(ThrowStmt throwStmt) { 138 | return null; 139 | } 140 | 141 | @Override 142 | public T visit(TryCatchStmt tryCatchStmt) { 143 | return null; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /Phase 4/src/main/visitor/Visitor.java: -------------------------------------------------------------------------------- 1 | package main.visitor; 2 | 3 | import main.ast.node.Program; 4 | import main.ast.node.declaration.*; 5 | import main.ast.node.expression.*; 6 | import main.ast.node.expression.values.*; 7 | import main.ast.node.statement.*; 8 | 9 | public class Visitor implements IVisitor { 10 | 11 | @Override 12 | public T visit(Program program) { 13 | return null; 14 | } 15 | 16 | @Override 17 | public T visit(OnInitDeclaration onInitDeclaration) { 18 | return null; 19 | } 20 | 21 | @Override 22 | public T visit(OnStartDeclaration onStartDeclaration) { 23 | return null; 24 | } 25 | 26 | @Override 27 | public T visit(FunctionDeclaration functionDeclaration) { 28 | return null; 29 | } 30 | 31 | @Override 32 | public T visit(VarDeclaration varDeclaration) { 33 | return null; 34 | } 35 | 36 | @Override 37 | public T visit(MainDeclaration mainDeclarationActors) { 38 | return null; 39 | } 40 | 41 | @Override 42 | public T visit(UnaryExpression unaryExpression) { 43 | return null; 44 | } 45 | 46 | @Override 47 | public T visit(BinaryExpression binaryExpression) { 48 | return null; 49 | } 50 | 51 | @Override 52 | public T visit(VarAccess varAccess) { 53 | return null; 54 | } 55 | 56 | @Override 57 | public T visit(Identifier identifier) { 58 | return null; 59 | } 60 | 61 | @Override 62 | public T visit(ArrayIdentifier arrayIdentifier) { 63 | return null; 64 | } 65 | 66 | @Override 67 | public T visit(IntValue value) { 68 | return null; 69 | } 70 | 71 | @Override 72 | public T visit(StringValue value) { 73 | return null; 74 | } 75 | @Override 76 | public T visit(NullValue value) { 77 | return null; 78 | } 79 | 80 | 81 | @Override 82 | public T visit(BoolValue boolValue) { 83 | return null; 84 | } 85 | 86 | @Override 87 | public T visit(FloatValue floatValue) { 88 | return null; 89 | } 90 | 91 | @Override 92 | public T visit(TradeValue tradeValue) { 93 | return null; 94 | } 95 | 96 | @Override 97 | public T visit(IfElseStmt conditional) { 98 | return null; 99 | } 100 | 101 | @Override 102 | public T visit(FunctionCall functionCall) { 103 | return null; 104 | } 105 | 106 | @Override 107 | public T visit(MethodCall methodCall) { 108 | return null; 109 | } 110 | 111 | @Override 112 | public T visit(AssignStmt assignStmt) { 113 | return null; 114 | } 115 | 116 | @Override 117 | public T visit(ForStmt forStmt) { 118 | return null; 119 | } 120 | 121 | @Override 122 | public T visit(WhileStmt whileStmt) { 123 | return null; 124 | } 125 | 126 | @Override 127 | public T visit(ContinueBreakStmt continueBreakStmt) { 128 | return null; 129 | } 130 | 131 | @Override 132 | public T visit(ExpressionStmt expressionStmt) { 133 | return null; 134 | } 135 | 136 | @Override 137 | public T visit(ReturnStmt returnStmt) { 138 | return null; 139 | } 140 | 141 | @Override 142 | public T visit(ThrowStmt throwStmt) { 143 | return null; 144 | } 145 | 146 | @Override 147 | public T visit(TryCatchStmt tryCatchStmt) { 148 | return null; 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /Phase 2/src/main/visitor/Visitor.java: -------------------------------------------------------------------------------- 1 | package main.visitor; 2 | 3 | import main.ast.node.Program; 4 | import main.ast.node.declaration.*; 5 | import main.ast.node.expression.*; 6 | import main.ast.node.expression.values.BoolValue; 7 | import main.ast.node.expression.values.FloatValue; 8 | import main.ast.node.expression.values.IntValue; 9 | import main.ast.node.expression.values.StringValue; 10 | import main.ast.node.expression.values.TradeValue; 11 | import main.ast.node.statement.*; 12 | 13 | public class Visitor implements IVisitor { 14 | 15 | @Override 16 | public T visit(Program program) { 17 | return null; 18 | } 19 | 20 | @Override 21 | public T visit(OnInitDeclaration onInitDeclaration) { 22 | return null; 23 | } 24 | 25 | @Override 26 | public T visit(OnStartDeclaration onStartDeclaration) { 27 | return null; 28 | } 29 | 30 | @Override 31 | public T visit(FunctionDeclaration functionDeclaration) { 32 | return null; 33 | } 34 | 35 | @Override 36 | public T visit(VarDeclaration varDeclaration) { 37 | return null; 38 | } 39 | 40 | @Override 41 | public T visit(GlobalVarDeclaration globalVarDeclaration) { 42 | return null; 43 | } 44 | 45 | @Override 46 | public T visit(MainDeclaration mainDeclarationActors) { 47 | return null; 48 | } 49 | 50 | @Override 51 | public T visit(UnaryExpression unaryExpression) { 52 | return null; 53 | } 54 | 55 | @Override 56 | public T visit(BinaryExpression binaryExpression) { 57 | return null; 58 | } 59 | 60 | @Override 61 | public T visit(VarAccess varAccess) { 62 | return null; 63 | } 64 | 65 | @Override 66 | public T visit(Identifier identifier) { 67 | return null; 68 | } 69 | 70 | @Override 71 | public T visit(ArrayIdentifier arrayIdentifier) { 72 | return null; 73 | } 74 | 75 | @Override 76 | public T visit(IntValue value) { 77 | return null; 78 | } 79 | 80 | @Override 81 | public T visit(StringValue value) { 82 | return null; 83 | } 84 | 85 | @Override 86 | public T visit(BoolValue boolValue) { 87 | return null; 88 | } 89 | 90 | @Override 91 | public T visit(TradeValue tradeValue) { 92 | return null; 93 | } 94 | 95 | @Override 96 | public T visit(FloatValue floatValue) { 97 | return null; 98 | } 99 | 100 | @Override 101 | public T visit(IfElseStmt conditional) { 102 | return null; 103 | } 104 | 105 | @Override 106 | public T visit(FunctionCall functionCall) { 107 | return null; 108 | } 109 | 110 | @Override 111 | public T visit(MethodCall methodCall) { 112 | return null; 113 | } 114 | 115 | @Override 116 | public T visit(AssignStmt assignStmt) { 117 | return null; 118 | } 119 | 120 | @Override 121 | public T visit(ForStmt forStmt) { 122 | return null; 123 | } 124 | 125 | @Override 126 | public T visit(WhileStmt whileStmt) { 127 | return null; 128 | } 129 | 130 | @Override 131 | public T visit(ContinueBreakStmt continueBreakStmt) { 132 | return null; 133 | } 134 | 135 | @Override 136 | public T visit(ExpressionStmt expressionStmt) { 137 | return null; 138 | } 139 | 140 | @Override 141 | public T visit(ReturnStmt returnStmt) { 142 | return null; 143 | } 144 | 145 | @Override 146 | public T visit(ThrowStmt throwStmt) { 147 | return null; 148 | } 149 | 150 | @Override 151 | public T visit(TryCatchStmt tryCatchStmt) { 152 | return null; 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /Phase 3/src/main/visitor/nameAnalyzer/NameAnalyzer.java: -------------------------------------------------------------------------------- 1 | package main.visitor.nameAnalyzer; 2 | 3 | import main.ast.node.Program; 4 | import main.ast.node.declaration.*; 5 | import main.ast.node.statement.ForStmt; 6 | import main.ast.node.statement.Statement; 7 | import main.ast.type.complexType.TradeType; 8 | import main.compileError.CompileError; 9 | import main.compileError.name.*; 10 | import main.symbolTable.SymbolTable; 11 | import main.symbolTable.itemException.ItemAlreadyExistsException; 12 | import main.symbolTable.itemException.ItemNotFoundException; 13 | import main.symbolTable.symbolTableItems.*; 14 | import main.visitor.Visitor; 15 | 16 | import java.util.ArrayList; 17 | 18 | public class NameAnalyzer extends Visitor { 19 | 20 | public ArrayList nameErrors = new ArrayList<>(); 21 | 22 | @Override 23 | public Void visit(Program program) { 24 | SymbolTable.root = new SymbolTable(); 25 | SymbolTable.push(SymbolTable.root); 26 | for (VarDeclaration varDeclaration : program.getVars()) 27 | varDeclaration.accept(this); 28 | for (FunctionDeclaration functionDeclaration : program.getFunctions()) 29 | functionDeclaration.accept(this); 30 | for (OnInitDeclaration onInitDeclaration : program.getInits()) 31 | onInitDeclaration.accept(this); 32 | for (OnStartDeclaration onStartDeclaration : program.getStarts()) 33 | onStartDeclaration.accept(this); 34 | program.getMain().accept(this); 35 | return null; 36 | } 37 | 38 | @Override 39 | public Void visit(OnInitDeclaration onInitDeclaration) { 40 | OnInitItem onInitItem = new OnInitItem(onInitDeclaration); 41 | SymbolTable onInitSymbolTable = new SymbolTable(SymbolTable.top, onInitDeclaration.getTradeName().getName()); 42 | onInitItem.setOnInitSymbolTable(onInitSymbolTable); 43 | try { 44 | SymbolTable.root.put(onInitItem); 45 | } catch (ItemAlreadyExistsException e) { 46 | if (!onInitItem.getKey().endsWith("$")) 47 | nameErrors.add(new PrimitiveFunctionRedefinition(onInitDeclaration.getLine(), onInitItem.getDeclaration().getTradeName().getName())); 48 | onInitItem.setName(onInitItem.getKey() + "$"); 49 | } 50 | SymbolTable.push(onInitSymbolTable); 51 | VarDeclaration initArg = new VarDeclaration(); 52 | initArg.setIdentifier(onInitDeclaration.getTradeName()); 53 | initArg.setType(new TradeType()); 54 | initArg.accept(this); 55 | for (Statement stmt : onInitDeclaration.getBody()) 56 | stmt.accept(this); 57 | SymbolTable.pop(); 58 | return null; 59 | } 60 | 61 | @Override 62 | public Void visit(OnStartDeclaration onStartDeclaration) { 63 | OnStartItem onStartItem = new OnStartItem(onStartDeclaration); 64 | SymbolTable onStartSymbolTable = new SymbolTable(SymbolTable.top, onStartDeclaration.getTradeName().getName()); 65 | onStartItem.setOnStartSymbolTable(onStartSymbolTable); 66 | try { 67 | SymbolTable.root.put(onStartItem); 68 | } catch (ItemAlreadyExistsException e) { 69 | if (!onStartItem.getKey().endsWith("$")) 70 | nameErrors.add(new PrimitiveFunctionRedefinition(onStartDeclaration.getLine(), onStartDeclaration.getTradeName().getName())); 71 | onStartItem.setName(onStartItem.getKey() + "$"); 72 | } 73 | SymbolTable.push(onStartSymbolTable); 74 | VarDeclaration initArg = new VarDeclaration(); 75 | initArg.setIdentifier(onStartDeclaration.getTradeName()); 76 | initArg.setType(new TradeType()); 77 | initArg.accept(this); 78 | for (Statement stmt : onStartDeclaration.getBody()) 79 | stmt.accept(this); 80 | SymbolTable.pop(); 81 | return null; 82 | } 83 | 84 | @Override 85 | public Void visit(MainDeclaration mainDeclaration) { 86 | MainItem mainItem = new MainItem(mainDeclaration); 87 | SymbolTable mainSymbolTable = new SymbolTable(SymbolTable.top, "main"); 88 | mainItem.setMainSymbolTable(mainSymbolTable); 89 | SymbolTable.push(mainSymbolTable); 90 | for (Statement stmt : mainDeclaration.getBody()) 91 | stmt.accept(this); 92 | SymbolTable.pop(); 93 | return null; 94 | } 95 | 96 | @Override 97 | public Void visit(FunctionDeclaration functionDeclaration) { 98 | FunctionItem functionItem = new FunctionItem(functionDeclaration); 99 | SymbolTable functionSymbolTable = new SymbolTable(SymbolTable.top, functionDeclaration.getName().getName()); 100 | functionItem.setFunctionSymbolTable(functionSymbolTable); 101 | try { 102 | SymbolTable.top.put(functionItem); 103 | } catch (ItemAlreadyExistsException e) { 104 | nameErrors.add(new MethodRedefinition(functionItem.getFunctionDeclaration().getLine(), functionItem.getFunctionDeclaration().getName().getName())); 105 | } 106 | SymbolTable.push(functionSymbolTable); 107 | try { 108 | SymbolTable.top.get("Variable_" + functionDeclaration.getName().getName()); 109 | nameErrors.add(new FunctionVariableConflict(functionDeclaration.getLine(), functionDeclaration.getName().getName())); 110 | } catch (ItemNotFoundException e) { 111 | // pass 112 | } 113 | for (VarDeclaration varDeclaration : functionDeclaration.getArgs()) 114 | varDeclaration.accept(this); 115 | for (Statement stmt : functionDeclaration.getBody()) 116 | stmt.accept(this); 117 | SymbolTable.pop(); 118 | return null; 119 | } 120 | 121 | @Override 122 | public Void visit(VarDeclaration varDeclaration) { 123 | VariableItem varItem = new VariableItem(varDeclaration); 124 | try { 125 | SymbolTable.top.get("Function_" + varDeclaration.getIdentifier().getName()); 126 | nameErrors.add(new FunctionVariableConflict(varDeclaration.getLine(), varDeclaration.getIdentifier().getName())); 127 | } catch (ItemNotFoundException e) { 128 | // pass 129 | } 130 | try { 131 | SymbolTable.top.put(varItem); 132 | } catch (ItemAlreadyExistsException e) { 133 | if (!varItem.getName().endsWith("$")) 134 | nameErrors.add(new VariableRedefinition(varDeclaration.getLine(), varDeclaration.getIdentifier().getName())); 135 | varItem.setName(varItem.getName() + "$"); 136 | } 137 | return null; 138 | } 139 | 140 | @Override 141 | public Void visit(ForStmt forStmt) { 142 | for (Statement stmt : forStmt.getInit()) 143 | stmt.accept(this); 144 | return null; 145 | } 146 | } 147 | 148 | -------------------------------------------------------------------------------- /Phase 4/src/main/visitor/nameAnalyzer/NameAnalyzer.java: -------------------------------------------------------------------------------- 1 | package main.visitor.nameAnalyzer; 2 | 3 | import main.ast.node.Program; 4 | import main.ast.node.declaration.*; 5 | import main.ast.node.statement.ForStmt; 6 | import main.ast.node.statement.Statement; 7 | import main.ast.type.complexType.TradeType; 8 | import main.compileError.CompileError; 9 | import main.compileError.name.*; 10 | import main.symbolTable.SymbolTable; 11 | import main.symbolTable.itemException.ItemAlreadyExistsException; 12 | import main.symbolTable.itemException.ItemNotFoundException; 13 | import main.symbolTable.symbolTableItems.*; 14 | import main.visitor.Visitor; 15 | 16 | import java.util.ArrayList; 17 | 18 | public class NameAnalyzer extends Visitor { 19 | 20 | public ArrayList nameErrors = new ArrayList<>(); 21 | 22 | @Override 23 | public Void visit(Program program) { 24 | SymbolTable.root = new SymbolTable(); 25 | SymbolTable.push(SymbolTable.root); 26 | for (VarDeclaration varDeclaration : program.getVars()) 27 | varDeclaration.accept(this); 28 | for (FunctionDeclaration functionDeclaration : program.getFunctions()) 29 | functionDeclaration.accept(this); 30 | for (OnInitDeclaration onInitDeclaration : program.getInits()) 31 | onInitDeclaration.accept(this); 32 | for (OnStartDeclaration onStartDeclaration : program.getStarts()) 33 | onStartDeclaration.accept(this); 34 | program.getMain().accept(this); 35 | return null; 36 | } 37 | 38 | @Override 39 | public Void visit(OnInitDeclaration onInitDeclaration) { 40 | OnInitItem onInitItem = new OnInitItem(onInitDeclaration); 41 | SymbolTable onInitSymbolTable = new SymbolTable(SymbolTable.top, onInitDeclaration.getTradeName().getName()); 42 | onInitItem.setOnInitSymbolTable(onInitSymbolTable); 43 | try { 44 | SymbolTable.root.put(onInitItem); 45 | } catch (ItemAlreadyExistsException e) { 46 | if (!onInitItem.getKey().endsWith("$")) 47 | nameErrors.add(new PrimitiveFunctionRedefinition(onInitDeclaration.getLine(), onInitItem.getDeclaration().getTradeName().getName())); 48 | onInitItem.setName(onInitItem.getKey() + "$"); 49 | } 50 | SymbolTable.push(onInitSymbolTable); 51 | VarDeclaration initArg = new VarDeclaration(); 52 | initArg.setIdentifier(onInitDeclaration.getTradeName()); 53 | initArg.setType(new TradeType()); 54 | initArg.accept(this); 55 | for (Statement stmt : onInitDeclaration.getBody()) 56 | stmt.accept(this); 57 | SymbolTable.pop(); 58 | return null; 59 | } 60 | 61 | @Override 62 | public Void visit(OnStartDeclaration onStartDeclaration) { 63 | OnStartItem onStartItem = new OnStartItem(onStartDeclaration); 64 | SymbolTable onStartSymbolTable = new SymbolTable(SymbolTable.top, onStartDeclaration.getTradeName().getName()); 65 | onStartItem.setOnStartSymbolTable(onStartSymbolTable); 66 | try { 67 | SymbolTable.root.put(onStartItem); 68 | } catch (ItemAlreadyExistsException e) { 69 | if (!onStartItem.getKey().endsWith("$")) 70 | nameErrors.add(new PrimitiveFunctionRedefinition(onStartDeclaration.getLine(), onStartDeclaration.getTradeName().getName())); 71 | onStartItem.setName(onStartItem.getKey() + "$"); 72 | } 73 | SymbolTable.push(onStartSymbolTable); 74 | VarDeclaration initArg = new VarDeclaration(); 75 | initArg.setIdentifier(onStartDeclaration.getTradeName()); 76 | initArg.setType(new TradeType()); 77 | initArg.accept(this); 78 | for (Statement stmt : onStartDeclaration.getBody()) 79 | stmt.accept(this); 80 | SymbolTable.pop(); 81 | return null; 82 | } 83 | 84 | @Override 85 | public Void visit(MainDeclaration mainDeclaration) { 86 | MainItem mainItem = new MainItem(mainDeclaration); 87 | SymbolTable mainSymbolTable = new SymbolTable(SymbolTable.top, "main"); 88 | mainItem.setMainSymbolTable(mainSymbolTable); 89 | try { 90 | SymbolTable.top.put(mainItem); 91 | } catch (ItemAlreadyExistsException e) { 92 | // pass 93 | } 94 | SymbolTable.push(mainSymbolTable); 95 | for (Statement stmt : mainDeclaration.getBody()) 96 | stmt.accept(this); 97 | SymbolTable.pop(); 98 | return null; 99 | } 100 | 101 | @Override 102 | public Void visit(FunctionDeclaration functionDeclaration) { 103 | FunctionItem functionItem = new FunctionItem(functionDeclaration); 104 | SymbolTable functionSymbolTable = new SymbolTable(SymbolTable.top, functionDeclaration.getName().getName()); 105 | functionItem.setFunctionSymbolTable(functionSymbolTable); 106 | try { 107 | SymbolTable.top.put(functionItem); 108 | } catch (ItemAlreadyExistsException e) { 109 | nameErrors.add(new MethodRedefinition(functionItem.getFunctionDeclaration().getLine(), functionItem.getFunctionDeclaration().getName().getName())); 110 | } 111 | SymbolTable.push(functionSymbolTable); 112 | try { 113 | SymbolTable.top.get("Variable_" + functionDeclaration.getName().getName()); 114 | nameErrors.add(new FunctionVariableConflict(functionDeclaration.getLine(), functionDeclaration.getName().getName())); 115 | } catch (ItemNotFoundException e) { 116 | // pass 117 | } 118 | for (VarDeclaration varDeclaration : functionDeclaration.getArgs()) 119 | varDeclaration.accept(this); 120 | for (Statement stmt : functionDeclaration.getBody()) 121 | stmt.accept(this); 122 | SymbolTable.pop(); 123 | return null; 124 | } 125 | 126 | @Override 127 | public Void visit(VarDeclaration varDeclaration) { 128 | VariableItem varItem = new VariableItem(varDeclaration); 129 | try { 130 | SymbolTable.top.get("Function_" + varDeclaration.getIdentifier().getName()); 131 | nameErrors.add(new FunctionVariableConflict(varDeclaration.getLine(), varDeclaration.getIdentifier().getName())); 132 | } catch (ItemNotFoundException e) { 133 | // pass 134 | } 135 | try { 136 | SymbolTable.top.put(varItem); 137 | } catch (ItemAlreadyExistsException e) { 138 | if (!varItem.getName().endsWith("$")) 139 | nameErrors.add(new VariableRedefinition(varDeclaration.getLine(), varDeclaration.getIdentifier().getName())); 140 | varItem.setName(varItem.getName() + "$"); 141 | } 142 | return null; 143 | } 144 | 145 | @Override 146 | public Void visit(ForStmt forStmt) { 147 | for (Statement stmt : forStmt.getInit()) 148 | stmt.accept(this); 149 | return null; 150 | } 151 | } 152 | 153 | --------------------------------------------------------------------------------