From 9e43ffed22d5ba25fe545a48ac732591c346aabb Mon Sep 17 00:00:00 2001 From: Teddy Date: Tue, 25 Mar 2014 04:58:57 +0800 Subject: wrong regex for char const --- ast.c | 2 +- cibic.l | 4 ++-- cibic.y | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ast.c b/ast.c index c1feff9..1b930fc 100644 --- a/ast.c +++ b/ast.c @@ -249,7 +249,7 @@ char *cnode_debug_type_repr(CNode *ast) { break; case CHAR: type = "char"; - aptr += sprintf(abuff, "%c", ast->rec.intval); + aptr += sprintf(abuff, "%s", ast->rec.strval); break; case STR: type = "str"; diff --git a/cibic.l b/cibic.l index 666069e..26fca1f 100644 --- a/cibic.l +++ b/cibic.l @@ -64,8 +64,8 @@ digit [0-9] return INT_CONST; } -'{letter}' { - yylval.intval = *(yytext); +'([^\'\\]|\\.)' { + yylval.strval = strdup(yytext); return CHAR_CONST; } diff --git a/cibic.y b/cibic.y index f85d28c..bbe7375 100644 --- a/cibic.y +++ b/cibic.y @@ -14,8 +14,8 @@ %token OPT_OR OPT_AND OPT_EQ OPT_NE OPT_LE OPT_GE OPT_SHL OPT_SHR OPT_INC OPT_DEC OPT_PTR %token ASS_MUL ASS_DIV ASS_MOD ASS_ADD ASS_SUB ASS_SHL ASS_SHR ASS_AND ASS_XOR ASS_OR %token UNKNOWN -%type INT_CONST CHAR_CONST -%type IDENTIFIER STR_CONST +%type INT_CONST +%type IDENTIFIER STR_CONST CHAR_CONST %type assignment_operator equality_operator relational_operator shift_operator additive_operator multiplicative_operator unary_operator struct_or_union %type expression assignment_expression constant_expression logical_or_expression logical_and_expression inclusive_or_expression exclusive_or_expression and_expression equality_expression relational_expression shift_expression additive_expression multiplicative_expression cast_expression type_name unary_expression postfix_expression identifier primary_expression arguments postfix type_specifier program declaration function_definition parameters declarators init_declarators init_declarator initializer array_initializer struct_fields struct_field plain_declaration declarator_array plain_declarator expression_statement compound_statement statement comp_decls comp_stmts selection_statement iteration_statement jump_statement optional_exp declarator prog_list %start program -- cgit v1.2.3