解析类似C的定义字符串的最有效方法? [英] Most effective way to parse C-like definition strings?

查看:98
本文介绍了解析类似C的定义字符串的最有效方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用类似C的语言编写了一组函数定义,并且可以在某些参数之前放置一些其他关键字(例如,与"unsigned"或"register"相同的方式),并且分析这些行以及一些函数存根,并从中生成实际的C代码.

I've got a set of function definitions written in a C-like language with some additional keywords that can be put before some arguments(the same way as "unsigned" or "register", for example) and I need to analyze these lines as well as some function stubs and generate actual C code from them.

  • 是否正确地指出Flex/Yacc是最合适的方法?

  • Is that correct that Flex/Yacc are the most proper way to do it?

这比使用regexps编写Shell或Python脚本要慢(如果我想的话,这可能会变得很痛苦,如果其他关键字的数量变大并且它们的效果会大不相同),只要我有零的分析人员/分析人员经验(尽管我知道LALR的工作原理)?

Will it be slower than writing a Shell or Python script using regexps(which may become big pain, as I suppose, if the number of additional keywords becomes bigger and their effects would be rather different) provided that I have zero experience with analysers/parsers(though I know how LALR does its job)?

Lex/Yacc上是否有涉及类似问题的优质材料?我能找到的所有论文都使用相同的玩具"计算器示例.

Are there any good materials on Lex/Yacc that cover similar problems? All papers I could find use the same primitive example of a "toy" calculator.

任何帮助将不胜感激.

推荐答案

还有柠檬解析器,它具有较少的语法限制.不利的一面是您嫁给了柠檬,当发现某些限制很糟糕时,将解析器的语法重新编写为其他语法.好的一面是它非常易于使用.您可以将其放入树中,而不必担心检查其他人是否存在.

There is also the Lemon Parser, which features a less restrictive grammar. The down side is you're married to lemon, re-writing a parser's grammar to something else when you discover some limitation sucks. The up side is its really easy to use .. and self contained. You can drop it in tree and not worry about checking for the presence of others.

SQLite3 与其他一些流行项目一样使用它.我并不是说要使用它,因为SQLite确实可以使用它,但是如果时间允许,可以尝试一下.

SQLite3 uses it, as do several other popular projects. I'm not saying use it because SQLite does, but perhaps give it a try if time permits.

这篇关于解析类似C的定义字符串的最有效方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