0

我正在尝试测试 GOLD Parser 网站上提供的 ANSI-C 语法。我似乎无法完全解析最小的 C 文件。

例子:

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

它找到 int 作为一个类型,然后 test_inc1 作为一个 Id,然后括号正确但在第二个 ) 之后,它期待一个 ; 代替 {。所以它会引发语法错误。我对所有这些语法时髦都很陌生。我只是想将我的代码解析为 AST :(

4

1 回答 1

1

根据语法,如果第一行<Func Proto>以分号结尾,则它可以是 a :

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

为了解析函数声明,引用语法的这个产生应该匹配括号之间的部分:

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

void是可以的<Type>,但是ID语法要求的只是不存在。

但是语法也包含这个提示:

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

所以可能不应该太认真。

于 2011-10-18T21:08:06.323 回答