|
|
@ -3,7 +3,7 @@ |
|
|
|
# Copyright (c) 2016-2021 Ian Piumarta and other contributors (see AUTHORS) |
|
|
|
# All rights reserved (see LICENSE) |
|
|
|
# |
|
|
|
# Last edited: 2023-03-22 17:45:58 by piumarta on zora-10.local |
|
|
|
# Last edited: 2023-03-22 17:53:24 by piumarta on zora-10.local |
|
|
|
|
|
|
|
%{ |
|
|
|
/* compile: leg -o ccmeta.c ccmeta.leg |
|
|
@ -35,17 +35,17 @@ |
|
|
|
#define META_PROTO_MAX t_Try |
|
|
|
|
|
|
|
// C protos must begin with Comment because it is a sentinel |
|
|
|
#define DO_C_PROTOS() \ |
|
|
|
_DO(Comment) _DO(Token) \ |
|
|
|
_DO(C_declaration) _DO(C_string) \ |
|
|
|
_DO(C_if) _DO(C_int) _DO(C_float) _DO(C_char) _DO(C_id) _DO(C_while) _DO(C_do) _DO(C_for) \ |
|
|
|
_DO(C_binary) _DO(C_initializer) _DO(C_range) _DO(C_conditional) _DO(C_index) \ |
|
|
|
_DO(C_designation) _DO(C_attribution) _DO(C_deref) _DO(C_block) _DO(C_call) _DO(C_subexpr) \ |
|
|
|
_DO(C_array) _DO(C_parameter) _DO(C_typeOf) _DO(C_unary) _DO(C_prefix) _DO(C_alignOf) \ |
|
|
|
_DO(C_sizeOf) _DO(C_cast) _DO(C_attributeSpec) _DO(C_asm) _DO(C_asmExpr) _DO(C_asmExprArg) \ |
|
|
|
_DO(C_aggregate) _DO(C_attribute) _DO(C_postfix) _DO(C_compound) _DO(C_functionDef) \ |
|
|
|
_DO(C_exprStatement) _DO(C_switch) _DO(C_goto) _DO(C_continue) _DO(C_break) _DO(C_return) \ |
|
|
|
_DO(C_case) _DO(C_default) _DO(C_label) _DO(C_labelDeclaration) _DO(C_structSpec) \ |
|
|
|
#define DO_C_PROTOS() \ |
|
|
|
_DO(Comment) _DO(Token) \ |
|
|
|
_DO(C_declaration) _DO(C_stringLiteral) \ |
|
|
|
_DO(C_if) _DO(C_int) _DO(C_float) _DO(C_string) _DO(C_char) _DO(C_id) _DO(C_while) _DO(C_do) _DO(C_for) \ |
|
|
|
_DO(C_binary) _DO(C_initializer) _DO(C_range) _DO(C_conditional) _DO(C_index) \ |
|
|
|
_DO(C_designation) _DO(C_attribution) _DO(C_deref) _DO(C_block) _DO(C_call) _DO(C_subexpr) \ |
|
|
|
_DO(C_array) _DO(C_parameter) _DO(C_typeOf) _DO(C_unary) _DO(C_prefix) _DO(C_alignOf) \ |
|
|
|
_DO(C_sizeOf) _DO(C_cast) _DO(C_attributeSpec) _DO(C_asm) _DO(C_asmExpr) _DO(C_asmExprArg) \ |
|
|
|
_DO(C_aggregate) _DO(C_attribute) _DO(C_postfix) _DO(C_compound) _DO(C_functionDef) \ |
|
|
|
_DO(C_exprStatement) _DO(C_switch) _DO(C_goto) _DO(C_continue) _DO(C_break) _DO(C_return) \ |
|
|
|
_DO(C_case) _DO(C_default) _DO(C_label) _DO(C_labelDeclaration) _DO(C_structSpec) \ |
|
|
|
_DO(C_structDeclarator) _DO(C_enumSpec) _DO(C_enum) |
|
|
|
|
|
|
|
typedef enum { |
|
|
@ -467,12 +467,18 @@ char *unescape(char *s) |
|
|
|
return t; |
|
|
|
} |
|
|
|
|
|
|
|
oop new_C_string(oop str) { |
|
|
|
oop object = newObject(C_string_proto); |
|
|
|
oop new_C_stringLiteral(oop str) { |
|
|
|
oop object = newObject(C_stringLiteral_proto); |
|
|
|
map_set(object, text_symbol, str); |
|
|
|
return object; |
|
|
|
} |
|
|
|
|
|
|
|
oop new_C_string(char *s) { |
|
|
|
oop object = newObject(C_string_proto); |
|
|
|
map_set(object, value_symbol, makeString(s)); |
|
|
|
return object; |
|
|
|
} |
|
|
|
|
|
|
|
oop new_C_char(char *s) { |
|
|
|
oop object = newObject(C_char_proto); |
|
|
|
map_set(object, value_symbol, makeString(s)); |
|
|
@ -1581,10 +1587,10 @@ hexadecimalEscapeSequence = '\\x' hexadecimalDigit+ |
|
|
|
|
|
|
|
stringLiteral = { listBegin(); } |
|
|
|
( s:stringLiteralPart { listAppend(s) } |
|
|
|
)+ { $$= new_C_string(listEnd()) } |
|
|
|
)+ { $$= new_C_stringLiteral(listEnd()) } |
|
|
|
|
|
|
|
stringLiteralPart = < '"' sCharSequence '"' > { $$= new_C_char(yytext) } - |
|
|
|
| < 'L''"' sCharSequence '"' > { $$= new_C_char(yytext) } - |
|
|
|
stringLiteralPart = < '"' sCharSequence '"' > { $$= new_C_string(yytext) } - |
|
|
|
| < 'L''"' sCharSequence '"' > { $$= new_C_string(yytext) } - |
|
|
|
|
|
|
|
sCharSequence = ( escapeSequence | !EOL [^\"\\] )* |
|
|
|
|
|
|
@ -3816,9 +3822,12 @@ void outputNode(oop node) |
|
|
|
case t_C_float: |
|
|
|
outputNode(map_get(node, text_symbol)); |
|
|
|
break; |
|
|
|
case t_C_string: |
|
|
|
case t_C_stringLiteral: |
|
|
|
outputNode(map_get(node, text_symbol)); |
|
|
|
break; |
|
|
|
case t_C_string: |
|
|
|
outputNode(map_get(node, value_symbol)); |
|
|
|
break; |
|
|
|
case t_C_char: |
|
|
|
outputNode(map_get(node, value_symbol)); |
|
|
|
break; |
|
|
|