Skip to content

[c] AsmBlock rule wrong, not ISO C11 anyways. #4609

@kaby76

Description

@kaby76

Noted here: https://stackoverflow.com/q/79751222/4779853

This input fails to parse because generated parser tokenizes the input wrong.

int main(int argc,char **argv)
{
  void asm_something();

  while (1) {
    if (!--argc) {  
         break; }
      else ++argv;
    
    break;
  }
  return 1;
}
$ ./bin/Debug/net8.0/Test.exe x -tokens
[@0,0:2='int',<37>,1:0]
[@1,3:3=' ',<117>,channel=1,1:3]
[@2,4:7='main',<110>,1:4]
[@3,8:8='(',<64>,1:8]
[@4,9:11='int',<37>,1:9]
[@5,12:12=' ',<117>,channel=1,1:12]
[@6,13:16='argc',<110>,1:13]
[@7,17:17=',',<93>,1:17]
[@8,18:21='char',<23>,1:18]
[@9,22:22=' ',<117>,channel=1,1:22]
[@10,23:23='*',<80>,1:23]
[@11,24:24='*',<80>,1:24]
[@12,25:28='argv',<110>,1:25]
[@13,29:29=')',<65>,1:29]
[@14,30:31='\r\n',<118>,channel=1,1:30]
[@15,32:32='{',<68>,2:0]
[@16,33:34='\r\n',<118>,channel=1,2:1]
[@17,35:36='  ',<117>,channel=1,3:0]
[@18,37:40='void',<51>,3:2]
[@19,41:41=' ',<117>,channel=1,3:6]
[@20,42:128='asm_something();\r\nvoid xxx();\r\n\r\n  while (1) {\r\n    if (!--argc) {  \r\n         break; }',<116>,channel=1,3:7]
[@21,129:130='\r\n',<118>,channel=1,8:17]
[@22,131:136='      ',<117>,channel=1,9:0]
[@23,137:140='else',<29>,9:6]
[@24,141:141=' ',<117>,channel=1,9:10]
[@25,142:143='++',<77>,9:11]
[@26,144:147='argv',<110>,9:13]
[@27,148:148=';',<92>,9:17]
[@28,149:150='\r\n',<118>,channel=1,9:18]
[@29,151:154='    ',<117>,channel=1,10:0]
[@30,155:156='\r\n',<118>,channel=1,10:4]
[@31,157:160='    ',<117>,channel=1,11:0]
[@32,161:165='break',<21>,11:4]
[@33,166:166=';',<92>,11:9]
[@34,167:168='\r\n',<118>,channel=1,11:10]
[@35,169:170='  ',<117>,channel=1,12:0]
[@36,171:171='}',<69>,12:2]
[@37,172:173='\r\n',<118>,channel=1,12:3]
[@38,174:175='  ',<117>,channel=1,13:0]
[@39,176:181='return',<41>,13:2]
[@40,182:182=' ',<117>,channel=1,13:8]
[@41,183:183='1',<111>,13:9]
[@42,184:184=';',<92>,13:10]
[@43,185:186='\r\n',<118>,channel=1,13:11]
[@44,187:187='}',<69>,14:0]
[@45,188:187='<EOF>',<-1>,14:1]

line 9:6 mismatched input 'else' expecting {'__stdcall', '__cdecl', '__clrcall', '__fastcall', '__thiscall', '__vectorcall', '(', '*', '^', ';', Identifier}
line 13:2 mismatched input 'return' expecting <EOF>
CSharp 0 x fail 0.0497374
Total Time: 0.1241031
08/30-12:56:58 ~/issues/g4-current/c/Generated-CSharp

Essentially, the AsmBlock rule is wrong.

In addition, the ISO spec says this is strictly an extension. We need to add a flag for extensions, or two grammars (with import) to allow--or not--extensions.

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions