// point - parse an x y pair into the sPoint* gboolean parser_help_point(sParser*parse, sPoint* point){ if(parser_token(parse) != TOK_NUMBER) return FALSE; point->x = parse->data.number; if(parser_token(parse) != TOK_NUMBER) return FALSE; point->y = parse->data.number; return TRUE; }
struct t_value * exec_stmt(struct t_exec *exec) { struct t_value *res; struct t_token *token; debug(1, "%s(): Calling parse_stmt()\n", __FUNCTION__); if (parse_stmt(&exec->parser) < 0) { res = NULL; } else { debug(1, "%s(): Calling exec_run()\n", __FUNCTION__); if (exec_run(exec) < 0) { res = NULL; } else { res = list_pop(&exec->stack); } } token = parser_token(&exec->parser); if (!res) { while (token->type != TT_EOL && token->type != TT_EOF) { token = parser_next(&exec->parser); } } while (token->type == TT_EOL) { token = parser_next(&exec->parser); } return res; }
sObject* object_parse(sParser* parse){ sObject* obj = object_new(); eTokType type; switch(type=parser_token(parse)){ case TOK_PIN: obj->Type = TYPE_PIN; break; case TOK_PAD: obj->Type = TYPE_PAD; break; case TOK_LINE: obj->Type = TYPE_LINE; break; case TOK_BRACE_CLOSE: case TOK_PAREN_CLOSE: printf("object_parse:CLOSED PAREN!\n"); return 0; default: printf("object_parse: unexpected token [%d] text [%s]\n",type,parse->ptr); object_delete(obj); exit(0); } TRY if(!parser_help_open(parse)) THROW; //open brace... if(!parser_help_point(parse,&obj->P1)) THROW; switch(obj->Type){ case TYPE_PIN: if(!obj_pin_parse(obj,parse)) THROW; break; case TYPE_PAD: if(!obj_pad_parse(obj,parse)) THROW; break; case TYPE_LINE: if(!obj_line_parse(obj,parse)) THROW; break; default:printf("pin_parse: unexpected text [%s]\n",parse->ptr); } if(!parser_help_close(parse)) THROW; //closed brace... CATCH object_delete(obj); return 0; ENDTRY return obj; }
// string - parse a string into the GString* gboolean parser_help_string(sParser* parse,GString** pstr){ if(parser_token(parse) != TOK_STRING) return FALSE; *pstr = parse->data.string; return TRUE; }
// number - parse numeric value into the int* gboolean parser_help_number(sParser* parse,int*pnum){ if(parser_token(parse) != TOK_NUMBER) return FALSE; *pnum = parse->data.number; return TRUE; }
// close - parse ) or ] and return TRUE gboolean parser_help_close(sParser* parse){ parser_token(parse); if((parse->type == TOK_BRACE_CLOSE)||(parse->type==TOK_PAREN_CLOSE)) return TRUE; return FALSE; }
// open - parse ( or [ and return TRUE. gboolean parser_help_open(sParser* parse){ parser_token(parse); if((parse->type == TOK_BRACE_OPEN)||(parse->type==TOK_PAREN_OPEN)) return TRUE; return FALSE; }