当前位置: 首页>>代码示例>>Python>>正文


Python Grammar.bnf2cnf方法代码示例

本文整理汇总了Python中grammar.Grammar.bnf2cnf方法的典型用法代码示例。如果您正苦于以下问题:Python Grammar.bnf2cnf方法的具体用法?Python Grammar.bnf2cnf怎么用?Python Grammar.bnf2cnf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在grammar.Grammar的用法示例。


在下文中一共展示了Grammar.bnf2cnf方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test

# 需要导入模块: from grammar import Grammar [as 别名]
# 或者: from grammar.Grammar import bnf2cnf [as 别名]
def test(string='balance.txt', spec='g1.txt'):
    from balance import BalanceLexer
    G = Grammar()
    source = open(spec,'r')
    G.generate(source)
    G.bnf2cnf()
    print "grammer==",G
    lexer= BalanceLexer()
    balance=open(string,'r')
    lexer.scanFile(balance)
    S=lexer.getStream()
    print "stream ===",S
    C=CYKChart()
    C.Build_CYK_Chart(G,S)
    print C
开发者ID:dacresni,项目名称:parse-tree-grapher,代码行数:17,代码来源:cyk.py

示例2: solve

# 需要导入模块: from grammar import Grammar [as 别名]
# 或者: from grammar.Grammar import bnf2cnf [as 别名]
def solve():
    G = Grammar()
    source = open("cky.txt",'r')
    G.generate(source)
    G.bnf2cnf()
    print "grammer==",G
    lexer= Telescope()
    balance=open('telescope','r')
    lexer.scanFile(balance)
    S=lexer.getStream()
    print "stream ===",S
    C=CYKChart()
    C.Build_CYK_Chart(G,S)
    print C
    genDot(C,"cky.dot")
    system("dot -Tjpg cky.dot -o cky.jpg")
    print "cky.jpg created"
开发者ID:dacresni,项目名称:parse-tree-grapher,代码行数:19,代码来源:ckyExample.py

示例3: main

# 需要导入模块: from grammar import Grammar [as 别名]
# 或者: from grammar.Grammar import bnf2cnf [as 别名]
def main(args):
    lexarname =None
    gramarspec =None
    inputfile =None
    outputtype =None
    outputfile =None
    argc= len(args)
    if argc == 1: 
        print "usage: main.py  lexarname, gramarspec, inputfile,[output-type] [output-file ]\n"
        return
    if argc > 1 : 
        lexarname = args[1]
    if argc > 2 :
        gramarspec = args[2]
    if argc > 3 : 
        inputfile = args[3]
    if argc > 4 :
        outputtype=args[4]
    else:
        outputtype="dot"
    if argc > 5 :
        outputfile = args[5]
    else:
        outputfile = inputfile
    G = Grammar()
    source = open(gramarspec,'r')
    G.generate(source)
    G.bnf2cnf()
    print "grammer==",G
    if sep in lexarname:
        lexarname = lexarname.replace(sep,".")
    lexerclass=__import__(lexarname)
    lexer=lexerclass.Lexer()
    lexer.scan(inputfile)
    S=lexer.getStream()
    print "stream ===",S
    C=CYKChart()
    C.Build_CYK_Chart(G,S)
    print C
    print C.graph
    if outputtype=="dot":
        genDot(C,outputfile)
        system("dot -Tjpg %s  -o %s "%(outputfile, outputfile)) # todo, see if dot takes STDIN so I can pipe this to it 
        print "%s generated"%(outputfile)
    elif outputtype=="js":
       genVIZ(C,outputfile)
开发者ID:dacresni,项目名称:parse-tree-grapher,代码行数:48,代码来源:main.py

示例4: solve

# 需要导入模块: from grammar import Grammar [as 别名]
# 或者: from grammar.Grammar import bnf2cnf [as 别名]
def solve():
    from os import system
    G = Grammar()
    source = open("infix.txt",'r')
    G.generate(source)
    G.bnf2cnf()
    print "grammer==",G
    lexer= Infix()
    balance=open('input.txt','r')
    lexer.scanFile(balance)
    S=lexer.getStream()
    print "stream ===",S
    C=CYKChart()
    C.Build_CYK_Chart(G,S)
    print C
    print C.graph
    genDot(C,"infix.dot")
    system("dot -Tjpg infix.dot -o infix.jpg")
    print "infix.jpg created"
开发者ID:dacresni,项目名称:parse-tree-grapher,代码行数:21,代码来源:infixExample.py


注:本文中的grammar.Grammar.bnf2cnf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。