even when switched over to infix-notation, parenthses still are too slow
This commit is contained in:
parent
ea07e1072c
commit
5d04064f6d
1 changed files with 7 additions and 41 deletions
48
main.py
48
main.py
|
|
@ -362,53 +362,19 @@ def get_simplifications(args, available_operators):
|
||||||
return cache[available_operators];
|
return cache[available_operators];
|
||||||
|
|
||||||
def create_parser():
|
def create_parser():
|
||||||
import pyparsing as pp
|
from pyparsing import infix_notation, opAssoc, Word, oneOf
|
||||||
|
|
||||||
root = pp.infix_notation(pp.Word("01wxyz"), [
|
# this can't handle parenthesis very well...
|
||||||
|
# do I really have to write my own parser?
|
||||||
|
root = infix_notation(Word("01wxyz"), [
|
||||||
('!', 1, opAssoc.RIGHT),
|
('!', 1, opAssoc.RIGHT),
|
||||||
|
(oneOf('< <= > >='), 2, opAssoc.LEFT),
|
||||||
|
(oneOf('== !='), 2, opAssoc.LEFT),
|
||||||
(oneOf('&& !& &!'), 2, opAssoc.LEFT),
|
(oneOf('&& !& &!'), 2, opAssoc.LEFT),
|
||||||
(oneOf('|| !| |!'), 2, opAssoc.LEFT)])
|
(oneOf('|| !| |!'), 2, opAssoc.LEFT)]);
|
||||||
|
|
||||||
# from pyparsing import Forward, Suppress, Keyword, Group, ZeroOrMore, Optional, Literal
|
|
||||||
|
|
||||||
# root = Forward()
|
|
||||||
|
|
||||||
# literal = pp.Word('01');
|
|
||||||
|
|
||||||
# variable = pp.Word('wxyz')
|
|
||||||
|
|
||||||
# highest = literal | variable | (Suppress('(') + root + Suppress(')'));
|
|
||||||
|
|
||||||
# prefix_expression = Group(Literal("!") + highest) | highest
|
|
||||||
|
|
||||||
# relational_expression = \
|
|
||||||
# Group(prefix_expression + Literal('<=') + prefix_expression) \
|
|
||||||
# | Group(prefix_expression + Literal('>=') + prefix_expression) \
|
|
||||||
# | Group(prefix_expression + Literal('>') + prefix_expression) \
|
|
||||||
# | Group(prefix_expression + Literal('<') + prefix_expression) \
|
|
||||||
# | Group(prefix_expression + Literal('==') + prefix_expression) \
|
|
||||||
# | Group(prefix_expression + Literal('!=') + prefix_expression) \
|
|
||||||
# | prefix_expression;
|
|
||||||
|
|
||||||
# logical_and_expression = Forward();
|
|
||||||
# logical_and_expression <<= \
|
|
||||||
# Group(relational_expression + Literal('&&') + logical_and_expression) \
|
|
||||||
# | Group(relational_expression + Literal('!&') + logical_and_expression) \
|
|
||||||
# | Group(relational_expression + Literal('&!') + logical_and_expression) \
|
|
||||||
# | relational_expression;
|
|
||||||
|
|
||||||
# logical_or_expression = Forward()
|
|
||||||
# logical_or_expression <<= \
|
|
||||||
# Group(logical_and_expression + Literal('||') + logical_or_expression) \
|
|
||||||
# | Group(logical_and_expression + Literal('!|') + logical_or_expression) \
|
|
||||||
# | Group(logical_and_expression + Literal('|!') + logical_or_expression) \
|
|
||||||
# | logical_and_expression;
|
|
||||||
|
|
||||||
# root <<= logical_or_expression;
|
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
|
|
||||||
|
|
||||||
def parse(parser, text):
|
def parse(parser, text):
|
||||||
return parser.parseString(text, parseAll = True).asList()[0]
|
return parser.parseString(text, parseAll = True).asList()[0]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue