Skip to content

Rewrite of the Python interpreter of the Grape Programming Language designed to be able to compile to native code using PyPy.

Notifications You must be signed in to change notification settings

grape-lang/grape2.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Grape Programming Language

This is a rewrite of the Python interpreter of the Grape Programming Language. It is designed to be able to compile to native code using PyPy.

Having a compiled interpreter should be A LOT quicker than an interpreter in interpreted python ;)

Unfortunately my new parsing method, which I REALLY like, doesn't work well in Python, so I'm once again rewriting. In Lua this time!

Design

Grammar

program       -> statement* EOF ;

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

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

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


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

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

logic_or      -> logic_and ( "or" logic_and )* ;
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)* ;

About

Rewrite of the Python interpreter of the Grape Programming Language designed to be able to compile to native code using PyPy.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published