Fix parser goof
This commit is contained in:
parent
c11e0792f4
commit
dc4d4aba24
|
@ -438,8 +438,7 @@ struct ASTNode* ParseStatement(void) {
|
||||||
VerifyToken(LI_RBRAC, "}");
|
VerifyToken(LI_RBRAC, "}");
|
||||||
return Node;
|
return Node;
|
||||||
case TY_IDENTIFIER:
|
case TY_IDENTIFIER:
|
||||||
DumpAllLists();
|
if (FindAlias(CurrentIdentifier) == NULL) {
|
||||||
if (FindAlias(CurrentIdentifier) != NULL) {
|
|
||||||
Node = ParsePrecedenceASTNode(0);
|
Node = ParsePrecedenceASTNode(0);
|
||||||
VerifyToken(LI_SEMIC, ";");
|
VerifyToken(LI_SEMIC, ";");
|
||||||
return Node;
|
return Node;
|
||||||
|
@ -451,7 +450,7 @@ struct ASTNode* ParseStatement(void) {
|
||||||
case KW_UNION:
|
case KW_UNION:
|
||||||
case KW_ENUM:
|
case KW_ENUM:
|
||||||
case KW_ALIAS:
|
case KW_ALIAS:
|
||||||
printf("\t\tNew Variable: %s\n", CurrentIdentifier);
|
printf("\t\tTrying new Variable: %s\n", CurrentIdentifier);
|
||||||
ParseDeclarationList(&Composite, SC_LOCAL, LI_SEMIC, LI_EOF, &Node);
|
ParseDeclarationList(&Composite, SC_LOCAL, LI_SEMIC, LI_EOF, &Node);
|
||||||
VerifyToken(LI_SEMIC, ";");
|
VerifyToken(LI_SEMIC, ";");
|
||||||
Safe();
|
Safe();
|
||||||
|
|
|
@ -88,6 +88,26 @@ int ParseLiteral(int Type) {
|
||||||
return CurrentFile->CurrentSymbol.value;
|
return CurrentFile->CurrentSymbol.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the type that a typedef declaration aliases.
|
||||||
|
* @param name the name of the typedef
|
||||||
|
* @param CompositeType out: the type if composite
|
||||||
|
* @return the type if scalar
|
||||||
|
*/
|
||||||
|
static int GetTypedef(char* name, struct SymbolTableEntry** CompositeType) {
|
||||||
|
struct SymbolTableEntry* type;
|
||||||
|
type = FindAlias(name);
|
||||||
|
|
||||||
|
if (type == NULL)
|
||||||
|
ErrorReport("Unknown alias type: %s\n", name);
|
||||||
|
Tokenise();
|
||||||
|
Safe();
|
||||||
|
|
||||||
|
*CompositeType = type->CompositeType;
|
||||||
|
return type->Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Resolve a typename to a type struct.
|
* Resolve a typename to a type struct.
|
||||||
* Short circuit on the case where a definition is present, as definitions are typeless.
|
* Short circuit on the case where a definition is present, as definitions are typeless.
|
||||||
|
@ -123,7 +143,6 @@ static int ParseType(struct SymbolTableEntry** CompositeType, int* Scope) {
|
||||||
Type = RET_LONG;
|
Type = RET_LONG;
|
||||||
Tokenise();
|
Tokenise();
|
||||||
break;
|
break;
|
||||||
case TY_IDENTIFIER:
|
|
||||||
case KW_ALIAS:
|
case KW_ALIAS:
|
||||||
Type = ParseAliasDeclaration(CompositeType);
|
Type = ParseAliasDeclaration(CompositeType);
|
||||||
if (CurrentFile->CurrentSymbol.type == LI_SEMIC)
|
if (CurrentFile->CurrentSymbol.type == LI_SEMIC)
|
||||||
|
@ -147,6 +166,9 @@ static int ParseType(struct SymbolTableEntry** CompositeType, int* Scope) {
|
||||||
if (CurrentFile->CurrentSymbol.type == LI_SEMIC)
|
if (CurrentFile->CurrentSymbol.type == LI_SEMIC)
|
||||||
Type = -1;
|
Type = -1;
|
||||||
break;
|
break;
|
||||||
|
case TY_IDENTIFIER:
|
||||||
|
Type = GetTypedef(CurrentIdentifier, CompositeType);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
ErrorReport("Illegal type on token %s\n", TokenNames[CurrentFile->CurrentSymbol.type]);
|
ErrorReport("Illegal type on token %s\n", TokenNames[CurrentFile->CurrentSymbol.type]);
|
||||||
}
|
}
|
||||||
|
@ -297,7 +319,7 @@ static struct SymbolTableEntry* ParseScalarDeclaration(char* name, int Type, str
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handles reading in a comma-separated list of declarations.
|
* Handles reading in a comma-or-semicolon separated list of declarations.
|
||||||
* Erythro treats structs, enums and function parameters the same in this regard -
|
* Erythro treats structs, enums and function parameters the same in this regard -
|
||||||
* comma separated.
|
* comma separated.
|
||||||
*
|
*
|
||||||
|
@ -525,25 +547,6 @@ static int ParseAliasDeclaration(struct SymbolTableEntry** CompositeType) {
|
||||||
return Type;
|
return Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the type that a typedef declaration aliases.
|
|
||||||
* @param name the name of the typedef
|
|
||||||
* @param CompositeType out: the type if composite
|
|
||||||
* @return the type if scalar
|
|
||||||
*/
|
|
||||||
static int GetTypedef(char* name, struct SymbolTableEntry** CompositeType) {
|
|
||||||
struct SymbolTableEntry* type;
|
|
||||||
type = FindAlias(name);
|
|
||||||
|
|
||||||
if (type == NULL)
|
|
||||||
ErrorReport("Unknown alias type");
|
|
||||||
Tokenise();
|
|
||||||
Safe();
|
|
||||||
|
|
||||||
*CompositeType = type->CompositeType;
|
|
||||||
return type->Type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse an array initialization.
|
* Parse an array initialization.
|
||||||
* Everything after the =, for example.
|
* Everything after the =, for example.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user