Skip to content

Commit 3e554a5

Browse files
committed
Add extra scanner rule for integers
ns-eel2 parses numbers without decimal point with atoi(), which causes overflows as it has a lower value range than double. We now mimic this behavior.
1 parent 0290017 commit 3e554a5

File tree

3 files changed

+66
-51
lines changed

3 files changed

+66
-51
lines changed

projectm-eval/Scanner.c

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Compiler.h"
44

55
#include <stdio.h>
6+
#include <stdint.h>
67

78
#define YY_NO_UNISTD_H
89
#define YY_STDINIT
@@ -755,8 +756,8 @@ static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner );
755756
yyg->yy_hold_char = *yy_cp; \
756757
*yy_cp = '\0'; \
757758
yyg->yy_c_buf_p = yy_cp;
758-
#define YY_NUM_RULES 51
759-
#define YY_END_OF_BUFFER 52
759+
#define YY_NUM_RULES 52
760+
#define YY_END_OF_BUFFER 53
760761
/* This struct is not used in this scanner,
761762
but its presence is necessary. */
762763
struct yy_trans_info
@@ -766,14 +767,14 @@ struct yy_trans_info
766767
};
767768
static const flex_int16_t yy_accept[80] =
768769
{ 0,
769-
0, 0, 0, 0, 0, 0, 52, 50, 49, 49,
770-
39, 50, 35, 37, 41, 42, 33, 31, 47, 32,
771-
50, 34, 13, 46, 48, 29, 40, 30, 45, 14,
772-
14, 43, 44, 36, 38, 51, 3, 51, 6, 5,
773-
26, 0, 10, 0, 0, 17, 28, 19, 21, 15,
774-
16, 13, 1, 4, 20, 13, 13, 0, 24, 23,
775-
25, 14, 14, 22, 18, 27, 2, 0, 0, 9,
776-
7, 13, 0, 13, 14, 8, 11, 12, 0
770+
0, 0, 0, 0, 0, 0, 53, 51, 50, 50,
771+
40, 51, 36, 38, 42, 43, 34, 32, 48, 33,
772+
51, 35, 13, 47, 49, 30, 41, 31, 46, 15,
773+
15, 44, 45, 37, 39, 52, 3, 52, 6, 5,
774+
27, 0, 10, 0, 0, 18, 29, 20, 22, 16,
775+
17, 13, 1, 4, 21, 13, 13, 0, 25, 24,
776+
26, 15, 15, 23, 19, 28, 2, 0, 0, 9,
777+
7, 13, 0, 13, 15, 8, 11, 12, 0
777778
} ;
778779

779780
static const YY_CHAR yy_ec[256] =
@@ -889,11 +890,11 @@ static const flex_int16_t yy_chk[169] =
889890

890891

891892
/* Table of booleans, true if rule could match eol. */
892-
static const flex_int32_t yy_rule_can_match_eol[52] =
893+
static const flex_int32_t yy_rule_can_match_eol[53] =
893894
{ 0,
894895
0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
895896
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
896-
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, };
897+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, };
897898

