实施"不"在boost ::精神mini_c [英] Implementing "NOT" in boost::spirit mini_c
问题描述
我试图修改提振::精神mini_c例如以匹配现有的词汇。
因此,我增加了一个运营商不就是应该表现为平等!
unary_expr =
primary_expr
| (NOT> primary_expr [OP(op_not))//这不起作用
| (大于!; primary_expr [OP(op_not)])
| (' - '> primary_expr [OP(op_neg)])
| ('+'> primary_expr)
;
我可以编译修改后的源$ C $ C,但是当我尝试执行它失败解析。我怎样才能解决这个问题?
编辑:
由于我要访问外部变量,我不得不为了建设这些变量的列表进行编译时做了另一个修改:
标识符(%)=
生[语义的α>> *(alnum |'§'|'_'|'。'|' - ')]
;
变量=
标识符[add_var(_1)
;
在哪里add_var和标识被定义为
规则<迭代器,标准::字符串(),white_space>标识符;
功能< var_adder> add_var;
如果我不使用此修改,NOT可以使用。随着修改,使用NOT产生一个解析错误。
编辑2:
下面的条件前pressions做的工作,虽然:
logical_expr =
relational_expr
>> *((和> relational_expr [OP(op_and)])
| (或> relational_expr [OP(op_or)])
)
;
随着你的改变小测试:
INT的main()
{
返回NOT 1;
}
成功解析并返回 0
。因此,这不是明显对我有什么不为你工作。你能否提供一个失败的输入样本为好,好吗?
I tried to modify the mini_c example of boost::spirit to match to my existing vocabulary.
I therefore added a operator "NOT that should behave equal as "!":
unary_expr =
primary_expr
| ("NOT" > primary_expr [op(op_not)]) // This does not work
| ('!' > primary_expr [op(op_not)])
| ('-' > primary_expr [op(op_neg)])
| ('+' > primary_expr)
;
I can compile the modified source code, but when i try to execute it it fails to parse. How can i solve this?
EDIT: As my want to access external variables, i had made another modification in order to build a list of these variables when compiling:
identifier %=
raw[lexeme[alpha >> *(alnum | '§' | '_' | '.' | '-' )]]
;
variable =
identifier [add_var(_1)]
;
Where add_var and identifier are defined as
rule<Iterator, std::string(), white_space> identifier;
function<var_adder> add_var;
If i don't use this modification, "NOT" can be used. With the modification, using "NOT" generates a parsing error.
EDIT 2: The following conditional expressions do work though:
logical_expr =
relational_expr
>> *( ("AND" > relational_expr [op(op_and)])
| ("OR" > relational_expr [op(op_or)])
)
;
With your change the small test:
int main()
{
return NOT 1;
}
parses successfully and returns 0
. So it is not obvious to me what doesn't work for you. Could you provide a failing input example as well, please?
这篇关于实施&QUOT;不&QUOT;在boost ::精神mini_c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!