Node:Rpcalc Compile, Previous:Rpcalc Gen, Up:RPN Calc



Compiling the Parser File

Here is how to compile and run the parser file:

# List files in current directory.
$ ls
rpcalc.tab.c  rpcalc.y

# Compile the Bison parser.
# -lm tells compiler to search math library for pow.
$ cc rpcalc.tab.c -lm -o rpcalc

# List files again.
$ ls
rpcalc  rpcalc.tab.c  rpcalc.y

The file rpcalc now contains the executable code. Here is an example session using rpcalc.

$ rpcalc
4 9 +
13
3 7 + 3 4 5 *+-
-13
3 7 + 3 4 5 * + - n              Note the unary minus, n
13
5 6 / 4 n +
-3.166666667
3 4 ^                            Exponentiation
81
^D                               End-of-file indicator
$