More statement types

This commit is contained in:
2023-07-08 19:09:32 -05:00
parent 10e6aa7f11
commit 927600c7bc
3 changed files with 182 additions and 30 deletions
+2 -3
View File
@@ -36,8 +36,7 @@ val = { // These are what get evaluated and left on the stack:
address = { "&" ~ name } // The address for a name
arrayref = { name ~ subscript } // Subscripting is only literal IDs. Anything else can be pointer arithmetic
call = { name ~ arglist } // Call syntax is only literal IDs. Calling things dynamically is done with a builtin; CALL(foo[3], 1, 2, 3)
arg = { expr | string }
arglist = { "(" ~ (arg ~ ("," ~ arg)*)? ~ ")" }
arglist = { "(" ~ (rvalue ~ ("," ~ rvalue)*)? ~ ")" }
subscript = { "[" ~ expr ~ "]" }
statement = { ((return_stmt | assignment | call | var_decl) ~ ";") | conditional | while_loop | repeat_loop }
@@ -57,7 +56,7 @@ argname = { name ~ typename? }
declaration = { function | global | struct_decl | const_decl }
program = { (COMMENT | WHITESPACE)? ~ declaration* ~ EOI }
return_stmt = { "return" ~ expr }
return_stmt = { "return" ~ expr? }
conditional = { "if" ~ "(" ~ expr ~ ")" ~ block ~ ("else" ~ block)? }
while_loop = { "while" ~ "(" ~ expr ~ ")" ~ block }
repeat_loop = { "repeat" ~ "(" ~ expr ~ ")" ~ name ~ block }