コード例 #1
0
ファイル: parser.py プロジェクト: xysheep/compbio
    """
    p[0] = p[1]


def p_error(p):
    if p:
        raise Exception("Syntax error at '%s'" % p.value)
    else:
        raise Exception("Syntax error")


#lex.lex()
#yacc.yacc()

outdir = os.path.dirname(__file__)
lex.lex(debug=0, optimize=1, lextab="sexp_lex", outputdir=outdir)
yacc.yacc(debug=0, optimize=1, tabmodule="sexp_tab", outputdir=outdir)

#outdir = os.path.dirname(__file__)
#lex.lex(debug=1, optimize=0, lextab="sexp_lex", outputdir=outdir)
#yacc.yacc(debug=1, optimize=0, tabmodule="sexp_tab", outputdir=outdir)

parse = yacc.parse

if __name__ == "__main__":
    print yacc.parse('(+ 223 36.6 (aaa) bbb \"ccc\")')
    print yacc.parse(
        r'(if (> 2 var) (cons a b) (display "no \\ \"quoted\" \\ " 22) )'
    )  # nopep8
    #print yacc.parse("(7:subject(3:ref5:alice6:mother))")
コード例 #2
0
ファイル: treelib_parser.py プロジェクト: xysheep/compbio
        p[0] = [p[1]] + p[3]


def p_error(p):
    if p:
        raise Exception("Syntax error at '%s'" % p.value)
    else:
        raise Exception("Syntax error")


#lex.lex()
#yacc.yacc()

outdir = os.path.dirname(__file__)
lex.lex(debug=0, optimize=1, lextab="treelib_lex", outputdir=outdir)
yacc.yacc(debug=0, optimize=1, tabmodule="treelib_tab", outputdir=outdir)

if __name__ == "__main__":
    print yacc.parse("(sss:1.0,(abc:.2, hello there:.1):2.0,abcd:4.0);")
    print yacc.parse("((xax:1.0,bbx:2));")
    print yacc.parse("((aa:1.0,bb:2)x:33,(cc:4,dd:5):6);")

#=============================================================================
# OLD parsing code
"""
   Tree --> Subtree ";" | Branch ";"
   Subtree --> Leaf | Internal
   Leaf --> Name
   Internal --> "(" BranchSet ")" Name
   BranchSet --> Branch | Branch "," BranchSet
   Branch --> Subtree Length
コード例 #3
0
    p[0] = p[1]


def p_error(p):
    if p:
        raise Exception("Syntax error at '%s'" % p.value)
    else:
        raise Exception("Syntax error")


#lex.lex()
#yacc.yacc()

outdir = os.path.dirname(__file__)
lex.lex(debug=0, optimize=1, lextab="sexp_lex", outputdir=outdir)
yacc.yacc(debug=0, optimize=1, tabmodule="sexp_tab", outputdir=outdir)

#outdir = os.path.dirname(__file__)
#lex.lex(debug=1, optimize=0, lextab="sexp_lex", outputdir=outdir)
#yacc.yacc(debug=1, optimize=0, tabmodule="sexp_tab", outputdir=outdir)


parse = yacc.parse




if __name__ == "__main__":
    print yacc.parse('(+ 223 36.6 (aaa) bbb \"ccc\")')
    print yacc.parse(r'(if (> 2 var) (cons a b) (display "no \\ \"quoted\" \\ " 22) )')
    #print yacc.parse("(7:subject(3:ref5:alice6:mother))")
コード例 #4
0
        p[0] = [p[1]] + p[3]
    

def p_error(p):
    if p:
        raise Exception("Syntax error at '%s'" % p.value)
    else:
        raise Exception("Syntax error")


#lex.lex()
#yacc.yacc()

outdir = os.path.dirname(__file__)
lex.lex(debug=0, optimize=1, lextab="treelib_lex", outputdir=outdir)
yacc.yacc(debug=0, optimize=1, tabmodule="treelib_tab", outputdir=outdir)

if __name__ == "__main__":
    print yacc.parse("(sss:1.0,(abc:.2, hello there:.1):2.0,abcd:4.0);")
    print yacc.parse("((xax:1.0,bbx:2));")
    print yacc.parse("((aa:1.0,bb:2)x:33,(cc:4,dd:5):6);")



#=============================================================================
# OLD parsing code



"""
   Tree --> Subtree ";" | Branch ";"