|
|
@ -31,8 +31,7 @@ |
|
|
|
_DO(Return) _DO(Break) _DO(Continue) _DO(Throw) _DO(Try) \ |
|
|
|
/* _DO(Quasiquote) _DO(Unquote) */ \ |
|
|
|
_DO(Comment) _DO(Token) \ |
|
|
|
_DO(C_if) \ |
|
|
|
_DO(C_int) |
|
|
|
_DO(C_if) _DO(C_int) _DO(C_float) _DO(C_char) |
|
|
|
|
|
|
|
typedef enum { |
|
|
|
t_UNDEFINED=0, |
|
|
@ -320,23 +319,15 @@ oop newSymbol(oop name) |
|
|
|
} |
|
|
|
|
|
|
|
oop new_C_int(int value) { |
|
|
|
oop integer = newObject(C_int_proto); |
|
|
|
map_set(integer, value_symbol, makeInteger(value)); |
|
|
|
return integer; |
|
|
|
oop object = newObject(C_int_proto); |
|
|
|
map_set(object, value_symbol, makeInteger(value)); |
|
|
|
return object; |
|
|
|
} |
|
|
|
|
|
|
|
oop newInteger(oop value) |
|
|
|
{ |
|
|
|
oop integer = newObject(Integer_proto); |
|
|
|
map_set(integer, value_symbol, value); |
|
|
|
return integer; |
|
|
|
} |
|
|
|
|
|
|
|
oop newFloat(oop value) |
|
|
|
{ |
|
|
|
oop obj = newObject(Float_proto); |
|
|
|
map_set(obj, value_symbol, value); |
|
|
|
return obj; |
|
|
|
oop new_C_float(float value) { |
|
|
|
oop object = newObject(C_float_proto); |
|
|
|
map_set(object, value_symbol, makeFloat(value)); |
|
|
|
return object; |
|
|
|
} |
|
|
|
|
|
|
|
int digitValue(int c) |
|
|
@ -406,6 +397,12 @@ oop newString(oop str) |
|
|
|
return string; |
|
|
|
} |
|
|
|
|
|
|
|
oop new_C_char(char *s) { |
|
|
|
oop object = newObject(C_char_proto); |
|
|
|
map_set(object, value_symbol, makeString(s)); |
|
|
|
return object; |
|
|
|
} |
|
|
|
|
|
|
|
oop newPreIncrement(oop rhs) |
|
|
|
{ assert(is(Map, rhs)); |
|
|
|
oop proto= map_get(rhs, __proto___symbol); assert(null != proto); |
|
|
@ -691,8 +688,8 @@ error = EOL* < (!EOL .)* EOL* (!EOL .)* > &{ error(yytext), 1 |
|
|
|
#| |
|
|
|
IDFIRST = [a-zA-Z_] | universalCharacterName | '$' &{gnu} |
|
|
|
IDREST = IDFIRST | [0-9] |
|
|
|
#| |
|
|
|
#|digit = [0-9] |
|
|
|
|
|
|
|
digit = [0-9] |
|
|
|
|
|
|
|
### A.1.4 Universal character names |
|
|
|
|
|
|
@ -708,8 +705,11 @@ hexQuad = hexadecimalDigit hexadecimalDigit hexadecimalDigit hexadecimalDigit |
|
|
|
|
|
|
|
# 6.4.4 |
|
|
|
|
|
|
|
constant = integerConstant { $$ = new_C_int(atoi(yytext)); } |
|
|
|
#| | floatingConstant | characterConstant |
|
|
|
constant = characterConstant |
|
|
|
| floatingConstant |
|
|
|
| integerConstant |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 6.4.4.1 |
|
|
|
|
|
|
@ -717,7 +717,7 @@ integerConstant = < ( hexadecimalConstant |
|
|
|
| octalConstant |
|
|
|
| binaryConstant &{gnu} |
|
|
|
| decimalConstant |
|
|
|
) integerSuffix? > |
|
|
|
) integerSuffix? > { $$ = new_C_int(atoi(yytext)); } - |
|
|
|
|
|
|
|
decimalConstant = [1-9][0-9]* |
|
|
|
|
|
|
@ -729,62 +729,62 @@ binaryConstant = '0'[bB][01]+ |
|
|
|
|
|
|
|
hexadecimalPrefix = '0'[xX] |
|
|
|
|
|
|
|
octalDigit = [0-7] |
|
|
|
octalDigit = [0-7] |
|
|
|
|
|
|
|
hexadecimalDigit = [0-9A-Fa-f] |
|
|
|
|
|
|
|
integerSuffix = ( [uU][lL]?[lL]? | [lL][lL]?[uU]? ) ( imaginarySuffix &{gnu} )? |
|
|
|
|
|
|
|
imaginarySuffix = [ij] |
|
|
|
#| |
|
|
|
#|# 6.4.4.2 |
|
|
|
#| |
|
|
|
#|floatingConstant = <( decimalFloatingConstant | hexadecimalFloatingConstant )> { $$= newFloat(yytext) } - |
|
|
|
#| |
|
|
|
#| |
|
|
|
#|decimalFloatingConstant = fractionalConstant exponentPart? floatingSuffix? |
|
|
|
#| | digitSequence exponentPart floatingSuffix? |
|
|
|
#| |
|
|
|
#|hexadecimalFloatingConstant = hexadecimalPrefix hexadecimalFractionalConstant binaryExponentPart floatingSuffix? |
|
|
|
#| | hexadecimalPrefix hexadecimalDigitSequence binaryExponentPart floatingSuffix? |
|
|
|
#| |
|
|
|
#|fractionalConstant = digitSequence '.' digitSequence? |
|
|
|
#| | '.' digitSequence |
|
|
|
#| |
|
|
|
#|exponentPart = [eE] [-+]? digitSequence |
|
|
|
#| |
|
|
|
#|digitSequence = digit+ |
|
|
|
#| |
|
|
|
#|hexadecimalFractionalConstant = hexadecimalDigitSequence '.' hexadecimalDigitSequence? |
|
|
|
#| | '.' hexadecimalDigitSequence |
|
|
|
#| |
|
|
|
#|binaryExponentPart = [pP] [-+]? digitSequence |
|
|
|
#| |
|
|
|
#|hexadecimalDigitSequence = hexadecimalDigit+ |
|
|
|
#| |
|
|
|
#|floatingSuffix = [fFlL] imaginarySuffix? |
|
|
|
#| |
|
|
|
#|# 6.4.4.4 |
|
|
|
#| |
|
|
|
#|characterConstant = < "'" cCharSequence "'" > { $$= newChar(yytext) } - |
|
|
|
#| | < "L'" cCharSequence "'" > { $$= newChar(yytext) } - |
|
|
|
#| |
|
|
|
#|cCharSequence = ( escapeSequence | !EOL [^\'\\] )* |
|
|
|
#| |
|
|
|
#|escapeSequence = simpleEscapeSequence |
|
|
|
#| | octalEscapeSequence |
|
|
|
#| | hexadecimalEscapeSequence |
|
|
|
#| | universalCharacterName |
|
|
|
#| | '\\' EOL |
|
|
|
#| | '\\' Blank+ EOL &{gnu} |
|
|
|
#| | '\\' . &{gnu} |
|
|
|
#| |
|
|
|
#|simpleEscapeSequence = '\\'([\'\"?\\abfnrtv] | 'e' &{gnu}) |
|
|
|
#| |
|
|
|
#|octalEscapeSequence = '\\' octalDigit octalDigit? octalDigit? |
|
|
|
#| |
|
|
|
#|hexadecimalEscapeSequence = '\\x' hexadecimalDigit+ |
|
|
|
#| |
|
|
|
|
|
|
|
# 6.4.4.2 |
|
|
|
|
|
|
|
floatingConstant = <( decimalFloatingConstant | hexadecimalFloatingConstant )> { $$ = new_C_float(atof(yytext)); } - |
|
|
|
|
|
|
|
|
|
|
|
decimalFloatingConstant = fractionalConstant exponentPart? floatingSuffix? |
|
|
|
| digitSequence exponentPart floatingSuffix? |
|
|
|
|
|
|
|
hexadecimalFloatingConstant = hexadecimalPrefix hexadecimalFractionalConstant binaryExponentPart floatingSuffix? |
|
|
|
| hexadecimalPrefix hexadecimalDigitSequence binaryExponentPart floatingSuffix? |
|
|
|
|
|
|
|
fractionalConstant = digitSequence '.' digitSequence? |
|
|
|
| '.' digitSequence |
|
|
|
|
|
|
|
exponentPart = [eE] [-+]? digitSequence |
|
|
|
|
|
|
|
digitSequence = digit+ |
|
|
|
|
|
|
|
hexadecimalFractionalConstant = hexadecimalDigitSequence '.' hexadecimalDigitSequence? |
|
|
|
| '.' hexadecimalDigitSequence |
|
|
|
|
|
|
|
binaryExponentPart = [pP] [-+]? digitSequence |
|
|
|
|
|
|
|
hexadecimalDigitSequence = hexadecimalDigit+ |
|
|
|
|
|
|
|
floatingSuffix = [fFlL] imaginarySuffix? |
|
|
|
|
|
|
|
# 6.4.4.4 |
|
|
|
|
|
|
|
characterConstant = < "'" cCharSequence "'" > { $$ = new_C_char(yytext) } - |
|
|
|
| < "L'" cCharSequence "'" > { $$ = new_C_char(yytext) } - |
|
|
|
|
|
|
|
cCharSequence = ( escapeSequence | !EOL [^\'\\] )* |
|
|
|
|
|
|
|
escapeSequence = simpleEscapeSequence |
|
|
|
| octalEscapeSequence |
|
|
|
| hexadecimalEscapeSequence |
|
|
|
| universalCharacterName |
|
|
|
| '\\' EOL |
|
|
|
| '\\' Blank+ EOL &{gnu} |
|
|
|
| '\\' . &{gnu} |
|
|
|
|
|
|
|
simpleEscapeSequence = '\\'([\'\"?\\abfnrtv] | 'e' &{gnu}) |
|
|
|
|
|
|
|
octalEscapeSequence = '\\' octalDigit octalDigit? octalDigit? |
|
|
|
|
|
|
|
hexadecimalEscapeSequence = '\\x' hexadecimalDigit+ |
|
|
|
|
|
|
|
#|### A.1.6 String literals |
|
|
|
#| |
|
|
|
#|# 6.4.5 |
|
|
@ -2582,6 +2582,13 @@ void outputInt(int value) { |
|
|
|
ocol += strlen(toString); |
|
|
|
} |
|
|
|
|
|
|
|
void outputFloat(float value) { |
|
|
|
printf("%f", value); |
|
|
|
char *toString = malloc(sizeof(value)); |
|
|
|
sprintf(toString,"%f", value); |
|
|
|
ocol += strlen(toString); |
|
|
|
} |
|
|
|
|
|
|
|
void outputNode(oop node) |
|
|
|
{ |
|
|
|
if (!node) return; |
|
|
@ -2596,6 +2603,9 @@ void outputNode(oop node) |
|
|
|
case Integer: |
|
|
|
outputInt(getInteger(node)); |
|
|
|
return; |
|
|
|
case Float: |
|
|
|
outputFloat(getFloat(node)); |
|
|
|
return; |
|
|
|
default: |
|
|
|
fprintf(stderr, "\noutputNode: unknown node type %i\n", node->type); |
|
|
|
abort(); |
|
|
@ -2615,6 +2625,11 @@ void outputNode(oop node) |
|
|
|
case t_C_int: |
|
|
|
outputNode(map_get(node, value_symbol)); |
|
|
|
break; |
|
|
|
case t_C_float: |
|
|
|
outputNode(map_get(node, value_symbol)); |
|
|
|
break; |
|
|
|
case t_C_char: |
|
|
|
outputNode(map_get(node, value_symbol)); |
|
|
|
case t_C_if: |
|
|
|
outputNode(map_get(node, if_symbol)); |
|
|
|
outputNode(map_get(node, lparen_symbol)); |
|
|
|