fcl-res: numeric expressions

Reintegrate fpcres-rc branch by Martok

git-svn-id: trunk@46379 -
This commit is contained in:
svenbarth 2020-08-12 19:05:21 +00:00
parent 8a10f1651d
commit 1ee401aee1
4 changed files with 1990 additions and 1409 deletions

View File

@ -92,9 +92,9 @@ begin
return(_ILLEGAL); return(_ILLEGAL);
8: 8:
return(_NUMDECIMAL); return(_NUMBER);
9: 9:
return(_NUMHEX); return(_NUMBER);
10: 10:
begin start(INSTRING); strbuf:= ''; end; begin start(INSTRING); strbuf:= ''; end;
11: 11:
@ -151,8 +151,8 @@ type YYTRec = record
const const
yynmarks = 59; yynmarks = 60;
yynmatches = 59; yynmatches = 60;
yyntrans = 116; yyntrans = 116;
yynstates = 88; yynstates = 88;
@ -170,6 +170,7 @@ yyk : array [1..yynmarks] of Integer = (
{ 8: } { 8: }
{ 9: } { 9: }
{ 10: } { 10: }
23,
24, 24,
{ 11: } { 11: }
8, 8,
@ -320,6 +321,7 @@ yym : array [1..yynmatches] of Integer = (
{ 8: } { 8: }
{ 9: } { 9: }
{ 10: } { 10: }
23,
24, 24,
{ 11: } { 11: }
8, 8,
@ -458,12 +460,12 @@ yym : array [1..yynmatches] of Integer = (
yyt : array [1..yyntrans] of YYTrec = ( yyt : array [1..yyntrans] of YYTrec = (
{ 0: } { 0: }
( cc: [ #1..#8,#11,#13..#31,'!','#'..'''','*','+', ( cc: [ #1..#8,#11,#13..#31,'!','#','$','''','*','+',
'-','.',':'..'@','['..'^','`','|','~'..#255 ]; s: 23), '-','.',':'..'@','['..']','`',#127..#255 ]; s: 23),
( cc: [ #9,#12,' ' ]; s: 22), ( cc: [ #9,#12,' ' ]; s: 22),
( cc: [ #10 ]; s: 20), ( cc: [ #10 ]; s: 20),
( cc: [ '"' ]; s: 14), ( cc: [ '"' ]; s: 14),
( cc: [ '(',')',',' ]; s: 21), ( cc: [ '%','&','(',')',',','^','|','~' ]; s: 21),
( cc: [ '/' ]; s: 10), ( cc: [ '/' ]; s: 10),
( cc: [ '0' ]; s: 13), ( cc: [ '0' ]; s: 13),
( cc: [ '1'..'9' ]; s: 11), ( cc: [ '1'..'9' ]; s: 11),
@ -474,12 +476,12 @@ yyt : array [1..yyntrans] of YYTrec = (
( cc: [ '{' ]; s: 16), ( cc: [ '{' ]; s: 16),
( cc: [ '}' ]; s: 18), ( cc: [ '}' ]; s: 18),
{ 1: } { 1: }
( cc: [ #1..#8,#11,#13..#31,'!','#'..'''','*','+', ( cc: [ #1..#8,#11,#13..#31,'!','#','$','''','*','+',
'-','.',':'..'@','['..'^','`','|','~'..#255 ]; s: 23), '-','.',':'..'@','['..']','`',#127..#255 ]; s: 23),
( cc: [ #9,#12,' ' ]; s: 22), ( cc: [ #9,#12,' ' ]; s: 22),
( cc: [ #10 ]; s: 20), ( cc: [ #10 ]; s: 20),
( cc: [ '"' ]; s: 14), ( cc: [ '"' ]; s: 14),
( cc: [ '(',')',',' ]; s: 21), ( cc: [ '%','&','(',')',',','^','|','~' ]; s: 21),
( cc: [ '/' ]; s: 10), ( cc: [ '/' ]; s: 10),
( cc: [ '0' ]; s: 13), ( cc: [ '0' ]; s: 13),
( cc: [ '1'..'9' ]; s: 11), ( cc: [ '1'..'9' ]; s: 11),
@ -677,52 +679,143 @@ yykl : array [0..yynstates-1] of Integer = (
{ 8: } 3, { 8: } 3,
{ 9: } 3, { 9: } 3,
{ 10: } 3, { 10: } 3,
{ 11: } 4, { 11: } 5,
{ 12: } 6, { 12: } 7,
{ 13: } 9, { 13: } 10,
{ 14: } 11, { 14: } 12,
{ 15: } 13, { 15: } 14,
{ 16: } 15, { 16: } 16,
{ 17: } 17, { 17: } 18,
{ 18: } 19, { 18: } 20,
{ 19: } 21, { 19: } 22,
{ 20: } 23, { 20: } 24,
{ 21: } 24, { 21: } 25,
{ 22: } 26, { 22: } 27,
{ 23: } 28, { 23: } 29,
{ 24: } 29, { 24: } 30,
{ 25: } 30, { 25: } 31,
{ 26: } 31, { 26: } 32,
{ 27: } 32, { 27: } 33,
{ 28: } 33, { 28: } 34,
{ 29: } 34, { 29: } 35,
{ 30: } 36, { 30: } 37,
{ 31: } 37, { 31: } 38,
{ 32: } 38, { 32: } 39,
{ 33: } 39, { 33: } 40,
{ 34: } 40, { 34: } 41,
{ 35: } 41, { 35: } 42,
{ 36: } 42, { 36: } 43,
{ 37: } 43, { 37: } 44,
{ 38: } 44, { 38: } 45,
{ 39: } 46,
{ 40: } 46,
{ 41: } 46,
{ 42: } 46,
{ 43: } 47,
{ 44: } 48,
{ 45: } 49,
{ 46: } 50,
{ 47: } 51,
{ 48: } 52,
{ 49: } 52,
{ 50: } 53,
{ 51: } 55,
{ 52: } 55,
{ 53: } 55,
{ 54: } 55,
{ 55: } 56,
{ 56: } 56,
{ 57: } 58,
{ 58: } 58,
{ 59: } 58,
{ 60: } 58,
{ 61: } 58,
{ 62: } 58,
{ 63: } 58,
{ 64: } 58,
{ 65: } 58,
{ 66: } 58,
{ 67: } 59,
{ 68: } 60,
{ 69: } 61,
{ 70: } 61,
{ 71: } 61,
{ 72: } 61,
{ 73: } 61,
{ 74: } 61,
{ 75: } 61,
{ 76: } 61,
{ 77: } 61,
{ 78: } 61,
{ 79: } 61,
{ 80: } 61,
{ 81: } 61,
{ 82: } 61,
{ 83: } 61,
{ 84: } 61,
{ 85: } 61,
{ 86: } 61,
{ 87: } 61
);
yykh : array [0..yynstates-1] of Integer = (
{ 0: } 1,
{ 1: } 2,
{ 2: } 2,
{ 3: } 2,
{ 4: } 2,
{ 5: } 2,
{ 6: } 2,
{ 7: } 2,
{ 8: } 2,
{ 9: } 2,
{ 10: } 4,
{ 11: } 6,
{ 12: } 9,
{ 13: } 11,
{ 14: } 13,
{ 15: } 15,
{ 16: } 17,
{ 17: } 19,
{ 18: } 21,
{ 19: } 23,
{ 20: } 24,
{ 21: } 26,
{ 22: } 28,
{ 23: } 29,
{ 24: } 30,
{ 25: } 31,
{ 26: } 32,
{ 27: } 33,
{ 28: } 34,
{ 29: } 36,
{ 30: } 37,
{ 31: } 38,
{ 32: } 39,
{ 33: } 40,
{ 34: } 41,
{ 35: } 42,
{ 36: } 43,
{ 37: } 44,
{ 38: } 45,
{ 39: } 45, { 39: } 45,
{ 40: } 45, { 40: } 45,
{ 41: } 45, { 41: } 45,
{ 42: } 45, { 42: } 46,
{ 43: } 46, { 43: } 47,
{ 44: } 47, { 44: } 48,
{ 45: } 48, { 45: } 49,
{ 46: } 49, { 46: } 50,
{ 47: } 50, { 47: } 51,
{ 48: } 51, { 48: } 51,
{ 49: } 51, { 49: } 52,
{ 50: } 52, { 50: } 54,
{ 51: } 54, { 51: } 54,
{ 52: } 54, { 52: } 54,
{ 53: } 54, { 53: } 54,
{ 54: } 54, { 54: } 55,
{ 55: } 55, { 55: } 55,
{ 56: } 55, { 56: } 57,
{ 57: } 57, { 57: } 57,
{ 58: } 57, { 58: } 57,
{ 59: } 57, { 59: } 57,
@ -732,9 +825,9 @@ yykl : array [0..yynstates-1] of Integer = (
{ 63: } 57, { 63: } 57,
{ 64: } 57, { 64: } 57,
{ 65: } 57, { 65: } 57,
{ 66: } 57, { 66: } 58,
{ 67: } 58, { 67: } 59,
{ 68: } 59, { 68: } 60,
{ 69: } 60, { 69: } 60,
{ 70: } 60, { 70: } 60,
{ 71: } 60, { 71: } 60,
@ -756,97 +849,6 @@ yykl : array [0..yynstates-1] of Integer = (
{ 87: } 60 { 87: } 60
); );
yykh : array [0..yynstates-1] of Integer = (
{ 0: } 1,
{ 1: } 2,
{ 2: } 2,
{ 3: } 2,
{ 4: } 2,
{ 5: } 2,
{ 6: } 2,
{ 7: } 2,
{ 8: } 2,
{ 9: } 2,
{ 10: } 3,
{ 11: } 5,
{ 12: } 8,
{ 13: } 10,
{ 14: } 12,
{ 15: } 14,
{ 16: } 16,
{ 17: } 18,
{ 18: } 20,
{ 19: } 22,
{ 20: } 23,
{ 21: } 25,
{ 22: } 27,
{ 23: } 28,
{ 24: } 29,
{ 25: } 30,
{ 26: } 31,
{ 27: } 32,
{ 28: } 33,
{ 29: } 35,
{ 30: } 36,
{ 31: } 37,
{ 32: } 38,
{ 33: } 39,
{ 34: } 40,
{ 35: } 41,
{ 36: } 42,
{ 37: } 43,
{ 38: } 44,
{ 39: } 44,
{ 40: } 44,
{ 41: } 44,
{ 42: } 45,
{ 43: } 46,
{ 44: } 47,
{ 45: } 48,
{ 46: } 49,
{ 47: } 50,
{ 48: } 50,
{ 49: } 51,
{ 50: } 53,
{ 51: } 53,
{ 52: } 53,
{ 53: } 53,
{ 54: } 54,
{ 55: } 54,
{ 56: } 56,
{ 57: } 56,
{ 58: } 56,
{ 59: } 56,
{ 60: } 56,
{ 61: } 56,
{ 62: } 56,
{ 63: } 56,
{ 64: } 56,
{ 65: } 56,
{ 66: } 57,
{ 67: } 58,
{ 68: } 59,
{ 69: } 59,
{ 70: } 59,
{ 71: } 59,
{ 72: } 59,
{ 73: } 59,
{ 74: } 59,
{ 75: } 59,
{ 76: } 59,
{ 77: } 59,
{ 78: } 59,
{ 79: } 59,
{ 80: } 59,
{ 81: } 59,
{ 82: } 59,
{ 83: } 59,
{ 84: } 59,
{ 85: } 59,
{ 86: } 59,
{ 87: } 59
);
yyml : array [0..yynstates-1] of Integer = ( yyml : array [0..yynstates-1] of Integer = (
{ 0: } 1, { 0: } 1,
{ 1: } 2, { 1: } 2,
@ -859,52 +861,143 @@ yyml : array [0..yynstates-1] of Integer = (
{ 8: } 3, { 8: } 3,
{ 9: } 3, { 9: } 3,
{ 10: } 3, { 10: } 3,
{ 11: } 4, { 11: } 5,
{ 12: } 6, { 12: } 7,
{ 13: } 9, { 13: } 10,
{ 14: } 11, { 14: } 12,
{ 15: } 13, { 15: } 14,
{ 16: } 15, { 16: } 16,
{ 17: } 17, { 17: } 18,
{ 18: } 19, { 18: } 20,
{ 19: } 21, { 19: } 22,
{ 20: } 23, { 20: } 24,
{ 21: } 24, { 21: } 25,
{ 22: } 26, { 22: } 27,
{ 23: } 28, { 23: } 29,
{ 24: } 29, { 24: } 30,
{ 25: } 30, { 25: } 31,
{ 26: } 31, { 26: } 32,
{ 27: } 32, { 27: } 33,
{ 28: } 33, { 28: } 34,
{ 29: } 34, { 29: } 35,
{ 30: } 36, { 30: } 37,
{ 31: } 37, { 31: } 38,
{ 32: } 38, { 32: } 39,
{ 33: } 39, { 33: } 40,
{ 34: } 40, { 34: } 41,
{ 35: } 41, { 35: } 42,
{ 36: } 42, { 36: } 43,
{ 37: } 43, { 37: } 44,
{ 38: } 44, { 38: } 45,
{ 39: } 46,
{ 40: } 46,
{ 41: } 46,
{ 42: } 46,
{ 43: } 47,
{ 44: } 48,
{ 45: } 49,
{ 46: } 50,
{ 47: } 51,
{ 48: } 52,
{ 49: } 52,
{ 50: } 53,
{ 51: } 55,
{ 52: } 55,
{ 53: } 55,
{ 54: } 55,
{ 55: } 56,
{ 56: } 56,
{ 57: } 58,
{ 58: } 58,
{ 59: } 58,
{ 60: } 58,
{ 61: } 58,
{ 62: } 58,
{ 63: } 58,
{ 64: } 58,
{ 65: } 58,
{ 66: } 58,
{ 67: } 59,
{ 68: } 60,
{ 69: } 61,
{ 70: } 61,
{ 71: } 61,
{ 72: } 61,
{ 73: } 61,
{ 74: } 61,
{ 75: } 61,
{ 76: } 61,
{ 77: } 61,
{ 78: } 61,
{ 79: } 61,
{ 80: } 61,
{ 81: } 61,
{ 82: } 61,
{ 83: } 61,
{ 84: } 61,
{ 85: } 61,
{ 86: } 61,
{ 87: } 61
);
yymh : array [0..yynstates-1] of Integer = (
{ 0: } 1,
{ 1: } 2,
{ 2: } 2,
{ 3: } 2,
{ 4: } 2,
{ 5: } 2,
{ 6: } 2,
{ 7: } 2,
{ 8: } 2,
{ 9: } 2,
{ 10: } 4,
{ 11: } 6,
{ 12: } 9,
{ 13: } 11,
{ 14: } 13,
{ 15: } 15,
{ 16: } 17,
{ 17: } 19,
{ 18: } 21,
{ 19: } 23,
{ 20: } 24,
{ 21: } 26,
{ 22: } 28,
{ 23: } 29,
{ 24: } 30,
{ 25: } 31,
{ 26: } 32,
{ 27: } 33,
{ 28: } 34,
{ 29: } 36,
{ 30: } 37,
{ 31: } 38,
{ 32: } 39,
{ 33: } 40,
{ 34: } 41,
{ 35: } 42,
{ 36: } 43,
{ 37: } 44,
{ 38: } 45,
{ 39: } 45, { 39: } 45,
{ 40: } 45, { 40: } 45,
{ 41: } 45, { 41: } 45,
{ 42: } 45, { 42: } 46,
{ 43: } 46, { 43: } 47,
{ 44: } 47, { 44: } 48,
{ 45: } 48, { 45: } 49,
{ 46: } 49, { 46: } 50,
{ 47: } 50, { 47: } 51,
{ 48: } 51, { 48: } 51,
{ 49: } 51, { 49: } 52,
{ 50: } 52, { 50: } 54,
{ 51: } 54, { 51: } 54,
{ 52: } 54, { 52: } 54,
{ 53: } 54, { 53: } 54,
{ 54: } 54, { 54: } 55,
{ 55: } 55, { 55: } 55,
{ 56: } 55, { 56: } 57,
{ 57: } 57, { 57: } 57,
{ 58: } 57, { 58: } 57,
{ 59: } 57, { 59: } 57,
@ -914,9 +1007,9 @@ yyml : array [0..yynstates-1] of Integer = (
{ 63: } 57, { 63: } 57,
{ 64: } 57, { 64: } 57,
{ 65: } 57, { 65: } 57,
{ 66: } 57, { 66: } 58,
{ 67: } 58, { 67: } 59,
{ 68: } 59, { 68: } 60,
{ 69: } 60, { 69: } 60,
{ 70: } 60, { 70: } 60,
{ 71: } 60, { 71: } 60,
@ -938,97 +1031,6 @@ yyml : array [0..yynstates-1] of Integer = (
{ 87: } 60 { 87: } 60
); );
yymh : array [0..yynstates-1] of Integer = (
{ 0: } 1,
{ 1: } 2,
{ 2: } 2,
{ 3: } 2,
{ 4: } 2,
{ 5: } 2,
{ 6: } 2,
{ 7: } 2,
{ 8: } 2,
{ 9: } 2,
{ 10: } 3,
{ 11: } 5,
{ 12: } 8,
{ 13: } 10,
{ 14: } 12,
{ 15: } 14,
{ 16: } 16,
{ 17: } 18,
{ 18: } 20,
{ 19: } 22,
{ 20: } 23,
{ 21: } 25,
{ 22: } 27,
{ 23: } 28,
{ 24: } 29,
{ 25: } 30,
{ 26: } 31,
{ 27: } 32,
{ 28: } 33,
{ 29: } 35,
{ 30: } 36,
{ 31: } 37,
{ 32: } 38,
{ 33: } 39,
{ 34: } 40,
{ 35: } 41,
{ 36: } 42,
{ 37: } 43,
{ 38: } 44,
{ 39: } 44,
{ 40: } 44,
{ 41: } 44,
{ 42: } 45,
{ 43: } 46,
{ 44: } 47,
{ 45: } 48,
{ 46: } 49,
{ 47: } 50,
{ 48: } 50,
{ 49: } 51,
{ 50: } 53,
{ 51: } 53,
{ 52: } 53,
{ 53: } 53,
{ 54: } 54,
{ 55: } 54,
{ 56: } 56,
{ 57: } 56,
{ 58: } 56,
{ 59: } 56,
{ 60: } 56,
{ 61: } 56,
{ 62: } 56,
{ 63: } 56,
{ 64: } 56,
{ 65: } 56,
{ 66: } 57,
{ 67: } 58,
{ 68: } 59,
{ 69: } 59,
{ 70: } 59,
{ 71: } 59,
{ 72: } 59,
{ 73: } 59,
{ 74: } 59,
{ 75: } 59,
{ 76: } 59,
{ 77: } 59,
{ 78: } 59,
{ 79: } 59,
{ 80: } 59,
{ 81: } 59,
{ 82: } 59,
{ 83: } 59,
{ 84: } 59,
{ 85: } 59,
{ 86: } 59,
{ 87: } 59
);
yytl : array [0..yynstates-1] of Integer = ( yytl : array [0..yynstates-1] of Integer = (
{ 0: } 1, { 0: } 1,
{ 1: } 15, { 1: } 15,

View File

@ -75,8 +75,8 @@ IDENT [a-zA-Z_]([a-zA-Z0-9_])*
<INCOMMENT>"*/" start(0); <INCOMMENT>"*/" start(0);
<INCOMMENT>\0 return(_ILLEGAL); <INCOMMENT>\0 return(_ILLEGAL);
{D}*L? return(_NUMDECIMAL); {D}*L? return(_NUMBER);
0x{H}*L? return(_NUMHEX); 0x{H}*L? return(_NUMBER);
\" begin start(INSTRING); strbuf:= ''; end; \" begin start(INSTRING); strbuf:= ''; end;
<INSTRING>\"\" strbuf:= strbuf + '"'; <INSTRING>\"\" strbuf:= strbuf + '"';
<INSTRING>\" begin <INSTRING>\" begin
@ -104,7 +104,7 @@ END|} return(_END);
return(_ID); return(_ID);
end; end;
[ \t\n\f] ; [ \t\n\f] ;
[,()] returnc(yytext[1]); [,()|^&+-*/%~] returnc(yytext[1]);
. return(_ILLEGAL); . return(_ILLEGAL);
%% %%

File diff suppressed because it is too large Load Diff

View File

@ -126,6 +126,14 @@ begin
Result.v:= StrToInt(s); Result.v:= StrToInt(s);
end; end;
function Max(a, b: LongWord): LongWord; inline;
begin
if a > b then
Result:= a
else
Result:= b;
end;
var var
aktresource: TAbstractResource; aktresource: TAbstractResource;
language: TLangID; language: TLangID;
@ -231,7 +239,7 @@ var
%} %}
%token _ILLEGAL %token _ILLEGAL
%token _NUMDECIMAL _NUMHEX _QUOTEDSTR %token _NUMBER _QUOTEDSTR
%token _STR_StringFileInfo _STR_VarFileInfo _STR_Translation %token _STR_StringFileInfo _STR_VarFileInfo _STR_Translation
%token _BEGIN _END _ID %token _BEGIN _END _ID
%token _LANGUAGE _CHARACTERISTICS _VERSION _MOVEABLE _FIXED _PURE _IMPURE _PRELOAD _LOADONCALL _DISCARDABLE %token _LANGUAGE _CHARACTERISTICS _VERSION _MOVEABLE _FIXED _PURE _IMPURE _PRELOAD _LOADONCALL _DISCARDABLE
@ -246,6 +254,13 @@ var
%type <TMemoryStream> raw_data raw_item %type <TMemoryStream> raw_data raw_item
%type <TFileStream> filename_string %type <TFileStream> filename_string
%left '|'
%left '^'
%left '&'
%left '+' '-'
%left '*' '/' '%'
%right '~' _NUMNEG
%% %%
rcfile rcfile
@ -379,13 +394,22 @@ numpos
; ;
numeral numeral
: _NUMDECIMAL { $$:= str_to_num(yytext); } : _NUMBER { $$:= str_to_num(yytext); }
| _NUMHEX { $$:= str_to_num(yytext); }
; ;
numexpr numexpr
: numeral : numeral
| '(' numexpr ')' { $$:= $2; } | '(' numexpr ')' { $$:= $2; }
| '~' numexpr %prec '~' { $$.v:= not $2.v; $$.long:= $2.long; }
| '-' numexpr %prec _NUMNEG { $$.v:= -$2.v; $$.long:= $2.long; }
| numexpr '*' numexpr { $$.v:= $1.v * $3.v; $$.long:= $1.long or $3.long; }
| numexpr '/' numexpr { $$.v:= $1.v div Max(1, $3.v); $$.long:= $1.long or $3.long; }
| numexpr '%' numexpr { $$.v:= $1.v mod Max(1, $3.v); $$.long:= $1.long or $3.long; }
| numexpr '+' numexpr { $$.v:= $1.v + $3.v; $$.long:= $1.long or $3.long; }
| numexpr '-' numexpr { $$.v:= $1.v - $3.v; $$.long:= $1.long or $3.long; }
| numexpr '&' numexpr { $$.v:= $1.v and $3.v; $$.long:= $1.long or $3.long; }
| numexpr '^' numexpr { $$.v:= $1.v xor $3.v; $$.long:= $1.long or $3.long; }
| numexpr '|' numexpr { $$.v:= $1.v or $3.v; $$.long:= $1.long or $3.long; }
; ;
ident_string ident_string