Skip to content

193s/margn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

margn

GPLv2 Build Status

margn is a JVM-based scripting language that compiles your source code into a Java class file.

let a = 100;
print "a == 100:";

if a == 100 : {
  print "yes";
  print "a =";
  print a;
};
else        : print "no";

ss 2015-05-30 at 22 01 27

Usage

To compile a script, type:

$ margn script.mg

To execute a compiled class file, type:

$ java script

Try margn --help for more detailed information.

Installation

  1. $ git clone https://github.com/193s/margn.git && cd margn
  2. $ sbt assembly

An executable shell file ./margn (contains jar) will be generated

  1. (Optional) add your current directory to the PATH, or simply move the file to /usr/local/bin.

Requirements

  • Scala
  • sbt

TODO

See Issues: https://github.com/193s/margn/issues

Language Reference

The syntax of Margn is defined by EBNF.

Program

program ::= { statement ";" }

Program is a sequence of Statements, splitted by ';'.

Statements

statement ::= block | print | assert | let | if | pass

print

print  ::= "print" expr

prints <expr> with EOL

pass

pass ::= "pass"

null operation

assert

assert ::= "assert" expr

evaluates <expr> and throws an AssertionError if it is False.

let

let    ::= "let" id "=" expr

creates a read-only variable named id.

block

block ::= "{" program "}"

block statements

if

if     ::= "if" expr ":" statement

evaluates <statement> if <expr> is True

Expressions

expr ::= expr op expr
       | "-" simpleExpr
       | literal
       | variable
       | "(" expr ")"

Operators

Unary Operators
unary_op ::=  ("-"|"+"|"~"|"!") expr
Binary Operators
bi_op ::= expr op expr
op    ::= "+" | "-" | "==" | ...
Precedence Op Description
0 and or logical and/or
0 ^ xor
1 == != compare
> >= < <=
2 + - addition and subtraction
3 * / multiplication and division

Types and Literals

Int

integerLiteral ::= [1-9][0-9]*
                 | 0x[0-9a-fA-F]+
                 | 0b[01]+

32-bit integer (range: -2147483648 ~ 2147483647)

Bool

booleanLiteral ::= "true" | "false"

Logical type

String

stringLiteral ::= '"' .* '"'

License

Copyright (c) 2015 193s

Published under the GNU GPLv2, see LICENSE

About

JVM-based scripting language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages