require ("fmt")
provide (main)
-let const_true bool = true
-let const_false bool = false
-let const_uint int = 123
-let const_string string = ""
-
-var var_true bool = true
-var var_false bool = false
-var var_uint int = 123
-var var_string string = ""
-
type type_int = int
type type_intary = int[]
type type_intaryary = int[][]
bar = float
}
+let const_true bool = true
+let const_false bool = false
+let const_uint int = 123
+let const_string string = ""
+let const_intary int[] = [123,321]
+
+var var_true bool = true
+var var_false bool = false
+var var_uint int = 123
+var var_string string = ""
+var var_intary int[] = [123,321]
+
fun main(args string[]) int {
let foo int = 123
var bar int = 123
static AST* expression_block(Parser* p);
static AST* if_expression(Parser* p);
static AST* identifier(Parser* p);
-static AST* func_expr_list(Parser* p);
+static AST* expr_list(Parser* p, int firstc, int endc);
/* Parsing Routines
*****************************************************************************/
expect(p, '(');
exp = expression(p);
expect(p, ')');
+ } else if (matches(p, '[')) {
+ exp = expr_list(p, '[', ']');
} else if (matches(p, '{')) {
exp = expression_block(p);
} else if (matches(p, T_IF)) {
/* determine if this is a function call */
if (matches(p, '(')) {
- exp = Apply(exp, func_expr_list(p));
+ exp = Apply(exp, expr_list(p, '(', ')'));
} else if (accept(p, '.')) {
AST* func = identifier(p);
- AST* args = func_expr_list(p);
+ AST* args = expr_list(p, '(', ')');
explist_prepend(args, exp);
exp = Apply(func, args);
}
}
}
-static AST* func_expr_list(Parser* p) {
- expect(p, '(');
+static AST* expr_list(Parser* p, int firstc, int endc) {
+ expect(p, firstc);
AST* list = ExpList();
- while (!matches(p, ')')) {
+ while (!matches(p, endc)) {
explist_append(list, expression(p));
- if (!matches(p, ')'))
+ if (!matches(p, endc)) {
expect(p, ',');
+ if (matches(p, endc))
+ error(p, "Expected an expression");
+ }
}
- expect(p, ')');
+ expect(p, endc);
return list;
}