use int64 in parsing

This commit is contained in:
David Rose 2004-06-18 20:35:01 +00:00
parent 9b3a2b9f98
commit 30ae40c21b
3 changed files with 43 additions and 13 deletions

View File

@ -130,7 +130,7 @@ input_chars(char *buffer, int &result, int max_size) {
// from the stream, copy it into the current_line array. This // from the stream, copy it into the current_line array. This
// is because the \n.* rule below, which fills current_line // is because the \n.* rule below, which fills current_line
// normally, doesn't catch the first line. // normally, doesn't catch the first line.
strncpy(current_line, yytext, max_error_width); strncpy(current_line, dcyytext, max_error_width);
current_line[max_error_width] = '\0'; current_line[max_error_width] = '\0';
line_number++; line_number++;
col_number = 0; col_number = 0;
@ -318,7 +318,7 @@ REALNUM ([+-]?(([0-9]+[.])|([0-9]*[.][0-9]+))([eE][+-]?[0-9]+)?)
// New line. Save a copy of the line so we can print it out for the // New line. Save a copy of the line so we can print it out for the
// benefit of the user in case we get an error. // benefit of the user in case we get an error.
strncpy(current_line, yytext+1, max_error_width); strncpy(current_line, dcyytext+1, max_error_width);
current_line[max_error_width] = '\0'; current_line[max_error_width] = '\0';
line_number++; line_number++;
col_number=0; col_number=0;
@ -464,7 +464,7 @@ mol[0-9]+ {
// A molecular keyword. // A molecular keyword.
accept(); accept();
dcyylval.u.integer = atoi(dcyytext + 3); dcyylval.u.integer = atoi(dcyytext + 3);
dcyylval.str = yytext; dcyylval.str = dcyytext;
return KW_MOL; return KW_MOL;
} }
@ -515,17 +515,47 @@ mol[0-9]+ {
{INTEGERNUM} { {INTEGERNUM} {
// An integer number. // An integer number.
accept(); accept();
dcyylval.u.integer = atoi(dcyytext);
dcyylval.str = yytext; // atoll isn't fully portable, so we'll decode the integer by hand.
dcyylval.u.integer = 0;
bool neg = false;
const char *p = dcyytext;
if (*p == '-') {
neg = true;
++p;
} else if (*p == '+') {
++p;
}
while (*p != '\0') {
dcyylval.u.integer = dcyylval.u.integer * 10 + (*p - '0');
++p;
}
if (neg) {
dcyylval.u.integer = -dcyylval.u.integer;
}
dcyylval.str = dcyytext;
return INTEGER; return INTEGER;
} }
{HEXNUM} { {HEXNUM} {
// A hexadecimal integer number. // A hexadecimal integer number.
accept(); accept();
dcyylval.u.integer = strtoul(yytext+2, NULL, 16);
dcyylval.str = yytext; // As above, we'll decode the hex string by hand.
dcyylval.u.integer = 0;
const char *p = dcyytext + 2;
while (*p != '\0') {
if (isalpha(*p)) {
dcyylval.u.integer = dcyylval.u.integer * 16 + (tolower(*p) - 'a' + 10);
} else {
dcyylval.u.integer = dcyylval.u.integer * 16 + (*p - '0');
}
++p;
}
dcyylval.str = dcyytext;
return INTEGER; return INTEGER;
} }
@ -533,7 +563,7 @@ mol[0-9]+ {
// A floating-point number. // A floating-point number.
accept(); accept();
dcyylval.u.real = atof(dcyytext); dcyylval.u.real = atof(dcyytext);
dcyylval.str = yytext; dcyylval.str = dcyytext;
return REAL; return REAL;
} }
@ -554,7 +584,7 @@ mol[0-9]+ {
[A-Za-z_][A-Za-z_0-9]* { [A-Za-z_][A-Za-z_0-9]* {
// Identifier. // Identifier.
accept(); accept();
dcyylval.str = yytext; dcyylval.str = dcyytext;
return IDENTIFIER; return IDENTIFIER;
} }

View File

@ -386,7 +386,7 @@ parameter_definition:
parameter_value: parameter_value:
INTEGER INTEGER
{ {
current_packer->pack_int($1); current_packer->pack_int64($1);
} }
| REAL | REAL
{ {
@ -427,7 +427,7 @@ parameter_value:
| INTEGER '*' INTEGER | INTEGER '*' INTEGER
{ {
for (int i = 0; i < $3; i++) { for (int i = 0; i < $3; i++) {
current_packer->pack_int($1); current_packer->pack_int64($1);
} }
} }
| REAL '*' INTEGER | REAL '*' INTEGER

View File

@ -44,7 +44,7 @@ int dcyyparse();
class DCTokenType { class DCTokenType {
public: public:
union U { union U {
int integer; PN_int64 integer;
double real; double real;
DCClass *dclass; DCClass *dclass;
DCAtomicField *atomic; DCAtomicField *atomic;