/SimpleRecursiveDescentParser

Very Simple Proof of Concept Parser for Simple Arithmetic Expressions.

Primary LanguageC#BSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

ArithmeticParser

Very Simple Proof of Concept Parser for Simple Arithmetic Expressions.

Build Status Parser NuGet package Lexer NuGet package

This is an example of a simple but clean recursive descent parser which builds an abstract syntax tree.

It illustrates the usage of the visitor pattern to traverse the syntax tree.

Supported Operations:

  • Binary Operations
    • Addition
    • Subtraction
    • Multiplication
    • Division
    • Modula
    • Power
  • Function Calls
  • Variables
    • Constants

Sample vistors include:

  • CalculateVisitor: calculates the result of the arithmetic expression as a double.
  • Parenthesizer: several visitors to create infix notation from a syntax tree.
  • RPN: Output as a postfix syntax tree also known as reverse polish notation
  • GraphViz: visualize parse tree with GraphViz

Example 1

Some Simple Tests are included, but no exhaustive test suite, the prser is intendet only as an academic example with a well designed architecture.