A simple C-like compiler built using Flex and Bison.
- Linux (Ubuntu, ...etc)
- GCC
- Flex
- Bison
- Install
gcc
- Install
Flex
usingsudo apt-get install flex
- Install
Bison
usingsudo apt-get install bison
- Run
make all
in the project folder - Type the code in a text file (input.txt) then run
./run.out < input.txt
int integer_number = 5;
float float_number = 10.0;
char character = 'c';
string str = "hello world";
bool istrue = true;
- Must be defined in the global scope
- Defined values must start with
$
enum enum_type = {$hello, $goodbye};
enum enum_type x = $hello;
const int integer_number = 5;
const float float_number = 10.0;
char character = 'c';
const string str = "hello world";
const bool istrue = true;
int x = 0;
int y;
if (x >= 0 && x < 5)
{
y = 1;
} else if (x >= 5 && x < 10)
{
y = 2;
}
else
{
y = 3;
}
- Works with all datatypes
int x = 5;
switch(x)
{
case 1:
break;
default:
break;
}
for (int i = 0; i < 5; i = i + 1)
{
}
int x = 5;
while (x <= 10)
{
i = i + 1;
}
int x = 5;
repeat {
x = x + 1;
} until(x <= 10);
- Must be defined in the global scope
- Must start with keyword
func
- Can be of type
int
,float
,char
,string
,bool
, andvoid
- All non-void functions must have a return value
func int sum (int x, int y)
{
int result = x + y;
return result;
}