static AST* statement(Parser* p);
static AST* expression(Parser* p);
static AST* definition(Parser* p, bool constant);
+static AST* func_expr_list(Parser* p);
static AST* const_expression(Parser* p);
static AST* identifier(Parser* p);
if (matches(p, '{')) {
expression_block(p);
} else {
- if (accept(p, T_RETURN)) {
+ if (matches(p, T_LET) || matches(p, T_VAR)) {
+ definition(p, (peek(p)->type == T_LET));
+ } else if (accept(p, T_RETURN)) {
expression(p);
expect(p, ';');
- } else if (matches(p, T_LET) || matches(p, T_VAR)) {
- definition(p, (peek(p)->type == T_LET));
+// } else if (matches(p, T_IF)) {
+// } else if (matches(p, T_WHILE)) {
+// } else if (matches(p, T_FOR)) {
+// } else if (matches(p, T_DO)) {
+// } else if (matches(p, T_SWITCH)) {
+// } else if (matches(p, T_MATCH)) {
} else {
expression(p);
expect(p, ';');
expect(p, ')');
} else if (matches(p, T_ID)) {
expr = identifier(p);
+ if (matches(p, '('))
+ func_expr_list(p);
} else {
expr = literal(p);
}
expect(p, T_ID);
type_expression(p);
expect(p, '=');
- const_expression(p);
+ expression(p);
expect(p, ';');
return NULL;
}
-
+static AST* func_expr_list(Parser* p) {
+ expect(p, '(');
+ if (!matches(p, ')')) {
+ while (true) {
+ expression(p);
+ if (!matches(p, ')'))
+ expect(p, ',');
+ else
+ break;
+ }
+ }
+ expect(p, ')');
+ return NULL;
+}