Sroot: Sline+ ;
Sline:
Tcomment Tnewline|
(Sparam | Sconst | Simport | Sset | Sblock | Saka | Sreturn | Spanic
| Spoint | Sinit | Sjump | Scondition | Scall | Sfunc | Sclass | Saccess | Sinterface) ( Tsemi | Tsemi? Tnewline ) ;
Sparam: "parameter" Tname (Tequal Sexpression)? ;
Sexpression: Tminus Sexpression
| Tplus Sexpression
| Tlparn Sexpression Trparn
| Tint | Sfloat | Tstr | Sname
| Sexpression Tvbar Sexpression | Sexpression "or" Sexpression
| Sexpression Tand Sexpression | Sexpression "and" Sexpression
| Sexpression (Tequal Tequal) Sexpression
| Sexpression (Texpl Tequal) Sexpression
| Sexpression Tflex Sexpression | Sexpression "xor" Sexpression
| Sexpression Tminus Sexpression
| Sexpression Tpercent Sexpression
| Sexpression Tplus Sexpression
| Sexpression Tslash Sexpression
| Sexpression (Texpl Tslash) Sexpression
| Sexpression Tstar Sexpression
| Sexpression (Tstar Tstar) Sexpression
| Sexpression (Texpl Tstar) Sexpression
| Texpl Sexpression | "not" Sexpression
| Ttilde Sexpression
| Sarray
| Sdict ;
Sfloat: (Tint Tdot Tint) ;
Sdict: Tlparf ((Tstr Tcolon Sexpression Tcomma)* Tstr Tcolon Sexpression)? Trparf ;
Sarray: Tlparb ((Sexpression Tcomma)* Sexpression)? Trparb ;
Sname: ((Tname Tdot)* Tname) ;
Spoint: Tbux Tname ;
Sblock: Tlparf Sline* Trparf ;
Sif: "if" Sexpression Sblock ;
Selif: ("elif" | "else" "if") Sexpression Sblock ;
Selse: "else" Sblock ;
Sinit: Sname Tcolon Sname Tequal Sexpression ;
Sconst: "const" Sname Tcolon Sname Tequal Sexpression ;
Simport: ("import" | "include") ("file" Tstr | "module"? Tname) ;
Sset: Sname Tequal Sexpression ;
Saka: "aka" Sname ;
Sreturn: "return" Sexpression? ;
Spanic: "panic" Tname Tstr? ;
Sjump: "goto" Spoint ;
Scondition: Sif Selif* Selse? ;
Scall: Sname Tlparn ((Sexpression Tcomma)* Sexpression)? Trparn ;
Sfunc: "def" Sname Tlparn ((Sname Tcolon Sname (Tequal Sexpression)? Tcomma)* Sname Tcolon Sname (Tequal Sexpression)?)? (Trparn "->" Sname)? Sblock ;
Sclass: "class" Sname Tcolon Sname (Tlpara ((Sname Tcolon Sname Tcomma)* Sname Tcolon Sname)? Trpara)? Sblock ;
Saccess: ("private" | "public") Sblock ;
Sinterface: "interface" Sname Sblock ;
terminals
Tcomment: /\/\/.*|\/\*.*\*\// ;
Tnewline: '\n' ;
Tint: /[+-]?(0[Xx][A-Za-z0-9][A-Za-z0-9_]*|\d+|1[01]*[Bb]|0[Bb])/ ;
Tstr: /(\'[.^\']*\'|\"[.^\"]*\")/ ;
Tname: /[A-Za-z_]\w*/ ;
Tplus: '+' ;
Tminus: '-' ;
Tstar: '*' ;
Tslash: '/' ;
Tcolon: ':' ;
Tsemi: ';' ;
Tand: '&' ;
Thash: '#' ;
Texpl: '!' ;
Tat: '@' ;
Tbux: '$' ;
Tpercent: '%' ;
Tflex: '^' ;
Tequal: '=' ;
Tapos: '`' ;
Ttilde: '~' ;
Tbslash: '\\' ;
Tvbar: '|' ;
Tdot: '.' ;
Tcomma: ',' ;
Tlparn: '(' ;
Trparn: ')' ;
Tlparf: '{' ;
Trparf: '}' ;
Tlparb: '[' ;
Trparb: ']' ;
Tlpara: '<' ;
Trpara: '>' ;