Skip to content

Commit

Permalink
Merge pull request #13 from zestones/4-handle-boolean-expression-with…
Browse files Browse the repository at this point in the history
…-arithmetic-operation

4 handle boolean expression with arithmetic operation
  • Loading branch information
zestones authored Dec 30, 2024
2 parents a6618cc + f929ae1 commit d4d2166
Show file tree
Hide file tree
Showing 128 changed files with 3,080 additions and 7,900 deletions.
39 changes: 39 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Compiler",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/compiler.exe",
"args": ["-lf", "./example/compilation/to-remove.txt", "-o", "test.a"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{ "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true }
],
"preLaunchTask": "Build Project"
},
{
"name": "Debug Interpreter",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/interpreter.exe",
"args": ["-f", "test.a"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{ "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true }
],
"preLaunchTask": "Build Project"
}
]
}
34 changes: 10 additions & 24 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
{
"files.associations": {
"*.rmd": "markdown",
"vm_cell.h": "c",
"stdio.h": "c",
"representation_table.h": "c",
"lexeme_table.h": "c",
"utility.h": "c",
"expression.h": "c",
"stdlib.h": "c",
"execution.h": "c",
"interpreter.h": "c",
"address_calculation.h": "c",
"stack_management.h": "c",
"ast.h": "c",
"table_printer.h": "c",
"system_error": "c",
"array": "c",
"functional": "c",
"tuple": "c",
"type_traits": "c",
"utility": "c",
"compare": "c",
"utils.h": "c",
"variable_manager.h": "c",
"cstdlib": "c",
"execution.h": "c",
"region_table.h": "c",
"address_calculation.h": "c",
"lexeme_table.h": "c",
"interpreter.h": "c",
"stack.h": "c",
"type_inference.h": "c",
"condition.h": "c",
"procedure.h": "c",
"format_specifiers.h": "c",
"cstdlib": "c"
"representation_table.h": "c",
"formatting.h": "c",
"stdlib.h": "c"
}
}
16 changes: 16 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build Project",
"type": "shell",
"command": "make",
"args": ["clean", "all"],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ clean: simple-clean
rm -f *.exe $(BIN_DIR)/*.tab.c $(BIN_DIR)/*.tab.h $(BIN_DIR)/lex.yy.c && \
rm -rf tests/**/__pycache__
rm -rf ./.pytest_cache/
rm -f log.txt *.a
rm -f log.txt
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,8 @@ Address of $S[3].f$:
$$
\text{Address} = 2000 + (3 \cdot 12) + 4 = 2040
$$

### Notes:

- **Dynamic**: Refers to the function frame index of the caller.
- **Static**: Refers to the frame index of the parent.
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ Root of the AST:
+------------------------------------------------------------------------+
Root of the AST:
├── A_FUNCTION_DECLARATION, Lexico Idx: 12, Decl Idx: 12 -- Lexeme: 'test'
│ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_FLOAT_LITERAL, Lexico Idx: 13, Decl Idx: -1 -- Lexeme: '1.0'
│ ├── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_FLOAT_LITERAL, Lexico Idx: 13, Decl Idx: -1 -- Lexeme: '1.0'
+------------------------------------------------------------------------+


Expand All @@ -236,7 +237,8 @@ Root of the AST:
├── A_FUNCTION_DECLARATION, Lexico Idx: 14, Decl Idx: 14 -- Lexeme: 'main'
│ ├── A_PARAMETER_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_PARAMETER, Lexico Idx: 15, Decl Idx: 15 -- Lexeme: 'a'
│ └── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_INTEGER_LITERAL, Lexico Idx: 16, Decl Idx: -1 -- Lexeme: '0'
│ └── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_INTEGER_LITERAL, Lexico Idx: 16, Decl Idx: -1 -- Lexeme: '0'
+------------------------------------------------------------------------+

Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ Root of the AST:
│ │ │ │ ├── A_MUL_OP, Lexico Idx: -1, Decl Idx: -1
│ │ │ │ │ ├── A_IDENTIFIER, Lexico Idx: 4, Decl Idx: 500 -- Lexeme: 'a'
│ │ │ │ │ └── A_INTEGER_LITERAL, Lexico Idx: 24, Decl Idx: -1 -- Lexeme: '2'
│ └── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_IDENTIFIER, Lexico Idx: 4, Decl Idx: 500 -- Lexeme: 'a'
└── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_IDENTIFIER, Lexico Idx: 4, Decl Idx: 500 -- Lexeme: 'a'
+------------------------------------------------------------------------+


