Skip to content

Delcior/Kac-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 

Repository files navigation

Kac-interpreter

This is dynamically typed language where every statement ends with ;. Scope is defined by { and }.

Logic operators:
and - logical AND
or - logical OR
== - comparison between two values

Variable declaration looks like this:

var variable_name = variable_value;

For example:

var a=10;
var b="Programming is fun";
var c=2.137;

For loop declaration:

for(initializer; condition; state_modifier){
//some code here
}

Example:

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

Analogically while loop declaration looks like this:

while(condition){
//some code here
}

Example:

while(1){
  print "this is endless loop";
}

var i=0;
while(i<10){
  print i;
  i=i+1;
}

Functions:

fun function_name (variable1, variable2,...){ //some code here }

Example:

fun fibbonaci(n){
	if(n==0)
		return 0;
	if(n==1 or n==2)
		return 1;
	var result=0;
	var a=1;
	var b=1;

	for(var i=2;i<n;i=i+1){
		result=a+b;
		a=b;
		b=result;
	}
	
	return result;
}

print fibbonaci(10);

Including other files:
#import pastes source code from imported file.

fib.ka file:

fun fibbonaci(n){
	if(n==0)
		return 0;
	if(n==1 or n==2)
		return 1;
	var result=0;
	var a=1;
	var b=1;

	for(var i=2;i<n;i=i+1){
		result=a+b;
		a=b;
		b=result;
	}
	
	return result;
}

script.ka file:

#import fib.ka;

print fibbonaci(15);

References: https://craftinginterpreters.com/contents.html

About

Interpreter for my language 'Kac'

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages