Permalink
Browse files

Added parentheses parser example

  • Loading branch information...
djspiewak committed May 9, 2009
1 parent 86d8377 commit 83842ea5676f22f4fe1cf778ff923d807c0d69d1
View
@@ -39,6 +39,10 @@ define 'examples' do
task :lambdacalc => :compile do
run_eg.call 'LambdaCalc'
end
+
+ task :paren => :compile do
+ run_eg.call 'Paren'
+ end
- task :run => [:arithmetic, :miniml, :lambdacalc]
+ task :run => [:arithmetic, :miniml, :lambdacalc, :paren]
end
@@ -0,0 +1 @@
+((())))
@@ -0,0 +1 @@
+(())
@@ -0,0 +1 @@
+((((((((((((((()))))))))))))))
@@ -0,0 +1,21 @@
+package paren
+
+object ParenParser extends common.Example[Int] {
+
+ // %%
+
+ lazy val expr: Parser[Int] = (
+ "(" ~> expr <~ ")" ^^ { _ + 1 }
+ | "()" ^^^ 1
+ )
+
+ // %%
+
+ def parser = expr
+
+ def handleSuccesses(forest: List[Int]) {
+ for (depth <- forest) {
+ println(" " + depth)
+ }
+ }
+}

0 comments on commit 83842ea

Please sign in to comment.