From 212bd64d9ddb53875d45a2c54c353003b0e9b91a Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 5 Apr 2003 01:21:08 +0000 Subject: [PATCH] introduce ulong token type to better support hex numbers appearing in egg files --- panda/src/egg/lexer.lxx | 9 ++++----- panda/src/egg/parser.yxx | 33 ++++++++++++++++++++++++++++----- panda/src/egg/parserDefs.h | 1 + 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/panda/src/egg/lexer.lxx b/panda/src/egg/lexer.lxx index f547cdaafd..bea8b9782e 100644 --- a/panda/src/egg/lexer.lxx +++ b/panda/src/egg/lexer.lxx @@ -275,7 +275,6 @@ eat_c_comment() { } - // accept() is called below as each piece is pulled off and // accepted by the lexer; it increments the current column number. INLINE void accept() { @@ -658,17 +657,17 @@ NUMERIC ([+-]?(([0-9]+[.]?)|([0-9]*[.][0-9]+))([eE][+-]?[0-9]+)?) {HEX} { // A hexadecimal integer number. accept(); - eggyylval._number = strtoul(yytext+2, NULL, 16); + eggyylval._ulong = strtoul(yytext+2, NULL, 16); eggyylval._string = yytext; - return NUMBER; + return ULONG; } {BINARY} { // A binary integer number. accept(); - eggyylval._number = strtoul(yytext+2, NULL, 2); + eggyylval._ulong = strtoul(yytext+2, NULL, 2); eggyylval._string = yytext; - return NUMBER; + return ULONG; } "nan"{HEX} { diff --git a/panda/src/egg/parser.yxx b/panda/src/egg/parser.yxx index 15e2e1d8af..e242e329a2 100644 --- a/panda/src/egg/parser.yxx +++ b/panda/src/egg/parser.yxx @@ -111,6 +111,7 @@ egg_cleanup_parser() { %} %token <_number> NUMBER +%token <_ulong> ULONG %token <_string> STRING %token BEZIERCURVE BFACE BILLBOARD BILLBOARDCENTER BUNDLE CLOSED @@ -862,6 +863,7 @@ group_body: EggGroup *group = DCAST(EggGroup, egg_stack.back()); string name = $3; double value = $<_number>5; + unsigned long ulong_value = $<_ulong>5; string strval = $<_string>5; if (cmp_nocase_uh(name, "fps") == 0) { @@ -897,15 +899,15 @@ group_body: group->set_depth_test_mode(m); } } else if (cmp_nocase_uh(name, "draw_order") == 0) { - group->set_draw_order((int)value); + group->set_draw_order(ulong_value); } else if (cmp_nocase_uh(name, "bin") == 0) { group->set_bin(strval); } else if (cmp_nocase_uh(name, "collide_mask") == 0) { - group->set_collide_mask((int)value); + group->set_collide_mask(ulong_value); } else if (cmp_nocase_uh(name, "from_collide_mask") == 0) { - group->set_from_collide_mask((int)value); + group->set_from_collide_mask(ulong_value); } else if (cmp_nocase_uh(name, "into_collide_mask") == 0) { - group->set_into_collide_mask((int)value); + group->set_into_collide_mask(ulong_value); } else { eggyywarning("Unknown group scalar " + name); } @@ -2291,6 +2293,10 @@ string: NUMBER { $$ = $<_string>1; +} + | ULONG +{ + $$ = $<_string>1; } | STRING ; @@ -2344,24 +2350,37 @@ repeated_string_body: */ real: NUMBER + | ULONG +{ + $$ = $1; +} ; /* * real_or_string * * enter: - * exit: Returns a number as ($<_number>1) or a string (as $<_string>1). + * exit: Returns a number as ($<_number>1) or as an unsigned long + * ($<_ulong>1) or a string (as $<_string>1). * */ real_or_string: NUMBER { $<_number>$ = $1; + $<_ulong>$ = (unsigned long)$1; + $<_string>$ = $<_string>1; +} + | ULONG +{ + $<_number>$ = $1; + $<_ulong>$ = $1; $<_string>$ = $<_string>1; } | STRING { $<_number>$ = 0.0; + $<_ulong>$ = 0; $<_string>$ = $1; } ; @@ -2382,6 +2401,10 @@ integer: eggyywarning("Integer expected."); $$ = (double)i; } +} + | ULONG +{ + $$ = $1; } ; diff --git a/panda/src/egg/parserDefs.h b/panda/src/egg/parserDefs.h index 3785a0ae6c..662e42d0b1 100644 --- a/panda/src/egg/parserDefs.h +++ b/panda/src/egg/parserDefs.h @@ -46,6 +46,7 @@ void egg_cleanup_parser(); class EXPCL_PANDAEGG EggTokenType { public: double _number; + unsigned long _ulong; string _string; PT(EggObject) _egg; PTA_double _number_list;