使用 BNF 语法将 c 变量的英文描述转换为 c 风格的变量声明
你好,我正在尝试编写一个语法,将英语 c 声明转换为 c 风格变量声明,例如: “x 是一个由 10 个指向 int 的指针组成的数组”, “x 是指向 char 的指针”, “x 是指向 type-struct 类型的结构的指针” <-> 整数*x[10], 字符**x, 结构类型-struct *x。
我的尝试: “{意味着有 0 个或多个项目}”
description ::= id declaration type
declaration ::= declarator
declarator ::= pointer|function|array
pointer ::= pointer-to {pointer-to} function|array
array ::= array-of-n {pointer-to}
function ::= function-that-return {pointer-to}
type ::= int|char|short|float...|spec-struct
spec-struct ::= struct type-struct
我想知道这个语法是否适合构建递归下降解析器。 谢谢。
Hello I'm trying to write a grammar that translate english c declaration into c-style variable declaration, for example:
"x is an array of 10 pointers to int",
"x is a pointer to pointer to char",
"x is a pointer to struct of type type-struct"
<->
int *x[10],
char **x,
struct type-struct *x.
My attempt:
"{means that there are 0 or more items}"
description ::= id declaration type
declaration ::= declarator
declarator ::= pointer|function|array
pointer ::= pointer-to {pointer-to} function|array
array ::= array-of-n {pointer-to}
function ::= function-that-return {pointer-to}
type ::= int|char|short|float...|spec-struct
spec-struct ::= struct type-struct
I want to know if this grammar is fine to build a recursive descent parser.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许,这已经足够了。但是,我建议您借助 LEX 看看您的语法是否正确和YACC 工具。
May be, this is sufficient. But, I would suggest you to see whether your grammar is fine with the help of a LEX and YACC tool.