global Intern_String intern_empty; function AST_Node * parse_enum(Parser *p){ AST_Node *result = 0; Token *name = token_match(p, TK_Identifier); if(token_match(p, TK_OpenBrace)){ Token *op_close_brace = token_match(p, TK_CloseBrace); if(!op_close_brace){ result = ast_enum(p, name, name->intern_val); do{ // Parse enum members Token *identifier = token_match(p, TK_Identifier); if(identifier){ Expr *expr = 0; if(token_match(p, TK_Assign)){ expr = parse_expr(p); } AST_Node *child = ast_enum_child(p, identifier, identifier->intern_val, expr); ast_node_push_child(result, child); { // Insert into scope } } else { parser_push_error(p, token_get(p), "invalid syntax of enum member"); break; } } while(token_match(p, TK_Comma)); token_expect(p, TK_CloseBrace); } else{ parser_push_error(p, op_close_brace, "enum without body"); } } else{ if(name == 0){ parser_push_error(p, token_get(p), "enum without name or body is illegal"); } } if(ast_is_named(result)){ // Insert into scope } return result; } function AST_Node_List * parse(Parser *p){ AST_Node_List *result = ast_node_new(p, AK_List, token_get(p), intern_empty); for(;;){ AST_Node *node = 0; if(token_is(p, TK_End)){ break; } else if(token_is(p, TK_Error)){ break; } else if(token_match_keyword(p, keyword_struct)){ } else if(token_match_keyword(p, keyword_union)){ } else if(token_match_keyword(p, keyword_enum)){ node = parse_enum(p); token_expect(p, TK_Semicolon); } else if(token_match_keyword(p, keyword_function)){ } else if(token_match_keyword(p, keyword_typedef)){ } else { token_next(p); } if(node){ ast_node_push_child(result, node); } } return result; }