]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
Rename tokens to have T_ prefix
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 24 Sep 2014 20:44:50 +0000 (16:44 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 24 Sep 2014 20:44:50 +0000 (16:44 -0400)
Rakefile
source/sclpl/lexer.c
source/sclpl/lexer.h
source/sclpl/main.c

index f5a3320bf0ef422bf0adf5518ea9d6312832dfc5..1ae79721539f46539b4395bca74ceb79a681315a 100644 (file)
--- a/Rakefile
+++ b/Rakefile
@@ -8,10 +8,11 @@ end
 # Envrionment Definitions
 #------------------------------------------------------------------------------
 # Define the compiler environment
-BaseEnv = BuildEnv.new(echo: :command) do |env|
+base_env = BuildEnv.new(echo: :command) do |env|
   env.build_dir('source','build/obj/source')
   env.set_toolset(:clang)
   env["CFLAGS"] += ['--std=c99', '-Wall', '-Wextra']#, '-Werror']
+  env["CPPPATH"] << 'modules/libopts/source'
 end
 
 #------------------------------------------------------------------------------
@@ -53,7 +54,8 @@ task :build => [:clang, :sclpl]
 
 desc "Build the sclpl compiler and interpreter"
 task :sclpl => ['source/sclpl/grammar.c'] do
-  BaseEnv.Program('build/bin/sclpl', FileList['source/sclpl/*.c'])
+  base_env.Program('build/bin/sclpl',
+    FileList['source/sclpl/*.c', 'modules/libopts/source/*.c'])
 end
 
 file 'source/sclpl/grammar.c' => ['source/sclpl/grammar.y'] do
index ca1b064d23dc5f909cc4e0cfd92830205cacb3bf..0b96c6fbfc1720ba5e37b5f9418c9500125da0b8 100644 (file)
@@ -93,14 +93,14 @@ lex_tok_t* lexer_punc(mpc_ast_t* p_tok_ast)
 {
     lex_tok_t* p_tok = NULL;
     switch (p_tok_ast->contents[0]) {
-        case '(': p_tok = lex_tok_new(LPAR,   NULL); break;
-        case ')': p_tok = lex_tok_new(RPAR,   NULL); break;
-        case '{': p_tok = lex_tok_new(LBRACE, NULL); break;
-        case '}': p_tok = lex_tok_new(RBRACE, NULL); break;
-        case '[': p_tok = lex_tok_new(LBRACK, NULL); break;
-        case ']': p_tok = lex_tok_new(RBRACK, NULL); break;
-        case ';': p_tok = lex_tok_new(END,    NULL); break;
-        case ',': p_tok = lex_tok_new(COMMA,  NULL); break;
+        case '(': p_tok = lex_tok_new(T_LPAR,   NULL); break;
+        case ')': p_tok = lex_tok_new(T_RPAR,   NULL); break;
+        case '{': p_tok = lex_tok_new(T_LBRACE, NULL); break;
+        case '}': p_tok = lex_tok_new(T_RBRACE, NULL); break;
+        case '[': p_tok = lex_tok_new(T_LBRACK, NULL); break;
+        case ']': p_tok = lex_tok_new(T_RBRACK, NULL); break;
+        case ';': p_tok = lex_tok_new(T_END,    NULL); break;
+        case ',': p_tok = lex_tok_new(T_COMMA,  NULL); break;
     }
     return p_tok;
 }
@@ -116,7 +116,7 @@ lex_tok_t* lexer_integer(mpc_ast_t* p_tok_ast, int base)
     errno = 0;
     *p_int = strtol(p_tok_ast->contents, NULL, base);
     assert(errno == 0);
-    return lex_tok_new(INT, p_int);
+    return lex_tok_new(T_INT, p_int);
 }
 
 lex_tok_t* lexer_float(mpc_ast_t* p_tok_ast)
@@ -125,7 +125,7 @@ lex_tok_t* lexer_float(mpc_ast_t* p_tok_ast)
     errno = 0;
     *p_dbl = strtod(p_tok_ast->contents, NULL);
     assert(errno == 0);
-    return lex_tok_new(FLOAT, p_dbl);
+    return lex_tok_new(T_FLOAT, p_dbl);
 }
 
 lex_tok_t* lexer_char(mpc_ast_t* p_tok_ast)
