Tag: Parser

Recursive Descent Parser with C# – Boolean logic expressions

In previous post we gave brief introduction on Recursive Descent Parsers and we implemented parser that was able to parse and calculate simple arithmetic expressions with addition and subtraction. To be (True) or !(To be True)? This time we will try to tackle little bit more complex example that will parse and evaluate Boolean logic expressions that will include negation and parenthesis. Examples of expressions we want to be able to parse and evaluate are: True And True And False True !False (!(False)) and (!(True) etc Let’s assemble a EBNF grammar for this type of expressions: Expression      := [ “!” ] <Boolean> { BooleanOperator Boolean } Boolean         := BooleanConstant | Expression | “(” <Expression> “)” BooleanOperator := “And” | “Or”  BooleanConstant := “True” | “False” You Read More