pyparsing

    2热度

    2回答

    我想用pyparsing编写一个解析所有字符串包含特殊单词的程序。我写了下面的代码,但它不工作: from pyparsing import * word = Word(alphas) sentence = OneOrMore(word) day = Literal("day") sentence_end_with_happy = sentence + day + sentence re

    1热度

    1回答

    这是我第一次尝试使用pyparsing,我很难设置它。我想用pyparsing来解析lexc文件。格式lexc用于声明编译成有限状态传感器的词典。 特殊字符: : divides 'upper' and 'lower' sides of a 'data' declaration ; terminates entry # reserved LEXICON name. end-of-word or

    5热度

    2回答

    我试图分析和评估表达式,从文件给我作为输入,形式为: var[3] = 0 and var[2] = 1 var[0] = 1 and var[2] = 0 and var[3] = 1 ... (其实我也让“多位访问“(即var[X:Y]),但让我们忽略它现在...) 其中var是一个整数,[]指示位访问。 例如,对于var = 0x9,上面的第一个表达式应该评估为False,第二个表达

    2热度

    2回答

    如何使一个解析器,这将使使用pyparsing库根据表达式算术优先括号,使? 例如*具有比+更高的优先级。 应该这样做: »> print(wholeexp.parseString('3+5-2')) [[['3', '+', '5'], '-', '2']] »> print(wholeexp.parseString('3+(5-2)')) [['3', '+', ['5', '-', '

    2热度

    2回答

    我有以下的语法和测试案例: from pyparsing import Word, nums, Forward, Suppress, OneOrMore, Group #A grammar for a simple class of regular expressions number = Word(nums)('number') lparen = Suppress('(') rpare

    1热度

    1回答

    我有以下的示例数据: 165 150 238 402 395 571 365 446 284 278 322 282 236 16 5 19 10 12 5 18 22 6 4 5 259 224 249 193 170 151 95 86 101 58 49 6013 7413 8976 10392 12678 9618 9054 8842 9387 11088 11393; 它是一个

    1热度

    1回答

    即使在使用enablePackrat后,我的infixNotation的执行速度比我想要的要慢,这大大提高了性能。 解析需要识别和分析以下类型的字符串: 基本运算,数字,否定和括号分组 分组格式prefix::dotted.alphanum.string -> [prefix::dotted.alphanum.string] 字符串,看起来像函数调用例如pow(some::var + 2.3, 5

    1热度

    1回答

    我是PyParser的新手,但如果能够使其工作,我非常乐意使用它。 我有消息字符串我想解析有一个命令动词,多字对象的名称,然后一个可选的后缀,一些例子: verb object verb another object verb object friday verb another object monday 动词是从固定列表,后缀也是如此(本例中为一周中的几天),但对象名称可以是任何其他

    1热度

    1回答

    在我能找到优先权的大多数例子中,使用分组(oneOf)文字来设置相同的级别。采用这种方法,我将不得不查找其中的2个(或更多),然后继续评估。我想要做的是将操作员分开,直接知道它是哪一个并对其进行评估。 这就是我想实现什么,但优先级别现在是错误的 arith_prec = [ (subtract_op, 2, opAssoc.LEFT, ast.Substraction), (a

    3热度

    1回答

    我有一堆句子,我需要解析并转换为相应的正则表达式搜索代码。我的句子的例子 - LINE_CONTAINS phrase one BEFORE {phrase2 AND phrase3} AND LINE_STARTSWITH Therefore we - 这意味着该行,phrase one来 phrase2和phrase3在什么地方。此外,该行必须以Therefore we LINE_CONTAI