Opertators
This commit is contained in:
+13
-13
@@ -37,15 +37,15 @@ block = { "{" ~ statement_list ~ "}" }
|
|||||||
statement_list = { statement* }
|
statement_list = { statement* }
|
||||||
|
|
||||||
statement = _{
|
statement = _{
|
||||||
expr_stmt
|
expr_stmt
|
||||||
| var_decl
|
| var_decl
|
||||||
| if_stmt
|
| if_stmt
|
||||||
| while_stmt
|
| while_stmt
|
||||||
| for_stmt
|
| for_stmt
|
||||||
| return_stmt
|
| return_stmt
|
||||||
| break_stmt
|
| break_stmt
|
||||||
| continue_stmt
|
| continue_stmt
|
||||||
| block
|
| block
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- basic statements ---
|
// --- basic statements ---
|
||||||
@@ -75,10 +75,7 @@ while_stmt = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for_stmt = {
|
for_stmt = {
|
||||||
"for" ~ "(" ~ (var_decl_no_semicolon | expr_stmt | ";")
|
"for" ~ "(" ~ (var_decl_no_semicolon | expr_stmt | ";") ~ expr? ~ ";" ~ expr? ~ ")" ~ statement
|
||||||
~ expr? ~ ";"
|
|
||||||
~ expr? ~ ")"
|
|
||||||
~ statement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper (same as var_decl but no trailing ;)
|
// helper (same as var_decl but no trailing ;)
|
||||||
@@ -100,6 +97,9 @@ primary = {
|
|||||||
postfix = {
|
postfix = {
|
||||||
("." ~ identifier)
|
("." ~ identifier)
|
||||||
| ("(" ~ (expr ~ ("," ~ expr)*)? ~ ")")
|
| ("(" ~ (expr ~ ("," ~ expr)*)? ~ ")")
|
||||||
|
| ("[" ~ expr ~ "]")
|
||||||
|
| ("++" | "--")
|
||||||
|
| (("+" | "-" | "*" | "/" | "%") ~ primary)
|
||||||
}
|
}
|
||||||
|
|
||||||
expr = {
|
expr = {
|
||||||
|
|||||||
+1
-10
@@ -1,12 +1,3 @@
|
|||||||
import "fmt";
|
|
||||||
|
|
||||||
struct Point {
|
|
||||||
x: int,
|
|
||||||
y: int
|
|
||||||
}
|
|
||||||
|
|
||||||
function add(a: int, b: int): int {
|
function add(a: int, b: int): int {
|
||||||
if (x) {
|
itm.a + itm.b();
|
||||||
if (y) return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user