I took George Weigt's Eigenmath project and replaced the recursive descent parser
in scan.cpp
with a Vaughan Ronald Pratt parser in pratt.cpp
.
To build the project, you need GCC under Linux and the following command in the project's directory:
$ make
This will produce object files *.o
and an executable math
in the project's directory.
To test the program, you can use the provided test-script.txt
:
$ ./math test-script.txt
You can also run the command selftest
:
$ ./math
> selftest
To quit the program, enter Ctrl-C:
$ ./math
> ^C
$
In this implementation of Pratt's parser I made use of the material presented in this article:
- Top Down Operator Precedence, Vaughan R. Pratt, 1973 available at http://tdop.github.io/. Original description of Pratt's algorithm.
The concept of nbp (next binding power) is from: