~grape-lang/grape-next

Experimental rewrite of the Grape interpreter in Elixir. Work-In-Progress (TM).

The Grape Programming Language

Design

Grammar

program       -> statement* EOF ;

statement     -> expression NEWLINE ;
expression    -> importing | reference | function | assignment | if | scoped | logic_or ;

importing     -> "import" "@" IDENTIFIER "from" string ;

function      -> named | lamda ;
named         -> "fn" IDENTIFIER "(" arguments? ")" block ;
lambda        -> "fn(" arguments? ")" block ;

arguments     -> IDENTIFIER ("," IDENTIFIER)* ;

assignment    -> IDENTIFIER "=" expression ;
if            -> "if" "(" expression ")" scoped

scoped        -> block | line
block         -> "do" statement* "end" ;
line          -> expression

logic_or      -> logic_and ( "or" logic_or )* ;
logic_and     -> equality ( "and" equality )* ;
equality      -> comparison ( ( "==" | "!=" ) comparison )* ;
comparison    -> term ( ( ">" | ">=" | "<" | "<=" ) term )* ;
term          -> factor ( ( "+" | "-" ) factor )* ;
factor        -> unary ( ( "/" | "*" | "%" ) unary )* ;
unary         -> ( "-" | "not" ) exponentation ;
exponentation -> call ( "^" expression )
call          -> primary ( "(" collection? ")" )* ;
primary       -> literal | grouping ;

literal       -> number | text | atom | bool | list | tuple | identifier ;

text          -> "\"" ANY "\"";
number        -> "." DIGITS | DIGITS "." DIGITS | DIGITS ;
atom          -> CAPITAL_CHAR + ALPHANUMERIC ;
identifier    -> ALPHANUMERIC ;
bool          -> "true" | "false" ;

list          -> "[" collection "]" ;
tuple         -> "(" collection ")" ;
grouping      -> "(" expression ")" ;

collection    -> expression ("," expression)* ;