Opertators

This commit is contained in:
2026-04-14 04:47:53 +02:00
parent 3223a8c854
commit 5a52582977
2 changed files with 14 additions and 23 deletions
+13 -13
View File
@@ -37,15 +37,15 @@ block = { "{" ~ statement_list ~ "}" }
statement_list = { statement* }
statement = _{
expr_stmt
| var_decl
| if_stmt
| while_stmt
| for_stmt
| return_stmt
| break_stmt
| continue_stmt
| block
expr_stmt
| var_decl
| if_stmt
| while_stmt
| for_stmt
| return_stmt
| break_stmt
| continue_stmt
| block
}
// --- basic statements ---
@@ -75,10 +75,7 @@ while_stmt = {
}
for_stmt = {
"for" ~ "(" ~ (var_decl_no_semicolon | expr_stmt | ";")
~ expr? ~ ";"
~ expr? ~ ")"
~ statement
"for" ~ "(" ~ (var_decl_no_semicolon | expr_stmt | ";") ~ expr? ~ ";" ~ expr? ~ ")" ~ statement
}
// helper (same as var_decl but no trailing ;)
@@ -100,6 +97,9 @@ primary = {
postfix = {
("." ~ identifier)
| ("(" ~ (expr ~ ("," ~ expr)*)? ~ ")")
| ("[" ~ expr ~ "]")
| ("++" | "--")
| (("+" | "-" | "*" | "/" | "%") ~ primary)
}
expr = {
+1 -10
View File
@@ -1,12 +1,3 @@
import "fmt";
struct Point {
x: int,
y: int
}
function add(a: int, b: int): int {
if (x) {
if (y) return 1;
}
itm.a + itm.b();
}