# HG changeset patch # User Michael Pavone # Date 1388355938 28800 # Node ID 25db1c7c73004aa0768929690d7409f0d12baaaa # Parent c6e321a538d4984b79a3e6b1745f6fbb12b422b5 Added addition and multiplication precedence level operators to grammar diff -r c6e321a538d4 -r 25db1c7c7300 modules/parser.tp --- a/modules/parser.tp Sun Dec 29 13:08:01 2013 -0800 +++ b/modules/parser.tp Sun Dec 29 14:25:38 2013 -0800 @@ -695,9 +695,55 @@ } } } + _processOpPieces <- :Left Pieces { + if: (Pieces length) > 0 { + Pieces fold: Left with: :acc piece { + #{ + left <- acc + op <- piece op + right <- piece right + string <- { + (string: left) . " " . op . " " . right + } + } + } + } else: { + Left + } + } + + addsub <- match: Left . Pieces where: { + Left <- match: muldiv + Pieces <- zeroPlus: (match: hws . Op . Right where: { + Op <- matchOne: ["+" "-" "."] + Right <- match: muldiv + } yield: { + #{ + op <- Op + right <- Right + } + }) + } yield: { + _processOpPieces: Left Pieces + } + + muldiv <- match: Left . Pieces where: { + Left <- match: primlitsym + Pieces <- zeroPlus: (match: hws . Op . Right where: { + Op <- matchOne: ["*" "/" "%"] + Right <- match: primlitsym + } yield: { + #{ + op <- Op + right <- Right + } + }) + } yield: { + _processOpPieces: Left Pieces + } //TODO: Implement operator expressions - opexpr <- match: primlitsym + opexpr <- match: addsub expr <- match: (hws . Expr . ws) where: { Expr <- matchOne: [ @@ -796,7 +842,7 @@ testmatchintlit: "0x20" :s {hexlit: s} testmatchintlit: "0x42u64" :s {hexlit: s} testmatchintlit: "0b10101" :s {binary: s} - code <- "#{ foo <- 123\n bar <- 0xABC\n baz <- 0b1010\n qux <- fo: 38 shizzle: bam\n}" + code <- "#{ foo <- 123\n bar <- 0xABC + 0b1010101\n baz <- 0b1010 * 5\n qux <- fo: 38 shizzle: bam\n}" codem <- expr: code if: (codem matched?) { print: code . "\nmatched with yield:\n" . (codem yield) . "\n"