From dfce9118b9cbfae1fb287f5e4488b971407522cd Mon Sep 17 00:00:00 2001 From: pommicket Date: Fri, 4 Feb 2022 19:31:45 -0500 Subject: parsing break, continue, return --- 05/constants.b | 15 ++++- 05/main.b | 11 ++++ 05/main.c | 3 +- 05/parse.b | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 05/tokenize.b | 6 -- 05/util.b | 1 + 6 files changed, 196 insertions(+), 13 deletions(-) diff --git a/05/constants.b b/05/constants.b index 6a0bba1..68481a1 100644 --- a/05/constants.b +++ b/05/constants.b @@ -30,6 +30,14 @@ ; highest ; NB: for equal precedence, operators are applied left-to-right except for assignment operators (precedence 2) + +; TOKENS +; tokens are 16 bytes and have the following format: +; uchar type +; uchar info +; ushort file +; uint line +; ulong data -- for int/float literals, the value; for string literals, the runtime address; for identifiers, the name of the identifier #define SYMBOL_COMMA 200 ; NOTE: operator_right_associative and others require SYMBOL_EQ to be the first assignment operator #define SYMBOL_EQ 201 @@ -79,6 +87,7 @@ #define SYMBOL_SEMICOLON 244 #define SYMBOL_DOT 245 + #define TOKEN_IDENTIFIER 1 #define TOKEN_CONSTANT_FLOAT 2 #define TOKEN_CONSTANT_INT 3 @@ -738,6 +747,10 @@ :str_union string union byte 0 -:str_typedef ; currently only used for nice debug output +; NB: some of these are only used for nice debug output +:str_typedef string typedef byte 0 +:str_return + string return + byte 0 diff --git a/05/main.b b/05/main.b index 381ad59..3f4fdf0 100644 --- a/05/main.b +++ b/05/main.b @@ -1,3 +1,10 @@ +; @TODO: if we have, +; 1 extern int blah; +; 2 ... +; n int blah; +; give `blah` an address on line 1, then ignore declaration on line n + + ; add 24 + 16 = 40 to the stack pointer to put argc, argv in the right place byte 0x48 byte 0x81 @@ -52,6 +59,8 @@ global function_statements global statement_datas global statement_datas_ends global parse_stmt_depth +global expressions +global expressions_end #include util.b #include idents.b @@ -198,6 +207,8 @@ function main *1file_list = 255 object_macros = malloc(4000000) function_macros = malloc(4000000) + expressions = malloc(16000000) + expressions_end = expressions types = malloc(16000000) types_init(types, &types_bytes_used) diff --git a/05/main.c b/05/main.c index c5d1b72..3fed294 100644 --- a/05/main.c +++ b/05/main.c @@ -1,5 +1,6 @@ int f(void) { -blah:blah:blah:; + lbl1:break;;; + continue;a:break;return;return 6+3<