Mercurial > repos > tabletprog
changeset 223:25db1c7c7300
Added addition and multiplication precedence level operators to grammar
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 29 Dec 2013 14:25:38 -0800 |
parents | c6e321a538d4 |
children | 97c3e33cd3f4 |
files | modules/parser.tp |
diffstat | 1 files changed, 48 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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"