From 7b0bfa91b400e89f32f19ef2987200562bbe3f8f Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Sat, 5 Feb 2022 22:34:44 -0500 Subject: [cup] Add support for builtin functions, add `print()` --- compiler/parser.cup | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'compiler/parser.cup') diff --git a/compiler/parser.cup b/compiler/parser.cup index 914c4e6..40df5a3 100644 --- a/compiler/parser.cup +++ b/compiler/parser.cup @@ -54,6 +54,7 @@ fn find_function_definition(token: Token*): Node* { fn identifier_exists(token: Token*): int { if (find_local_variable(token)) return true; if (find_function_definition(token)) return true; + if (find_builtin_function(token)) return true; return false; } @@ -160,6 +161,11 @@ fn parse_identifier(lexer: Lexer*): Node* { return parse_function_call_args(lexer, func); } + func = find_builtin_function(&token); + if (func != null) { + return parse_function_call_args(lexer, func); + } + die_loc2(&token.loc, "Unknown identifier in parse_identifier: ", token.value.as_string); } @@ -642,6 +648,8 @@ fn parse_function(lexer: Lexer*): Node* { } fn parse_program(lexer: Lexer*): Node* { + initialize_builtins(); + let node = node_new(AST_PROGRAM); node.d.block.children = vector_new(); -- cgit v1.2.3