diff options
author | Ting-Wei Lan <lantw44@gmail.com> | 2015-11-30 02:57:28 +0800 |
---|---|---|
committer | Ting-Wei Lan <lantw44@gmail.com> | 2015-11-30 02:57:28 +0800 |
commit | e9e1ab12507adb5278fdfddcd1e269a44672cfe1 (patch) | |
tree | 3749996075765cebfb47f500e7634f7e180691ef | |
parent | d45970ea583807d9a9bc88f915ef29a1d0376d24 (diff) | |
download | compiler2015-e9e1ab12507adb5278fdfddcd1e269a44672cfe1.tar.gz compiler2015-e9e1ab12507adb5278fdfddcd1e269a44672cfe1.tar.zst compiler2015-e9e1ab12507adb5278fdfddcd1e269a44672cfe1.zip |
Drop tab usage in source files
-rw-r--r-- | src/ast.h | 32 | ||||
-rw-r--r-- | src/parser.y | 94 |
2 files changed, 63 insertions, 63 deletions
@@ -139,30 +139,30 @@ typedef struct TypeSpecSemanticValue //don't modify or lexer may break typedef struct CON_Type{ - C_type const_type; - union { - int intval; - double fval; - char *sc; } - const_u; + C_type const_type; + union { + int intval; + double fval; + char *sc; } + const_u; } CON_Type; struct AST_NODE { - struct AST_NODE *child; - struct AST_NODE *parent; - struct AST_NODE *rightSibling; - struct AST_NODE *leftmostSibling; - AST_TYPE nodeType; - DATA_TYPE dataType; - int linenumber; - union { + struct AST_NODE *child; + struct AST_NODE *parent; + struct AST_NODE *rightSibling; + struct AST_NODE *leftmostSibling; + AST_TYPE nodeType; + DATA_TYPE dataType; + int linenumber; + union { IdentifierSemanticValue identifierSemanticValue; STMTSemanticValue stmtSemanticValue; DECLSemanticValue declSemanticValue; EXPRSemanticValue exprSemanticValue; - CON_Type *const1; - } semantic_value; + CON_Type *const1; + } semantic_value; }; typedef struct AST_NODE AST_NODE; diff --git a/src/parser.y b/src/parser.y index 6246f53..985cb3e 100644 --- a/src/parser.y +++ b/src/parser.y @@ -20,9 +20,9 @@ extern int g_anyErrorOccur; %} %union{ - char *lexeme; - CON_Type *const1; - AST_NODE *node; + char *lexeme; + CON_Type *const1; + AST_NODE *node; }; %token <lexeme>ID @@ -78,17 +78,17 @@ extern int g_anyErrorOccur; /* ==== Grammar Section ==== */ /* Productions */ /* Semantic actions */ -program : global_decl_list - { +program : global_decl_list + { $$=Allocate(PROGRAM_NODE); makeChild($$,$1); prog=$$; - } - | - { + } + | + { $$=Allocate(PROGRAM_NODE); prog=$$; - } - ; + } + ; global_decl_list: global_decl_list global_decl { @@ -100,7 +100,7 @@ global_decl_list: global_decl_list global_decl } ; -global_decl : type_decl +global_decl : type_decl { $$ = $1; } @@ -114,7 +114,7 @@ global_decl : type_decl } ; -function_decl : type ID DL_LPAREN param_list DL_RPAREN DL_LBRACE block DL_RBRACE +function_decl : type ID DL_LPAREN param_list DL_RPAREN DL_LBRACE block DL_RBRACE { $$ = makeDeclNode(FUNCTION_DECL); AST_NODE* parameterList = Allocate(PARAM_LIST_NODE); @@ -142,7 +142,7 @@ function_decl : type ID DL_LPAREN param_list DL_RPAREN DL_LBRACE block DL_RBRACE } ; -param_list : param_list DL_COMMA param +param_list : param_list DL_COMMA param { $$ = makeSibling($1, $3); } @@ -152,7 +152,7 @@ param_list : param_list DL_COMMA param } ; -param : type ID +param : type ID { $$ = makeDeclNode(FUNCTION_PARAMETER_DECL); makeFamily($$, 2, $1, makeIDNode($2, NORMAL_ID)); @@ -163,7 +163,7 @@ param : type ID makeFamily($$, 2, $1, makeChild(makeIDNode($2, ARRAY_ID), $3)); } ; -dim_fn : DL_LBRACK expr_null DL_RBRACK +dim_fn : DL_LBRACK expr_null DL_RBRACK { $$ = $2; } @@ -171,9 +171,9 @@ dim_fn : DL_LBRACK expr_null DL_RBRACK { $$ = makeSibling($1, $3); } - ; + ; -expr_null :expr +expr_null :expr { $$ = $1; } @@ -203,7 +203,7 @@ block : decl_list stmt_list } ; -decl_list : decl_list decl +decl_list : decl_list decl { $$ = makeSibling($1, $2); } @@ -213,7 +213,7 @@ decl_list : decl_list decl } ; -decl : type_decl +decl : type_decl { $$ = $1; } @@ -223,7 +223,7 @@ decl : type_decl } ; -type_decl : TYPEDEF type id_list DL_SEMICOL +type_decl : TYPEDEF type id_list DL_SEMICOL { $$ = makeDeclNode(TYPE_DECL); makeFamily($$, 2, $2, $3); @@ -235,7 +235,7 @@ type_decl : TYPEDEF type id_list DL_SEMICOL } ; -var_decl : type init_id_list DL_SEMICOL +var_decl : type init_id_list DL_SEMICOL { $$ = makeDeclNode(VARIABLE_DECL); makeFamily($$, 2, $1, $2); @@ -247,7 +247,7 @@ var_decl : type init_id_list DL_SEMICOL } ; -type : INT +type : INT { $$ = makeIDNode("int", NORMAL_ID); } @@ -257,7 +257,7 @@ type : INT } ; -id_list : ID +id_list : ID { $$ = makeIDNode($1, NORMAL_ID); } @@ -273,8 +273,8 @@ id_list : ID { $$ = makeChild(makeIDNode($1, ARRAY_ID), $2); } - ; -dim_decl : DL_LBRACK cexpr DL_RBRACK + ; +dim_decl : DL_LBRACK cexpr DL_RBRACK { $$ = $2; } @@ -283,7 +283,7 @@ dim_decl : DL_LBRACK cexpr DL_RBRACK $$ = makeSibling($1, $3); } ; -cexpr : cexpr OP_ADD mcexpr +cexpr : cexpr OP_ADD mcexpr { $$ = makeExprNode(BINARY_OPERATION, BINARY_OP_ADD); makeFamily($$, 2, $1, $3); @@ -298,7 +298,7 @@ cexpr : cexpr OP_ADD mcexpr $$ = $1; } ; -mcexpr : mcexpr OP_MUL cfactor +mcexpr : mcexpr OP_MUL cfactor { $$ = makeExprNode(BINARY_OPERATION, BINARY_OP_MUL); makeFamily($$, 2, $1, $3); @@ -314,7 +314,7 @@ mcexpr : mcexpr OP_MUL cfactor } ; -cfactor: CONST +cfactor: CONST { $$ = Allocate(CONST_VALUE_NODE); $$->semantic_value.const1=$1; @@ -325,7 +325,7 @@ cfactor: CONST } ; -init_id_list : init_id +init_id_list : init_id { $$ = $1; } @@ -335,7 +335,7 @@ init_id_list : init_id } ; -init_id : ID +init_id : ID { $$ = makeIDNode($1, NORMAL_ID); } @@ -350,7 +350,7 @@ init_id : ID } ; -stmt_list : stmt_list stmt +stmt_list : stmt_list stmt { $$ = makeSibling($1, $2); } @@ -362,7 +362,7 @@ stmt_list : stmt_list stmt -stmt : DL_LBRACE block DL_RBRACE +stmt : DL_LBRACE block DL_RBRACE { $$ = $2; } @@ -441,9 +441,9 @@ assign_expr : ID OP_ASSIGN relop_expr { $$ = $1; } - ; + ; -relop_expr : relop_term +relop_expr : relop_term { $$ = $1; } @@ -454,7 +454,7 @@ relop_expr : relop_term } ; -relop_term : relop_factor +relop_term : relop_factor { $$ = $1; } @@ -465,7 +465,7 @@ relop_term : relop_factor } ; -relop_factor : expr +relop_factor : expr { $$ = $1; } @@ -476,7 +476,7 @@ relop_factor : expr } ; -rel_op : OP_EQ +rel_op : OP_EQ { $$ = makeExprNode(BINARY_OPERATION, BINARY_OP_EQ); } @@ -503,7 +503,7 @@ rel_op : OP_EQ ; -relop_expr_list : nonempty_relop_expr_list +relop_expr_list : nonempty_relop_expr_list { $$ = Allocate(NONEMPTY_RELOP_EXPR_LIST_NODE); makeChild($$, $1); @@ -514,7 +514,7 @@ relop_expr_list : nonempty_relop_expr_list } ; -nonempty_relop_expr_list : nonempty_relop_expr_list DL_COMMA relop_expr +nonempty_relop_expr_list : nonempty_relop_expr_list DL_COMMA relop_expr { $$ = makeSibling($1, $3); } @@ -524,7 +524,7 @@ nonempty_relop_expr_list : nonempty_relop_expr_list DL_COMMA relop_expr } ; -expr : expr add_op term +expr : expr add_op term { $$ = $2; makeFamily($$, 2, $1, $3); @@ -535,7 +535,7 @@ expr : expr add_op term } ; -add_op : OP_ADD +add_op : OP_ADD { $$ = makeExprNode(BINARY_OPERATION, BINARY_OP_ADD); } @@ -545,7 +545,7 @@ add_op : OP_ADD } ; -term : term mul_op factor +term : term mul_op factor { $$ = $2; makeFamily($$, 2, $1, $3); @@ -556,7 +556,7 @@ term : term mul_op factor } ; -mul_op : OP_MUL +mul_op : OP_MUL { $$ = makeExprNode(BINARY_OPERATION, BINARY_OP_MUL); } @@ -566,7 +566,7 @@ mul_op : OP_MUL } ; -factor : DL_LPAREN relop_expr DL_RPAREN +factor : DL_LPAREN relop_expr DL_RPAREN { $$ = $2; } @@ -658,7 +658,7 @@ factor : DL_LPAREN relop_expr DL_RPAREN } ; -var_ref : ID +var_ref : ID { $$ = makeIDNode($1, NORMAL_ID); } @@ -670,7 +670,7 @@ var_ref : ID ; -dim_list : dim_list DL_LBRACK expr DL_RBRACK +dim_list : dim_list DL_LBRACK expr DL_RBRACK { $$ = makeSibling($1, $3); } @@ -678,7 +678,7 @@ dim_list : dim_list DL_LBRACK expr DL_RBRACK { $$ = $2; } - ; + ; %% |