comparison modules/parser.tp @ 225:262f5ae1bb1b

Added a new binaryOps:withHigherPrec macro to simplify specification of binary operator precedence level rules in the grammar
author Michael Pavone <pavone@retrodev.com>
date Sun, 29 Dec 2013 14:39:54 -0800
parents 25db1c7c7300
children 6055f56d0e45
comparison
equal deleted inserted replaced
224:97c3e33cd3f4 225:262f5ae1bb1b
421 } else: { 421 } else: {
422 print: "#error Error in main match expression of match:where:yield: " . (mcMain message) . "\n" 422 print: "#error Error in main match expression of match:where:yield: " . (mcMain message) . "\n"
423 } 423 }
424 } 424 }
425 425
426 binaryOps:withHigherPrec <- macro: :oplist :higher {
427 quote: (match: Left . Pieces where: {
428 Left <- match: higher
429 Pieces <- zeroPlus: (match: hws . Op . Right where: {
430 Op <- matchOne: oplist
431 Right <- match: higher
432 } yield: {
433 #{
434 op <- Op
435 right <- Right
436 }
437 })
438 } yield: {
439 _processOpPieces: Left Pieces
440 })
441 }
442
443 addsub <- binaryOps: ["+" "-" "."] withHigherPrec: muldiv
444 muldiv <- binaryOps: ["*" "/" "%"] withHigherPrec: primlitsym
445
446 //TODO: Implement operator expressions
447 opexpr <- match: addsub
426 448
427 _alpha <- charClass: "a-zA-Z" 449 _alpha <- charClass: "a-zA-Z"
428 alpha <- zeroPlus: _alpha 450 alpha <- zeroPlus: _alpha
429 alphaNum <- zeroPlus: (charClass: "a-zA-Z0-9") 451 alphaNum <- zeroPlus: (charClass: "a-zA-Z0-9")
430 452
710 } else: { 732 } else: {
711 Left 733 Left
712 } 734 }
713 } 735 }
714 736
715 addsub <- match: Left . Pieces where: {
716 Left <- match: muldiv
717 Pieces <- zeroPlus: (match: hws . Op . Right where: {
718 Op <- matchOne: ["+" "-" "."]
719 Right <- match: muldiv
720 } yield: {
721 #{
722 op <- Op
723 right <- Right
724 }
725 })
726 } yield: {
727 _processOpPieces: Left Pieces
728 }
729
730 muldiv <- match: Left . Pieces where: {
731 Left <- match: primlitsym
732 Pieces <- zeroPlus: (match: hws . Op . Right where: {
733 Op <- matchOne: ["*" "/" "%"]
734 Right <- match: primlitsym
735 } yield: {
736 #{
737 op <- Op
738 right <- Right
739 }
740 })
741 } yield: {
742 _processOpPieces: Left Pieces
743 }
744
745 //TODO: Implement operator expressions
746 opexpr <- match: addsub
747
748 expr <- match: (hws . Expr . ws) where: { 737 expr <- match: (hws . Expr . ws) where: {
749 Expr <- matchOne: [ 738 Expr <- matchOne: [
750 funcall 739 funcall
751 methcall 740 methcall
752 opexpr 741 opexpr