-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
97 lines (85 loc) · 3.38 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
AUTHORS:
Lucian Hymer
Jack Kerby
DESCRIPTION:
This is a compiler for the z-plus language. This is only a demo, demonstrating
the function of if/then/else, getn(), and basic for-loops.
USAGE:
# Build both the compiler and pstack:
bnfc -cpp_stl -m ./zp.cf
make
make -f Makefile.codegen
# Compile fib.cmm, producing fib.apm:
./compiler fib.cmm fib.apm
# Disassemble fib.apm:
./pstack/apd fib
# Execute fib.apm:
./pstack/api fib
# Test with (note that this script
# is modified from the original)
./test.sh myTESTS
FILES:
* Makefile.codegen
* The Makefile for `zp2pstack`
* zp.cf
* Grammar of the zp language used by `bnfc`
* Absyn.C/H
* Abstract syntax tree files generated by `bnfc`
* zp.l/y
* Flex and Bison files generated by bnfc
* codegen.cc/h
* Defines the p-code generation class
* Lexer.C/H
* Lexer files generated by `bnfc`
* Parser.C/H
* Parser files generated by `bnfc`
* Parser.C/H
* Printer files generated by `bnfc`
* pstcode.cc/h
* Implements prolog functions such as `getnum()`` and other functions
* Skeleton.C/H
* Skeleton files generated by `bnfc`
* symbtable.cc/h
* Defines the Symbol and SymbolTable classes
* typescript
* Script of the tests being run
* myTests
* Directory containing the tests
* pstack
* Directory containing the pstack supplied by the instructor
* test.sh
* Test script
BUILT-IN-FUNCTIONS:
The cmm standard library contains these functions:
exit() : ends the program immediately
puts("...") : prints a string (only literal strings are supported)
putn(int) : prints an integer (like printf("\t%d\n", int))
putd(double) : prints a double (like printf("\t%d\n", double))
getnum() : gets an integer
itod(int) : returns int as a double
dtoi(double) : returns double as an integer
All functions return a value.
IMPLEMENTED-FEATURES:
* if and if-else: **Complete**
* for2-loop: **Complete**
* for3-loop: **Complete**
* Optimization: **Complete**
* Globals: **Complete**
* repeat-until-loop: **Complete**
* Scoped for-loop: **Complete**
* Argument count checking: **Complete**
* Type checking: **Complete**
* Doubles: **Complete**
EXTRA-FEATURES:
* itod and dtoi : Built-in functions to typecast between ints and doubles
* multiple arguments : Functions work with multiple arguments
DEVELOPERS NOTES:
We tried to modify the existing structure as little as possible. The most difficult part was typechecking.
For function parameters and arguments, it was not too difficult because all types were evaluated in the
visitFunc and visitCall definitions respectively. So, we just pass the parameter type list when creating a function symbol
and this creates an ArgumentChecker object which can be called at function call time with the list of argument types. Same
for the return value. After doing this, however, we realized that typechecking involved much more than checking function argument
and return types. So, we had to modify most visit* calls to set currtype at the correct time.
It was difficult to implement doubles as well. We had to change most I_ calls to check the type, and it took a while
to realize we needed to call I_TO_R when loading in a double. We also had to find some way to deal with mixed
types. We decided to disallow mixing types, and provided builtin typecasting functions itod and dtoi.