From 4fe9c909421981975ab88815e7200715f1829918 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 10 Oct 2022 18:06:01 -0500 Subject: [PATCH] Parse ... as a single punctuator token. This accords with its definition in the C standards. For the time being, the old form of three separate tokens is still accepted too, because the ... token may not be scanned correctly in the obscure case where there is a line continuation between the second and third dots. One observable effect of this is that there are no longer spaces between the dots in #pragma expand output. --- CCommon.pas | 2 +- Header.pas | 2 +- Parser.pas | 9 +++++++-- Scanner.pas | 32 ++++++++++++++++++++++---------- Table.asm | 4 +++- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/CCommon.pas b/CCommon.pas index 30b34d6..3fec42f 100644 --- a/CCommon.pas +++ b/CCommon.pas @@ -195,7 +195,7 @@ type lteqop,gteqop,eqeqop,exceqop,andandop, barbarop,pluseqop,minuseqop,asteriskeqop,slasheqop, percenteqop,ltlteqop,gtgteqop,andeqop,caroteqop, - bareqop,poundpoundop, + bareqop,poundpoundop,dotdotdotsy, eolsy,eofsy, {control characters} typedef, {user types} uminus,uand,uasterisk, {converted operations} diff --git a/Header.pas b/Header.pas index 0dbd579..50ce175 100644 --- a/Header.pas +++ b/Header.pas @@ -18,7 +18,7 @@ uses CCommon, MM, Scanner, Symbol, CGI; {$segment 'SCANNER'} const - symFileVersion = 28; {version number of .sym file format} + symFileVersion = 29; {version number of .sym file format} var inhibitHeader: boolean; {should .sym includes be blocked?} diff --git a/Parser.pas b/Parser.pas index e6b3e3f..ce10e00 100644 --- a/Parser.pas +++ b/Parser.pas @@ -1500,13 +1500,18 @@ var end; {if} if token.kind = commach then begin NextToken; - if token.kind = dotch then begin + if token.kind = dotdotdotsy then begin + NextToken; + varargs := true; + done2 := true; + end {if} + else if token.kind = dotch then begin NextToken; Match(dotch,89); Match(dotch,89); varargs := true; done2 := true; - end; {if} + end; {else if} end {if} else done2 := true; diff --git a/Scanner.pas b/Scanner.pas index 9362be7..6673611 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -1039,6 +1039,8 @@ case token.kind of else write('%:%:'); + dotdotdotsy: write('...'); + macroParm: write('$', token.pnum:1); parameteroper, @@ -2583,17 +2585,21 @@ var done := false; end; {if} end {if} - else if token.kind = dotch then begin - NextToken; - if token.kind = dotch then begin - NextToken; - if token.kind = dotch then - NextToken + else if token.kind in [dotch,dotdotdotsy] then begin + if token.kind = dotdotdotsy then + NextToken + else begin + NextToken; + if token.kind = dotch then begin + NextToken; + if token.kind = dotch then + NextToken + else + Error(89); + end else Error(89); - end - else - Error(89); + end; {else} new(np); np^.next := nil; np^.str := '__VA_ARGS__'; @@ -5229,7 +5235,13 @@ case charKinds[ord(ch)] of DoNumber(false) else begin NextCh; - token.kind := dotch; + if (ch = '.') and (chPtr <> eofPtr) and (chr(chPtr^) = '.') then begin + token.kind := dotdotdotsy; + NextCh; + NextCh; + end {if} + else + token.kind := dotch; end; {else} end; diff --git a/Table.asm b/Table.asm index a3cd7d3..d0ae402 100644 --- a/Table.asm +++ b/Table.asm @@ -308,7 +308,7 @@ charSym start single character symbols enum (lteqop,gteqop,eqeqop,exceqop,andandop) enum (barbarop,pluseqop,minuseqop,asteriskeqop,slasheqop) enum (percenteqop,ltlteqop,gtgteqop,andeqop,caroteqop) - enum (bareqop,poundpoundop) + enum (bareqop,poundpoundop,dotdotdotsy) enum (eolsy,eofsy) control characters enum (typedef) user types enum (uminus,uand,uasterisk) converted operations @@ -464,6 +464,7 @@ icp start in-coming priority for expression dc i1'3' caroteqop dc i1'3' bareqop dc i1'200' poundpoundop + dc i1'200' dotdotdotsy dc i1'200' eolsy dc i1'200' eofsy dc i1'200' typedef @@ -639,6 +640,7 @@ isp start in stack priority for expression dc i1'2' caroteqop dc i1'2' bareqop dc i1'0' poundpoundop + dc i1'0' dotdotdotsy dc i1'0' eolsy dc i1'0' eofsy dc i1'0' typedef