You are here
Laboratory 5
In laboratory 5 you will create a lexer and parser combination for a simple calculator language using the Antlr parser generator tools. Using Antlr, you will create a Java based lexer and parser that reads in an expression from the command line and outputs the value of that expression. Additionally, you will learn to use the AntlrWorks tools to help debug your parser.
Start your project by downloading the laboratory 5 template. This template contains a Makefile, a base grammar, and the Antlr toolset. The Makefile supports three major commands 'make all', 'make run', and 'make edit'. The 'make all' command will build the Java based parser using the Antlr tools. The 'make run' command will run the parser, allowing you to type in an expression to evaluate (remember to hit <ENTER> <CTRL>-D to finish entering the expression). The 'make edit' command will open the AntlrWorks tools set so that you can edit and evaluate the parser. Be sure to make use of the syntax diagram and parser interpreter features of the tools to aid in the creation of your parser.
The calculator program that you are creating must be able to parse and evaluate the following expressions using the proper mathematical precedence:
- Binary values : 0b10110
- Octal values : 01234
- Decimal values : 1293
- Hexadecimal values : 0x10A3
- Real values : 1.2392
- Addition : 1 + 2
- Subtraction : 1 - 2
- Multiplication : 2 * 5
- Division : 10 / 6
- Exponentiation : 10 ^ 12
- Parentheses : ( 10 + 12 )
- Logarithm Function: log 12
- Sine Function : sin 180
- Cosine Function : cos 192
- Tangent Function : tan 193
When performing evaluation you must perform all arithmetic using floating point values. Additionally, the sine, cosine, and tangent functions should assume that their operand is in radians.
