From d75b4154d375e4012a15be461edfc424a0377214 Mon Sep 17 00:00:00 2001 From: pommicket Date: Fri, 4 Feb 2022 22:36:22 -0500 Subject: parse goto, case --- 05/constants.b | 11 ++++++-- 05/main.c | 5 +++- 05/parse.b | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 92 insertions(+), 12 deletions(-) (limited to '05') diff --git a/05/constants.b b/05/constants.b index 68481a1..ca3bda9 100644 --- a/05/constants.b +++ b/05/constants.b @@ -269,6 +269,7 @@ ; - STATEMENT_CONTINUE - data1,2,3,4 are unused ; - STATEMENT_BREAK - data1,2,3,4 are unused ; - STATEMENT_RETURN - data1 is a pointer to the expression, or 0 if there is none; data2,3,4 are unused +; - STATEMENT_CASE - data1 is the value; data2,3,4 are unused #define STATEMENT_EXPRESSION 1 #define STATEMENT_LOCAL_DECLARATION 2 #define STATEMENT_LABEL 3 @@ -282,7 +283,7 @@ #define STATEMENT_CONTINUE 0xb #define STATEMENT_BREAK 0xc #define STATEMENT_RETURN 0xd - +#define STATEMENT_CASE 0xe :keyword_table @@ -507,6 +508,7 @@ byte 0 byte 255 +; NB: some of these are only used for nice debug output :str_missing_closing_paren string Missing closing ). byte 0 @@ -747,10 +749,15 @@ :str_union string union byte 0 -; NB: some of these are only used for nice debug output :str_typedef string typedef byte 0 :str_return string return byte 0 +:str_goto + string goto + byte 0 +:str_case + string case + byte 0 diff --git a/05/main.c b/05/main.c index 3fed294..17e960f 100644 --- a/05/main.c +++ b/05/main.c @@ -1,6 +1,9 @@ int f(void) { - lbl1:break;;; + lbl1:break;;goto blah; + case -1-3: continue;a:break;return;return 6+3< ; <- token += 16 ; skip semicolon goto parse_statement_ret - + function print_statement argument statement print_statement_with_depth(statement, 0) @@ -427,11 +483,13 @@ function print_statement_with_depth dat4 = statement + 32 dat4 = *8dat4 - if c == STATEMENT_LABEL goto print_stmt_label if c == STATEMENT_BLOCK goto print_stmt_block if c == STATEMENT_CONTINUE goto print_stmt_continue if c == STATEMENT_BREAK goto print_stmt_break if c == STATEMENT_RETURN goto print_stmt_return + if c == STATEMENT_GOTO goto print_stmt_goto + if c == STATEMENT_LABEL goto print_stmt_label + if c == STATEMENT_CASE goto print_stmt_case die(.pristmtNI) :pristmtNI @@ -480,7 +538,19 @@ function print_statement_with_depth :print_block_loop_end putcln('}) return - + :print_stmt_goto + puts(.str_goto) + putc(32) + puts(dat1) + puts(.str_semicolon_newline) + return + :print_stmt_case + puts(.str_case) + putc(32) + putn_signed(dat1) + putcln(':) + return + ; parse a global variable's initializer ; e.g. int x[5] = {1+8, 2, 3, 4, 5}; ; advances *p_token to the token right after the initializer @@ -2367,8 +2437,8 @@ function type_alignof ; evaluate an expression which can be the size of an array, e.g. ; enum { A, B, C }; ; int x[A * sizeof(float) + 3 << 5]; -; @NONSTANDARD: doesn't handle floats, but really why would you use floats in an array size -; e.g. SomeType x[(int)3.3]; +; @NONSTANDARD: doesn't handle floats. this means you can't do +; e.g. double x[] = {1.5,2.3}; ; this is also used for #if evaluation ; token is used for error messages (e.g. if this "constant" expression is *x or something) ; NOTE: this returns the end of the expression, not the value (which is stored in *8p_value) -- cgit v1.2.3