diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2008-02-07 12:39:51 +0000 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2008-02-07 12:39:51 +0000 |
commit | 0eae9599357eb76fb38d2a95d1d4d6f089b814b3 (patch) | |
tree | 0cb296642e3d3f8b4d9d63bfab76d374750d3c13 /docs/examples/parsing/ArithmeticParser.scala | |
parent | f3e42a50ab77e51040b3698c710b1ca86bfc0611 (diff) | |
download | scala-0eae9599357eb76fb38d2a95d1d4d6f089b814b3.tar.gz scala-0eae9599357eb76fb38d2a95d1d4d6f089b814b3.tar.bz2 scala-0eae9599357eb76fb38d2a95d1d4d6f089b814b3.zip |
updated examples and json parser to use combina...
updated examples and json parser to use combinator1-style parsing,
have not yet renamed combinator -> combinatorold, and combinator1 ->
combinator --> doing that using SVN rename, so history is preserved
(thus, the build for this revision will break, but the next one should
be okay. sorry)
Diffstat (limited to 'docs/examples/parsing/ArithmeticParser.scala')
-rw-r--r-- | docs/examples/parsing/ArithmeticParser.scala | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/docs/examples/parsing/ArithmeticParser.scala b/docs/examples/parsing/ArithmeticParser.scala index 2aac4b6f6c..57ead13fef 100644 --- a/docs/examples/parsing/ArithmeticParser.scala +++ b/docs/examples/parsing/ArithmeticParser.scala @@ -21,9 +21,9 @@ object arithmeticParser extends StdTokenParsers { type Tokens = StdLexical ; val lexical = new StdLexical lexical.delimiters ++= List("(", ")", "+", "-", "*", "/") - lazy val expr = term*("+" ^^ {(x: int, y: int) => x + y} | "-" ^^ {(x: int, y: int) => x - y}) - lazy val term = factor*("*" ^^ {(x: int, y: int) => x * y} | "/" ^^ {(x: int, y: int) => x / y}) - lazy val factor: Parser[int] = "(" ~ expr ~ ")" | numericLit ^^ (_.toInt) + lazy val expr = term*("+" ^^^ {(x: int, y: int) => x + y} | "-" ^^^ {(x: int, y: int) => x - y}) + lazy val term = factor*("*" ^^^ {(x: int, y: int) => x * y} | "/" ^^^ {(x: int, y: int) => x / y}) + lazy val factor: Parser[int] = "(" ~> expr <~ ")" | numericLit ^^ (_.toInt) def main(args: Array[String]) { println( @@ -41,9 +41,9 @@ object arithmeticParserDesugared extends StdTokenParsers { type Tokens = StdLexical ; val lexical = new StdLexical lexical.delimiters ++= List("(", ")", "+", "-", "*", "/") - lazy val expr = chainl1(term, (keyword("+").^^{(x: int, y: int) => x + y}).|(keyword("-").^^{(x: int, y: int) => x - y})) - lazy val term = chainl1(factor, (keyword("*").^^{(x: int, y: int) => x * y}).|(keyword("/").^^{(x: int, y: int) => x / y})) - lazy val factor: Parser[int] = keyword("(").~(expr.~(keyword(")"))).|(numericLit.^^(x => x.toInt)) + lazy val expr = chainl1(term, (keyword("+").^^^{(x: int, y: int) => x + y}).|(keyword("-").^^^{(x: int, y: int) => x - y})) + lazy val term = chainl1(factor, (keyword("*").^^^{(x: int, y: int) => x * y}).|(keyword("/").^^^{(x: int, y: int) => x / y})) + lazy val factor: Parser[int] = keyword("(").~>(expr.<~(keyword(")"))).|(numericLit.^^(x => x.toInt)) def main(args: Array[String]) { println( |