[ \t\r\n] { /* whitespace is insignificant */ }
#.*[\r\n] { /* skip line comments */ }
-"package" { return T_PACKAGE; }
-"requires" { return T_REQUIRES; }
-"provides" { return T_PROVIDES; }
+"require" { return T_REQUIRES; }
+"provide" { return T_PROVIDES; }
"let" { return T_LET; }
"var" { return T_VAR; }
"fun" { return T_FUN; }
static AST* expression(Parser* p);
static AST* identifier(Parser* p);
static AST* function(Parser* p);
-static Type* type_annotation(Parser* p);
static AST* literal(Parser* p);
static AST* expr_block(Parser* p);
static AST* if_stmnt(Parser* p);
return tok;
}
-
/* Grammar Definition
*****************************************************************************/
AST* toplevel(Parser* p) {
- expect(p, T_PACKAGE);
- expect(p, T_ID);
- if (accept(p, T_REQUIRES)) {
+ if (matches(p, T_REQUIRES)) {
require_list(p);
}
- if (accept(p, T_PROVIDES)) {
+ if (matches(p, T_PROVIDES)) {
provide_list(p);
}
definition_list(p);
}
static void require_list(Parser* p) {
+ accept(p, T_REQUIRES);
expect(p, T_LPAR);
while (!matches(p, T_RPAR)) {
expect(p, T_STRING);
}
static void provide_list(Parser* p) {
+ accept(p, T_PROVIDES);
expect(p, T_LPAR);
while (!matches(p, T_RPAR)) {
expect(p, T_ID);
static AST* const_definition(Parser* p, bool constant) {
if (!accept(p, T_LET) && !accept(p, T_VAR))
error(p, "constant or variable definition expected");
- Tok* id = expect_val(p, T_ID);
- Type* type = type_annotation(p);
+ expect(p, T_ID);
+ type_expression(p);
expect(p, T_ASSIGN);
- AST* expr = const_expression(p);
+ const_expression(p);
expect(p, T_SEMI);
return NULL;
}
-
-
static Type* get_typedef(Parser* p, char* typename) {
Sym* sym = sym_get(&(p->syms), typename);
if (!sym) error(p, "unknown type '%s'", typename);
return sym->type;
}
-static Type* type_annotation(Parser* p) {
- Tok* id = expect_val(p, T_ID);
- return get_typedef(p, id->value.text);
-}
-
static AST* literal(Parser* p) {
AST* ret = NULL;
Tok* tok = peek(p);