@@ -139,11 +139,11 @@ lex_tok_t* lexer_char(mpc_ast_t* p_tok_ast)
         "\v\0vtab"
     };
     if (strlen(p_tok_ast->contents) == 1) {
-        p_tok = lex_tok_new(CHAR, (void*)(p_tok_ast->contents[0]));
+        p_tok = lex_tok_new(T_CHAR, (void*)(p_tok_ast->contents[0]));
     } else {
         for(int i = 0; i < 5; i++) {
             if (strcmp(p_tok_ast->contents, &(lookup_table[i][2]))) {
-                p_tok = lex_tok_new(CHAR, (void*)(lookup_table[i][0]));
+                p_tok = lex_tok_new(T_CHAR, (void*)(lookup_table[i][0]));
                 break;
             }
         }
@@ -153,13 +153,13 @@ lex_tok_t* lexer_char(mpc_ast_t* p_tok_ast)
 
 lex_tok_t* lexer_bool(mpc_ast_t* p_tok_ast)
 {
-    return lex_tok_new(BOOL, (void*)((0==strcmp(p_tok_ast->contents,"True")) ? true : false));
+    return lex_tok_new(T_BOOL, (void*)((0==strcmp(p_tok_ast->contents,"True")) ? true : false));
 }
 
 lex_tok_t* lexer_var(mpc_ast_t* p_tok_ast)
 {
     char* p_str = lexer_dup(p_tok_ast->contents);
-    return lex_tok_new(VAR, p_str);
+    return lex_tok_new(T_VAR, p_str);
 }
 
 lex_tok_t* lex_tok_new(lex_tok_type_t type, void* val) {
index 40131428b794b3f22a1941cb295a36045f14c501..7727919249d5b9ff26bd65f1bbb424b00de5005d 100644 (file)
@@ -19,8 +19,8 @@ typedef struct {
 } lexer_t;
 
 typedef enum {
-    END, STRING, CHAR, INT, FLOAT, BOOL, LBRACE, RBRACE, LBRACK, RBRACK, LPAR,
-    RPAR, COMMA, VAR, END_FILE
+    T_END, T_STRING, T_CHAR, T_INT, T_FLOAT, T_BOOL, T_LBRACE, T_RBRACE,
+    T_LBRACK, T_RBRACK, T_LPAR, T_RPAR, T_COMMA, T_VAR, T_END_FILE
 } lex_tok_type_t;
 
 typedef struct {
index 43c1a11a8ef1d72addabe2c8fd0e21fc943201c1..7c42ce8fba80e414d4e4cd9c3ef9f898730c092b 100644 (file)
@@ -1,6 +1,7 @@
 #include "mpc.h"
 #include "scanner.h"
 #include "lexer.h"
+#include "opts.h"
 #include <stdio.h>
 
 /*****************************************************************************/
@@ -9,7 +10,7 @@ typedef struct {
     lex_tok_t* p_tok;
 } parser_t;
 
-lex_tok_t tok_eof = { END_FILE, NULL, 0, 0, NULL };
+lex_tok_t tok_eof = { T_END_FILE, NULL, 0, 0, NULL };
 
 parser_t* parser_new(char* p_prompt, FILE* input)
 {
@@ -34,7 +35,7 @@ lex_tok_t* parser_peek(parser_t* p_parser)
 }
 
 bool parser_eof(parser_t* p_parser) {
-    return (parser_peek(p_parser)->type == END_FILE);
+    return (parser_peek(p_parser)->type == T_END_FILE);
 }
 
 void parser_error(parser_t* p_parser, const char* p_text)
@@ -98,9 +99,9 @@ void parser_fn_stmnt(parser_t* p_parser);
 
 void parser_toplevel(parser_t* p_parser)
 {
-    if (parser_accept_str(p_parser, VAR, "import"))
+    if (parser_accept_str(p_parser, T_VAR, "import"))
         parser_import(p_parser);
-    else if (parser_accept_str(p_parser, VAR, "def"))
+    else if (parser_accept_str(p_parser, T_VAR, "def"))
         parser_definition(p_parser);
     else if (p_parser->p_lexer->scanner->p_input == stdin)
         parser_expression(p_parser);
@@ -110,33 +111,33 @@ void parser_toplevel(parser_t* p_parser)
 
 void parser_import(parser_t* p_parser)
 {
-    parser_expect(p_parser, VAR);
-    parser_expect(p_parser, END);
+    parser_expect(p_parser, T_VAR);
+    parser_expect(p_parser, T_END);
 }
 
 void parser_definition(parser_t* p_parser)
 {
-    parser_expect(p_parser,VAR);
-    if (parser_peek(p_parser)->type == LPAR) {
+    parser_expect(p_parser,T_VAR);
+    if (parser_peek(p_parser)->type == T_LPAR) {
         parser_fn_stmnt(p_parser);
     } else {
         parser_expression(p_parser);
-        parser_expect(p_parser,END);
+        parser_expect(p_parser,T_END);
     }
 }
 
 void parser_expression(parser_t* p_parser)
 {
-    if (parser_accept(p_parser, LPAR)) {
+    if (parser_accept(p_parser, T_LPAR)) {
         parser_expression(p_parser);
-        parser_accept(p_parser, RPAR);
-    } else if (parser_accept_str(p_parser, VAR, "if")) {
+        parser_accept(p_parser, T_RPAR);
+    } else if (parser_accept_str(p_parser, T_VAR, "if")) {
         parser_if_stmnt(p_parser);
-    } else if (parser_accept_str(p_parser, VAR, "fn")) {
+    } else if (parser_accept_str(p_parser, T_VAR, "fn")) {
         parser_fn_stmnt(p_parser);
-    } else if (parser_peek(p_parser)->type == VAR) {
-        parser_expect(p_parser, VAR);
-        if (parser_peek(p_parser)->type == LPAR) {
+    } else if (parser_peek(p_parser)->type == T_VAR) {
+        parser_expect(p_parser, T_VAR);
+        if (parser_peek(p_parser)->type == T_LPAR) {
             parser_arglist(p_parser);
         }
     } else {
@@ -148,11 +149,11 @@ void parser_literal(parser_t* p_parser)
 {
     switch (parser_peek(p_parser)->type)
     {
-        case BOOL:
-        case CHAR:
-        case STRING:
-        case INT:
-        case FLOAT:
+        case T_BOOL:
+        case T_CHAR:
+        case T_STRING:
+        case T_INT:
+        case T_FLOAT:
             parser_accept(p_parser, parser_peek(p_parser)->type);
             break;
 
@@ -164,37 +165,37 @@ void parser_literal(parser_t* p_parser)
 
 void parser_arglist(parser_t* p_parser)
 {
-    parser_expect(p_parser, LPAR);
-    while(parser_peek(p_parser)->type != RPAR) {
+    parser_expect(p_parser, T_LPAR);
+    while(parser_peek(p_parser)->type != T_RPAR) {
         parser_expression(p_parser);
-        if(parser_peek(p_parser)->type != RPAR)
-            parser_expect(p_parser, COMMA);
+        if(parser_peek(p_parser)->type != T_RPAR)
+            parser_expect(p_parser, T_COMMA);
     }
-    parser_expect(p_parser, RPAR);
+    parser_expect(p_parser, T_RPAR);
 }
 
 void parser_if_stmnt(parser_t* p_parser)
 {
     parser_expression(p_parser);
     parser_expression(p_parser);
-    parser_expect_str(p_parser,VAR,"else");
+    parser_expect_str(p_parser,T_VAR,"else");
     parser_expression(p_parser);
-    parser_expect(p_parser,END);
+    parser_expect(p_parser,T_END);
 }
 
 void parser_fn_stmnt(parser_t* p_parser)
 {
-    parser_expect(p_parser, LPAR);
-    while(parser_peek(p_parser)->type != RPAR) {
-        parser_expect(p_parser, VAR);
-        if(parser_peek(p_parser)->type != RPAR)
-            parser_expect(p_parser, COMMA);
+    parser_expect(p_parser, T_LPAR);
+    while(parser_peek(p_parser)->type != T_RPAR) {
+        parser_expect(p_parser, T_VAR);
+        if(parser_peek(p_parser)->type != T_RPAR)
+            parser_expect(p_parser, T_COMMA);
     }
-    parser_expect(p_parser, RPAR);
-    while(parser_peek(p_parser)->type != END) {
+    parser_expect(p_parser, T_RPAR);
+    while(parser_peek(p_parser)->type != T_END) {
         parser_expression(p_parser);
     }
-    parser_expect(p_parser, END);
+    parser_expect(p_parser, T_END);
 }
 
 /* SCLPL Parser