Пример #1
0
import pyparse.pyparsing as pp
import config

returnStack = []


def pushReturn(str, loc, toks):
    global returnStack
    returnStack.append(toks[0])

reg8 = \
    pp.Combine(pp.Suppress("%") + "al") \
    | pp.Combine(pp.Suppress("%") + "bl") \
    | pp.Combine(pp.Suppress("%") + "cl") \
    | pp.Combine(pp.Suppress("%") + "dl") \
    | pp.Combine(pp.Suppress("%") + "ah") \
    | pp.Combine(pp.Suppress("%") + "bh") \
    | pp.Combine(pp.Suppress("%") + "ch") \
    | pp.Combine(pp.Suppress("%") + "dh")

reg32 = \
    pp.Combine(pp.Suppress("%") + "eax") \
    | pp.Combine(pp.Suppress("%") + "ebx") \
    | pp.Combine(pp.Suppress("%") + "ecx") \
    | pp.Combine(pp.Suppress("%") + "edx") \
    | pp.Combine(pp.Suppress("%") + "esp") \
    | pp.Combine(pp.Suppress("%") + "ebp") \
    | pp.Combine(pp.Suppress("%") + "esi") \
    | pp.Combine(pp.Suppress("%") + "edi") \
    | pp.Combine(pp.Suppress("%") + "r8d") \
    | pp.Combine(pp.Suppress("%") + "r9d") \
Пример #2
0
                    "text": line.strip()
                })

        # format texts
        for entry in attribs:
            if 'text' in entry and len(entry['text']) > 0:
                if format_:
                    entry["text"] = self.formatText(entry["text"])
                else:
                    entry["text"] = self.cleanupText(entry["text"])

        #from pprint import pprint
        #pprint( attribs)
        return attribs

    gr_at__default_ = (py.Suppress('@') + py.Word(py.alphas)('category') +
                       py.restOfLine("text"))

    ##
    # "@<hint> text"
    def parse_at__default_(self, line):
        grammar = self.gr_at__default_
        presult = grammar.parseString(line)
        res = {
            'category': presult.category,
            'text': presult.text.strip(),
        }
        return res

    # the next would be close to the spec (but huge!)
    #identi = py.Word(u''.join(lang.IDENTIFIER_CHARS_START), u''.join(lang.IDENTIFIER_CHARS_BODY))
Пример #3
0
lpar = pp.Literal("(")
rpar = pp.Literal(")")
shiftOpGroup = pp.oneOf(">> >>> << <<<")
andOpGroup = pp.oneOf("& | ^")
plusOpGroup = pp.oneOf("+ -")
multOpGroup = pp.oneOf("* /")
unOpGroup = pp.oneOf("!")
comparator = pp.oneOf("= > >= < <= == !=")

constant = pp.Combine(pp.Optional(pp.Literal("-")) + pp.Word(pp.hexnums)) + pp.Optional(pp.Combine(pp.Literal(":") + pp.Word(pp.hexnums)), default=":32")
tempVar = pp.Optional(pp.Combine(pp.Word(pp.alphas, pp.alphanums) + pp.Literal("."))) + pp.Word(pp.alphas, pp.alphanums + "_") + pp.Optional(pp.Combine(pp.Literal(":") + pp.Word(pp.hexnums)), default=":32")
hexConstant = pp.Combine("0x" + pp.Word(pp.hexnums)) + pp.Optional(pp.Combine(pp.Literal(":") + pp.Word(pp.hexnums)), default=":32")
label = pp.Combine(pp.Literal("L$") + pp.Word(pp.alphas, pp.alphanums + "_"))

orExpression = pp.Forward()
argList = (orExpression + pp.ZeroOrMore(pp.Suppress(pp.Literal(",")) + orExpression)).setParseAction(pushCallArg)
callVar = (tempVar + pp.Suppress(lpar) + pp.Optional(argList) + pp.Suppress(rpar)).setParseAction(pushCallVar)
arrayVar = (tempVar + pp.Suppress(pp.Literal("[")) + orExpression + pp.Suppress(pp.Literal("]"))).setParseAction(pushArrayVar)

factor = arrayVar | callVar | (label | tempVar | hexConstant | constant).setParseAction(CreateVar) | (pp.Suppress(pp.Literal("(")) + orExpression + pp.Suppress(pp.Literal(")")))

unaryExpression = ((unOpGroup + factor) | factor).setParseAction(pushUnaryExpr)
multExpression = unaryExpression + pp.ZeroOrMore(multOpGroup + unaryExpression)
multExpression.setParseAction(pushLeftAssocExpr)
plusExpression = multExpression + pp.ZeroOrMore(plusOpGroup + multExpression)
plusExpression.setParseAction(pushLeftAssocExpr)
shiftExpression = plusExpression + pp.ZeroOrMore(shiftOpGroup + plusExpression)
shiftExpression.setParseAction(pushLeftAssocExpr)
andExpression = shiftExpression + pp.ZeroOrMore(pp.Literal("&") + shiftExpression)
andExpression.setParseAction(pushLeftAssocExpr)
xorExpression = andExpression + pp.ZeroOrMore(pp.Literal("^") + andExpression)