forked from Vbhaskar125/COOL-Compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
151 lines (118 loc) · 5.71 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
README file for Programming Assignment 4 (C++ edition)
======================================================
Your directory should now contain the following files:
Makefile -> [course dir]/assignments/PA4/Makefile
README
ast-lex.cc -> [course dir]/src/PA4/ast-lex.cc
ast-parse.cc -> [course dir]/src/PA4/ast-parse.cc
bad.cl
cgen -> [course dir]/etc/../lib/.i
cool-tree.cc -> [course dir]/src/PA4/cool-tree.cc
cool-tree.h
cool-tree.handcode.h
dumptype.cc -> [course dir]/src/PA4/dumptype.cc
good.cl
handle_flags.cc -> [course dir]/src/PA4/handle_flags.cc
mycoolc -> [course dir]/src/PA4/mycoolc
mysemant -> [course dir]/src/PA4/mysemant
semant-phase.cc -> [course dir]/src/PA4/semant-phase.cc
semant.cc
semant.h
stringtab.cc -> [course dir]/src/PA4/stringtab.cc
symtab_example.cc -> [course dir]/src/PA4/symtab_example.cc
tree.cc -> [course dir]/src/PA4/tree.cc
utilities.cc -> [course dir]/src/PA4/utilities.cc
*.d dependency files
The include (.h) files for this assignment can be found in
[course dir]/include/PA4
The Makefile contains targets for compiling and running your
program. DO NOT MODIFY.
good.cl and bad.cl test a few features of the semantic checker.
You should add tests to ensure that good.cl exercises as many
legal semantic combinations as possible and that bad.cl
exercises as many kinds of semantic errors as possible.
semant.h contains declarations and definitions for the semantic
analyzer. Place class definitions for the structures you will
use here.
cool-tree.aps contains the definitions for the tree language
which you use to construct the abstract syntax tree (AST).
From this file, cool-tree.h and cool-tree.cc are automatically
generated by a utility that compiles the specification into
C++ functions for producing and consuming the tree nodes.
This file is provided for your reference. DO NOT MODIFY.
tree.{cc|h} contain definitions used by the tree package. DO
NOT MODIFY.
cool-tree.h, and cool-tree.handcode.h specify and give an
implementation of Cool ASTs (see the README for PA3 and the
"Cool Tour"). In this assignment, you will need to add
functions to the AST classes to store, fetch, and compute
information about the AST. Note that cool-tree.handcode.h
differs slightly from the file supplied for PA3.
You should NOT remove any definitions that are already present
in cool-tree.h and cool-tree.handcode.h. These functions and
data members are required for the system to function properly.
You should add any fields and methods to the classes you need to
perform semantic analysis. You will need to add, for example,
methods which traverse the expressions of the tree and implement
the type-checking rules.
cool-tree.cc contains definitions of the provided methods,
and instantiations of the template for the list handling functions.
You should not modify this file, but place definitions of all
methods you add to cool-tree.h or cool-tree.handcode.h in semant.cc.
DO NOT MODIFY cool-tree.cc
semant.cc is the file in which you should write your semantic
analyzer. The main() procedure calls the method `semant'
on `ast_root', the root of the abstract syntax tree generated by
the parser. There are methods supplied that you should use to report
errors. You are relatively free in how you decide to structure the
semantic checker, but don't modify the error printing routines.
ast-lex.cc and ast-parse.cc implement a lexer and a parser for
reading text representation of ASTs from console in the format
produced by the parser phase. DO NOT MODIFY.
semant-phase.cc contains a test driver for semantic analysis.
The main program reads an AST in text form from standard input,
parses it, and then produces a type-annotated AST on standard
output. The script mycoolc can pass any of the standard flags
to the semantic analyzer as well; for this assignment, -s
(semantic analysis debug) may be useful as it sets a global
variable semant_debug to true (1). If you want your semantic
checker to print debug information when the option is set, write
your debug code in the following format:
if (semant_debug)
{
...
}
semant_debug is provided as a convenience. You don't need to use
the debugging flags if you don't want to. DON'T MODIFY
semant-phase.cc
symtab.h contains a symbol table implementation. Read the
comments in the file, the "Cool Tour", and look at the example
in symtab_example.cc. You are not required to use this code,
but you may find it useful. DO NOT MODIFY.
Instructions
------------
To compile the example use of the symbol table, type
% make symtab_example
% ./symtab_example
To compile your semantic analyzer program type:
% make semant
To test your semantic checker, type:
% ./mysemant good.cl
mysemant is a version of mycoolc that omits code generation.
mysemant parses all the cool files given on the command line and
builds a single abstract syntax tree containing all class
definitions appearing in the input files. Your semantic checker
is then called on this abstract syntax tree. If there are no
errors, the program produces a type-annotated abstract syntax
tree as output.
To run your checker on the files good.cl and bad.cl type:
% make dotest
If you think your semantic checker is correct and behaves like
the one we wrote, you can try to run mycoolc using your checker,
your parser and also your lexical analyzer if you choose (see
below for instructions). Remember if your lexer, parser or
checker behaves in an unexpected manner, you may get errors
anywhere.
Instructions for turning in the assignment will be posted on the
course web page.
GOOD LUCK!