當前位置: 首頁>>代碼示例>>Python>>正文


Python yacc.yacc方法代碼示例

本文整理匯總了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') 
開發者ID:nojanath,項目名稱:SublimeKSP,代碼行數:20,代碼來源:ksp_parser.py

示例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) 
開發者ID:modelop,項目名稱:hadrian,代碼行數:27,代碼來源:prettypfa.py

示例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 
開發者ID:dropbox,項目名稱:stone,代碼行數:20,代碼來源:parser.py

示例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'] 
開發者ID:Qiskit,項目名稱:qiskit-terra,代碼行數:24,代碼來源:qasmparser.py

示例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 
開發者ID:spdx,項目名稱:tools-python,代碼行數:18,代碼來源:tagvalue.py

示例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,
        ) 
開發者ID:altair-viz,項目名稱:altair-transform,代碼行數:23,代碼來源:_parser.py

示例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: 
開發者ID:nicolashernandez,項目名稱:PyRATA,代碼行數:21,代碼來源:syntactic_step_parser.py

示例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 
開發者ID:DFO-Ocean-Navigator,項目名稱:Ocean-Data-Map-Project,代碼行數:19,代碼來源:parser.py

示例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 
開發者ID:pywbem,項目名稱:pywbem,代碼行數:23,代碼來源:_mof_compiler.py

示例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) 
開發者ID:Dador,項目名稱:JavascriptSubtitlesOctopus,代碼行數:18,代碼來源:WebIDL.py

示例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

### 
開發者ID:modelop,項目名稱:hadrian,代碼行數:29,代碼來源:prettypfa.py

示例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 
開發者ID:modelop,項目名稱:hadrian,代碼行數:38,代碼來源:prettypfa.py

示例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) 
開發者ID:modelop,項目名稱:hadrian,代碼行數:14,代碼來源:parser.py

示例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 
開發者ID:pyGSTio,項目名稱:pyGSTi,代碼行數:11,代碼來源:__init__.py

示例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)

    ############################################## 
開發者ID:FabriceSalvaire,項目名稱:PySpice,代碼行數:8,代碼來源:Parser.py


注:本文中的ply.yacc.yacc方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。