898899
/* The intent behind this definition is that it'll catch
899900
* any uses of REJECT which flex missed.
@@ -1445,6 +1446,13 @@ YY_RULE_SETUP
14451446
YY_BREAK
14461447
case 14:
14471448
YY_RULE_SETUP
1449+
{
1450+
yylval->NUM = (PRJM_EVAL_F)atoi(yytext);
1451+
return NUM;
1452+
}
1453+
YY_BREAK
1454+
case 15:
1455+
YY_RULE_SETUP
14481456
{
14491457
if (prjm_eval_compiler_name_is_function(cctx, yytext))
14501458
{
@@ -1456,156 +1464,156 @@ YY_RULE_SETUP
14561464
}
14571465
YY_BREAK
14581466
/* Operators */
1459-
case 15:
1467+
case 16:
14601468
YY_RULE_SETUP
14611469
{ return ADDOP; }
14621470
YY_BREAK
1463-
case 16:
1471+
case 17:
14641472
YY_RULE_SETUP
14651473
{ return SUBOP; }
14661474
YY_BREAK
1467-
case 17:
1475+
case 18:
14681476
YY_RULE_SETUP
14691477
{ return MODOP; }
14701478
YY_BREAK
1471-
case 18:
1479+
case 19:
14721480
YY_RULE_SETUP
14731481
{ return OROP; }
14741482
YY_BREAK
1475-
case 19:
1483+
case 20:
14761484
YY_RULE_SETUP
14771485
{ return ANDOP; }
14781486
YY_BREAK
1479-
case 20:
1487+
case 21:
14801488
YY_RULE_SETUP
14811489
{ return DIVOP; }
14821490
YY_BREAK
1483-
case 21:
1491+
case 22:
14841492
YY_RULE_SETUP
14851493
{ return MULOP; }
14861494
YY_BREAK
1487-
case 22:
1495+
case 23:
14881496
YY_RULE_SETUP
14891497
{ return POWOP; }
14901498
YY_BREAK
1491-
case 23:
1499+
case 24:
14921500
YY_RULE_SETUP
14931501
{ return EQUAL; }
14941502
YY_BREAK
1495-
case 24:
1503+
case 25:
14961504
YY_RULE_SETUP
14971505
{ return BELEQ; }
14981506
YY_BREAK
1499-
case 25:
1507+
case 26:
15001508
YY_RULE_SETUP
15011509
{ return ABOEQ; }
15021510
YY_BREAK
1503-
case 26:
1511+
case 27:
15041512
YY_RULE_SETUP
15051513
{ return NOTEQ; }
15061514
YY_BREAK
1507-
case 27:
1515+
case 28:
15081516
YY_RULE_SETUP
15091517
{ return BOOLOR; }
15101518
YY_BREAK
1511-
case 28:
1519+
case 29:
15121520
YY_RULE_SETUP
15131521
{ return BOOLAND; }
15141522
YY_BREAK
1515-
case 29:
1523+
case 30:
15161524
YY_RULE_SETUP
15171525
{ return '<'; }
15181526
YY_BREAK
1519-
case 30:
1527+
case 31:
15201528
YY_RULE_SETUP
15211529
{ return '>'; }
15221530
YY_BREAK
1523-
case 31:
1531+
case 32:
15241532
YY_RULE_SETUP
15251533
{ return '+'; }
15261534
YY_BREAK
1527-
case 32:
1535+
case 33:
15281536
YY_RULE_SETUP
15291537
{ return '-'; }
15301538
YY_BREAK
1531-
case 33:
1539+
case 34:
15321540
YY_RULE_SETUP
15331541
{ return '*'; }
15341542
YY_BREAK
1535-
case 34:
1543+
case 35:
15361544
YY_RULE_SETUP
15371545
{ return '/'; }
15381546
YY_BREAK
1539-
case 35:
1547+
case 36:
15401548
YY_RULE_SETUP
15411549
{ return '%'; }
15421550
YY_BREAK
1543-
case 36:
1551+
case 37:
15441552
YY_RULE_SETUP
15451553
{ return '^'; }
15461554
YY_BREAK
1547-
case 37:
1555+
case 38:
15481556
YY_RULE_SETUP
15491557
{ return '&'; }
15501558
YY_BREAK
1551-
case 38:
1559+
case 39:
15521560
YY_RULE_SETUP
15531561
{ return '|'; }
15541562
YY_BREAK
1555-
case 39:
1563+
case 40:
15561564
YY_RULE_SETUP
15571565
{ return '!'; }
15581566
YY_BREAK
1559-
case 40:
1567+
case 41:
15601568
YY_RULE_SETUP
15611569
{ return '='; }
15621570
YY_BREAK
15631571
/* Syntactic elements */
1564-
case 41:
1572+
case 42:
15651573
YY_RULE_SETUP
15661574
{ return '('; }
15671575
YY_BREAK
1568-
case 42:
1576+
case 43:
15691577
YY_RULE_SETUP
15701578
{ return ')'; }
15711579
YY_BREAK
1572-
case 43:
1580+
case 44:
15731581
YY_RULE_SETUP
15741582
{ return '['; }
15751583
YY_BREAK
1576-
case 44:
1584+
case 45:
15771585
YY_RULE_SETUP
15781586
{ return ']'; }
15791587
YY_BREAK
1580-
case 45:
1588+
case 46:
15811589
YY_RULE_SETUP
15821590
{ return '?'; }
15831591
YY_BREAK
1584-
case 46:
1592+
case 47:
15851593
YY_RULE_SETUP
15861594
{ return ':'; }
15871595
YY_BREAK
1588-
case 47:
1596+
case 48:
15891597
YY_RULE_SETUP
15901598
{ return ','; }
15911599
YY_BREAK
15921600
/* Expression terminator */
1593-
case 48:
1601+
case 49:
15941602
YY_RULE_SETUP
15951603
{ return ';'; }
15961604
YY_BREAK
15971605
/* Ignored whitespace */
1598-
case 49:
1599-
/* rule 49 can match eol */
1606+
case 50:
1607+
/* rule 50 can match eol */
16001608
YY_RULE_SETUP
16011609
{ }
16021610
YY_BREAK
16031611
/* All other tokens are invalid */
1604-
case 50:
1612+
case 51:
16051613
YY_RULE_SETUP
16061614
{ return PRJM_EVAL_UNDEF; }
16071615
YY_BREAK
1608-
case 51:
1616+
case 52:
16091617
YY_RULE_SETUP
16101618
ECHO;
16111619
YY_BREAK

projectm-eval/Scanner.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "Compiler.h"
88

99
#include <stdio.h>
10+
#include <stdint.h>
1011

1112
#define YY_NO_UNISTD_H
1213
#define YY_STDINIT

projectm-eval/Scanner.l

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "Compiler.h"
1515

1616
#include <stdio.h>
17+
#include <stdint.h>
1718

1819
#define YY_NO_UNISTD_H
1920
#define YY_STDINIT
@@ -41,6 +42,7 @@ HEX [0-9a-fA-F]
4142
SIGN [+-]
4243
EXPO [eE]{SIGN}?{DIGIT}+
4344
FLOAT ({DIGIT}+|{DIGIT}+\.{DIGIT}*|{DIGIT}*\.{DIGIT}+){EXPO}?
45+
INT {DIGIT}+
4446
NAME [_a-zA-Z][_a-zA-Z0-9]*
4547

4648
%%
@@ -67,10 +69,14 @@ NAME [_a-zA-Z][_a-zA-Z0-9]*
6769

6870
(?i:gmem) { return GMEM; }
6971

70-
{FLOAT} {
72+
{FLOAT} {
7173
yylval->NUM = atof(yytext);
7274
return NUM;
7375
}
76+
{INT} {
77+
yylval->NUM = (PRJM_EVAL_F)atoi(yytext);
78+
return NUM;
79+
}
7480
{NAME} {
7581
if (prjm_eval_compiler_name_is_function(cctx, yytext))
7682
{

0 commit comments

Comments
 (0)