Skip to content
/ murphy Public

Scanner, Parser and Interpreter of a simple functional programming language

License

Notifications You must be signed in to change notification settings

1boch1/murphy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Murphy

Scanner, Parser and Interpreter of a simple Functional Programming Language

Libraries

No external libraries were used, you only need to have OCaml installed.

Preview

image

image

Project setup (Linux)

  • Compile the file murphy.ml

    ocamlc murphy.ml -o murphy.byte

  • Write your code in a file name.txt and run it

    ./murphy.byte ./name.txt

Syntax

  • This language only works with Integer Numbers
  • IF, LET, IN, TEST, SUCCESS, FAIL, FUNC must be capitalized
  • Variables can't contain Capital Letters
  • Variables can't start with a Number

Algebraic expressions

 (exp)      //brackets
 exp + exp  //sum
 exp - exp  //difference
 exp * exp  //multiplication
 exp / exp  //division

examples

 5 - 2      //3
 0/0        //NaN
 2/0        //PLUS_INFINITY
 5 - 1/0    //MINUS_INFINITY 
 2/0 - 3/0  //NaN
 ...

Comparison

 exp == exp
 exp < exp
 exp > exp

examples

 3 + 2 == 5   //TRUE
 1 == 0       //FALSE
 1 > 0        //TRUE
 1 < 0        //FALSE
 ...

TEST statement

 TEST exp [ == | < | > ] exp
 SUCCESS
    exp
 FAIL 
    exp

examples

 TEST (5 + 5) / 2 == 5
 SUCCES
    10
 FAIL
    1/0
 ...

LET statement

 LET ide = exp
 IN
    exp

examples

 LET x = 1
 IN
 
 LET y = 2
 IN
 
 x*x + y*y
 ...

Function declaration

 FUNC fname (ide1, ide2, ...) =
    exp
 IN
    exp

examples

 FUNC sum (x, y) = x + y
 IN
  5 + 5 
 ...

Function call

 fname (exp1, exp2, ...)

examples

 FUNC sum (x, y) = x + y
 IN
  TEST sum(2, 3) == 5
  SUCCESS sum(2, 3)
  FAIL 0
 ...

About

Scanner, Parser and Interpreter of a simple functional programming language

Topics

Resources

License

Stars

Watchers

Forks

Languages