How to use the ply.yacc function in ply

To help you get started, we’ve selected a few ply examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dabeaz / ply / test / yacc_uprec2.py View on Github external
def p_expression_number(t):
    'expression : NUMBER'
    t[0] = t[1]

def p_expression_name(t):
    'expression : NAME'
    try:
        t[0] = names[t[1]]
    except LookupError:
        print("Undefined name '%s'" % t[1])
        t[0] = 0

def p_error(t):
    print("Syntax error at '%s'" % t.value)

yacc.yacc()
github shogun-toolbox / shogun / examples / example-generation / parse.py View on Github external
def __init__(self):
        from ply import lex
        from ply import yacc

        # Add all shogun types to reserved identifiers
        self.addShogunTypes(self.reserved)

        # Build the lexer and the parser
        self.lexer = lex.lex(module=self,optimize=1)
        self.parser = yacc.yacc(module=self)
github pywbem / pywbem / pywbem / _mof_compiler.py View on Github external
Returns:

      yacc.Parser: YACC parser object for the MOF compiler.
    """

    # The write_tables argument controls whether the YACC parser writes
    # the YACC table module file.
    write_tables = (out_dir is not None)

    # In yacc(), the 'debug' parameter controls the main error
    # messages to the 'errorlog' in addition to the debug messages
    # to the 'debuglog'. Because we want to see the error messages,
    # we enable debug but set the debuglog to the NullLogger.
    # To enable debug logging, set debuglog to some other logger
    # (ex. PlyLogger(sys.stdout) to generate log output.
    return yacc.yacc(optimize=_optimize,
                     tabmodule=_tabmodule,
                     outputdir=out_dir,
                     write_tables=write_tables,
                     debug=verbose,
                     debuglog=yacc.NullLogger(),
                     errorlog=yacc.PlyLogger(sys.stdout) if verbose
                     else yacc.NullLogger())
github Zeex / sampgdk / scripts / cidl.py View on Github external
self._func_class = func_class
    self._const_class = const_class

    self._data = None
    self._paramlist = []
    self._attrlist = []
    self._constlist = []
    self._funclist = []

    self._lexer = ply.lex.lex(
      object=self,
      optimize=True,
      lextab='cidl_lextab'
    )

    self._parser = ply.yacc.yacc(
      module=self,
      errorlog=Logger(),
      debugfile='cidl_parser.out',
      tabmodule='cidl_parsetab'
    )
github crmccreary / AbqParse / src / AbqParse / abaqus_parser.py View on Github external
Points to the yacc table that's used for optimized
                mode. Only if you're modifying the parser, make 
                this point to a local yacc table file
                        
            yacc_debug:
                Generate a parser.out file that explains how yacc
                built the parsing table from the grammar.
        """
        self.clex = AbaqusLexer(error_func=self._lex_error_func)
            
        self.clex.build(
            optimize=lex_optimize,
            lextab=lextab)
        self.tokens = self.clex.tokens
        
        self.cparser = ply.yacc.yacc(
            module=self, 
            start='keyword_list',
            debug=yacc_debug,
            optimize=yacc_optimize,
            tabmodule=yacctab)
github StellarCN / py-stellar-base / stellar_sdk / xdr / xdrgen.py View on Github external
def run(infile, filters=True, pass_attrs=True, debug=False):
    global use_filters, allow_attr_passthrough
    use_filters = filters
    allow_attr_passthrough = pass_attrs

    # Parse the input data with yacc
    global name_dict
    name_dict = {}

    import ply.yacc as yacc
    parser = yacc.yacc(debug=0, write_tables=0)
    name_base = "StellarXDR"

    if os.path.isfile(infile):
        with open(infile) as content:
            data = content.read()
        print("Input file is", infile)
        # name_base = os.path.basename(infile[:infile.rfind(".")])
        name_base = os.path.splitext(os.path.basename(infile))[0]
        parser.parse(data)

    # stellar XDR dir/files
    elif os.path.isdir(infile):
        print("Input dir is", infile)
        # name_base = os.path.basename(os.path.abspath(infile))
        global file_list
        file_list = [
github slaclab / lacquer / lacquer / parsers / parser.py View on Github external
err.line = text_lines[err.lineno-1]
        err.offset = p.lexpos - err_line_offset
        err.msg = ("Syntax error at position %d (%s)"
                   % (err.offset, str(err.token_value)))
        def _print_error(self):
            pointer = " " * self.offset + "^" * len(self.token_value)
            print(self.line + "\n" + pointer)
        _print_error = types.MethodType(_print_error, err)
        err.print_file_and_line = _print_error

        raise err
    raise SyntaxError("Syntax error in input. Check your statement")

parser = yacc.yacc(tabmodule="parser_table", debugfile="parser.out")
expression_parser = yacc.yacc(tabmodule="expression_parser_table",
                              start="single_expression",
                              debugfile="expression_parser.out")
github soartech / soar / GGP / scripts / pyparser / gdlyacc.py View on Github external
def parse_file(filename):
	global int_rep
	global tokens

	int_rep = IntermediateRep()
	gdllex.lex_file(filename)
	tokens = gdllex.tokens

	yacc.yacc()
	file = open(filename, 'rU').read()
	yacc.parse(file)