如果条件解析器,则创建C ++. [英] Create C++ if condition parser.

查看:90
本文介绍了如果条件解析器,则创建C ++.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

最近两天我遇到麻烦了.我必须解析字符串模式,例如

Hello friends,

I am in trouble for last 2 days. I have to parse string pattern like,

([nDeductible]==76)&&( [nLimit] == 5 ||  [nLimit] == 9 ||  [nLimit] == 7 )  ||  ( [nFees]  >= 8 && [nFees] <= 9 ) 



如果条件表达式,我花了2天的时间为这种C ++/C#创建解析器.但是失败了.有没有人帮我为这种代码创建解析器...


上面的[...]之间是可变的.但是在我的程序变量中,[...]包围了它.如果您能给我正则表达式,那就尽力了.我也尝试为此创建正则表达式.但是在递归表达式分析期间,我举起了手.请帮助这个可怜的人.. !!



I have spend 2 days for creating a parser for this kind of C++/C# if condition expression. But failed. Do any one help me to create parser for this kind of code...


Here above between [...] is variable. But in my program variable is surrounded with [...]. IF you can give me regular expression then its best. I have also tried to create regular expression for this. But I up my hands during time of recursive expression analysis. Please help this poor person..!!

推荐答案

在这里,正则表达式可能不是一个好主意,因为您说表达式评估是自然递归的,而正则表达式不是不擅长.

您是否考虑过表达式解析和转换/评估?那里有很多示例: https://www.google.co. uk/search?q = parse + logical + expression + c%23 [
A regular expression is probably not a good idea here, as you say the expression evaluation is naturally recursive, which regexes aren''t good at.

Have you considered look at expression parsing and conversion / evaluation? There are loads of examples out there: https://www.google.co.uk/search?q=parse+logical+expression+c%23[^] Most of them either convert to a stack based RPN or to an expression tree - I don''t know which is more applicable to your application.

[edit]typo - OriginalGriff[/edit]


可能希望查看以下内容是否有帮助:使用正则表达式的C#公式计算器(http://www.jarloo.com/c-formula-evaluator [
Might want to look at the following to see if it might help: C# Formula Evaluator using Regular Expressions ( http://www.jarloo.com/c-formula-evaluator[^]). Not exactly what you are trying to do but they did parse something similar using regular expressons.


这篇关于如果条件解析器,则创建C ++.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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