Mercurial > hg > expressionparser
changeset 11:e17a3464a0b9
get precedence from a list position vs magic constants
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 03 Jun 2011 10:51:36 -0700 |
parents | 15fb1081784f |
children | 835efd8acb04 |
files | expr.py |
diffstat | 1 files changed, 4 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/expr.py Fri Jun 03 10:16:19 2011 -0700 +++ b/expr.py Fri Jun 03 10:51:36 2011 -0700 @@ -45,33 +45,28 @@ class eq_op_token(object): "==" - lbp = 20 def led(self, parser, left): return left == parser.expression(self.lbp) class neq_op_token(object): "!=" - lbp = 20 def led(self, parser, left): return left != parser.expression(self.lbp) class and_op_token(object): "&&" - lbp = 11 def led(self, parser, left): right = parser.expression(self.lbp) return left and right class or_op_token(object): "||" - lbp = 10 def led(self, parser, left): right = parser.expression(self.lbp) return left or right class lparen_token(object): "(" - lbp = 50 def nud(self, parser): expr = parser.expression() parser.advance(rparen_token) @@ -79,11 +74,9 @@ class rparen_token(object): ")" - lbp = 0 class end_token(object): - # lowest left binding power, always ends parsing - lbp = 0 + """always ends parsing""" ### derived literal tokens @@ -106,6 +99,9 @@ (eq_op_token, neq_op_token), (lparen_token,), ] +for index, rank in enumerate(precedence): + for token in rank: + token.lbp = index # lbp = lowest left binding power class ParseError(Exception): """errror parsing conditional expression"""