使用Boost :: Spirit的简单表达式解析器示例? [英] Simple expression parser example using Boost::Spirit?
问题描述
有人知道一个在线资源,我可以找到如何使用Boost :: Spirit编写一个简单的表达式解析器。
Is anyone aware of an online resource where I can find out how to write a simple expression parser using Boost::Spirit?.
我不一定需要评估表达式,但我需要解析它,并能够返回一个布尔值以指示表达式是否可解析(例如,括号不匹配等)。
I do not necessarily need to evaluate the expression, but I need to parse it and be able to return a boolean to indicate whether the expression is parsable or not (e.g. brackets not matching etc).
I需要解析器能够识别函数名(例如foo和foobar),所以这也将是一个有用的例子,帮助我学习编写BNF符号。
I need the parser to be able recognise function names (e.g. foo and foobar), so this would also be a useful example to help me learn writing BNF notation.
是正则算术方程,即包括以下符号:
The expressions will be normal arithmetic equations, i.e. comprising of the following symbols:
- 打开/关闭括号
推荐答案
Spirit(V2.x)的当前版本包含一系列从非常简单到完整的mini-c解释器的计算器示例。你应该看看那里,因为这是一个完美的起点,编写自己的表达式解析器。
The current version of Spirit (V2.x) contains a whole series of calculator examples from the very simple to a full fledged mini-c interpreter. You should have a look there as those are a perfect starting point for writing your own expression parser.
这篇关于使用Boost :: Spirit的简单表达式解析器示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!