static void declarePredefines(void) { TreeNode *input; TreeNode *output; TreeNode *temp; /* define "int input(void)" */ input = newDecNode(FuncDecK); input->name = copyString("input"); input->functionReturnType = Integer; input->expressionType = Function; /* define "void output(int)" */ temp = newDecNode(ScalarDecK); temp->name = copyString("arg"); temp->variableDataType = Integer; temp->expressionType = Integer; output = newDecNode(FuncDecK); output->name = copyString("output"); output->functionReturnType = Void; output->expressionType = Function; output->child[0] = temp; /* get input() and output() added to global scope */ insertSymbol("input", input, 0); insertSymbol("output", output, 0); }
static dec_node *declaration(void){ dec_node *decn = newDecNode(); if((decn->typeKey = match(TOKEN_TYPEKEY, CONSUME)) != NULL){ if((decn->id = match(TOKEN_IDENTIFIER, CONSUME)) != NULL); if((decn->scol = match(TOKEN_SCOL, CONSUME)) != NULL) return decn; } else if((decn->scol = match(TOKEN_SCOL, CONSUME)) != NULL) return decn; freeDec(decn); return NULL; }