You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
then input your Username and Password in the command prompt
15
+
then enter your Username and Password in the command prompt
16
16
17
17
## The project structure
18
18
19
19
The project is divided by 2 parts
20
20
21
-
- phase1: the first delivery which contains the lexical and syntax analyzer for the language minijava
22
-
- phase2: the second delivery which contains the semantic analyzer for the language minijava based on the lexical and syntax analyzer that offered by professors
23
-
24
-
to build or execute the compiler, you should entre one of these folder, `cd ./phase1` or `cd ./phase2`
21
+
- phase1: the first deliverable that contains the lexical and syntax analyzer for the language minijava
22
+
- phase2: the second deliverable that contains the type checking, compiling and executing for the language minijava based on the lexical and syntax analyzer that offered by professors
25
23
26
24
## How to build the compiler
27
25
28
-
Using the shell script `build`
26
+
To build or execute the compiler, plase enter one of the two deliverables, either `phase1` or `phase2`
27
+
28
+
Using `cd ./phase1` or `cd ./phase2`
29
+
30
+
Then using the shell script `build` to build the compiler
29
31
30
32
```sh
31
33
./build
@@ -37,14 +39,12 @@ or using `ocamlbuild` to build the compiler
37
39
ocamlbuild Main.byte
38
40
```
39
41
40
-
*Notes*
42
+
*Notes for contributors*
41
43
> The main file is `Main/Main.ml`, it should not be modified. It opens the given file,creates a lexing buffer, initializes the location and call the compile function of the module `Main/compile.ml`. It is this function that you should modify to call your parser.
42
44
43
-
44
45
## How to execute the compiler
45
46
46
-
47
-
Using the shell script `minijavac`
47
+
Using the shell script `minijavac` to execute the compiler
48
48
49
49
```sh
50
50
./minijavac <filename>
@@ -61,7 +61,7 @@ it does not end with it.
61
61
62
62
## How to test the Compiler
63
63
64
-
Using the shell script `test`
64
+
Using the shell script `test` to test the Compiler
65
65
66
66
```sh
67
67
./test
@@ -71,7 +71,7 @@ it will execute `Main.byte` on all files in the directory `Evaluator`
71
71
72
72
## How to contribute to the Project
73
73
74
-
If you are a team member of the project, please follow the [Working Standard](./WorkingStandard.md) to make appropriate contributions
74
+
If you are a team member of the project, please review the [Guidelines for Contributing](./CONTRIBUTING.md) to this repository in order to make appropriate contributions
75
75
76
76
## To do list
77
77
@@ -135,59 +135,73 @@ If you are a team member of the project, please follow the [Working Standard](./
135
135
136
136
-[x] The construction of the class definition environment. This environment contains the type of methods for each class. This phase ignores the attributes (which are not visible outside the class) and the method bodies.
137
137
-[x] create a class definition environment type called `class_env`, it contains 4 fields as follows
138
-
- methods: a `Hashtbl` that maps from methode name to methode return type and argument type
138
+
- methods: a `Hashtbl` that maps from method name to method return type and argument type
139
139
- constructors: a `Hashtbl` that maps from constructor name to class reference type and argument type
140
140
- attributes: a `Hashtbl` that maps from attribute name to attribute type (declared type)
141
141
- parent: a class reference type that refers to its class
142
142
-[x] create a `Hashtbl` that maps from class
143
-
-[] The second phase is concerned with verifying that the inside of classes is correct (mainly the body of methods). She will also make sure of the correction of the higher level expression.
144
-
-[x] create 3 verification methode that verifies the following aspects of the program
143
+
-[] The second phase is concerned with verifying that the inside of classes is correct (mainly the body of methods). She will also make sure of the correction of the higher level expression.
144
+
-[x] create 3 verification method that verifies the following aspects of the program
145
145
- [x]`verify_methods` that checks the type of methods
146
146
- [x] create a local definition environment type called `current_env` it contains 3 fields as follows
147
-
- returntype: the declared return type of the methode
147
+
- returntype: the declared return type of the method
148
148
- variables: a `Hashtbl` that maps from local variable name to local variable declared type
149
149
- this_class: the id of the class
150
-
- env_type: a string that identifies the type of the local definition environment, it could be `constructor`, `methode` or `attribute`, in this case, the `env_type` is `methode`
151
-
- [x] write a verification methode (`verify_declared_args`) that checks the declared type of variables in the methode arguments
150
+
- env_type: a string that identifies the type of the local definition environment, it could be `constructor`, `method` or `attribute`, in this case, the `env_type` is `method`
151
+
- [x] write a verification method (`verify_declared_args`) that checks the declared type of variables in the method arguments
152
152
- [x] check if there exists Duplicate Local Variable
153
-
- [] write a verification methode (`verify_statement`) that checks the body of the methode
153
+
- [] write a verification method (`verify_statement`) that checks the body of the method
154
154
- [x] check declared variables
155
155
- [x] check block of statement
156
156
- [x] check expression
157
157
- [x] check return statement when it's none, ex: `return;`
158
158
- [x] check return statement when it's not none, ex: `return x;`
159
-
- [] check throw statement
159
+
- [] check throw statement
160
160
- [x] check while statement
161
161
- [x] check if statement when it doesn't have `else`
162
162
- [x] check if statement when it has `else`
163
163
- [x] check for statement
164
-
- [] check try statement
164
+
- [] check try statement
165
165
- [x]`verify_constructors` that checks the type of constructors
166
166
- [x]`verify_attributes` that checks the type of attributes
167
167
168
168
##### Errors that can be found during Type-checking
169
169
170
170
- ArgumentAlreadyExists
171
+
- when found duplicated argument in constructor argument list -> ArgumentAlreadyExists("[pident of argument]")
172
+
- when found duplicated argument in method argument list -> ArgumentAlreadyExists("[pident of argument]")
171
173
- ArgumentTypeNotExiste
172
174
- ArgumentTypeNotMatch
173
175
- AttributeAlreadyExists
176
+
- when found duplicated attribute in class definition environment -> AttributeAlreadyExists("[aname of attribute]")
174
177
- ClassAlreadyExists
175
178
- ConstructorAlreadyExists
179
+
- when found duplicated constructor in class definition environment -> ConstructorAlreadyExists("[cname of constructor]")
176
180
- DuplicateLocalVariable
181
+
- when found duplcated variable in variable declaration statement (VarDecl) -> DuplicateLocalVariable("[decalred type][variable id]")
182
+
- when found duplcated variable in the init part of for loop statement (For(fil,eo,el,s)) -> DuplicateLocalVariable("[decalred type][variable id]")
183
+
- also raise this exception when found duplcated variable in variable declaration statement in the body of block, if, if else, for, while statement -> DuplicateLocalVariable("[decalred type][variable id]")
177
184
- IncompatibleTypes
178
185
- when constructor try to return a variable -> ("unexpected return value")
179
-
- when methode return does not contain variable -> IncompatibleTypes("missing return value")
180
-
- when methode return type does not corresponds with the declared one -> IncompatibleTypes("missing return value")
186
+
- when method return does not contain variable -> IncompatibleTypes("missing return value")
187
+
- when method return type does not corresponds with the declared one -> IncompatibleTypes("missing return value")
181
188
- when condition in if statement is not boolean -> IncompatibleTypes("[actual type] cannot be converted to boolean")
182
189
- when condition in if else statement is not boolean -> IncompatibleTypes("[actual type] cannot be converted to boolean")
183
190
- when loop condition in for statement is not boolean -> IncompatibleTypes("[actual type] cannot be converted to boolean")
184
191
- when loop condition in while statement is not boolean -> IncompatibleTypes("[actual type] cannot be converted to boolean")
185
192
- InvalidMethodDeclaration
193
+
- when method declaration does not have return type -> InvalidMethodDeclaration("return type required")
186
194
- MethodAlreadyExists
195
+
- when found duplicated method in class definition environment -> MethodAlreadyExists("[mname of method]")
196
+
- UnknownActualType
197
+
- when actual type of a variable cannot be determined in variable declaration statement (VarDecl) -> UnknownActualType("[edesc] don't have type information")
198
+
- when actual type of a variable cannot be determined in the init part of for loop statement (For(fil,eo,el,s)) -> UnknownActualType("[edesc] don't have type information")
199
+
- when actual type of variable cannot be determined in the condition part of while loop statement (While(e,s)) -> UnknownActualType("[edesc]: unknow type in while condition")
200
+
- when actual type of variable cannot be determined in the condition part of if statement (If(e,s,None)) -> UnknownActualType("[edesc]: unknow type in if condition")
201
+
- when actual type of variable cannot be determined in the condition part of if else statement (If(e,s,Some s2)) -> UnknownActualType("[edesc]: unknow type in if else condition")
0 commit comments