summaryrefslogtreecommitdiffstats
path: root/src/Compiler/Statement.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Compiler/Statement.java')
-rw-r--r--src/Compiler/Statement.java48
1 files changed, 45 insertions, 3 deletions
diff --git a/src/Compiler/Statement.java b/src/Compiler/Statement.java
index dd3ff04..5e94d35 100644
--- a/src/Compiler/Statement.java
+++ b/src/Compiler/Statement.java
@@ -1,9 +1,14 @@
package Compiler;
import java.util.List;
-
+/**
+ * Classes for possible statements in the language
+ */
abstract class Statement {
+ /**
+ * Class for the main function of the program
+ */
static class MainFunction extends Statement{
MainFunction(Statement block){
this.block = block;
@@ -18,6 +23,9 @@ abstract class Statement {
}
+ /**
+ * Class for representing a function
+ */
static class Function extends Statement{
Function(Token name,Statement block,List<Expression> arguments,List<String> argumentTypes,String returnType){
this.block=block;
@@ -39,6 +47,10 @@ abstract class Statement {
}
}
+ /**
+ * Class for representing a function declaration
+ * needed for compiling to C
+ */
static class FunctionDeclaration extends Statement{
FunctionDeclaration(Token name,List<String> argumentTypes,String returnType){
this.returnType=returnType;
@@ -56,6 +68,9 @@ abstract class Statement {
}
}
+ /**
+ * Class for representing a return statement
+ */
static class ReturnStatement extends Statement{
ReturnStatement(Expression returnValue){
@@ -71,6 +86,9 @@ abstract class Statement {
}
+ /**
+ * Class for representing a statement for an expression
+ */
static class ExpressionStatement extends Statement{
ExpressionStatement(Expression expr){
this.expr = expr;
@@ -85,6 +103,9 @@ abstract class Statement {
}
}
+ /**
+ * Class for representing a block of statements
+ */
static class BlockStatement extends Statement{
BlockStatement(List<Statement> statements){
this.statements=statements;
@@ -99,6 +120,9 @@ abstract class Statement {
}
+ /**
+ * Class for representing an if statement
+ */
static class IfStatement extends Statement{
IfStatement(Expression condition, Statement ifBlock,Statement elseBlock){
this.condition=condition;
@@ -116,6 +140,9 @@ abstract class Statement {
}
}
+ /**
+ * Class for representing a do loop
+ */
static class DoStatement extends Statement{
DoStatement(Expression variable, Expression start,Expression stop,Expression step,Statement codeBlock){
this.variable=variable;
@@ -138,6 +165,9 @@ abstract class Statement {
}
}
+ /**
+ * Class for representing a do while loop
+ */
static class DoWhileStatement extends Statement{
DoWhileStatement(Expression condition,Statement codeBlock){
this.condition=condition;
@@ -154,7 +184,10 @@ abstract class Statement {
}
}
-
+ /**
+ * Class for representing a integer or real declaration
+ *
+ */
static class VariableDeclaration extends Statement{
VariableDeclaration(Token name,String type){
this.name=name;
@@ -172,6 +205,9 @@ abstract class Statement {
}
+ /**
+ * Class for representing a string variable declaration
+ */
static class StringDeclaration extends Statement{
StringDeclaration(Token name,Expression length){
this.name=name;
@@ -189,6 +225,9 @@ abstract class Statement {
}
+ /**
+ * Class for representing an array declaration
+ */
static class ArrayDeclaration extends Statement{
ArrayDeclaration(Token name,String type,List<Expression> dimensions){
this.name=name;
@@ -207,6 +246,9 @@ abstract class Statement {
}
+ /**
+ * Class for representing a print statement
+ */
static class PrintStatement extends Statement{
PrintStatement(List<Expression> exprList){
this.exprList=exprList;
@@ -219,6 +261,6 @@ abstract class Statement {
}
}
-
+ //Abstract function for getting the statement type
public abstract String getStatmentType();
}