Mercurial > hg > expressionparser
comparison expr.py @ 12:835efd8acb04
add some vocab
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Fri, 03 Jun 2011 11:09:08 -0700 |
| parents | e17a3464a0b9 |
| children | ec0e83ec329f |
comparison
equal
deleted
inserted
replaced
| 11:e17a3464a0b9 | 12:835efd8acb04 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 # Implements a top-down parser/evaluator for simple boolean expressions. | 1 # Implements a top-down parser/evaluator for simple boolean expressions. |
| 4 # ideas taken from http://effbot.org/zone/simple-top-down-parsing.htm | 2 # ideas taken from http://effbot.org/zone/simple-top-down-parsing.htm |
| 5 # | 3 # |
| 6 # Rough grammar: | 4 # Rough grammar: |
| 7 # expr := literal | 5 # expr := literal |
| 20 # IDENT := [A-Za-z_]\w* | 18 # IDENT := [A-Za-z_]\w* |
| 21 | 19 |
| 22 # Identifiers take their values from a mapping dictionary passed as the second | 20 # Identifiers take their values from a mapping dictionary passed as the second |
| 23 # argument. | 21 # argument. |
| 24 | 22 |
| 23 # Glossary (see above URL for details): | |
| 24 # - nud: null denotation | |
| 25 # - led: left detonation | |
| 26 # - lbp: left binding power | |
| 27 # - rbp: right binding power | |
| 28 | |
| 25 __all__ = ['parse', 'ParseError', 'ExpressionParser'] | 29 __all__ = ['parse', 'ParseError', 'ExpressionParser'] |
| 26 import re | 30 import re |
| 27 | 31 |
| 28 # token classes | 32 # token classes |
| 29 class token(object): | 33 class token(object): |
