forked from coolsidd/Compiler-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flatten all sub-directories, fix makefile
- Loading branch information
1 parent
2717927
commit ada8be1
Showing
45 changed files
with
142 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,57 @@ | ||
# PPL_Assignment_1 | ||
# PPL Assignment-1 | ||
|
||
## Type checking and type expressions | ||
|
||
### Requirement | ||
According to the assignment PDF, The Type Expression Table is expected to store the following: | ||
+ Field 1: The name of variable extracted from the declaration statement and to be used in the | ||
assignment statement. | ||
+ Field 2: The information about whether it is an array or not, if yes, then whether it is rectangular | ||
array or a jagged array. | ||
Use numbers enumerated values of 0, 1 and 2 for primitive data type, rectangular array and jagged array respectively. | ||
The value 0 corresponds to integer, real and Boolean types. However, these primitive type details are filled in the fourth field | ||
explicitly defining the integer, real or Boolean specifications appropriately. | ||
+ Field 3: If the type is a rectangular array, then whether it is static or dynamic based on the typeof range parameters used in | ||
defining the array type. If it is not a rectangular array this value is stored as “not_applicable”. | ||
+ Field 4: type expression, which is implemented using the union data type. | ||
|
||
### Design Overview | ||
My design is as follows: | ||
|
||
### type_exp_table.h | ||
+ We will have a `TYPE_EXPRESSION_TABLE` data structure which would store the `root` node [of a `linked_list` of | ||
`TYPE_EXPRESSION_TABLE_NODE`(s)] and the `SYMBOL_TABLE`. | ||
+ A `TYPE_EXPRESSION_TABLE_NODE` would store the Fields(1,2,3) of a variable. | ||
+ `SYMBOL_TABLE` would be implemented as a `HASH_MAP` with the key as `variable_name` and value as | ||
`TYPE_EXPRESSION` of the variable. | ||
+ `TYPE_EXPRESSION_TABLE_NODE` would store the first 3 fields as per requirement -: | ||
* `variable_name`: `char*` | ||
* `variable_type`: `VariableType` which is an enum field of `{PRIMITIVE_TYPE, RECT_ARRAY, JAGGED_ARRAY}` | ||
* `declaration_type`: `DeclarationType` which is an enum field of `{NOT_APPLICABLE, STATIC, DYNAMIC}` | ||
|
||
#### Function Prototypes | ||
* Initialise the type expression table | ||
+ `type_exp_table* create_type_expression_table();` | ||
* Get type expression of a variable | ||
+ `type_expression get_type_expression(type_exp_table* t, char* variable);` | ||
* Add entry | ||
+ `void add_entry_to_table(type_exp_table* t, char* variable_name, VariableType var_type,` | ||
` declaration_type decl_type, type_expression t);` | ||
* Remove entry | ||
+ `void remove_entry_from_table(type_exp_table* t, char* variable_name);` | ||
|
||
### type_expression.h | ||
+ The `TYPE_EXPRESSION` data structure would store the type expression(Field 4) of a variable | ||
(with a unique `variable_name`). | ||
+ The necessary fields of `TYPE_EXPRESSION` are(fields with ** are tentative and under review): | ||
* `is_declared`: which is set to `true` when a valid `decl_stmt` corresponding to its `variable_name` is encountered. | ||
* `variable_type`**: could be used as a `tag` for allocating union value. | ||
* `to_be_named`: The union data structure which would store amongst: | ||
+ `PrimitiveDataType` | ||
+ `RECT_ARRAY_TYPE` | ||
+ `JAGGED_ARRAY_TYPE` | ||
### Function Prototypes | ||
* Get the desired String Representation of TypeExpression | ||
+ `char* get_string_representation(type_expression tp)`; | ||
* Set is_declared to true on encountering decl_stmt | ||
+ `void set_declare_flag(type_expression t);` |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
main_program program ( ) { stmts } | ||
stmts decl_stmts assign_stmts | ||
decl_stmts decl_stmt decl_stmts | ||
decl_stmts decl_stmt | ||
assign_stmts assign_stmt assign_stmts | ||
assign_stmts assign_stmt | ||
decl_stmt decl_non_jagged | ||
decl_stmt decl_jagged | ||
decl_non_jagged declare list_of_identifiers : declaration_type | ||
decl_jagged declare list_of_identifiers : jagged_array | ||
list_of_identifiers list of variables id_list | ||
list_of_identifiers ID | ||
id_list ID id_list | ||
id_list ID ID | ||
declaration_type primitive_type ; | ||
declaration_type rect_array ; | ||
primitive_type integer | ||
primitive_type real | ||
primitive_type boolean | ||
rect_array array range_list of primitive_type | ||
range_list [ var .. var ] range_list | ||
range_list [ var .. var ] | ||
jagged_array jagged array jagged2list of primitive_type ; jagged2init | ||
jagged_array jagged array jagged3list of primitive_type ; jagged3init | ||
jagged2list range_list [ ] | ||
jagged3list range_list [ ] [ ] | ||
jagged2init R1 [ var ] : size var : values { j2list } jagged2init | ||
jagged2init R1 [ var ] : size var : values { j2list } | ||
j2list value_list ; j2list | ||
j2list value_list | ||
j2list ; j2list | ||
j2list ; | ||
jagged3init R1 [ var ] : size var : values { j3list } jagged3init | ||
jagged3init R1 [ var ] : size var : values { j3list } | ||
j3list value_list ; j3list | ||
j3list value_list | ||
j3list ; j3list | ||
j3list ; | ||
value_list var value_list | ||
value_list var | ||
index_list var index_list | ||
index_list var | ||
var ID [ index_list ] | ||
var CONST | ||
var ID | ||
assign_stmt var_lhs = expr | ||
var_lhs ID [ index_list ] | ||
var_lhs ID | ||
expr arithmeticexpr ; | ||
arithmeticexpr term + arithmeticexpr | ||
arithmeticexpr term - arithmeticexpr | ||
arithmeticexpr term ||| arithmeticexpr | ||
arithmeticexpr term | ||
term fact * term | ||
term fact / term | ||
term fact &&& term | ||
term fact | ||
fact var | ||
fact ( arithmeticexpr ) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Oops, something went wrong.