Skip to content

Instantly share code, notes, and snippets.

@pandaman64
Created February 4, 2017 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandaman64/7fd2998d874a1f3ba3b411a65d1cd2ce to your computer and use it in GitHub Desktop.
Save pandaman64/7fd2998d874a1f3ba3b411a65d1cd2ce to your computer and use it in GitHub Desktop.
MyML Grammar
// '\'はPEGの分岐,'?'はオプショナル, '*'は0回以上の繰り返し
Expr := LetRec \ Let \ If \ Literal \ Apply \ Identifier
LetRec := "let rec" Identifier Identifier? "=" Expr "in" Expr
Let := "let" Identifier Identifier? "=" Expr "in" Expr
If := "if" Expr "then" Expr "else" Expr
Literal := ライブラリの整数パースする奴使ってる
Apply := Value Value*
Value := "(" Expr ")" \ Primitive
Primitive := LetRec \ Let \ If \ Literal \ Ident // <- Apply := Expr Expr* ってするとApplyが左再帰するのでこんなんやってる
Identifier := [a-zA-Z] [a-zA-Z0-9!?]* (但し予約語ではない)
予約語 := "if" \ "then" \ "else" \ "let" \ "in"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment