Skip to content
Snippets Groups Projects
Commit 36798cba authored by John Hodge's avatar John Hodge
Browse files

SpiderScript - For loop, #if'd out experimental code

parent ef39d857
Branches
No related merge requests found
...@@ -188,6 +188,7 @@ size_t AST_GetNodeSize(tAST_Node *Node) ...@@ -188,6 +188,7 @@ size_t AST_GetNodeSize(tAST_Node *Node)
return ret; return ret;
} }
#if 0
/** /**
* \brief Write a node to a file * \brief Write a node to a file
*/ */
...@@ -195,6 +196,7 @@ void AST_WriteNode(FILE *FP, tAST_Node *Node) ...@@ -195,6 +196,7 @@ void AST_WriteNode(FILE *FP, tAST_Node *Node)
{ {
tAST_Node *node; tAST_Node *node;
intptr_t ptr; intptr_t ptr;
int ret;
if(!Node) return ; if(!Node) return ;
...@@ -315,6 +317,7 @@ void AST_WriteNode(FILE *FP, tAST_Node *Node) ...@@ -315,6 +317,7 @@ void AST_WriteNode(FILE *FP, tAST_Node *Node)
} }
return ret; return ret;
} }
#endif
/** /**
* \brief Free a node and all subnodes * \brief Free a node and all subnodes
......
...@@ -203,6 +203,7 @@ extern tAST_Node *AST_NewCodeBlock(void); ...@@ -203,6 +203,7 @@ extern tAST_Node *AST_NewCodeBlock(void);
extern void AST_AppendNode(tAST_Node *Parent, tAST_Node *Child); 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_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_NewAssign(tParser *Parser, int Operation, tAST_Node *Dest, tAST_Node *Value);
extern tAST_Node *AST_NewCast(tParser *Parser, int Target, tAST_Node *Value); extern tAST_Node *AST_NewCast(tParser *Parser, int Target, tAST_Node *Value);
......
...@@ -48,7 +48,7 @@ void SyntaxAssert(tParser *Parser, int Have, int Want); ...@@ -48,7 +48,7 @@ void SyntaxAssert(tParser *Parser, int Have, int Want);
tAST_Script *Parse_Buffer(tSpiderVariant *Variant, char *Buffer) tAST_Script *Parse_Buffer(tSpiderVariant *Variant, char *Buffer)
{ {
tParser parser = {0}; tParser parser = {0};
tParser *Parser = &parser; //< Keeps code consitent tParser *Parser = &parser; //< Keeps code consistent
tAST_Script *ret; tAST_Script *ret;
tAST_Node *mainCode; tAST_Node *mainCode;
char *name; char *name;
...@@ -194,6 +194,10 @@ tAST_Node *Parse_DoBlockLine(tParser *Parser) ...@@ -194,6 +194,10 @@ tAST_Node *Parse_DoBlockLine(tParser *Parser)
switch(LookAhead(Parser)) switch(LookAhead(Parser))
{ {
// Empty statement
case TOK_SEMICOLON:
GetToken(Parser);
return NULL;
// Return from a method // Return from a method
case TOK_RWD_RETURN: case TOK_RWD_RETURN:
...@@ -219,9 +223,31 @@ tAST_Node *Parse_DoBlockLine(tParser *Parser) ...@@ -219,9 +223,31 @@ tAST_Node *Parse_DoBlockLine(tParser *Parser)
} }
return ret; return ret;
case TOK_RWD_FOR: 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_DO:
case TOK_RWD_WHILE: case TOK_RWD_WHILE:
TODO(Parser, "Implement if, for, do and while\n"); TODO(Parser, "Implement do and while\n");
break; break;
// Define Variables // Define Variables
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment