Prof. Dr. A. Poetzsch-Heffter Dr. Annette Bieniusa Dipl.-Inf. P. Michel
TU Kaiserslautern
Fachbereich Informatik AG Softwaretechnik
Lab 1: Compiler and Language Processing Tools (SS 2013)
Deadline: 29.04.13, 23:59
1 Shopping list (4+2)
You have to scan and parse a shopping list. Each line of the shopping list contains a shopping item. Each item consists of
• the amount (number of pieces),
• a description of the product, and
• the price per piece in Euro.
They are seperated by a comma. Example:
12, eggs , 0.20
3, parcels of spaghetti , 2.00
6, bottles 7up , 0.90
2, bottles of French wine , 12.50
1. Write a scanner and a parser specification of shopping lists for the above format using JFlex and Beaver. The resulting program should take a file name as input and process the content of the file.
2. Compute the total prize for all items on a (parsed) shopping list using the parser’s action routines. Print to the price in the correct format System.out. For the above example, the total prize is 38.80.
Generate some test cases and test your implementation.
2 Calculator (2+2+2)
Implement a small calculator for arithmetic expressions, supporting addition, subtrac- tion, and multiplication on integers. The evaluation of an expression should follow the usual rules of arithmetics regarding operator precedence and associativity.
Examples:
• The expression 2 - 4 + 5 should evaluate to 3.
• The expression 2 * 4 + 3 should evaluate to 11.
1. Define and implement an abstract syntax tree (AST) for the expression language in Java.
2. Write a scanner and a parser specification for arithmetic expressions using JFlex and Beaver that constructs the AST. The resulting program should take a file name as input and process the content of the file.
3. Implement an evaluator that calculates the value of an expression by processing the AST.
Submission
• Deadline: 29.04.13, 23:59.
• Late submissions will not be accepted.
• Don’t forget to add some documentation to your code.
• Submit your solution via your group’s repository.