Browse Source

Fill out minor grammar items

Forest Belton 6 months ago
parent
commit
1584e3ca6c
2 changed files with 25 additions and 8 deletions
  1. 12
    8
      grammar.peg
  2. 13
    0
      include/ast/type.h

+ 12
- 8
grammar.peg View File

@@ -2,6 +2,7 @@
2 2
 #include "ast/ast.h"
3 3
 #include "ast/expr.h"
4 4
 #include "ast/stmt.h"
5
+#include "ast/type.h"
5 6
 #include "list.h"
6 7
 #include "token.h"
7 8
 #include "util.h"
@@ -62,11 +63,11 @@ DeclarationSpecifier
62 63
     | FunctionSpecifier
63 64
 
64 65
 StorageClassSpecifier
65
-    = TYPEDEF
66
-    | EXTERN
67
-    | STATIC
68
-    | AUTO
69
-    | REGISTER
66
+    = TYPEDEF  { $$ = token_int(STORAGE_TYPEDEF); }
67
+    | EXTERN   { $$ = token_int(STORAGE_EXTERN); }
68
+    | STATIC   { $$ = token_int(STORAGE_STATIC); }
69
+    | AUTO     { $$ = token_int(STORAGE_AUTO); }
70
+    | REGISTER { $$ = token_int(STORAGE_REGISTER); }
70 71
 
71 72
 TypeSpecifier
72 73
     = VOID
@@ -219,11 +220,14 @@ CompoundStatement
219 220
     }
220 221
 
221 222
 BlockItemList
222
-    = h:BlockItem t:BlockItemList?
223
+    = h:BlockItem t:BlockItemList? {
224
+        list *l = list_cons(h, t);
225
+        $$ = token_list(l);
226
+    }
223 227
 
224 228
 BlockItem
225
-    = Declaration
226
-    | Statement
229
+    = decl:Declaration { $$ = token_list(list_single(decl)); }
230
+    | stmt:Statement   { $$ = token_list(list_single(stmt)); }
227 231
 
228 232
 ExpressionStatement
229 233
     = e:Expression? SEMI {

+ 13
- 0
include/ast/type.h View File

@@ -0,0 +1,13 @@
1
+#ifndef CCC_AST_TYPE_H_
2
+#define CCC_AST_TYPE_H_
3
+
4
+typedef enum {
5
+    STORAGE_AUTO,
6
+    STORAGE_EXTERN,
7
+    STORAGE_REGISTER,
8
+    STORAGE_STATIC,
9
+    STORAGE_TYPEDEF
10
+} storage_type;
11
+
12
+#endif
13
+

Loading…
Cancel
Save