From: Michael D. Lowis Date: Thu, 28 May 2015 02:29:09 +0000 (-0400) Subject: Reworked syntax to be more like Self X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=60294ed92a76b772c91938c42ca82fbd63b5d8d2;p=proto%2Fgir.git Reworked syntax to be more like Self --- diff --git a/Makefile b/Makefile index e481cda..4bef298 100644 --- 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) diff --git a/source/lexer.l b/source/lexer.l index c2b161c..5331c31 100644 --- a/source/lexer.l +++ b/source/lexer.l @@ -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); diff --git a/source/main.c b/source/main.c index 62fcc7a..3cb0448 100644 --- a/source/main.c +++ b/source/main.c @@ -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); } /*****************************************************************************/ diff --git a/source/parser.h b/source/parser.h index 292ea85..c89fc60 100644 --- a/source/parser.h +++ b/source/parser.h @@ -13,30 +13,36 @@ #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 */