Code Monkey home page Code Monkey logo

sage's Introduction

SAGE


GRAMMER

program         -> declaration* EOF ;
declaration     -> class_decl | func_decl | let_decl | statement ;
class_decl      -> "class" IDENTIFIER ( "(" IDENTIFIER ")" )? "{" NL func_decl* "}" NL ;
func_decl       -> "fn" IDENTIFIER "(" parameters? ")" block_stmt ;
parameters      -> IDENTIFIER ( "," IDENTIFIER )* ;
let_decl        -> "let" IDENTIFIER ( "=" expression )? NL ;
statement       -> if_stmt | while_stmt | for_stmt | return_stmt | break_stmt
                 | print_stmt | block_stmt | expr_stmt ;
if_stmt         -> "if" expression block_stmt ( "else" block_stmt )? ;
while_stmt      -> "while" expression block_stmt ;
for_stmt        -> "for" init_clause expression? ";" expression? block_stmt ;
init_clause     -> loop_let | loop_expr | ";" ;
loop_let        -> "let" IDENTIFIER ( "=" expression )? ";" ;
loop_expr       -> expression ";" ;
return_stmt     -> "return" expression? NL ;
break_stmt      -> "break" NL ;
print_stmt      -> "print" ( expression ( "," expression )* )? NL ;
block_stmt      -> "{" NL declaration* "}" NL ;
expr_stmt       -> expression NL ;

expression      -> assignment ;
assignment      -> ( call "." )? IDENTIFIER ( assign_oper ) assignment
                 | logic_or ;
assign_oper     -> "=" | "+=" | "-=" | "*=" | "/=" | "%=" ;
logic_or        -> logic_and ( "or" logic_and )* ;
logic_and       -> equality ( "and" equality )* ;
equality        -> comparison ( ( "is" | "!=" | "==" ) comparison )* ;
comparison      -> addition ( ( ">" | ">=" | "<" | "<=" ) addition )* ;
addition        -> multiplication ( ( "+" | "-" ) multiplication )* ;
multiplication  -> unary ( ( "*" | "/" | "%" ) unary )* ;
unary           -> ( "not" | "!" | "-" ) unary | call ;
call            -> primary ( "(" arguments? ")" | "." IDENTIFIER )* ;
arguments       -> expression ( "," expression )* ;
primary         -> INTEGER | DECIMAL | STRING
                 | "true" | "false" | "nil" | "self"
                 | "(" expression ")" | "super" "." IDENTIFIER ;

sage's People

Contributors

asmlover avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.