This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
''' Script for precedence climbing parsing for infix operators, based | |
on binding powers; iterative and recursive implementation. Binding | |
powers are in range 1 to 99. - Separate tokens in DEMOS by spaces. | |
''' | |
LBP = {"+": 14, "*": 17, "^": 21, ":=": 22, "$END": -1} | |
RBP = {"+": 15, "*": 18, "^": 20, ":=": 8} | |
DEMOS = ['x + 3.4 * y', 'a + b + c', 'n ^ m ^ k', '3 * x := v + 1'] |