diff --git a/lab3-4/README.md b/lab3-4/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3c18a97dfb81a88afcff4e6ab766c89bc0541b07 --- /dev/null +++ b/lab3-4/README.md @@ -0,0 +1,43 @@ +# Code Skeleton for Lab 3 and Lab 4 +This folder contains the code skeleton that you will be working on during Lab 3 and Lab 4. + +## Lab 3 +For Lab 3 two files are of interest, `parser.y` and `scanner.l`. + +To start, begin by integrating what you did in lab 1 to the `scanner.l` file. +Here it is important that you are careful, and that you do not simply copy paste. +Look at the structure of `scanner.l` and enter your rules s.t you do not remove any includes present in that file. + +### Testing Lab 3. +There is a number of test files in the `test` directory that you may use to check if your parser works as expected. + +We also provide traces that you can use to compare the output of your solution to some expected output. + +To do this you can exceute the following sequence of commands. + +To check if you get about the same result for expressions you can run: + +```bash +./compiler ./test/expression_test.prog > my_output.txt +diff -y my_output.txt ../traces/trace_expression_test.txt +``` + +The same procedure can be done for the more advanced test, that is `traces/trace-lab3.txt` + +``` +./compiler ./test/test > my_output.txt +diff -y my_output.txt ../traces/trace-lab3.txt +``` + +## Lab 4 + +In lab 4 you will work in file `codegen.cc` search for `/* --- Your code here --- */`' +to see where you need to introduce your changes. + +### Testing Lab 4 +In order to test Lab 4, there exists a test script. +For more details see the README in the test folder. + + +## Other notes +For more exhaustive documentation see [The Lab Skeleton Documentation](https://www.ida.liu.se/~TDDD55/laboratories/instructions/_static/skeleton.pdf) diff --git a/traces/trace_expression_test.txt b/traces/trace_expression_test.txt new file mode 100644 index 0000000000000000000000000000000000000000..537252c83d7971da7f6d8da0ec89d6f82b667f15 --- /dev/null +++ b/traces/trace_expression_test.txt @@ -0,0 +1,208 @@ +FunctionInformation @ 0x564ef0e59ed0 + Tag: 0 + ID: main + Table: 0 + Parent: 0 + Returns: 0 + Parameters: none + Locals: + 0x564ef0e6c9d0 b + 0x564ef0e6c8c0 a + + Body: 0x564ef0e6e780 +StatementList (statement, preceding) ++-CallStatement (call) +| +-FunctionCall (function, arguments) [<SymbolInformation @ 0x0>] +| +-putline +| +-0 ++-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [integer] + | +-putreal + | +-ExpressionList (expression, preceding) + | +-Identifier (b) + | +-0 + +-StatementList (statement, preceding) + +-Assignment (left, right) + | +-Identifier (b) + | +-Power (left, right) [real] + | +-RealConstant (2) [real] + | +-RealConstant (2) [real] + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [<SymbolInformation @ 0x0>] + | +-putline + | +-0 + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [integer] + | +-putreal + | +-ExpressionList (expression, preceding) + | +-Identifier (b) + | +-0 + +-StatementList (statement, preceding) + +-Assignment (left, right) + | +-Identifier (b) + | +-Divide (left, right) [real] + | +-RealConstant (2) [real] + | +-RealConstant (2) [real] + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [<SymbolInformation @ 0x0>] + | +-putline + | +-0 + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [integer] + | +-putreal + | +-ExpressionList (expression, preceding) + | +-Identifier (b) + | +-0 + +-StatementList (statement, preceding) + +-Assignment (left, right) + | +-Identifier (b) + | +-Times (left, right) [real] + | +-RealConstant (2) [real] + | +-RealConstant (2) [real] + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [<SymbolInformation @ 0x0>] + | +-putline + | +-0 + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [integer] + | +-putreal + | +-ExpressionList (expression, preceding) + | +-Identifier (b) + | +-0 + +-StatementList (statement, preceding) + +-Assignment (left, right) + | +-Identifier (b) + | +-Minus (left, right) [real] + | +-RealConstant (2) [real] + | +-RealConstant (2) [real] + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [<SymbolInformation @ 0x0>] + | +-putline + | +-0 + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [integer] + | +-putreal + | +-ExpressionList (expression, preceding) + | +-Identifier (b) + | +-0 + +-StatementList (statement, preceding) + +-Assignment (left, right) + | +-Identifier (b) + | +-Plus (left, right) [real] + | +-RealConstant (1) [real] + | +-RealConstant (2) [real] + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [<SymbolInformation @ 0x0>] + | +-putline + | +-0 + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [integer] + | +-putint + | +-ExpressionList (expression, preceding) + | +-Identifier (a) + | +-0 + +-StatementList (statement, preceding) + +-Assignment (left, right) + | +-Identifier (a) + | +-Power (left, right) [integer] + | +-IntegerConstant (2) [integer] + | +-IntegerConstant (2) [integer] + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [<SymbolInformation @ 0x0>] + | +-putline + | +-0 + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [integer] + | +-putint + | +-ExpressionList (expression, preceding) + | +-Identifier (a) + | +-0 + +-StatementList (statement, preceding) + +-Assignment (left, right) + | +-Identifier (a) + | +-Divide (left, right) [integer] + | +-IntegerConstant (2) [integer] + | +-IntegerConstant (2) [integer] + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [<SymbolInformation @ 0x0>] + | +-putline + | +-0 + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [integer] + | +-putint + | +-ExpressionList (expression, preceding) + | +-Identifier (a) + | +-0 + +-StatementList (statement, preceding) + +-Assignment (left, right) + | +-Identifier (a) + | +-Times (left, right) [integer] + | +-IntegerConstant (2) [integer] + | +-IntegerConstant (2) [integer] + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [<SymbolInformation @ 0x0>] + | +-putline + | +-0 + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [integer] + | +-putint + | +-ExpressionList (expression, preceding) + | +-Identifier (a) + | +-0 + +-StatementList (statement, preceding) + +-Assignment (left, right) + | +-Identifier (a) + | +-Minus (left, right) [integer] + | +-IntegerConstant (2) [integer] + | +-IntegerConstant (2) [integer] + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [<SymbolInformation @ 0x0>] + | +-putline + | +-0 + +-StatementList (statement, preceding) + +-CallStatement (call) + | +-FunctionCall (function, arguments) [integer] + | +-putint + | +-ExpressionList (expression, preceding) + | +-Identifier (a) + | +-0 + +-StatementList (statement, preceding) + +-Assignment (left, right) + | +-Identifier (a) + | +-Plus (left, right) [integer] + | +-IntegerConstant (1) [integer] + | +-IntegerConstant (2) [integer] + +-0 + Quads: 0 + +------------------------------------------------------------------------------- +SymbolTable @ 0x564ef0e59f28 +------------------------------------------------------------------------------- +11 0x564ef0e64320 getint() -> integer +65 0x564ef0e6c8c0 a : 0x564ef0e5bf80 integer [8] +66 0x564ef0e6c9d0 b : 0x564ef0e5bff0 real [8] --> 0x564ef0e6c8c0 a +88 0x564ef0e5bf80 0x564ef0e5bf80 integer [8] +92 0x564ef0e5c060 putreal(x) -> integer +481 0x564ef0e5e110 putline() -> no return type +603 0x564ef0e5bff0 0x564ef0e5bff0 real [8] +775 0x564ef0e601c0 putint(x) -> integer +918 0x564ef0e62270 getreal() -> real +-------------------------------------------------------------------------------