本文整理汇总了Python中ply.yacc.yacc方法的典型用法代码示例。如果您正苦于以下问题:Python yacc.yacc方法的具体用法?Python yacc.yacc怎么用?Python yacc.yacc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ply.yacc
的用法示例。
在下文中一共展示了yacc.yacc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def init(outputdir=None):
outputdir = outputdir or os.path.dirname(__file__) # os.getcwd()
current_module = sys.modules[__name__]
#print (outputdir, current_module)
debug = 0
optimize = 0
lexer = lex.lex(optimize=0, debug=debug)
# lexer.input('on init\n declare shared parameter cutoff')
# while True:
# tok = lexer.token()
# if tok is None:
# break
# print (tok)
return yacc.yacc(method="LALR", optimize=optimize, debug=debug,
write_tables=0, module=current_module, start='script',
outputdir=outputdir, tabmodule='ksp_parser_tab')
示例2: ppfas
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def ppfas(text, subs={}, **subs2):
"""Parse a string of several PrettyPFA expressions (delimited by semicolons) as a list of PFA abstract syntax trees.
:type text: string
:param text: PrettyPFA expressions (delimited by semicolons)
:type subs: dict from substitution names to substitutions
:param subs: replacement values as PFA titus.pfaast.Ast, PrettyPFA strings, or PFA Pythonized JSON
:type subs2: dict from substitution names to substitutions
:param subs2: added to ``subs`` (a more convenient way to pass them)
:rtype: list of titus.pfaast.Expression
:return: parsed expressions as PFA
"""
subs2.update(subs)
if not exprParser.initialized:
try:
import ply.lex as lex
import ply.yacc as yacc
except ImportError:
raise ImportError("ply (used to parse the PrettyPFA) is not available on your system")
else:
exprParser.initialize(lex, yacc)
return exprParser.parse(text, subs2)
示例3: parse
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def parse(self, data, path=None):
"""
Args:
data (str): Raw specification text.
path (Optional[str]): Path to specification on filesystem. Only
used to tag tokens with the file they originated from.
"""
assert not self.exhausted, 'Must call get_parser() to reset state.'
self.path = path
parsed_data = self.yacc.parse(data, lexer=self.lexer, debug=self.debug)
# It generally makes sense for lexer errors to come first, because
# those can be the root of parser errors. Also, since we only show one
# error max right now, it's best to show the lexing one.
for err_msg, lineno in self.lexer.errors[::-1]:
self.errors.insert(0, (err_msg, lineno, self.path))
parsed_data.extend(self.anony_defs)
self.exhausted = True
return parsed_data
示例4: __init__
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def __init__(self, filename):
"""Create the parser."""
if filename is None:
filename = ""
self.lexer = QasmLexer(filename)
self.tokens = self.lexer.tokens
self.parse_dir = tempfile.mkdtemp(prefix='qiskit')
self.precedence = (
('left', '+', '-'),
('left', '*', '/'),
('left', 'negative', 'positive'),
('right', '^'))
# For yacc, also, write_tables = Bool and optimize = Bool
self.parser = yacc.yacc(module=self, debug=False,
outputdir=self.parse_dir)
self.qasm = None
self.parse_deb = False
self.global_symtab = {} # global symtab
self.current_symtab = self.global_symtab # top of symbol stack
self.symbols = [] # symbol stack
self.external_functions = ['sin', 'cos', 'tan', 'exp', 'ln', 'sqrt',
'acos', 'atan', 'asin']
示例5: parse
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def parse(self, text):
self.document = document.Document()
self.error = False
self.yacc.parse(text, lexer=self.lex)
# FIXME: this state does not make sense
self.builder.reset()
validation_messages = []
# Report extra errors if self.error is False otherwise there will be
# redundent messages
validation_messages = self.document.validate(validation_messages)
if not self.error:
if validation_messages:
for msg in validation_messages:
self.logger.log(msg)
self.error = True
return self.document, self.error
示例6: __init__
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def __init__(self, **kw):
self.debug = kw.get("debug", 0)
try:
modname = (
os.path.split(os.path.splitext(__file__)[0])[1]
+ "_"
+ self.__class__.__name__
)
except ValueError:
modname = "parser" + "_" + self.__class__.__name__
self.debugfile = modname + ".dbg"
self.tabmodule = modname + "_" + "parsetab"
# Build the lexer and parser
lex.lex(module=self, debug=self.debug)
yacc.yacc(
module=self,
debug=self.debug,
debugfile=self.debugfile,
tabmodule=self.tabmodule,
)
示例7: __init__
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def __init__(self, **kwargs):
if 'tokens' in kwargs.keys(): # MANDATORY
self.tokens = kwargs['tokens']
kwargs.pop('tokens', None)
# debugging and logging http://www.dabeaz.com/ply/ply.html#ply_nn44
#self.parser = yacc.yacc(module=self, start='step', errorlog=yacc.NullLogger(), debug = True, debugfile='debug_file', **kwargs)
self.parser = yacc.yacc(module=self, start='step', errorlog=yacc.NullLogger(), debug = False, **kwargs)
# https://github.com/dabeaz/ply/blob/master/ply/yacc.py
# debug yaccdebug = True # Debugging mode. If set, yacc generates a
# a 'parser.out' file in the current directory
# """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
# MAIN
# """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
# example use:
示例8: __init__
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def __init__(self, **kwargs):
self.lexer = data.calculated_parser.lexer.Lexer()
self.tokens = self.lexer.tokens
# Sets the operator precedence for the parser. The unary minus is the
# highest, followed by exponentiation, then multiplication/division and
# addition/subtraction is last on the list.
self.precedence = (
('left', 'PLUS', 'MINUS'),
('left', 'TIMES', 'DIVIDE'),
('left', 'POWER'),
('right', 'UMINUS'),
)
self.parser = yacc.yacc(module=self)
self.data = None
self.expression = None
self.result = np.nan
示例9: __init__
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def __init__(self, msg, parser_token=None, cim_error=None):
"""
Parameters:
msg (:term:`string`):
Message text describing the error.
parser_token (lex.LexToken or yacc.YaccProduction):
PLY lex or yacc parser token (that is, the ``p`` argument of a yacc
parser function or the ``t`` argument of a lex parser function).
This token is used to obtain the MOF source text and location
information.
`None` will result in no MOF source text and location information
to be obtained.
cim_error (:class:`~pywbem.CIMError`):
CIM error returned by the CIM repository.
"""
super(MOFRepositoryError, self).__init__(msg, parser_token)
self._cim_error = cim_error
示例10: __init__
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def __init__(self, outputdir='', lexer=None):
Tokenizer.__init__(self, outputdir, lexer)
self.parser = yacc.yacc(module=self,
outputdir=outputdir,
tabmodule='webidlyacc',
errorlog=yacc.NullLogger(),
picklefile='WebIDLGrammar.pkl')
self._globalScope = IDLScope(BuiltinLocation("<Global Scope>"), None, None)
self._installBuiltins(self._globalScope)
self._productions = []
self._filename = "<builtin>"
self.lexer.input(Parser._builtins)
self._filename = None
self.parser.parse(lexer=self.lexer,tracking=True)
示例11: parse
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def parse(self, text, subs):
"""Parse the given text, returning a PFA abstract syntax tree.
:type text: string
:param text: command line to parse
:type subs: dict of substitutions
:param subs: substitutions to apply to any strings in ``<<French quotes>>``
:rtype: titus.pfaast.EngineConfig or titus.pfaast.Expression
:return: parsed text as an abstract syntax tree
"""
self.lexer.lineno = 1
self.text = text
self.subs = subs
out = self.yacc.parse(text, lexer=self.lexer)
if self.wholeDocument:
return out
else:
state = InterpretationState()
if isinstance(out, (list, tuple)):
out2 = [x.asExpr(state) for x in out]
else:
out2 = out.asExpr(state)
state.avroTypeBuilder.resolveTypes()
return out2
###
示例12: ast
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def ast(text, check=True, version=None, subs={}, **subs2):
"""Parse PrettyPFA and return the result as a PFA abstract syntax tree.
:type text: string
:param text: PrettyPFA to parse
:type check: bool
:param check: if ``True``, check the result for PFA semantic errors (default ``True``); **Note:** if the PrettyPFA contains any unresolved substitutions (in ``<<French quotes>>``), it will **not** be checked
:type version: string or ``None``
:param version: version of the PFA language to use while interpreting (``None`` defaults to titus.version.defaultPFAVersion)
:type subs: dict from substitution names to substitutions
:param subs: replacement values as PFA titus.pfaast.Ast, PrettyPFA strings, or PFA Pythonized JSON
:type subs2: dict from substitution names to substitutions
:param subs2: added to ``subs`` (a more convenient way to pass them)
:rtype: titus.pfaast.EngineConfig
:return: PFA abstract syntax tree
"""
subs2.update(subs)
if not parser.initialized:
try:
import ply.lex as lex
import ply.yacc as yacc
except ImportError:
raise ImportError("ply (used to parse the PrettyPFA) is not available on your system")
else:
parser.initialize(lex, yacc)
out = parser.parse(text, subs2)
anysubs = lambda x: x
anysubs.isDefinedAt = lambda x: isinstance(x, Subs)
if check and len(out.collect(anysubs)) == 0:
PFAEngine.fromAst(out, version=version)
return out
示例13: parse
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def parse(self, text):
"""Parse the given text, returning an abstract syntax tree.
:type text: string
:param text: command line to parse
:rtype: titus.inspector.parser.Ast
:return: parsed text as an abstract syntax tree
"""
self.text = text
self.groupCounter = 1
return self.yacc.parse(text, lexer=self.lexer)
示例14: __init__
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def __init__(self, lexer_object=None, lookup={}):
if self.mode == "ply":
self._lookup = lookup
self._lexer = lex.lex(object=lexer_object if lexer_object else CircuitLexer())
self._parser = yacc.yacc(module=self, start="ppstring", debug=False,
tabmodule='pygsti.io.parsetab_string')
self.parse = self.ply_parse
else:
self.parse = self._parse
示例15: _build
# 需要导入模块: from ply import yacc [as 别名]
# 或者: from ply.yacc import yacc [as 别名]
def _build(self, **kwargs):
self._lexer = lex.lex(module=self, **kwargs)
self._parser = yacc.yacc(module=self, **kwargs)
##############################################