- code generation using stack machines
- enums
- switch cases (should be easy)
- if variable is not initialized, then warning
- if variable is used without being initialized, then error (in char and strings only)
- if variable is not used, then warning
- Check if always false, then warning
- do until (easy)
- handling constant variables checks
- (Not sure if needed) treating INT as a subtype of REAL (double, floats) "y3ni momken a3mel assignment l variable float b int" in operations only
- check the symbol table format (scopes)
- print the scope symbol table as a table in the output file
- test the semantic analyzer more
- edit the error messages to be more indicative (super easy)
- CoDuck
- TODO
- Table of Contents
- program structure
- Some limitations:
- Symbol table
- Language specs
- How To Run
- Resources
- // optional function declarations
- // statements
- // end;
- in for loops declaration (i=0; i<1; i++) is valid, but (int i=0; i<1; i++) is not
- In case of initialization in the same line of declaration, only constants are allowed. i.e. integer x = 5; is valid, but integer x = y; is not
- There's no bit-wise logical operations
- Global scope table is printed after parsing
- for each new scope, we create a new symboltable and we print it while exiting the scope
- Global Symbol Table structure
==================================================================================
Scope Symbol Table
------------ -------------- ------------ --------------------------- ------- ----------
Name Type Value Parent Declared in Scope Line Numbers
------------ -------------- ------------ --------------------------- ------- ----------
a INT 0 2 1 4
b INT 8 2 1 5 6
j INT 2 2 1 3 10 15 22 27
==================================================================================
- Block Symbol Table structure
=====================================================================
Main Symbol Table
------------ -------------- ------------ ------- -------------------
Name Type Value Scope Line Numbers
------------ -------------- ------------ ------- -------------------
test STRING (null) 0 48
coduck INT 1 0 34
func1 func ret INT 0 0 2
===================================================================
- CHAR
- INTEGER
- FLOAT
- BOOL
- VOID
- STRING
-
IF
-
ELIF
-
ELSE
-
CASE
-
SWITCH
-
DEFAULT
-
true (case sensitive)
-
false (case sensitive)
- WHILE
- FOR
- DO
- UNTIL
- CONTINUE
- BREAK
- FUNC
- RETURN
- ENUM
- ADD_OP
+
- SUB_OP
-
- MUL_OP
*
- DIV_OP
/
- MOD_OP
%
- INC_OP
++
- DEC_OP
--
- OR_OP
||
,or
- AND_OP
&&
,and
- NOT_OP
!
,not
- EQ_OP
==
- NE_OP
!=
- LT_OP
<
- GT_OP
>
- LE_OP
<=
- GE_OP
>=
- ASSIGN_OP
=
- BIT_OR_OP
|
- & -> for
REF
andbitwise-and
- BIT_XOR_OP
^
- BIT_LSHIFT_OP
<<
- BIT_RSHIFT_OP
>>
- BIT_NOT_OP
~
- LEFT_PAREN
(
- RIGHT_PAREN
)
- LEFT_SQ_BRACKET
[
- RIGHT_SQ_BRACKET
]
- LEFT_CURLY_BRACKET
{
- RIGHT_CURLY_BRACKET
}
- COMMA
,
- DOT
.
- SEMICOLON
;
- QUESTION_MARK
?
- IDENT
- CONST_INT
- CONST_FLOAT
- CONST_CHAR
- STRING_LITERAL
- Single line: // this is a single line comment
- Multi-line: /_ This is a Multi-line Comment _/
a. examples
String S = "hello, world !"; // this is a string
String S2 = 'hii !'; // this is also a string
String _S = 5; // invalid indentifier
float float_number2 = .6; // invalid float
float float_number3 = 0.; // valid float
float float_number4 = 00.6 // invalid float
float float_number5 = -0.006 // valid float
integer x = 000 // invalid integer
if(expression logical_operator expression){ // the parenthesis are optional
}elif(expression logical_operator expression){// the parenthesis are optional
}else{
}
switch (expression){ // the parenthesis are optional
case constant1:
// statements
break;
case constant2:
// statements
break;
.
.
.
default:
// default statements
}
while(condition){ // parenthesis are optional
}
do{
...
}until(condition); // parenthesis are optional
for(var; cond; postfix;){
// parenthesis are optional
}
func function_name(type name, ...) return_type{
return value;
}
enum Level {
LOW,
MEDIUM,
HIGH
};
enum a{
x = 0,
y= 1
};
Quadruple | Quadruple Description |
---|---|
push J | used for the variables declarations (i.e int J;) |
Add | used for the addtion of the two previous operands (i.e J = 1 + 2 will be 1 , 2, ADD) |
store J | used for the store of the previous value in the variable J (i.e J = 1 + 2 will be 1 , 2, ADD, store J) |
if false goto # | if condition false goto the else part at line (#) |
Quadruple | Quadruple Description |
---|---|
push J | used for the variables declarations (i.e int J;) |
Add,Sub,Mul,<,> | used for the addtion of the two previous operands (i.e J = 1 + 2 will be 1 , 2, ADD) |
store J | used for the store of the previous value in the variable J (i.e J = 1 + 2 will be 1 , 2, ADD, store J) |
if false goto # | if condition false goto the else part at line (#) |
cd to the project directory "design/tests"
- Run the following command to compile the code
bison -d parser.y
flex lex.l
gcc -o compiler parser.tab.c lex.yy.c
rm lex.yy.c parser.tab.c
- to run a test file, run the following command
.\compiler test_file_name symbol_table_file_name revisit_queue_file_name
example:
.\compiler full_example.kak symbol_table_full_example.out revisit_queue_full_example.out
https://en.cppreference.com/w/c/language/operator_precedence
http://marvin.cs.uidaho.edu/Teaching/CS445/c-Grammar.pdf