Skip to content

Instantly share code, notes, and snippets.

@Chase-san
Created May 25, 2013 23:40
Show Gist options
  • Save Chase-san/5651203 to your computer and use it in GitHub Desktop.
Save Chase-san/5651203 to your computer and use it in GitHub Desktop.
Coco/R is somewhat annoying...
COMPILER CompilationUnit
CHARACTERS
tab = '\u0009' .
lf = '\u000a' .
cr = '\u000d' .
digit = "1234567890" .
letter = 'A' .. 'Z' + 'a' .. 'z' + '_'.
TOKENS
ident = letter { letter | digit }.
intLit = digit { digit } .
IGNORE lf + cr + tab
PRODUCTIONS
CompilationUnit = AssignExpr .
/* STATEMENTS */
/* EXPRESSIONS */
//with this... 2 + 2 = 16 = pi is possible... :(
AssignExpr = SumExpr { AssignOp SumExpr } .
SumExpr = ProductExpr { SumOp ProductExpr } .
ProductExpr = UnaryExpr { ProductOp UnaryExpr } .
UnaryExpr = [ UnaryOp ] PrimaryExpr .
PrimaryExpr
=
'(' AssignExpr ')'
| intLit
| ident
.
/* OPERATORS */
AssignOp
=
'='
| "+="
| "-="
| "*="
| "/="
| "&="
| "|="
| "^="
| "%="
| "<<="
| ">>="
.
SumOp
=
"+"
| "-"
| "|"
| "^"
.
ProductOp
=
"*"
| "/"
| "%"
| "<<"
| ">>"
| "&"
.
UnaryOp
=
"-"
| "~"
.
END CompilationUnit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment