1.1 KiB
1.1 KiB
C-val Compiler
Lexical Spec
- LBRACK
[ - RBRACK
] - LCURLY
{ - RCURLY
} - LPAREN
( - RPAREN
) - ID
[any character without whitespace]+ - SEMI
; - COMMA
, - ARROW
-> - STAR
* - ANDREF
& - DOLLAR
$ - COMMENT
// - NUM
[0-9]* - VAL
- STRING
"{any}"
Syntax Spec
program := defn*
defn := VAL type ID ;
| VAL type ID expr ;
type := ID | type STAR
| LBRACK RBRACK | LBRACK type RBRACK
| LBRACK type* ARROW type? RBRACK
expr := atom atom*
atom := ID
| NUM
| STR
| lambda
| compound
| STAR
| ANDREF
stmt := defn
| expr ; // expr statement
| return expr ; // return statement
| DOLLAR ID expr ; // assignment statement
| if expr compound ; // if statement
| if expr compound else compound ; // if-else statement
param_list := LPAREN (type ID)* RPAREN
lambda := param_list compound
compound := LCURLY (stmt)* expr? RCURLY