Skip to content

Latest commit

 

History

History
86 lines (82 loc) · 7.38 KB

grammar.md

File metadata and controls

86 lines (82 loc) · 7.38 KB

Tokens

Token Name Token Value
CLASS 'class'
OBJECT 'object'
TRAIT 'trait'
DEF 'def'
NEW 'new'
LPAREN '('
RPAREN ')'
LBRACE '{'
RBRACE '}'
COMMA ','
DOT '.'
EQ '='
SEMICOLON ';'
COLON ':'
IF 'if'
ELSE 'else'
WHILE 'while'
FOR 'for'
RETURN 'return'
VAR 'var'
VAL 'val'
ARROW '<-'
EQEQ '=='
NEQ '!='
LT '<'
GT '>'
LTEQ '<='
GTEQ '>='
PRO '%'
AND '&&'
OR '
PLUS '+'
MINUS '-'
ASTERISK '*'
SLASH '/'
BANG '!'
BOOLEAN_LITERAL 'true' or 'false'
INT_LITERAL Any series of digits (0-9)
STRING_LITERAL Any series between " "
IDENTIFIER Alphabetic followed by alphanumeric characters
WS Whitespaces

Productions

Production Name Production Value
Plure topLevelDef* EOF
TopLevelDef classDef | objectDef | traitDef | def
ClassDef CLASS IDENTIFIER classBody
ObjectDef OBJECT IDENTIFIER classBody
TraitDef TRAIT IDENTIFIER traitBody
Def DEF IDENTIFIER parameterList returnType EQ defBlock
ClassBody LBRACE classMember* RBRACE
TraitBody LBRACE traitMember* RBRACE
ClassMember classDef | def | assignment SEMICOLON | definition SEMICOLON
TraitMember traitDef | def
ParameterList LPAREN parameter (COMMA parameter)* RPAREN | LPAREN RPAREN
Parameter IDENTIFIER COLON IDENTIFIER
ReturnType COLON IDENTIFIER | *epsilon*
DefBlock LBRACE statement* returnVal? RBRACE
Block LBRACE statement* RBRACE
ReturnVal RETURN expressionStatement
Statement block | ifStatement | whileStatement | forStatement | expressionStatement
IfStatement IF LPAREN logicExpression RPAREN (block | statement) (ELSE (block | statement))?
WhileStatement WHILE LPAREN logicExpression RPAREN block
ForStatement FOR LPAREN logicExpression RPAREN block
Enumeration IDENTIFIER ARROW expression
ExpressionStatement expression SEMICOLON
LogicExpression expression binaryOperator expression | unaryOperator expression | LPAREN expression RPAREN
Expression literal | IDENTIFIER | functionCall | objectMethodAccess | assignment | definition
FunctionCall IDENTIFIER argumentList
ObjectMethodAccess IDENTIFIER DOT IDENTIFIER argumentList?
ArgumentList LPAREN (expression (COMMA expression)*)? RPAREN
Definition (VAR | VAL) IDENTIFIER
Assignment (VAR | VAL) IDENTIFIER EQ (operation | creation)
Operation (IDENTIFIER | literal) (simpleOperator (IDENTIFIER | literal))*
Creation NEW functionCall
BinaryOperator EQEQ | NEQ | LT | GT | LTEQ | GTEQ | AND | OR | PRO
UnaryOperator PLUS | MINUS | BANG
SimpleOperator PLUS | MINUS | ASTERISK | SLASH
Literal BOOLEAN_LITERAL | INT_LITERAL | STRING_LITERAL