Quellcode durchsuchen

New tests, Constants OK? TODO : figure out isInteger

master
Nathan R vor 4 Jahren
Ursprung
Commit
c4811cf925
4 geänderte Dateien mit 125 neuen und 76 gelöschten Zeilen
  1. +15
    -1
      ccmeta-test.ref
  2. +15
    -1
      ccmeta-test.txt
  3. +87
    -72
      ccmeta.leg
  4. +8
    -2
      object.c

+ 15
- 1
ccmeta-test.ref Datei anzeigen

@ -3,8 +3,22 @@
// comment
/* Test Int */
3
52
13
/* Test Float */
13.700000
42.000000
1.000000
/* Test Char */
'salut'
'bonjour tout le monde'
'je m appelle Nathan et je suis né en 1998'
'enchanté !'
/* multi
* line
* comment
*/
*/

+ 15
- 1
ccmeta-test.txt Datei anzeigen

@ -3,8 +3,22 @@
;
// comment
;
/* Test Int */
3;
52;
13;
;
/* Test Float */
13.7;
42.0;
1e+0;
;
/* Test Char */
'salut';
'bonjour tout le monde';
'je m appelle Nathan et je suis né en 1998';
'enchanté !';
/* multi
* line
* comment
*/
*/

+ 87
- 72
ccmeta.leg Datei anzeigen

@ -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));

+ 8
- 2
object.c Datei anzeigen

@ -226,6 +226,10 @@ int_t getInteger(oop obj)
return get(obj, Integer, _value);
}
float_t getFloat(oop obj) {
return get(obj, Float, _value);
}
#if (USE_TAG)
int isIntegerValue(int_t value)
{
@ -241,7 +245,8 @@ oop makeInteger(int_t value)
#endif
oop newInt = malloc(sizeof(struct Integer));
newInt->type = Integer;
newInt->Integer._value = value;
set(newInt, Integer, _value, value);
//newInt->Integer._value = value;
return newInt;
}
@ -249,7 +254,8 @@ oop makeFloat(flt_t value)
{
oop newFloat= malloc(sizeof(struct Float));
newFloat->type= Float;
newFloat->Float._value= value;
set(newFloat, Float, _value, value);
//newFloat->Float._value= value;
return newFloat;
}

Laden…
Abbrechen
Speichern