• Login or register

discuss.effbot.org

  • Popular
  • Recent
  • 1 point by thenendo 1 year ago on Simple Top-Down Parsing in Python 2 children

    More specifically, postfix operators with high precedence. For instance, say I want to write a parser of regular expressions. "ab*c" should be equivalent to "a(b*)c", not "(ab)*c"... the "b" somehow has to telepathically know that a "*" is coming up, and to combine with that, not with the "a" before it.

    • parent
    • reply
    • 2 points by effbot 1 year ago 1 child

      I stumbled upon that myself recently, but in that case, it was sufficient to treat the postfix operators as "modifiers" -- just let the operator's "led" method modify the left node, and then return that node instead of itself. More extensive tree modifications are also possible, but is more work.

      • link
      • reply
      • 1 point by thenendo 1 year ago 0 children

        Excellent suggestion, thanks. In my case the solution was to have the postfix "led" make a copy of its "left" argument, then modify the original to have a new "id", signifying the postfix operation, with the copy as its "first" argument. Works beautifully.

        • link
        • reply
  • Widget
  • Recent Comments
  • Leaders
Powered by