From 2f9d1c3509a1e98dcaf489f0e83b75ed7735c505 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 22 May 2018 20:49:57 -0400 Subject: [PATCH] minor refactoring --- source/lexer.l | 2 +- source/parser.c | 4 ++-- source/pprint.c | 2 +- source/sclpl.h | 8 +------- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/source/lexer.l b/source/lexer.l index c69e6bf..4747bea 100644 --- a/source/lexer.l +++ b/source/lexer.l @@ -106,7 +106,7 @@ false { } "require" { return T_REQUIRE; } -"def" { return T_DEF; } +"let" { return T_LET; } "if" { return T_IF; } "fn" { return T_FN; } "then" { return T_THEN; } diff --git a/source/parser.c b/source/parser.c index 205a5f0..64705a9 100644 --- a/source/parser.c +++ b/source/parser.c @@ -64,7 +64,7 @@ static Tok* expect_val(Parser* parser, TokType type) { 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"); @@ -184,7 +184,7 @@ static AST* expr_block(Parser* p) { 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)); diff --git a/source/pprint.c b/source/pprint.c index f8bb651..7a273c6 100644 --- a/source/pprint.c +++ b/source/pprint.c @@ -130,7 +130,7 @@ void pprint_tree(FILE* file, AST* tree, int depth) 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; diff --git a/source/sclpl.h b/source/sclpl.h index b734428..cfb803c 100644 --- a/source/sclpl.h +++ b/source/sclpl.h @@ -42,7 +42,7 @@ void vec_set(vec_t* vec, size_t index, void* data); 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 { @@ -208,13 +208,7 @@ 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 -- 2.54.0