Expand All @@ -289,7 +289,7 @@ Root of the AST:
│ │ │ │ ├── A_DIV_OP, Lexico Idx: -1, Decl Idx: -1
│ │ │ │ │ ├── A_IDENTIFIER, Lexico Idx: 26, Decl Idx: 26 -- Lexeme: 'g'
│ │ │ │ │ └── A_INTEGER_LITERAL, Lexico Idx: 24, Decl Idx: -1 -- Lexeme: '2'
│ └── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_IDENTIFIER, Lexico Idx: 26, Decl Idx: 26 -- Lexeme: 'g'
└── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_IDENTIFIER, Lexico Idx: 26, Decl Idx: 26 -- Lexeme: 'g'
+------------------------------------------------------------------------+

Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ Root of the AST:
│ ├── A_PARAMETER_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_PARAMETER, Lexico Idx: 19, Decl Idx: 19 -- Lexeme: 'a'
│ │ └── A_PARAMETER, Lexico Idx: 20, Decl Idx: 20 -- Lexeme: 'b'
│ └── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_INTEGER_LITERAL, Lexico Idx: 21, Decl Idx: -1 -- Lexeme: '0'
│ └── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_INTEGER_LITERAL, Lexico Idx: 21, Decl Idx: -1 -- Lexeme: '0'
+------------------------------------------------------------------------+

Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ Root of the AST:
+------------------------------------------------------------------------+
Root of the AST:
├── A_FUNCTION_DECLARATION, Lexico Idx: 5, Decl Idx: 5 -- Lexeme: 'one_int'
│ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_INTEGER_LITERAL, Lexico Idx: 6, Decl Idx: -1 -- Lexeme: '1'
│ ├── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_INTEGER_LITERAL, Lexico Idx: 6, Decl Idx: -1 -- Lexeme: '1'
+------------------------------------------------------------------------+


Expand All @@ -157,8 +158,9 @@ Root of the AST:
+------------------------------------------------------------------------+
Root of the AST:
├── A_FUNCTION_DECLARATION, Lexico Idx: 7, Decl Idx: 7 -- Lexeme: 'one_float'
│ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_FLOAT_LITERAL, Lexico Idx: 8, Decl Idx: -1 -- Lexeme: '1.0'
│ ├── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_FLOAT_LITERAL, Lexico Idx: 8, Decl Idx: -1 -- Lexeme: '1.0'
+------------------------------------------------------------------------+


