c - 使用 BNF 语法将 c 变量的英文描述转换为 c 风格的变量声明

标签 c grammar bnf

你好,我正在尝试编写一个语法,将英语 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

我想知道这个语法是否适合构建递归下降解析器。 谢谢。

最佳答案

也许,这已经足够了。但是,我建议您借助 LEX 看看您的语法是否正确。和 YACC tool .

关于c - 使用 BNF 语法将 c 变量的英文描述转换为 c 风格的变量声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7795938/

相关文章:

c++ - Boost.Spirit SQL 语法/词法分析器失败

antlr - 是否有工具可以在 ANTLR 和其他形式的 BNF 之间进行转换?

c++ - 将数组作为操作数的语法

c - 用于 DMA 的快速映射内存缓冲区

自定义 PCI 驱动程序无法探测设备

compiler-errors - (...)*构造中的JAVACC ERROR选择冲突

c++ - Gnuplot 保存许 multimap 像

debugging - ANTLRWorks 调试 - 不同颜色的含义?

antlr - 帮助对语法进行左分解以消除左递归