matanbt / compilation Goto Github PK
View Code? Open in Web Editor NEWBuilding a compiler from scratch, as final project for Compilation course.
Building a compiler from scratch, as final project for Compilation course.
Function Epilogue
Function Prologue
Function Return
Make sure we get the correct size for the array. That means that if it is a constant integral size, just save it, else we should save the AST node containing the element containing the size of the array (for example, the variable holding the size of the array when we create it).
The total size of the array is: (1 + length) * 4
, where the 1 stands for a field that holds the length of the array.
Currently the following code is considered OK by our code:
int var := 1; var var_name := 1;
That's bc in the second line 'var' is looked for in the SYMBOL_TABLE and is found and we take it as a TYPE int. That's bad.
What we should do? I'll propose a solution in a new branch. Also another think I thought is maybe it'd be a good idea to keep a TYPE_TABLE, in which we should always consult with when deciding that an identifier is a TYPE. Anyway my solution bypasses it for now.
AST_VAR_FIELD
AST_VAR_SIMPLE
According to what I understand (didn't go to the bottom of it), in get Line we fetch the line of the NEXT token, this of course is not expected behavior.
My suggested solution is to keep track of the previous' token line number.
We currently need to implement the MIPS code for the following actions:
Note that I don't think we should do anything in the case of load/store of classes, since we are always working with objects of size 4 (a pointer to the actual class).
Also, need to consider adding PrintString (@ShirFrenkel added the MIPS code for that, but we need to add the IR for it too).
Need to make sure we are passing the following comment tests:
/* bla bla bla
NOT VALID/* bla bla bla <
NOT VALID/* bla bla bla < */
NOT VALID/* comment */ id */
NOT VALID*/
: /* comment * / */
VALID/* SA */ < */
VALIDCheck if the lexer returns us the string token with quotation marks or not, and fix our printing based on the answer
AST_CFIELD.java
AST_DEC_CLASS.java
We should just eval it to 1
in place.
Emphasis on TYPE_VOID integration
Includes: AST_DEC_VAR, AST_STMT_ASSIGN, AST_STMT_ASSIGN_NEW
Depends on:
We should decide how we verify the existence of a void and argument-less global function main()
.
I see it as an addition to AST_FUNC_DEC semantMe, that will be checked by Main.java.
I wrote this function thinking mainly about classes, I might've neglected arrays assignments.
TABLE_ENTRY.stack_offset
TYPE_CFIELD.object_offset
is required.TYPE.size
property .TABLE_ENTRY.size
When we cloned the HW assignment, we also cloned AST_EXP_VAR_FIELD.java AST_EXP_VAR_SIMPLE.java AST_EXP_VAR_SUBSCRIPT.java
, which are the old names of the following files - AST_VAR_FIELD.java AST_VAR_SIMPLE.java AST_VAR_SUBSCRIPT.java
.
I didn't remove them yet, because some of the old files still have some useful SemantMe
in them.
We should support:
Father[] arr =Son[l]
(Well not synthetically, but the concept)
We should create a list containing all the fields of the class. This should support inheritance. The list should be ordered, having the greatest ancestor's fields first.
We can implement it efficiently by creating a JOIN operation in the AST class node, that takes the list of the father, and joins it with the list of immediate fields of the son, while making sure we are ignoring "override" fields, like an int x;
field in both father and son, since only the father's should count.
We should create a similar list of (name, function_object)
, but for methods. This should also support a JOIN operation, but this time we override the values function_object
in case of collision.
We can now get the size of the class: (1 + total_fields) * 4
, where the 1 stands for the vtable of the class.
Just a recap of what I did so we wouldn't do double work + some notes.
Ill edit this comment whenever I have progress:
And implemnt SYMBOL_TABLE.getContext() that will return the relevant AST_Node of the context.
After this is implemented we gain:
function calls currently naively assume that builtins functions are defined in the beginning of MIPS. (i.e. PrintString
PrintInt
are implemented.)
When calling SemantMe()
on the function body, we should run a counter on the number of variable declarations (including inside if and while blocks). That way, we will know how much space to leave for the prelude of the function. We should also save the total number of variable declarations inside the function.
Inside the statement of the variable declaration (and only inside statements, not in global variables), we should save the index of the variable declaration inside the encompassing function.
The total size of the prelude should be: (1 + counter) * 4
, where the 1 stands for the RA.
change findScopeClass to return TYPE_CLASS (and not AST)
Suggestion: do more general func: findScope (instead of findScopeClass, findScopeFunc), and return there TYPE and not AST
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.