GOLD 解析器:ANSI-C 语法实际上并未解析 ANSI-C?
我正在尝试测试 GOLD Parser 网站上提供的 ANSI-C 语法。 我似乎无法完全解析最小的 C 文件。
示例:
int test_inc1(void)
{
int t;
t = 2 + 2;
return 0;
}
它找到 int 作为类型,然后 test_inc1 作为 Id,然后正确地找到括号,但在第二个 ) 之后,它需要一个 ;而不是 {.所以它会抛出语法错误。 我对这些时髦的语法很陌生。我只是想将我的代码解析为 AST :(
I'm trying to test the ANSI-C grammar provided on the GOLD Parser website.
I can'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 :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据语法,第一行可能是
,如果它以分号终止:对于解析函数声明,引用语法的产生式应该与之间的部分匹配括号:
void
对于
来说是可以的,但是语法要求的ID
不存在。但语法中也包含这样的提示:
所以也许不应该太认真地对待它。
According to the grammar, the first line could be a
<Func Proto>
, if it was terminated by a semicolon:For parsing a function declaration, this production from the quoted grammar should have matched the part between the parentheses:
void
was OK for the<Type>
, but theID
that the grammar asks for just is not there.But the grammar also contains this hint:
so it should probably not be taken too seriously.