AST* toplevel(Parser* p) {
AST* ret = NULL;
if (!match(p, T_END_FILE)) {
- if (accept(p, T_DEF))
+ if (accept(p, T_LET))
ret = const_definition(p);
else
error(p, "only definitions are allowed at the toplevel");
vec_init(&exprs);
/* Build all expressions into let forms with no bodies */
do {
- if (accept(p, T_DEF)) {
+ if (accept(p, T_LET)) {
AST* def = definition(p);
Tok name = { .value.text = def_name(def) };
vec_push_back(&exprs, Let(Ident(&name), def_value(def), NULL));
break;
case AST_DEF:
- printf("(def %s ", def_name(tree));
+ printf("(let %s ", def_name(tree));
pprint_tree(file, def_value(tree), depth);
printf(")");
break;
typedef enum {
T_NONE, T_ID, T_CHAR, T_INT, T_FLOAT, T_BOOL, T_STRING, T_LBRACE, T_RBRACE,
T_LBRACK, T_RBRACK, T_LPAR, T_RPAR, T_COMMA, T_SQUOTE, T_DQUOTE, T_END,
- T_COLON, T_AMP, T_REQUIRE, T_DEF, T_IF, T_FN, T_THEN, T_ELSE, T_END_FILE
+ T_COLON, T_AMP, T_REQUIRE, T_LET, T_IF, T_FN, T_THEN, T_ELSE, T_END_FILE
} TokType;
typedef struct {
Tok tok;
} Parser;
-// Lexer routines
void gettoken(Parser* ctx, Tok* tok);
-
-// Parser routines
-Parser* parser_new(char* p_prompt, FILE* input);
-
-// Grammar Routines
AST* toplevel(Parser* p);
/* Option Parsing