summaryrefslogtreecommitdiff
path: root/test/string_view_test.c
diff options
context:
space:
mode:
authorCarlos Maniero <carlos@maniero.me>2023-05-11 15:00:10 -0300
committerCarlos Maniero <carlos@maniero.me>2023-05-11 15:29:57 -0300
commitea7f65fe1250be8f49edcaaedd3410aed1401648 (patch)
treeffe7d6ec48bc6018b5eea7e9ef573cd1bbd57c2f /test/string_view_test.c
parent5042a4ffc1363d6f0f99a3afd79f76cf2da738d6 (diff)
gas: implement recursion and late evaluation
Until now the below code was not valid for pipac. fn main(): i32 { return fib(13); } fn fib(n: i32): i32 { if n <= 1 { return n; } return fib(n - 1) + fib(n - 2); } Pipa's parser was adding a function to scope after they were fully parsed which means that fib's self-reference would not work. Also, functions were required to follow the be called in the order they are declared for the same scope reason so, the main function was required to be defined after fib. And how it is working now? When a TOKEN_NAME is not found in the scope, instead of returning an error, an unknown token is created as placeholder. The parser stores the node reference and the token it was trying to parse. During type checks, if the parser detects an unknown node, instead of returning an error, it stores in that node what was the expected type. After the NS is fully parsed a reevaluation is made on those unknown nodes by setting the lexer back on the node's token position and parsing the TOKEN_NAME again. Ps: There is a typo on the unknown token. It will be addressed in another commit since this issue was not introduced by this change. Signed-off-by: Carlos Maniero <carlos@maniero.me>
Diffstat (limited to 'test/string_view_test.c')
0 files changed, 0 insertions, 0 deletions