extern void AST_AppendNode(tAST_Node *Parent, tAST_Node *Child);
extern tAST_Node *AST_NewIf(tParser *Parser, tAST_Node *Condition, tAST_Node *True, tAST_Node *False);
+extern tAST_Node *AST_NewLoop(tParser *Parser, tAST_Node *Init, int bPostCheck, tAST_Node *Condition, tAST_Node *Increment, tAST_Node *Code);
extern tAST_Node *AST_NewAssign(tParser *Parser, int Operation, tAST_Node *Dest, tAST_Node *Value);
extern tAST_Node *AST_NewCast(tParser *Parser, int Target, tAST_Node *Value);
tAST_Script *Parse_Buffer(tSpiderVariant *Variant, char *Buffer)
{
tParser parser = {0};
- tParser *Parser = &parser; //< Keeps code consitent
+ tParser *Parser = &parser; //< Keeps code consistent
tAST_Script *ret;
tAST_Node *mainCode;
char *name;
switch(LookAhead(Parser))
{
+ // Empty statement
+ case TOK_SEMICOLON:
+ GetToken(Parser);
+ return NULL;
// Return from a method
case TOK_RWD_RETURN:
}
return ret;
case TOK_RWD_FOR:
+ {
+ tAST_Node *init=NULL, *cond=NULL, *inc=NULL, *code;
+ GetToken(Parser); // Eat 'for'
+ SyntaxAssert(Parser, GetToken(Parser), TOK_PAREN_OPEN);
+
+ if(LookAhead(Parser) != TOK_SEMICOLON)
+ init = Parse_DoExpr0(Parser);
+
+ SyntaxAssert(Parser, GetToken(Parser), TOK_SEMICOLON);
+ if(LookAhead(Parser) != TOK_SEMICOLON)
+ cond = Parse_DoExpr0(Parser);
+
+ SyntaxAssert(Parser, GetToken(Parser), TOK_SEMICOLON);
+ if(LookAhead(Parser) != TOK_SEMICOLON)
+ inc = Parse_DoExpr0(Parser);
+
+ SyntaxAssert(Parser, GetToken(Parser), TOK_PAREN_CLOSE);
+
+ code = Parse_DoCodeBlock(Parser);
+ ret = AST_NewLoop(Parser, init, 0, cond, inc, code);
+ }
+ return ret;
case TOK_RWD_DO:
case TOK_RWD_WHILE:
- TODO(Parser, "Implement if, for, do and while\n");
+ TODO(Parser, "Implement do and while\n");
break;
// Define Variables