aboutsummaryrefslogtreecommitdiff
path: root/compiler/parser.cup
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-02-05 22:34:44 -0500
committerMustafa Quraish <[email protected]>2022-02-05 22:34:44 -0500
commit7b0bfa91b400e89f32f19ef2987200562bbe3f8f (patch)
treed44f6cb1525ebbe6cc0c958191dd4ab1d76eb4f6 /compiler/parser.cup
parent[cup] Fix error in codegen for `if` (diff)
downloadcup-7b0bfa91b400e89f32f19ef2987200562bbe3f8f.tar.xz
cup-7b0bfa91b400e89f32f19ef2987200562bbe3f8f.zip
[cup] Add support for builtin functions, add `print()`
Diffstat (limited to 'compiler/parser.cup')
-rw-r--r--compiler/parser.cup8
1 files changed, 8 insertions, 0 deletions
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();