def parse(input, eof=False, debug=False):
"""Parse a whole script at once and return the generated AST and unconsumed
data in a tuple.
NOTE: eof is probably meaningless for now, the parser being unable to work
in pull mode. It should be set to True.
"""
lexer = pyshlex.PLYLexer()
remaining = lexer.add(input, eof)
if lexer.is_empty():
return [], remaining
if debug:
debug = 2
return yacc.parse(lexer=lexer, debug=debug), remaining
#-------------------------------------------------------------------------------
# AST rendering helpers
#-------------------------------------------------------------------------------
python类parse()的实例源码
def p_initializer_list(p):
'''initializer_list : initializer_clause
| initializer_list ',' initializer_clause
'''
pass
#---------------------------------------------------------------------------------------------------
# A.8 Classes
#---------------------------------------------------------------------------------------------------
#
# An anonymous bit-field declaration may look very like inheritance:
# const int B = 3;
# class A : B ;
# The two usages are too distant to try to create and enforce a common prefix so we have to resort to
# a parser hack by backtracking. Inheritance is much the most likely so we mark the input stream context
# and try to parse a base-clause. If we successfully reach a { the base-clause is ok and inheritance was
# the correct choice so we unmark and continue. If we fail to find the { an error token causes
# back-tracking to the alternative parse in elaborated_type_specifier which regenerates the : and
# declares unconditional success.
#
def p_initializer_list(p):
'''initializer_list : initializer_clause
| initializer_list ',' initializer_clause
'''
pass
#---------------------------------------------------------------------------------------------------
# A.8 Classes
#---------------------------------------------------------------------------------------------------
#
# An anonymous bit-field declaration may look very like inheritance:
# const int B = 3;
# class A : B ;
# The two usages are too distant to try to create and enforce a common prefix so we have to resort to
# a parser hack by backtracking. Inheritance is much the most likely so we mark the input stream context
# and try to parse a base-clause. If we successfully reach a { the base-clause is ok and inheritance was
# the correct choice so we unmark and continue. If we fail to find the { an error token causes
# back-tracking to the alternative parse in elaborated_type_specifier which regenerates the : and
# declares unconditional success.
#
parameter_evolution.py 文件源码
项目:DT2118-Speech-and-Speaker-Recognition
作者: Morikko
项目源码
文件源码
阅读 25
收藏 0
点赞 0
评论 0
def comparePhonemes():
s =0
mean = []
phonemes = []
hfile = open("models_MFCC_0/hmm7/hmmdefs.mmf")
data = hfile.read()
hmms = yacc.parse(data)
for m in range(len(hmms)):
thishmm = hmms[m]
print('model number '+str(m+1)+' is called '+thishmm.name+' and state '+str(s+1))
phonemes.append(thishmm.name)
thisstate = thishmm.states[s][1]
thiscomponent = thisstate.mixtures[0][2]
mean.append(thiscomponent.mean.vector)
return phonemes, mean
parameter_evolution.py 文件源码
项目:DT2118-Speech-and-Speaker-Recognition
作者: Morikko
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def getParameter(models):
"""
Get through the folder models and analyse each hmm
Take the phone m ans the state s
Get the mean and the variance of the first gaussian
Return all the mean and var
"""
m = 2
s =1
mean = []
var = []
# Get the values of the 3rd phones for each hmm
for i in range(8):
hfile = open(models + "/hmm" + str(i) + "/hmmdefs.mmf")
data = hfile.read()
hmms = yacc.parse(data)
if i == 0:
m = 10
else:
m = 2
thishmm = hmms[m]
print('Iteration: ' + str(i))
print('model number '+str(m+1)+' is called '+thishmm.name+' and state '+str(s+1))
thisstate = thishmm.states[s][1]
thiscomponent = thisstate.mixtures[0][2]
mean.append(thiscomponent.mean.vector)
var.append(thiscomponent.var.vector)
return mean, var
def parse(self, value):
raise NotImplementedError('The parse method must be implemented')
def parse(self, value):
return yacc.parse(value)