你好,我正在尝试编写一个语法,将英语 c 声明转换为 c 风格变量声明,例如: “x 是一个由 10 个指向 int 的指针组成的数组”, “x 是指向 char 的指针”, “x 是指向 type-struct 类型的结构的指针” <-> 整数*x[10], 字符**x, struct 类型-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
我想知道这个语法是否适合构建递归下降解析器。 谢谢。
最佳答案
关于c - 使用 BNF 语法将 c 变量的英文描述转换为 c 风格的变量声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7795938/