]> git.mdlowis.com Git - proto/gir.git/commitdiff
Reworked syntax to be more like Self
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 28 May 2015 02:29:09 +0000 (22:29 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 28 May 2015 02:29:09 +0000 (22:29 -0400)
Makefile
source/lexer.l
source/main.c
source/parser.h

index e481cdac35b137402ea6c10ec92459f626290c59..4bef298e0101da6c8db67ea56a16714e12803af0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,6 @@ LD = $(CC)
 MAKEDEPEND = $(CPP) -M $(CPPFLAGS) -o  $<
 CCDEPGEN = -MMD -MF $*.d
 CFLAGS = -Wall -Wextra -O3 --std=c99 --pedantic $(addprefix -I,$(INCLUDES))
-LDFLAGS = -static
 
 -include $(SOURCES:.c=.d)
 
index c2b161c58e036cb1bcb74493236d2c48832da7f8..5331c31321c1b6fead22449304a485298fe9bdcb 100644 (file)
@@ -18,14 +18,19 @@ int yywrap(void){ return 1; }
 [ \t]                       Column++;
 #.*[\r\n]+                  Row++; Column = 1;
 
+"="                         TOKEN(ASSIGN);
+"<-"                        TOKEN(ASSIGN);
+
 "."                         TOKEN(END);
 ","                         TOKEN(COMMA);
-"="                         TOKEN(ASSIGN);
 ":"                         TOKEN(COLON);
+"|"                         TOKEN(PIPE);
 "("                         TOKEN(LPAR);
 ")"                         TOKEN(RPAR);
+"@["                        TOKEN(ALBRACK);
 "["                         TOKEN(LBRACK);
 "]"                         TOKEN(RBRACK);
+"@{"                        TOKEN(ALBRACE);
 "{"                         TOKEN(LBRACE);
 "}"                         TOKEN(RBRACE);
 
index 62fcc7a90871b3abd15038bd3333eaade2cbfca2..3cb04485a7b5e9ffba4380a011b8a21ca233a377 100644 (file)
@@ -114,19 +114,12 @@ static void operand(void);
 static void messages(void);
 static void literal(void);
 static void array(void);
+static void object(void);
 static void hashmap(void);
+static void hashset(void);
 
 static void expression(void) {
-    if (accept(ID)) {
-        shift_reduce(ID, 0);
-        if (accept(ASSIGN)) {
-            expect(ASSIGN);
-            expression();
-            push_reduce(ASSIGN, 2);
-        }
-    } else {
-        keyword_send();
-    }
+    keyword_send();
     optional(END);
 }
 
@@ -173,15 +166,17 @@ static void operand(void) {
 
 static void literal(void) {
     switch (Current) {
-        case ID:     shift_reduce(ID, 0u);     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 CHAR:   shift_reduce(CHAR, 0u);   break;
-        case LBRACK: array();                  break;
-        case LBRACE: hashmap();                break;
-        default:     error("Invalid literal");
+        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 CHAR:    shift_reduce(CHAR, 0u);   break;
+        case LBRACK:  array();                  break;
+        case LBRACE:  object();                 break;
+        case ALBRACE: hashmap();                break;
+        case ALBRACK: hashset();                break;
+        default:      error("Invalid literal");
     }
 }
 
@@ -201,7 +196,7 @@ static void array(void) {
 
 static void hashmap(void) {
     int count = 0;
-    expect(LBRACE);
+    expect(ALBRACE);
     if (!accept(RBRACE)) {
         do {
             optional(COMMA);
@@ -213,7 +208,36 @@ static void hashmap(void) {
         } while(accept(COMMA));
     }
     expect(RBRACE);
-    push_reduce(MAP, count);
+    push_reduce(HASHMAP, count);
+}
+
+static void hashset(void)
+{
+    int count = 0;
+    expect(ALBRACK);
+    if (!accept(RBRACK)) {
+        do {
+            optional(COMMA);
+            expression();
+            count++;
+        } while(accept(COMMA));
+    }
+    expect(RBRACK);
+    push_reduce(HASHSET, count);
+}
+
+static void object(void)
+{
+    expect(LBRACE);
+    if (accept(PIPE)) {
+        expect(PIPE);
+        expect(PIPE);
+    }
+    while (!accept(RBRACE)) {
+        expression();
+    }
+    expect(RBRACE);
+    push_reduce(OBJECT, 0);
 }
 
 /*****************************************************************************/
index 292ea858ef139a2f508a5ea661fce631dbbb2eb3..c89fc6063212d694220ce68b8a0197cec7509340 100644 (file)
 #define BOOL    4
 #define CHAR    5
 
-#define LPAR    6
-#define RPAR    7
-#define LBRACK  8
-#define RBRACK  9
-#define LBRACE  10
-#define RBRACE  11
-
-#define COMMA   12
-#define COLON   13
-#define END     14
-#define BINOP   15
-
-#define RETURN  16
-#define ASSIGN  17
-#define ID      18
-#define KEYW    19
+#define LPAR    10
+#define RPAR    11
+#define ALBRACK 12
+#define LBRACK  13
+#define RBRACK  14
+#define ALBRACE 15
+#define LBRACE  16
+#define RBRACE  17
+
+#define COMMA   20
+#define COLON   21
+#define END     22
+#define BINOP   23
+#define PIPE    24
+
+#define RETURN  30
+#define ASSIGN  31
+#define ID      32
+#define KEYW    33
 
 #define ARRAY        100
-#define MAP          101
-#define PAIR         102
-#define UNARY_MSG    103
-#define BINARY_MSG   104
-#define KEYWORD_MSG  105
-#define KEYWORD_PAIR 106
+#define OBJECT       101
+#define HASHMAP      102
+#define HASHSET      103
+
+#define PAIR         104
+#define UNARY_MSG    105
+#define BINARY_MSG   106
+#define KEYWORD_MSG  107
+#define KEYWORD_PAIR 108
 
 #endif /* PARSER_H */