Author: Orkhan Huseynli, BSIT 2018, "ADA" University
Steps implemented:
- Lexing - Process of tokenizing input string.
- Parsing - Process of analyzing token list given by Lexer and creating parse tree (AST). Used LL(k) parsing algorithm.
- TypeChecking - Checking if the program is well typed.
- Evaluation - Process of evaluting expression and statement.
Test codes that interpreter is able to process:
int main() {
string name = "Orkhan"; string res;
int privilege = 1;
if (privilege == 0) {
res = "Hello, " + name;
} else {
res = "you don't have privilege for the operation";
}
return res;
}
//Output: you don't have privilege for the operation
int main() {
int count = 0;
string res = "Iteration: ";
while (true && count <= 10) {
res = res + "," + count;
count++;
}
return res;
}
//Output: Iteration: ,0,1,2,3,4,5,6,7,8,9,10
int main() {
int x;
int y;
x = 12;
return x + y;
}
//Output: Variable y has never been initalized
int main() {
int x;
int y
x = 12;
return x + y;
}
//Output: Parse error: Unexpected token IDENT at position {x} expected SEMICOLON
int main() {
int x = "myString";
return x;
}
//Output: trying to assign string to integer
int main() {
int z = 12;
bool x = true && x > 12;
return x;
}
//Output: true
int main() {
int y = 1;
bool isOk = true;
string res = "";
while (isOk) {
y = y * 2;
if (y > 100) {
isOk = false;
res = "Y is: " + y;
}
else {
isOk = true;
}
}
return res;
}
//Output: Y is: 128