private Statements ParseStatements() { Statements statements = new Statements(); Statement st; while ((st = this.ParseStatement()) != null) { statements.AddStatement(st); } return(statements); }
public Program Parse(ArrayList <Token> tokens) { this.tokens = tokens; Program prog = new Program(); Statements st = this.ParseStatements(); if (st != null) { prog.AddStatement(st); } return(prog); }
public Function(string name, Statements inner, ArrayList <string> parameters, Expression returnValue) { this.Name = name; this.Parameters = parameters; this.innerStatements = inner; }
// If then else public Statement(StatementType type, Condition cond, Statements stat1, Statements stat2) : this(type, cond, stat1) { this.statements2 = stat2; }
// If then, while public Statement(StatementType type, Condition cond, Statements stat1) : this(type) { this.condition = cond; this.statements1 = stat1; }
public void AddStatement(Statements st) { this.statemets.AddRange(st.statemets); }
private Function ParseFunction() { string name = ""; if (this.CurrentType == TokenType.ALPHANUMERIC) { name = this.Pop().Value; } if (this.CurrentType != TokenType.L_PAREN) { return(null); } this.Pop(); ArrayList <string> parameters = new ArrayList <string> (); while (this.CurrentType == TokenType.ALPHANUMERIC) { parameters.Push(this.Pop().Value); if (this.CurrentType == TokenType.COMMA) { this.Pop(); } } if (this.CurrentType != TokenType.R_PAREN) { return(null); } this.Pop(); if (this.CurrentType != TokenType.L_BRACE) { return(null); } this.Pop(); Statements st = this.ParseStatements(); Expression returnValue = null; if (this.CurrentType == TokenType.RETURN) { this.Pop(); returnValue = this.ParseExpression(); if (this.CurrentType != TokenType.SEMI) { return(null); } this.Pop(); } if (this.CurrentType != TokenType.R_BRACE) { return(null); } this.Pop(); return(new Function(name, st, parameters, returnValue)); }
private Statement ParseStatement() { while (this.CurrentType == TokenType.LINE_END) { this.Pop(); } TokenType type = this.CurrentType; if (type == TokenType.FUNCTION) { this.Pop(); Function fun = this.ParseFunction(); return(new Statement(StatementType.FUNCTION_DECLARATION, fun)); // If then, if then else } else if (type == TokenType.IF) { this.Pop(); Condition cnd = this.ParseCondition(); if (this.CurrentType != TokenType.L_BRACE) { return(null); } this.Pop(); Statements st1 = this.ParseStatements(); if (this.CurrentType != TokenType.R_BRACE) { return(null); } this.Pop(); if (this.CurrentType == TokenType.ELSE) { this.Pop(); if (this.CurrentType != TokenType.L_BRACE) { return(null); } this.Pop(); Statements st2 = this.ParseStatements(); if (this.CurrentType != TokenType.R_BRACE) { return(null); } this.Pop(); return(new Statement(StatementType.IF_THEN_ELSE, cnd, st1, st2)); } else { return(new Statement(StatementType.IF_THEN, cnd, st1)); } // while } else if (type == TokenType.WHILE) { this.Pop(); Condition cnd = this.ParseCondition(); if (this.CurrentType != TokenType.L_BRACE) { return(null); } this.Pop(); Statements st = this.ParseStatements(); if (this.CurrentType != TokenType.R_BRACE) { return(null); } this.Pop(); return(new Statement(StatementType.WHILE, cnd, st)); } else if (type == TokenType.RETURN) { this.Pop(); Expression returnValue = this.ParseExpression(); if (this.CurrentType != TokenType.SEMI) { return(null); } this.Pop(); return(new Statement(StatementType.RETURN, returnValue)); // var, alphanumeric or alphanumeric () } else { if (this.NextType != TokenType.L_PAREN) { Assignment asg = this.ParseAssignment(); if (asg == null) { return(null); } else { return(new Statement(StatementType.ASSIGN, asg)); }; } else { Expression fun = this.ParseExpression(); if (fun == null) { return(null); } else { if (this.CurrentType != TokenType.SEMI) { return(null); } this.Pop(); return(new Statement(StatementType.FUNCTION, fun)); } } } }
public void AddStatement(Statements stat) { this.statements.AddStatement(stat); }
public Program(Statements statements) { this.statements = statements; }
public Program() { this.statements = new Statements(); }