In this project, you should implement a C interpreter. The supported input file should at least contain the following features:
- integer and floating-point data types: int, float.
- Statements for arithmetic computation. (ex: a = b+2*(100-1)) (3) Comparison expression. (ex: a > b)
- if-then-else program construct.
- printf() function with one/two parameters. (support types: %d, %f)
- scanf() (support types: %d, %f)
The following is a sample C program (input file):
- void main()
- {
- int num;
- float s;
- printf(Please enter a number:); 7. scanf(%d, &num);
- if (num > 10) {
- s = 3 * (num + 3.14);
- } else {
- s = num * (num 3.14);
- }
- printf(The result is %f
, s); - }
In your hand-in report, you need to have the followings:
- Describe the C subset supported by your interpreter.
- Give a set of testing programs which can illustrate the features of your interpreter. (at least 3 test programs)
- Use the ANTLR to help you develop your interpreter.
- You can use Java or other programming languages to write your interpreter. (Java is recommended)
- Please ensure your program can be executed under the mcore8 or
1
Compiler Design
linux.cs.ccu.edu.tw workstation.
3
Reviews
There are no reviews yet.