def asterix(parser): lastToken = parser.lookBehind() op = Tree.Operator("*", parser) if isUnary(parser, lastToken): Parser.precidences["*"] = (100, True) Parser.Opcode(parser, "*", lambda: operatorPop(parser, op, 1, unary=True)) Parser.precidences["*"] = (40, True) op.unary = True else: Parser.Opcode(parser, "*", lambda: operatorPop(parser, op, 2))
def send(parser): lastToken = parser.lookBehind() op = Tree.Operator("<-", parser) if not isUnary(parser, lastToken): Parser.precidences["<-"] = (2, True) Parser.Opcode(parser, "<-", lambda: operatorPop(parser, op, 2)) Parser.precidences["<-"] = (100, True) else: # newOperator("set", (2, True), 2, func=set, token=False) op.unary = True Parser.Opcode(parser, "<-", lambda: operatorPop(parser, op, 1, unary=True))
def minus(parser): lastToken = parser.lookBehind() op = Tree.Operator("-", parser) if isUnary(parser, lastToken): # unary- Parser.precidences["-"] = (100, True) # give higher power Parser.Opcode(parser, "-", lambda: operatorPop(parser, op, 1, unary= True)) Parser.precidences["-"] = (20, True) op.unary = True else: Parser.Opcode(parser, "-", lambda: operatorPop(parser, op, 2))
def plus(parser): lastToken = parser.lookBehind() node = Tree.Operator("+", parser) if isUnary(parser, lastToken): # unary+ node.unary = True Parser.precidences["+"] = (100, True) Parser.Opcode(parser, "+", lambda: operatorPop(parser, node, 1, unary= True)) Parser.precidences["+"] = (20, True) return Parser.Opcode(parser, "+", lambda: operatorPop(parser, node, 2))
def asOperator(parser): lastToken = parser.lookBehind() if not isUnary(parser, lastToken): op = Tree.Operator("as", parser) parser.nextToken() op.type = Types.parseType(parser) Parser.Opcode(parser, "as", lambda: operatorPop(parser, op, 1, unary=True)) else: Error.parseError(parser, "unexpected as operator ")
def f(parser): op = Tree.Operator(kind, parser) actuallyUnary = isUnary(parser, parser.lookBehind()) if len(parser.currentNode.nodes) != 0: if not unary and actuallyUnary: Error.parseError(parser, "unexpected "+kind) elif unary and not actuallyUnary: Error.parseError(parser, "unexpected "+kind) #parser.nodeBookmark.append(len(parser.currentNode.nodes)-1) Parser.Opcode(parser, kind, lambda: operatorPop(parser, op, takesIn, actuallyUnary))
def f(parser): op = Tree.Operator(kind, parser) if kind == "|>": print(kind) if not kind in ["|>"] and len(parser.currentNode.nodes) != 0: if not unary and isUnary(parser, parser.lookBehind()): Error.parseError(parser, "unexpected " + kind) elif unary and not isUnary(parser, parser.lookBehind()): Error.parseError(parser, "unexpected " + kind) #parser.nodeBookmark.append(len(parser.currentNode.nodes)-1) Parser.Opcode(parser, kind, lambda: operatorPop(parser, op, takesIn, unary))
def set(parser): op = Tree.Operator("<-", parser) Parser.Opcode(parser, "<-", lambda: operatorPop(parser, op, 2, unary=False))
def read(parser): op = Tree.Operator("<-", parser) Parser.Opcode(parser, "<-", lambda: operatorPop(parser, op, 1, unary=True))