8000 Typing: fix typos and update README · compiler-experts/miniJava@c1f50c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit c1f50c3

Browse files
committed
Typing: fix typos and update README
1 parent 9b0ab8f commit c1f50c3

File tree

4 files changed

+50
-35
lines changed

4 files changed

+50
-35
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
< 8000 /tr>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# The to contribute to the minijava Project
1+
# Guidelines for Contributing
22

33
## How to collaborate
44

README.md

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@ Using `git clone`
1212
git clone https://redmine-df.telecom-bretagne.eu/git/f2b304_compiler_cn
1313
```
1414

15-
then input your Username and Password in the command prompt
15+
then enter your Username and Password in the command prompt
1616

1717
## The project structure
1818

1919
The project is divided by 2 parts
2020

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
2523

2624
## How to build the compiler
2725

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
2931

3032
```sh
3133
./build
@@ -37,14 +39,12 @@ or using `ocamlbuild` to build the compiler
3739
ocamlbuild Main.byte
3840
```
3941

40-
*Notes*
42+
*Notes for contributors*
4143
> 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.
4244
43-
4445
## How to execute the compiler
4546

46-
47-
Using the shell script `minijavac`
47+
Using the shell script `minijavac` to execute the compiler
4848

4949
```sh
5050
./minijavac <filename>
@@ -61,7 +61,7 @@ it does not end with it.
6161

6262
## How to test the Compiler
6363

64-
Using the shell script `test`
64+
Using the shell script `test` to test the Compiler
6565

