Exemplo n.º 1
0
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))
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
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))
Exemplo n.º 4
0
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))
Exemplo n.º 5
0
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 ")
Exemplo n.º 6
0
    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))
Exemplo n.º 7
0
    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))
Exemplo n.º 8
0
def set(parser):
    op = Tree.Operator("<-", parser)
    Parser.Opcode(parser, "<-",
                  lambda: operatorPop(parser, op, 2, unary=False))
Exemplo n.º 9
0
def read(parser):
    op = Tree.Operator("<-", parser)
    Parser.Opcode(parser, "<-", lambda: operatorPop(parser, op, 1, unary=True))