Expand All @@ -170,7 +172,8 @@ Root of the AST:
│ ├── A_PARAMETER_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_PARAMETER, Lexico Idx: 10, Decl Idx: 10 -- Lexeme: 'a'
│ │ └── A_PARAMETER, Lexico Idx: 11, Decl Idx: 11 -- Lexeme: 'b'
│ └── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_INTEGER_LITERAL, Lexico Idx: 12, Decl Idx: -1 -- Lexeme: '0'
│ └── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_INTEGER_LITERAL, Lexico Idx: 12, Decl Idx: -1 -- Lexeme: '0'
+------------------------------------------------------------------------+

Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ Root of the AST:
│ ├── A_PARAMETER_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_PARAMETER, Lexico Idx: 16, Decl Idx: 16 -- Lexeme: 'a'
│ │ └── A_PARAMETER, Lexico Idx: 17, Decl Idx: 17 -- Lexeme: 'b'
│ └── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_INTEGER_LITERAL, Lexico Idx: 18, Decl Idx: -1 -- Lexeme: '0'
│ └── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_INTEGER_LITERAL, Lexico Idx: 18, Decl Idx: -1 -- Lexeme: '0'
+------------------------------------------------------------------------+

Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ Root of the AST:
+------------------------------------------------------------------------+
Root of the AST:
├── A_FUNCTION_DECLARATION, Lexico Idx: 6, Decl Idx: 6 -- Lexeme: 'test2'
│ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_INTEGER_LITERAL, Lexico Idx: 7, Decl Idx: -1 -- Lexeme: '1'
│ ├── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_INTEGER_LITERAL, Lexico Idx: 7, Decl Idx: -1 -- Lexeme: '1'
+------------------------------------------------------------------------+


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ Root of the AST:
│ ├── A_PARAMETER_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_PARAMETER, Lexico Idx: 16, Decl Idx: 16 -- Lexeme: 'a'
│ │ └── A_PARAMETER, Lexico Idx: 17, Decl Idx: 17 -- Lexeme: 'b'
│ └── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_INTEGER_LITERAL, Lexico Idx: 18, Decl Idx: -1 -- Lexeme: '0'
│ └── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_INTEGER_LITERAL, Lexico Idx: 18, Decl Idx: -1 -- Lexeme: '0'
+------------------------------------------------------------------------+

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[Type Error] Type mismatch for function return value at example/compilation/errors/semantic/func_proc/prototype/prototype.txt:17:2.
[Type Error] Type mismatch for function return value at example/compilation/errors/semantic/func_proc/prototype/prototype.txt:16:23.
Function returned value has type 'float', but it should be of type 'int'.
Ensure the function return type matches the expected type.

Expand Down Expand Up @@ -106,8 +106,9 @@ Root of the AST:
+------------------------------------------------------------------------+
Root of the AST:
├── A_FUNCTION_DECLARATION, Lexico Idx: 4, Decl Idx: 4 -- Lexeme: 'zero'
│ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_FLOAT_LITERAL, Lexico Idx: 5, Decl Idx: -1 -- Lexeme: '0.0'
│ ├── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_FLOAT_LITERAL, Lexico Idx: 5, Decl Idx: -1 -- Lexeme: '0.0'
+------------------------------------------------------------------------+


Expand All @@ -118,8 +119,9 @@ Root of the AST:
├── A_FUNCTION_DECLARATION, Lexico Idx: 6, Decl Idx: 6 -- Lexeme: 'one'
│ ├── A_PARAMETER_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_PARAMETER, Lexico Idx: 7, Decl Idx: 7 -- Lexeme: 'x'
│ └── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_IDENTIFIER, Lexico Idx: 7, Decl Idx: 7 -- Lexeme: 'x'
│ └── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_IDENTIFIER, Lexico Idx: 7, Decl Idx: 7 -- Lexeme: 'x'
+------------------------------------------------------------------------+


Expand All @@ -136,9 +138,9 @@ Root of the AST:
│ │ ├── A_ASSIGNMENT_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_VARIABLE_ASSIGNMENT, Lexico Idx: 7, Decl Idx: 500 -- Lexeme: 'x'
│ │ │ │ ├── A_FLOAT_LITERAL, Lexico Idx: 10, Decl Idx: -1 -- Lexeme: '45.0'
│ └── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_ADD_OP, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_IDENTIFIER, Lexico Idx: 7, Decl Idx: 500 -- Lexeme: 'x'
│ │ │ └── A_FUNC_PROC_CALL_STATEMENT, Lexico Idx: 4, Decl Idx: 4 -- Lexeme: 'zero'
└── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_ADD_OP, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_IDENTIFIER, Lexico Idx: 7, Decl Idx: 500 -- Lexeme: 'x'
│ │ │ └── A_FUNC_PROC_CALL_STATEMENT, Lexico Idx: 4, Decl Idx: 4 -- Lexeme: 'zero'
+------------------------------------------------------------------------+

Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ Root of the AST:
+------------------------------------------------------------------------+
Root of the AST:
├── A_FUNCTION_DECLARATION, Lexico Idx: 4, Decl Idx: 4 -- Lexeme: 'main'
│ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_INTEGER_LITERAL, Lexico Idx: 5, Decl Idx: -1 -- Lexeme: '0'
│ ├── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_INTEGER_LITERAL, Lexico Idx: 5, Decl Idx: -1 -- Lexeme: '0'
+------------------------------------------------------------------------+


