aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeddy <[email protected]>2014-03-25 04:58:57 +0800
committerTeddy <[email protected]>2014-03-25 04:58:57 +0800
commit9e43ffed22d5ba25fe545a48ac732591c346aabb (patch)
treee56c5d18e2441ef78a00bb54bb118872897229cc
parent4f90efb9a08b697b7ef270a4d2ee067dc853f251 (diff)
wrong regex for char const
-rw-r--r--ast.c2
-rw-r--r--cibic.l4
-rw-r--r--cibic.y4
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<intval> INT_CONST CHAR_CONST
-%type<strval> IDENTIFIER STR_CONST
+%type<intval> INT_CONST
+%type<strval> IDENTIFIER STR_CONST CHAR_CONST
%type<intval> assignment_operator equality_operator relational_operator shift_operator additive_operator multiplicative_operator unary_operator struct_or_union
%type<cnode> 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