comparison modules/parser.tp @ 226:6055f56d0e45

Implement all the binary operators except and/or/xor in grammar
author Michael Pavone <pavone@retrodev.com>
date Sun, 29 Dec 2013 14:56:46 -0800
parents 262f5ae1bb1b
children 8c16ef123aee
comparison
equal deleted inserted replaced
225:262f5ae1bb1b 226:6055f56d0e45
438 } yield: { 438 } yield: {
439 _processOpPieces: Left Pieces 439 _processOpPieces: Left Pieces
440 }) 440 })
441 } 441 }
442 442
443 opexpr <- binaryOps: ["&&" "||"] withHigherPrec: compare
444 compare <- binaryOps: ["<=" ">=" "<" ">" "=" "!="] withHigherPrec: maybecons
445 maybecons <- matchOne: [
446 consop
447 addsub
448 ]
449 consop <- match: Left . hws . "|" . Right where: {
450 Left <- match: addsub
451 Right <- match: maybecons
452 } yield: {
453 #{
454 left <- Left
455 op <- "|"
456 right <- Right
457 }
458 }
443 addsub <- binaryOps: ["+" "-" "."] withHigherPrec: muldiv 459 addsub <- binaryOps: ["+" "-" "."] withHigherPrec: muldiv
444 muldiv <- binaryOps: ["*" "/" "%"] withHigherPrec: primlitsym 460 muldiv <- binaryOps: ["*" "/" "%"] withHigherPrec: primlitsym
445 461
446 //TODO: Implement operator expressions 462 //TODO: Implement operator expressions
447 opexpr <- match: addsub 463
448 464
449 _alpha <- charClass: "a-zA-Z" 465 _alpha <- charClass: "a-zA-Z"
450 alpha <- zeroPlus: _alpha 466 alpha <- zeroPlus: _alpha
451 alphaNum <- zeroPlus: (charClass: "a-zA-Z0-9") 467 alphaNum <- zeroPlus: (charClass: "a-zA-Z0-9")
452 468
829 testmatchintlit: "-567" :s {decimal: s} 845 testmatchintlit: "-567" :s {decimal: s}
830 testmatchintlit: "123u16" :s {decimal: s} 846 testmatchintlit: "123u16" :s {decimal: s}
831 testmatchintlit: "0x20" :s {hexlit: s} 847 testmatchintlit: "0x20" :s {hexlit: s}
832 testmatchintlit: "0x42u64" :s {hexlit: s} 848 testmatchintlit: "0x42u64" :s {hexlit: s}
833 testmatchintlit: "0b10101" :s {binary: s} 849 testmatchintlit: "0b10101" :s {binary: s}
834 code <- "#{ foo <- 123\n bar <- 0xABC + 0b1010101\n baz <- 0b1010 * 5\n qux <- fo: 38 shizzle: bam\n}" 850 code <- "#{ foo <- 123 > 0x42 && 42 < 104\n bar <- 0xABC + 0b1010101\n baz <- 0b1010 * 5\n qux <- fo: 38 shizzle: bam\n}"
835 codem <- expr: code 851 codem <- expr: code
836 if: (codem matched?) { 852 if: (codem matched?) {
837 print: code . "\nmatched with yield:\n" . (codem yield) . "\n" 853 print: code . "\nmatched with yield:\n" . (codem yield) . "\n"
838 } else: { 854 } else: {
839 print: code . "\ndid not match\n" 855 print: code . "\ndid not match\n"