From 4e3656dfea811ebe912babd03dc3cb5cecaaf940 Mon Sep 17 00:00:00 2001 From: hatsusato Date: Sun, 11 Sep 2016 14:08:21 +0900 Subject: [PATCH 1/9] Add identifier action --- src/parser.y | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/parser.y b/src/parser.y index a655abc5..f5acee34 100644 --- a/src/parser.y +++ b/src/parser.y @@ -88,7 +88,9 @@ void set_yyin_string(const char *code); %% identifier -: IDENTIFIER +: IDENTIFIER { + $$ = cons(sexpr_make_ast(AST_IDENTIFIER), $[IDENTIFIER]); +} ; expression.opt From 5037925c120253190bdfcde378ac87f393e4828d Mon Sep 17 00:00:00 2001 From: hatsusato Date: Sun, 11 Sep 2016 14:15:36 +0900 Subject: [PATCH 2/9] Add integer-constant action --- src/ast.h | 3 ++- src/parser.y | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ast.h b/src/ast.h index 424a2620..a3d82c64 100644 --- a/src/ast.h +++ b/src/ast.h @@ -2,7 +2,8 @@ #define KMC_C90_COMPILER_AST_H enum AstTag { - AST_IDENTIFIER + AST_IDENTIFIER, + AST_INTEGER_CONSTANT }; #endif /* KMC_C90_COMPILER_AST_H */ diff --git a/src/parser.y b/src/parser.y index f5acee34..49152cf7 100644 --- a/src/parser.y +++ b/src/parser.y @@ -103,6 +103,11 @@ expression | INTEGER_CONSTANT ; +integer-constant +: INTEGER_CONSTANT { + $$ = cons(sexpr_make_ast(AST_INTEGER_CONSTANT), $[INTEGER_CONSTANT]); +} + fundamental-specifier : VOID | INT From eebd0aa5991053d80f9508358174c3c1b20fdffd Mon Sep 17 00:00:00 2001 From: hatsusato Date: Sun, 11 Sep 2016 14:18:38 +0900 Subject: [PATCH 3/9] Add expression action --- src/parser.y | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/parser.y b/src/parser.y index 49152cf7..d62f9c80 100644 --- a/src/parser.y +++ b/src/parser.y @@ -94,13 +94,21 @@ identifier ; expression.opt -: %empty -| expression +: %empty { + $$ = NULL; +} +| expression { + $$ = $[expression]; +} ; expression -: identifier -| INTEGER_CONSTANT +: identifier { + $$ = $[identifier]; +} +| integer-constant { + $$ = $[integer-constant]; +} ; integer-constant From df1262088be0d3c8da8ec0ada2b4f1481359799e Mon Sep 17 00:00:00 2001 From: hatsusato Date: Sun, 11 Sep 2016 14:23:55 +0900 Subject: [PATCH 4/9] Add fundamental-specifier action --- src/ast.h | 4 +++- src/parser.y | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ast.h b/src/ast.h index a3d82c64..d70f169d 100644 --- a/src/ast.h +++ b/src/ast.h @@ -3,7 +3,9 @@ enum AstTag { AST_IDENTIFIER, - AST_INTEGER_CONSTANT + AST_INTEGER_CONSTANT, + AST_TYPE_VOID, + AST_TYPE_INT }; #endif /* KMC_C90_COMPILER_AST_H */ diff --git a/src/parser.y b/src/parser.y index d62f9c80..b80c52b4 100644 --- a/src/parser.y +++ b/src/parser.y @@ -117,8 +117,12 @@ integer-constant } fundamental-specifier -: VOID -| INT +: VOID { + $$ = sexpr_make_ast(AST_TYPE_VOID); +} +| INT { + $$ = sexpr_make_ast(AST_TYPE_INT); +} /* | CHAR */ /* | SIGNED CHAR */ /* | UNSIGNED CHAR */ From 7518e2e1900f6779eae985727c0e9771a1873b69 Mon Sep 17 00:00:00 2001 From: hatsusato Date: Sun, 11 Sep 2016 14:30:17 +0900 Subject: [PATCH 5/9] Add storage-class-specifier action --- src/ast.h | 5 ++++- src/parser.y | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/ast.h b/src/ast.h index d70f169d..a3599b55 100644 --- a/src/ast.h +++ b/src/ast.h @@ -5,7 +5,10 @@ enum AstTag { AST_IDENTIFIER, AST_INTEGER_CONSTANT, AST_TYPE_VOID, - AST_TYPE_INT + AST_TYPE_INT, + AST_SPEC_AUTO, + AST_SPEC_REGISTER, + AST_SPEC_STATIC }; #endif /* KMC_C90_COMPILER_AST_H */ diff --git a/src/parser.y b/src/parser.y index b80c52b4..02189d9d 100644 --- a/src/parser.y +++ b/src/parser.y @@ -138,14 +138,24 @@ fundamental-specifier ; storage-class-specifier.opt -: %empty -| storage-class-specifier +: %empty { + $$ = NULL; +} +| storage-class-specifier { + $$ = $[storage-class-specifier]; +} ; storage-class-specifier -: AUTO -| REGISTER -| STATIC +: AUTO { + $$ = sexpr_make_ast(AST_SPEC_AUTO); +} +| REGISTER { + $$ = sexpr_make_ast(AST_SPEC_REGISTER); +} +| STATIC { + $$ = sexpr_make_ast(AST_SPEC_STATIC); +} ; linkage-specifier.opt From 7ee7ca0044f82e054c5b392d7a029e009d688cc1 Mon Sep 17 00:00:00 2001 From: hatsusato Date: Sun, 11 Sep 2016 14:33:55 +0900 Subject: [PATCH 6/9] Add linkage-specifier action --- src/ast.h | 3 ++- src/parser.y | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ast.h b/src/ast.h index a3599b55..bab64d4f 100644 --- a/src/ast.h +++ b/src/ast.h @@ -8,7 +8,8 @@ enum AstTag { AST_TYPE_INT, AST_SPEC_AUTO, AST_SPEC_REGISTER, - AST_SPEC_STATIC + AST_SPEC_STATIC, + AST_SPEC_EXTERN }; #endif /* KMC_C90_COMPILER_AST_H */ diff --git a/src/parser.y b/src/parser.y index 02189d9d..2fb9b184 100644 --- a/src/parser.y +++ b/src/parser.y @@ -159,13 +159,21 @@ storage-class-specifier ; linkage-specifier.opt -: %empty -| linkage-specifier +: %empty { + $$ = NULL; +} +| linkage-specifier { + $$ = $[linkage-specifier]; +} ; linkage-specifier -: EXTERN -| STATIC +: EXTERN { + $$ = sexpr_make_ast(AST_SPEC_EXTERN); +} +| STATIC { + $$ = sexpr_make_ast(AST_SPEC_STATIC); +} ; typedef-specifier From 8fc85da096f60cc0bcb2cdc5d342edcfa88d6915 Mon Sep 17 00:00:00 2001 From: hatsusato Date: Sun, 11 Sep 2016 15:17:05 +0900 Subject: [PATCH 7/9] Add typedef-specifier action --- src/ast.h | 3 ++- src/parser.y | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ast.h b/src/ast.h index bab64d4f..46fbea33 100644 --- a/src/ast.h +++ b/src/ast.h @@ -9,7 +9,8 @@ enum AstTag { AST_SPEC_AUTO, AST_SPEC_REGISTER, AST_SPEC_STATIC, - AST_SPEC_EXTERN + AST_SPEC_EXTERN, + AST_SPEC_TYPEDEF }; #endif /* KMC_C90_COMPILER_AST_H */ diff --git a/src/parser.y b/src/parser.y index 2fb9b184..3a4b0527 100644 --- a/src/parser.y +++ b/src/parser.y @@ -177,7 +177,9 @@ linkage-specifier ; typedef-specifier -: TYPEDEF +: TYPEDEF { + $$ = sexpr_make_ast(AST_SPEC_TYPEDEF); +} ; type-specifier From 4a5f65a08ce7e16da402919f929f1510318dbbc6 Mon Sep 17 00:00:00 2001 From: hatsusato Date: Sun, 11 Sep 2016 14:41:28 +0900 Subject: [PATCH 8/9] Add fundamental-specifier action --- src/parser.y | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/parser.y b/src/parser.y index 3a4b0527..a3c9de83 100644 --- a/src/parser.y +++ b/src/parser.y @@ -183,7 +183,9 @@ typedef-specifier ; type-specifier -: fundamental-specifier +: fundamental-specifier { + $$ = cons($[fundamental-specifier], NULL); +} /* | struct-or-union-specifier */ /* | enum-specifier */ /* | typedef-name */ From 4cca5da380eeded805e9564c09a49cfa2ce25fbe Mon Sep 17 00:00:00 2001 From: hatsusato Date: Sun, 11 Sep 2016 14:43:45 +0900 Subject: [PATCH 9/9] Add declaration-specifiers action --- src/parser.y | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/parser.y b/src/parser.y index a3c9de83..d7bf60a3 100644 --- a/src/parser.y +++ b/src/parser.y @@ -192,7 +192,9 @@ type-specifier ; declaration-specifiers -: type-specifier +: type-specifier { + $$ = $[type-specifier]; +} /* : type-specifier type-qualifier-list.opt */ /* | type-qualifier declaration-specifiers */ ;