public Node FunctionDefinition() { MatchAndEat(TokenType.DEF); String functionName = MatchAndEat(TokenType.KEYWORD).text; MatchAndEat(TokenType.LEFT_PAREN); List <Parameter> parameters = FunctionDefParameters(); MatchAndEat(TokenType.RIGHT_PAREN); Node functionBody = Block(); Function function = new Function(functionName, functionBody, parameters); Node functionVariable = new AssignmentNode(functionName, function, this); return(functionVariable); }
public Node Assignment() { Node node = null; String name = MatchAndEat(TokenType.KEYWORD).text; MatchAndEat(TokenType.ASSIGNMENT); if (CurrentToken().type == TokenType.LEFT_BRACKET) { node = ArrayDefinition(name); } else { Node value = Expression(); node = new AssignmentNode(name, value, this); } return(node); }
public Node For() { MatchAndEat(TokenType.FOR); Node variable = Assignment(); MatchAndEat(TokenType.COMMA); Node condition = Expression(); MatchAndEat(TokenType.COMMA); String name = MatchAndEat(TokenType.KEYWORD).text; MatchAndEat(TokenType.ASSIGNMENT); Node operation = Expression(); Node action = new AssignmentNode(name, operation, this); Node body = Block(); return(new ForNode(variable, condition, action, body)); }