Validate a Boolean expression with brackets in C#

后端 未结 6 616
清歌不尽
清歌不尽 2021-01-18 01:12

I want to validate a string in C# that contains a Boolean expression with brackets. The string should only contain numbers 1-9, round brackets, \"OR\" , \"AND\".

Exa

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-18 02:03

    If you consider a boolean expression as generated by a formal grammar writing a parser is easier.

    I made an open source library to interpret simple boolean expressions. You can take a look at it on GitHub, in particular look at the AstParser class and Lexer.

提交回复
热议问题