Parsing exprs, enum_decls, Introduce intern table, symbol table
This commit is contained in:
60
parse_decl.c
Normal file
60
parse_decl.c
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
function Decl *
|
||||
parse_decl_enum(Parser *p){
|
||||
Token *token = token_get(p);
|
||||
Intern_String name = {};
|
||||
if(token_match(p, TK_Identifier)){
|
||||
name = token->intern_val;
|
||||
}
|
||||
|
||||
Decl *result = decl_enum(p, token, name);
|
||||
if(token_match(p, TK_OpenBrace)){
|
||||
for(;;){
|
||||
Token *token = token_get(p);
|
||||
if(token_match(p, TK_Identifier)){
|
||||
Expr *expr = 0;
|
||||
if(token_match(p, TK_Assign)){
|
||||
expr = parse_expr(p);
|
||||
}
|
||||
Decl_Enum_Child *child = decl_enum_child(p, token, expr);
|
||||
decl_enum_push(result, child);
|
||||
}
|
||||
else break;
|
||||
|
||||
if(!token_match(p, TK_Comma))
|
||||
break;
|
||||
}
|
||||
token_expect(p, TK_CloseBrace);
|
||||
}
|
||||
else {
|
||||
if(name.s.str == 0){
|
||||
parser_push_error(p, token, "Unnamed enum without body is illegal");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function Decl *
|
||||
parse_decl_global(Parser *p){
|
||||
Decl *result = 0;
|
||||
if(token_match_keyword(p, keyword_enum)){
|
||||
result = parse_decl_enum(p);
|
||||
}
|
||||
else if(token_match_keyword(p, keyword_typedef)){
|
||||
|
||||
}
|
||||
else if(token_match_keyword(p, keyword_union)){
|
||||
|
||||
}
|
||||
else if(token_match_keyword(p, keyword_struct)){
|
||||
|
||||
}
|
||||
else if(token_match_keyword(p, keyword_global)){
|
||||
|
||||
}
|
||||
else if(token_match_keyword(p, keyword_function)){
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user