/* parse a type - a complete declaration including identifier */ void TypeParse(struct ParseState *Parser, struct ValueType **Typ, char **Identifier, int *IsStatic) { struct ValueType *BasicType; TypeParseFront(Parser, &BasicType, IsStatic); TypeParseIdentPart(Parser, BasicType, Typ, Identifier); }
/* declare a variable or function */ int ParseDeclaration(struct ParseState *Parser, enum LexToken Token) { char *Identifier; struct ValueType *BasicType; struct ValueType *Typ; struct Value *NewVariable = NULL; int IsStatic = FALSE; int FirstVisit = FALSE; Picoc *pc = Parser->pc; TypeParseFront(Parser, &BasicType, &IsStatic); do { TypeParseIdentPart(Parser, BasicType, &Typ, &Identifier); if ((Token != TokenVoidType && Token != TokenStructType && Token != TokenUnionType && Token != TokenEnumType) && Identifier == pc->StrEmpty) ProgramFail(Parser, "identifier expected"); if (Identifier != pc->StrEmpty) { /* handle function definitions */ if (LexGetToken(Parser, NULL, FALSE) == TokenOpenBracket) { ParseFunctionDefinition(Parser, Typ, Identifier); return FALSE; } else { if (Typ == &pc->VoidType && Identifier != pc->StrEmpty) ProgramFail(Parser, "can't define a void variable"); if (Parser->Mode == RunModeRun || Parser->Mode == RunModeGoto) NewVariable = VariableDefineButIgnoreIdentical(Parser, Identifier, Typ, IsStatic, &FirstVisit); if (LexGetToken(Parser, NULL, FALSE) == TokenAssign) { /* we're assigning an initial value */ LexGetToken(Parser, NULL, TRUE); ParseDeclarationAssignment(Parser, NewVariable, !IsStatic || FirstVisit); } } } Token = LexGetToken(Parser, NULL, FALSE); if (Token == TokenComma) LexGetToken(Parser, NULL, TRUE); } while (Token == TokenComma); return TRUE; }