6666
```sh
6767
./test
@@ -71,7 +71,7 @@ it will execute `Main.byte` on all files in the directory `Evaluator`
7171

7272
## How to contribute to the Project
7373

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
7575

7676
## To do list
7777

@@ -135,59 +135,73 @@ If you are a team member of the project, please follow the [Working Standard](./
135135

136136
- [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.
137137
- [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
139139
- constructors: a `Hashtbl` that maps from constructor name to class reference type and argument type
140140
- attributes: a `Hashtbl` that maps from attribute name to attribute type (declared type)
141141
- parent: a class reference type that refers to its class
142142
- [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
145145
- [x] `verify_methods` that checks the type of methods
146146
- [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
148148
- variables: a `Hashtbl` that maps from local variable name to local variable declared type
149149
- 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
152152
- [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
154154
- [x] check declared variables
155155
- [x] check block of statement
156156
- [x] check expression
157157
- [x] check return statement when it's none, ex: `return;`
158158
- [x] check return statement when it's not none, ex: `return x;`
159-
- [] check throw statement
159+
- [ ] check throw statement
160160
- [x] check while statement
161161
- [x] check if statement when it doesn't have `else`
162162
- [x] check if statement when it has `else`
163163
- [x] check for statement
164-
- [] check try statement
164+
- [ ] check try statement
165165
- [x] `verify_constructors` that checks the type of constructors
166166
- [x] `verify_attributes` that checks the type of attributes
167167

168168
##### Errors that can be found during Type-checking
169169

170170
- 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]")
171173
- ArgumentTypeNotExiste
172174
- ArgumentTypeNotMatch
173175
- AttributeAlreadyExists
176+
- when found duplicated attribute in class definition environment -> AttributeAlreadyExists("[aname of attribute]")
174177
- ClassAlreadyExists
175178
- ConstructorAlreadyExists
179+
- when found duplicated constructor in class definition environment -> ConstructorAlreadyExists("[cname of constructor]")
176180
- 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]")
177184
- IncompatibleTypes
178185
- 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")
181188
- when condition in if statement is not boolean -> IncompatibleTypes("[actual type] cannot be converted to boolean")
182189
- when condition in if else statement is not boolean -> IncompatibleTypes("[actual type] cannot be converted to boolean")
183190
- when loop condition in for statement is not boolean -> IncompatibleTypes("[actual type] cannot be converted to boolean")
184191
- when loop condition in while statement is not boolean -> IncompatibleTypes("[actual type] cannot be converted to boolean")
185192
- InvalidMethodDeclaration
193+
- when method declaration does not have return type -> InvalidMethodDeclaration("return type required")
186194
- 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")
187202
- UnknownVariable
188203
- UnknownClass
189204
- UnknownMethod
190-
- UnknowActualType
191205
- WrongTypePrefixOperation
192206
- WrongTypePostfixOperation
193207
- WrongInvokedArgumentsLength

phase2/Typing/TypeError.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ exception IncompatibleTypes of string
1212
exception InvalidMethodDeclaration of string
1313
exception MethodAlreadyExists of string
1414
exception UnknownAttribute of string * string
15-
exception UnknownVariable of string
15+
exception UnknownActualType of string
1616
exception UnknownClass of string
1717
exception UnknownMethod of string
18-
exception UnknowActualType of string
18+
exception UnknownVariable of string
1919
exception WrongTypePrefixOperation of string * string
2020
exception WrongTypePostfixOperation of string
2121
exception WrongInvokedArgumentsLength of string

phase2/Typing/Typing.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let verify_invoke_args args const_info func_name =
5656
List.iter2 compare_args args const_info
5757
end
5858

59-
(* verify declared types of variables in constructor arguments or methodes arguments *)
59+
(* verify declared types of variables in constructor arguments or methods arguments *)
6060
let verify_declared_args current_env arguments =
6161
if (Hashtbl.mem current_env.variables arguments.pident) <> true
6262
then (
@@ -266,12 +266,12 @@ let add_local_variable current_env id t =
266266
- if actual type matches declared type:
267267
add variable id and its type to the current_env
268268
- if e.type is None or type donesn't match:
269-
raise UnknowActualType exception and IncompatibleTypes
269+
raise UnknownActualType exception and IncompatibleTypes
270270
exception respectively *)
271271
let verify_actual_type_with_declared_type e t id current_env =
272272
let s = string_of_expression_desc e.edesc in
273273
match e.etype with
274-
| None -> raise(UnknowActualType(" "^s^" don't have type information"));
274+
| None -> raise(UnknownActualType(" "^s^" don't have type information"));
275275
(* check int i = 2, int j = i *)
276276
| Some actual_t -> (
277277
if actual_t <> t (*actual type not equals to declared type*)
@@ -284,11 +284,12 @@ let verify_actual_type_with_declared_type e t id current_env =
284284
- err_msg if of string: the customized exception message
285285
Function:
286286
- if e.type is None or type 1241 donesn't match:
287-
raise UnknowActualType exception and IncompatibleTypes
287+
raise UnknownActualType exception and IncompatibleTypes
288288
exception respectively *)
289289
let verify_actual_type_with_boolean e err_msg =
290+
let s = string_of_expression_desc e.edesc in
290291
match e.etype with
291-
| None -> raise(UnknowActualType(err_msg))
292+
| None -> raise(UnknownActualType(s^": "^err_msg))
292293
| Some actual_t -> if actual_t <> Primitive(Boolean)
293294
then raise(IncompatibleTypes((stringOf actual_t)^" cannot be converted to boolean"))
294295

@@ -318,11 +319,11 @@ let rec verify_statement current_env envs statement =
318319
match current_env.returntype with
319320
| Ref(ref)-> if current_env.env_type <> "constructor" then raise(IncompatibleTypes("missing return value"))
320321
| Void -> ()
321-
| _ -> raise(IncompatibleTypes("This methode must return a result of type "^(Type.stringOf current_env.returntype)))
322+
| _ -> raise(IncompatibleTypes("This method must return a result of type "^(Type.stringOf current_env.returntype)))
322323
)
323324
(* check when the return clause is not none, ex: return x;*)
324325
| Return Some(e) -> (verify_expression envs current_env e;
325-
if current_env.env_type <> "methode" then raise(IncompatibleTypes("unexpected return value"));
326+
if current_env.env_type <> "method" then raise(IncompatibleTypes("unexpected return value"));
326327
match current_env.returntype, e.etype with
327328
| declared_t, Some(actual_t) -> if declared_t <> actual_t
328329
then raise(IncompatibleTypes((stringOf actual_t)^" cannot be converted to "^(stringOf declared_t)))
@@ -381,7 +382,7 @@ let verify_methods envs current_class meths =
381382
returntype = meths.mreturntype;
382383
variables = Hashtbl.create 17;
383384
this_class = current_class;
384-
env_type = "methode"} in
385+
env_type = "method"} in
385386
List.iter (verify_declared_args current_env) meths.margstype;
386387
List.iter (verify_statement current_env envs) meths.mbody
387388

0 commit comments

Comments
 (0)
0