Skip to content

Simple Programming Language using Lex and Yacc

Notifications You must be signed in to change notification settings

HazemAbdo/CLOWN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLOWN Logo

CLOWN

Programming doesn't have to be a joke - unless it's CLOWN

CLOWN is a simple programming language that is designed to be easy to learn and use. It is a high-level language and a mixture of C, Python, and JavaScript. It is statically typed, and supports functions, loops, and many other features.

Note:

  • This is a project for the course "CMP4060 Compilers and Languages" at the University of Cairo, Faculty of Engineering, Computer Engineering Department.
  • The compiler doesn't execute the code, it only checks for syntax errors and prints the intermediate assembly code (Quadruples).
  • Not all the features have quadruples generation (Functions, Enums, Break, Continue, and Return).
  • The compiler is not fully tested, so it may contain bugs.

Run The code (Ubuntu)

  • Remove extern int yydebug; in src/clown.y if any
  • Remove yydebug = 1; in main function in src/clown.y if any
make all
make run INPUT_FILE=inputs/code.clown

Run The code with debug (Ubuntu)

  • Add extern int yydebug; to src/clown.y
  • Add yydebug = 1; to main function in src/clown.y
make all
make run INPUT_FILE=inputs/code.clown

Keywords and Operators

"int", "float", "string", "bool", "print", "if", "else", "elif", "while", "for", "do", "break", "continue", "return", "=", "==", "!=", ">", ">=", "<", "<=", "+", "-", "*", "/", "^", "%", "||", "&&", "!", "(", ")", "{", "}", ";", "function", "const", "switch", "case", "default", "enum", "NULL", ":", ","

Syntax

print

print("Hello World");
print(a);
print(a + b);
print(1 + 2 + 3);

if elif else

if (a == 1) {
    print("a is 1");
} elif (a == 2) {
    print("a is 2");
} else {
    print("a is not 1 or 2");
}

while

int a = 0;
while (a < 10) {
    print(a);
    a = a + 1;
}

for loop

for (int i = 0; i < 10; i = i + 1) {
    print(i);
}

do while

int a = 0;
do {
    print(a);
    a = a + 1;
} while (a < 10);

break

int a = 0;
while (a < 10) {
    print(a);
    a = a + 1;
    if (a == 5) {
        break;
    }
}

continue

int a = 0;
while (a < 10) {
    a = a + 1;
    if (a == 5) {
        continue;
    }
    print(a);
}

return

function add(a, b) {
    return a + b;
}

function call