开发者

GOLD Parser : ANSI-C grammar not actually parsing ANSI-C?

开发者 https://www.devze.com 2023-03-28 04:49 出处:网络
I\'m trying to test the ANSI-C grammar provided on the GOLD Parser website. I ca开发者_如何学Gon\'t seem to even completly parse the smallest of the C file.

I'm trying to test the ANSI-C grammar provided on the GOLD Parser website. I ca开发者_如何学Gon't seem to even completly parse the smallest of the C file.

Example:

int test_inc1(void)
{
  int t;
  t = 2 + 2;
  return 0;
}

It find int as a type, then test_inc1 as an Id, then parantheses correctly but after the second ), it is expecting a ; instead of a {. So it throws a syntax error. I'm very new into all this grammar funkyness. I'd simply like to parse my code into an AST :(


According to the grammar, the first line could be a <Func Proto>, if it was terminated by a semicolon:

<Func Proto> ::= <Func ID> '(' <Types>  ')' ';'
               | <Func ID> '(' <Params> ')' ';'
               | <Func ID> '(' ')' ';'

For parsing a function declaration, this production from the quoted grammar should have matched the part between the parentheses:

<Param>      ::= const <Type> ID
               |       <Type> ID

void was OK for the <Type>, but the ID that the grammar asks for just is not there.

But the grammar also contains this hint:

! Note: This is an ad hoc version of the language. If there are any flaws, 
! please visit the contact page and tell me.

so it should probably not be taken too seriously.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号