Skip to content

realdanvanth/compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 

Repository files navigation

compiler

minimal x86_64 compiler that converts cslop to assembly it is written entirely from scratch without any dependencies except the java runtime environment and nasm assembler currently all the code is modular in assembly ,meaning its really unoptimized and it still manages to beat python at speed

installation

npm install real-compiler 

execution

npx compiler yourfile.tl

operators

  • ':' -> equal to
  • '|' -> or
  • '&' -> and

the rest are standard

variable declaration statement

int a = {NumExp} \\ all integers and booleans are 64 bit
boolean a = {BoolExp}

if statements

if(cond a){
{Program}
}
elif(cond b){
{Program}
}
else
{
{Program}
};

loop statements

while(cond a){
{Prog}
};

exit statement

exit({NumExp});

program

a program is a list of statements

int i = 1;
int n = 2147483647;
int f = 0;
int rem = 0;
while(i<n){
  rem = n%i;
  if(rem:0){
    f = f+1;
  };
  i = i+1;
};
if(f:1){
  exit(1);
};
exit(0);

features implemented and yet to be

  • 1. lexer
  • 2. parser
  • 3. ast
  • 4. code gen
  • 5. stack management
  • 7. arithmetic expressions
  • 8. boolean expressions
  • 9. while loops
  • 10. variable scopes
  • 11. error handling
  • 12. functions
  • 13. peephole optimization
  • 14. arrays and strings
  • 15. input and output

what motivated me to do this?

https://youtu.be/NYClgSGzWnI?si=0JVQt2eyNDXL4UK_

About

x86_64 compiler written in java

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published