We had to calculate statistics over text. This was to learn about flex and how to use it.
Design a C lexer that could lex C and output the important information about the C code. This made us read the C spec for the first time.
We had to design a maths parser and then analyse the tree that was created by parsing it. The additional parts where to differentiate equations using the different rules for differentiating. We also had to evaluate the expressions and do other operations on the tree. This taught us how to use bison.
Finsihed the AST for now, using polymorphism to achieve this. Right now i t achieves the goal of this coursework as it does print out the AST in xml format and supports all the features that the parser should support. The expressions branch of the AST is completely bare because they are not needed for this parser. I will continue working on this AST in the compiler section so that it supports all the other constructs that I need for the compiler.
The grammar is not completely done yet as I dont support all of the declartions that are possible, and as I add more constructs in the AST I will also have to add declarations in the bison file. This I will only continue in the Compiler section.
In this lab we used the setup provided to us to make a compiler for the language specified in the lab. The AST was already built for us and the language was already parsed using C++ instead of bison.
- %hi(id)
- loads the upper address of the global variable id
- %lo(id)
- loads the lower address of the global variable id
- addiu
- Add Immediate Unsigned
- jr
- Jump Register
- li
- Pseudo instruction interpreted as ( lui $rd, LabelAddr[31:16] ori $rd,$rd, LabelAddr[15:0] )
- lui
- loads uppper immediate.
- lw
- Load Word
- move
- Pseudo instruction interpreted as (add $rt, $rs, $zero)
- nop
- No Operation
- sw
- Store Word
The class will contain map of strings containing the variable name as the key and the stack position as the stack position and type as the attributes, which will be combined using a struct.
Implement the adding to the bindings part that has to be added in the statements and declarations.
To do this I created a function in my VariableStackBindings that will store the position of the stack that will be used for the next expression.
Add more expression.
- Work on bison file to get the parameters correctly
- Work on storing them correctly in the binding
comment code to know where I am at and what I still have to do.
- need function that will print the code for declaration. Basic code should be:
li $2, 6 sw $2, 4($fp)
- Before that is executed it should evaluate the expression.
- The expression should be the thing doing: li $2, 6 That is if we want a 6 stored in the variable.
- The declaration class should only be in charge of storing it in the right location in the stack and adding that to the bindings.
Expressions like > or < or == etc..
Have to fix type assigment for declaration lists, need to make new pointers of the right type.
I have to store the temporary expression in normal registers.
convert all cout to printf
Change code so that it also prints global variables. This should be done with the globalAsm function.
I might have to change the print Asm and the global Asm function in the declarations.
For post increment I will have a special class that handles that, for pre increment I will rewrite in terms of addition, which should be possible.
Finished arrays
Finished pointers