Expand All @@ -102,8 +103,9 @@ Root of the AST:
+------------------------------------------------------------------------+
Root of the AST:
├── A_FUNCTION_DECLARATION, Lexico Idx: 4, Decl Idx: 500 -- Lexeme: 'main'
│ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_INTEGER_LITERAL, Lexico Idx: 5, Decl Idx: -1 -- Lexeme: '0'
│ ├── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_INTEGER_LITERAL, Lexico Idx: 5, Decl Idx: -1 -- Lexeme: '0'
+------------------------------------------------------------------------+


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ Root of the AST:
│ ├── A_PARAMETER_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_PARAMETER, Lexico Idx: 15, Decl Idx: 15 -- Lexeme: 'a'
│ │ └── A_PARAMETER, Lexico Idx: 16, Decl Idx: 16 -- Lexeme: 'b'
│ └── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_INTEGER_LITERAL, Lexico Idx: 17, Decl Idx: -1 -- Lexeme: '0'
│ └── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_INTEGER_LITERAL, Lexico Idx: 17, Decl Idx: -1 -- Lexeme: '0'
+------------------------------------------------------------------------+

Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ Root of the AST:
├── A_FUNCTION_DECLARATION, Lexico Idx: 8, Decl Idx: 8 -- Lexeme: 'my_func'
│ ├── A_DECLARATION_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_VARIABLE_DECLARATION, Lexico Idx: 9, Decl Idx: 9 -- Lexeme: 'x'
│ └── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_IDENTIFIER, Lexico Idx: 9, Decl Idx: 9 -- Lexeme: 'x'
│ └── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_IDENTIFIER, Lexico Idx: 9, Decl Idx: 9 -- Lexeme: 'x'
+------------------------------------------------------------------------+


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,9 @@ Root of the AST:
+------------------------------------------------------------------------+
Root of the AST:
├── A_FUNCTION_DECLARATION, Lexico Idx: 22, Decl Idx: 22 -- Lexeme: 'test'
│ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_INTEGER_LITERAL, Lexico Idx: 14, Decl Idx: -1 -- Lexeme: '1'
│ ├── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_INTEGER_LITERAL, Lexico Idx: 14, Decl Idx: -1 -- Lexeme: '1'
+------------------------------------------------------------------------+


Expand All @@ -275,7 +276,8 @@ Root of the AST:
├── A_FUNCTION_DECLARATION, Lexico Idx: 23, Decl Idx: 23 -- Lexeme: 'main'
│ ├── A_PARAMETER_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_PARAMETER, Lexico Idx: 24, Decl Idx: 24 -- Lexeme: 'a'
│ └── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_INTEGER_LITERAL, Lexico Idx: 25, Decl Idx: -1 -- Lexeme: '0'
│ └── A_STATEMENT_LIST, Lexico Idx: -1, Decl Idx: -1
│ │ ├── A_RETURN_STATEMENT, Lexico Idx: -1, Decl Idx: -1
│ │ │ ├── A_INTEGER_LITERAL, Lexico Idx: 25, Decl Idx: -1 -- Lexeme: '0'
+------------------------------------------------------------------------+

Loading

0 comments on commit d4d2166

Please sign in to comment.