Skip to content
/ Lm Public

Functional programming language Lm written in Kotlin

Notifications You must be signed in to change notification settings

slaytanic87/Lm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lm

This is a Kotlin based demo compiler for a functional language called Lm (TBD Register Alloc)

Grammar

prog -> program scope
scope -> { sdecls } | €
sdecls -> decl sdecls | function sdecls | €
function -> type func id param block
param -> ( pdecls ) | ()
pdecls -> type id , pdecls | type id
block -> { decls stmts }
decls -> decl decls | €
decl -> type ids ;
ids -> id , ids | id
type -> basic dims
dims -> [ num ] dims | €
stmts -> stmt stmts | €
stmt -> ;
| if ( bool ) stmt
| if ( bool ) stmt else stmt
| while ( bool ) stmt
| do stmt while ( bool ) ;
| for ( assign ; bool ; assign ) stmt
| break ;
| block
| assign ;
| return bool ;
| bool ;
funcall -> id (paramcall)
paramcall -> bool, paramcall | bool
assign -> id offset = bool
offset -> [ id ] offset | [ num ] offset | €
bool -> bool or join | join
join -> join and equality | equality
equality -> equality eq rel | equality ne rel | rel
rel -> expr < expr | expr le expr | expr ge expr | expr > expr | expr
expr -> expr + term | expr - term | term
term -> term * unary | term / unary | unary
unary -> ! unary | - unary | factor
factor -> ( bool ) | funcall | id offset | num | real | bool | true | false

Token classes
id : identifier or = |
num : Integer-number and = &&
real : Floating Point number eq = ==
char : sign ne = !=
bool : boolean value le = <=
basic = num | real | char | bool ge = >=

reserves words

if, else, while, do, for, break, true, false, program, func, return

Example

program {
  int i; int j; float v;
  float x; float[100] a;
  int func demo (int p) {
    while( true ) {
        do i = i + 1; while( a[i] < v);
        do j = j-1; while( a[j] > v);
        if ( i >= j ) break;
        x = a[i]; a[i] = a[j]; a[j] = x;
    }
    return 2;
  }
}
program {
  float v; float[100] a;
  float func myfunction (float f){
    while (true) {
        int i; int j;
        do i = i+1; while (a[i] < v);
        do j = j-1; while (a[j] > v);
        if (i >= j) break;
        {
            float x;
            x = a[i]; a[i] = a[j]; a[j] = x;
        }
        return j;
    }
  }
}

About

Functional programming language Lm written in Kotlin

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages