]> git.mdlowis.com Git - proto/gir.git/commitdiff
Removed unneccessary tokens from the lexer
authorMike D. Lowis <mike.lowis@gentex.com>
Thu, 28 May 2015 20:53:32 +0000 (16:53 -0400)
committerMike D. Lowis <mike.lowis@gentex.com>
Thu, 28 May 2015 20:53:32 +0000 (16:53 -0400)
build.rb
source/lexer.l
source/main.c
source/parser.h

index 60714482601974979dccc26431c38c789ce66f90..372ed05ad2642b99581e80d831e701267e11194f 100755 (executable)
--- a/build.rb
+++ b/build.rb
@@ -19,15 +19,12 @@ runtime_libs = ['build/lib/libcds.a']
 
 # Build the parser
 main_env.CFile('source/lex.yy.c', 'source/lexer.l')
-main_env.Program('parser', FileList['source/*.c'] + ['source/lex.yy.c'] + runtime_libs)
+parser_srcs = (FileList['source/*.c'] + ['source/lex.yy.c']).uniq
+main_env.Program('parser',  parser_srcs + runtime_libs)
 
 #------------------------------------------------------------------------------
 # Test Build Targets
 #------------------------------------------------------------------------------
 if Opts[:profile].include? "test"
-#  compiler_libs = ['build/lib/libparse-test.a'] + runtime_libs
-#  test_env.Library('build/lib/libparse-test.a', FileList['source/libparse/*.c'])
-#  test_env.Program('build/bin/sclpl-test', FileList['source/sclpl/*.c'] + compiler_libs)
-#  test_env.Command('RSpec', [], 'CMD' => [
-#      'rspec', '--pattern', 'spec/**{,/*/**}/*_spec.rb', '--format', 'documentation'])
+  # Do nothing for now
 end
index 5331c31321c1b6fead22449304a485298fe9bdcb..3d13e1b6d9407c6ba5109e7532f74f0e456b65d3 100644 (file)
@@ -21,8 +21,7 @@ int yywrap(void){ return 1; }
 "="                         TOKEN(ASSIGN);
 "<-"                        TOKEN(ASSIGN);
 
-"."                         TOKEN(END);
-","                         TOKEN(COMMA);
+"."                         TOKEN(PERIOD);
 ":"                         TOKEN(COLON);
 "|"                         TOKEN(PIPE);
 "("                         TOKEN(LPAR);
@@ -34,11 +33,10 @@ int yywrap(void){ return 1; }
 "{"                         TOKEN(LBRACE);
 "}"                         TOKEN(RBRACE);
 
-"self"                      TOKEN(SELF);
-"true"|"false"              TOKEN(BOOL);
 [0-9]+                      TOKEN(NUM);
 '[^\\]'                     TOKEN(CHAR);
 \"[^"]*\"                   TOKEN(STRING);
+$[_a-zA-Z][_a-zA-Z0-9]*     TOKEN(SYMBOL);
 
 [+-]+                       TOKEN(BINOP);
 [_a-zA-Z][_a-zA-Z0-9]*      TOKEN(ID);
index 1aab45e283087db8387e126eabc962aeee875602..51ceab855e869836bb4569a901e6eadcb9d319e1 100644 (file)
@@ -119,7 +119,7 @@ static void hashset(void);
 
 static void expression(void) {
     keyword_send();
-    optional(END);
+    optional(PERIOD);
 }
 
 static void keyword_send(void) {
@@ -167,9 +167,8 @@ static void literal(void) {
     switch (Current) {
         case ID:      shift_reduce(ID, 0u);     push_reduce(UNARY_MSG, 1); break;
         case NUM:     shift_reduce(NUM, 0u);    break;
-        case SELF:    shift_reduce(SELF, 0u);   break;
         case STRING:  shift_reduce(STRING, 0u); break;
-        case BOOL:    shift_reduce(BOOL, 0u);   break;
+        case SYMBOL:  shift_reduce(SYMBOL, 0u); break;
         case CHAR:    shift_reduce(CHAR, 0u);   break;
         case LBRACK:  array();                  break;
         case LBRACE:  object();                 break;
@@ -182,12 +181,9 @@ static void literal(void) {
 static void array(void) {
     int count = 0;
     expect(LBRACK);
-    if (!accept(RBRACK)) {
-        do {
-            optional(COMMA);
-            expression();
-            count++;
-        } while(accept(COMMA));
+    while (!accept(RBRACK)) {
+        expression();
+        count++;
     }
     expect(RBRACK);
     push_reduce(ARRAY, count);
@@ -196,15 +192,12 @@ static void array(void) {
 static void hashmap(void) {
     int count = 0;
     expect(ALBRACE);
-    if (!accept(RBRACE)) {
-        do {
-            optional(COMMA);
-            shift_reduce(STRING, 0);
-            expect(COLON);
-            expression();
-            push_reduce(PAIR, 2);
-            count++;
-        } while(accept(COMMA));
+    while (!accept(RBRACE)) {
+        shift_reduce(STRING, 0);
+        expect(COLON);
+        expression();
+        push_reduce(PAIR, 2);
+        count++;
     }
     expect(RBRACE);
     push_reduce(HASHMAP, count);
@@ -214,12 +207,9 @@ static void hashset(void)
 {
     int count = 0;
     expect(ALBRACK);
-    if (!accept(RBRACK)) {
-        do {
-            optional(COMMA);
-            expression();
-            count++;
-        } while(accept(COMMA));
+    while (!accept(RBRACK)) {
+        expression();
+        count++;
     }
     expect(RBRACK);
     push_reduce(HASHSET, count);
index c89fc6063212d694220ce68b8a0197cec7509340..2acadd696ac1fdd6e8596523342ee04e163ade9c 100644 (file)
@@ -8,10 +8,9 @@
 #define UNKNOWN 0
 
 #define NUM     1
-#define SELF    2
-#define STRING  3
-#define BOOL    4
-#define CHAR    5
+#define STRING  2
+#define CHAR    3
+#define SYMBOL  4
 
 #define LPAR    10
 #define RPAR    11
 #define LBRACE  16
 #define RBRACE  17
 
-#define COMMA   20
-#define COLON   21
-#define END     22
-#define BINOP   23
-#define PIPE    24
+#define COLON   20
+#define PERIOD  21
+#define BINOP   22
+#define PIPE    23
 
 #define RETURN  30
 #define ASSIGN  31