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";
To compile a script, type:
$ margn script.mg
To execute a compiled class file, type:
$ java script
Try margn --help
for more detailed information.
$ git clone https://github.com/193s/margn.git && cd margn
$ sbt assembly
An executable shell file
./margn
(contains jar) will be generated
- (Optional) add your current directory to the PATH, or simply move the file to
/usr/local/bin
.
- Scala
- sbt
See Issues: https://github.com/193s/margn/issues
The syntax of Margn is defined by EBNF.
program ::= { statement ";" }
Program
is a sequence of Statements, splitted by ';'.
statement ::= block | print | assert | let | if | pass
print ::= "print" expr
prints <expr> with EOL
pass ::= "pass"
null operation
assert ::= "assert" expr
evaluates <expr> and throws an AssertionError
if it is False
.
let ::= "let" id "=" expr
creates a read-only variable named id
.
block ::= "{" program "}"
block statements
if ::= "if" expr ":" statement
evaluates <statement> if <expr> is True
expr ::= expr op expr
| "-" simpleExpr
| literal
| variable
| "(" expr ")"
unary_op ::= ("-"|"+"|"~"|"!") expr
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 |
integerLiteral ::= [1-9][0-9]*
| 0x[0-9a-fA-F]+
| 0b[01]+
32-bit integer (range: -2147483648
~ 2147483647
)
booleanLiteral ::= "true" | "false"
Logical type
stringLiteral ::= '"' .* '"'
Copyright (c) 2015 193s
Published under the GNU GPLv2, see LICENSE