Skip to content
This repository has been archived by the owner on Apr 4, 2020. It is now read-only.
/ AGH-Compilers Public archive

AGH University of science and technology - Compilers Labs - Custom 'M' language compiler

Notifications You must be signed in to change notification settings

jan-golda/AGH-Compilers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom M language compiler

Usage

$ pipenv install
$ pipenv run cli

M language examples

Constants

b1 = true;            # boolean
b2 = false;           # boolean
i1 = 10;              # integer
f1 = 60.5;            # float
f2 = 60.;             # float
f3 = .5;              # float
f4 = 60.52E2;         # float
f4 = 60.52E-2;        # float
s1 = "Hello world";   # string

Matrix initialization

# 'zeros' and 'ones' accepts any number of arguments
A = zeros(5);         # create vector of size 5 filled with zeros
B = ones(7, 4);       # create 7x4 matrix filled with ones
C = zeros(1, 2, 3);   # create 1x2x3 matrix filled with zeros

# eye accepts exactly two arguments
D = eye(10, 8);      # create 10x8 matrix filled with ones on diagonal and zeros elsewhere

E = [1, 2, 3, 4]      # vector of size 4
F = [[1, 2, 3],       # matrix of size 2x3
     [4, 5, 6]]

Scalars operations

r = a + b             # addition
r = a - b             # subtraction
r = a * b             # multiplication
r = a / b             # division

r = -a                # negation

r += a                # assignment with addition
r -= a                # assignment with subtraction
r *= a                # assignment with multiplication
r /= a                # assignment with division

r = a > b             # comparision: greater
r = a < b             # comparision: lesser
r = a >= b            # comparision: greater or equal
r = a <= b            # comparision: lesser or equal

Matrix operations

R = A .+ B            # element wise addition
R = A .- B            # element wise subtraction
R = A .* B            # element wise multiplication
R = A ./ B            # element wise division
R = A'                # matrix transpositon

A[1,2] = B[3,4]       # metrix selectors

Comparators

r = A == B            # equality comparator
r = a == b       
       
r = A != B            # not equality comparator
r = a != b

IF statement

if (a > b)
    print "Yes";

if (a > b) {
    print "Yes";
}

if (a > b)
    print "Yes";
else
    print "No";

if (a > b) {
    print "Yes";
} else {
    print "No";
}

Loops

# while loops
while (a > b)
    b += 1;

while (a > b) {
    b += 1;
}

# for (range) loops
for i = 1:5
    print i;

for i = 1:5 {
    print i;
}

# break and continue keywords
while(a > b) {
    if (a > 10)
        break;
    if (a > 5)
        continue;
    a += 1;
}

Built-in instructions

print a, b, c;       # prints to stdout, acepts any amount of arguments 
return a;            # terminates program with given value as result

About

AGH University of science and technology - Compilers Labs - Custom 'M' language compiler

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages