Last active
March 2, 2016 14:36
-
-
Save taku0/a5d3375539586722b2c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# '1'を並べた数で自然数を表すとする。 | |
# a+b=c$をチェックする。 | |
Plus = Plus0(); | |
Plus0(Left) | |
= &(Left "+") Plus1(Left, ) | |
/ &(Left "1") Plus0(Left "1"); | |
Plus1(Left, Right) | |
= &(Left "+" Right "=") Plus2(Left, Right) | |
/ &(Left "+" Right "1") Plus1(Left, Right "1"); | |
Plus2(Left, Right) | |
= Left "+" Right "=" Left Right "$"; | |
# a*b=c$をチェックする。 | |
Mul = Mul0(); | |
Mul0(Left) | |
= &(Left "*") Mul1(Left, , ) | |
/ &(Left "1") Mul0(Left "1"); | |
Mul1(Left, Right, Prod) | |
= &(Left "*" Right "=") Mul2(Left, Right, Prod) | |
/ &(Left "*" Right "1") Mul1(Left, Right "1", Prod Left); | |
Mul2(Left, Right, Prod) | |
= Left "*" Right "=" Prod "$"; | |
# a-b=c$をチェックする。 | |
Minus = Minus0() | |
Minus0(Right) | |
= &(.* "-" Right "=") Minus1(Right, ) | |
/ &(.* "-" Right "1") Minus0(Right "1"); | |
Minus1(Right, Diff) | |
= &(.* "-" Right "=" Diff "$") Minus2(Right, Diff) | |
/ &(.* "-" Right "=" Diff "1") Minus1(Right, Diff "1"); | |
Minus2(Right, Diff) | |
= Right Diff "-" Right "=" Diff "$"; | |
# a/b=cも同様にチェックできるはず。 | |
# おまけ | |
# 終端記号をt1, t2, ..., tnとする。また、入力の末尾には特殊な記号$があるものとする。 | |
# 入力を消費せずに、入力にのみマッチするパターンで継続を呼ぶ | |
ReadAll(C) = ReadAll0(, C) | |
ReadAll0(I, C) | |
= &(I "$") C(I "$") | |
/ &(I "t1") ReadAll(I "t1", C) | |
/ &(I "t2") ReadAll(I "t2", C) | |
... | |
/ &(I "tn") ReadAll(I "tn", C); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment