Skip to content

Latest commit

 

History

History
35 lines (33 loc) · 747 Bytes

garmmar.md

File metadata and controls

35 lines (33 loc) · 747 Bytes

Token

ADD -> '+'
SUB -> '-'
MUL -> '*'
DIV -> '/'
ASS -> '='
SQM -> '\''
DQM -> '\"'
NUM -> [0-9]+
WORD -> ([a-z] | [A-Z])+
STR -> \" [^\"]+ \"
CMT -> ("//")(!('\n')) -> skip
SPA -> ' ' | '\t' | '\n'  -> skip
PTHL -> '('
PTHR -> ')'
BRKL -> '['
BRKR -> ']'
BRCL -> '{'
BRCR -> '}'
KEYWORD ->  "print" |
			"fun" | "main" | "ret"

grammar

string -> DQM STR DQM negative -> SUB NUM
factor -> (PTHL expr PTHR) | NUM | IDN | negative
term -> factor ((ADD|SUB) factor)*
expr -> term ((MUL|DIV) term)*
assign -> IDN ASS expr
print -> KEYWORD<0> PTHL (IDN | string | char) PTHR
program -> KEYWORD<1> KEYWORD<2> PTHL PTHR BRCL (assign | print)+ KEYWORD<3> NUM BRCR

tip: The BOLD grammar is completed.