python类yacc()的实例源码

parser.py 文件源码 项目:etcdb 作者: box 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self):
        self._parser = yacc.yacc(debug=False)
pyshyacc.py 文件源码 项目:isar 作者: ilbers 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def p_error(p):
    msg = []
    w = msg.append
    w('%r\n' % p)
    w('followed by:\n')
    for i in range(5):
        n = yacc.token()
        if not n:
            break
        w('  %r\n' % n)
    raise sherrors.ShellSyntaxError(''.join(msg))

# Build the parser
flask_docjson.py 文件源码 项目:flask-docjson 作者: elemepi 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def parse_schema(data):
    """Parse schema string to schema dict.
    """
    # Rebuild `lexer` and `parser` each time.
    lexer = lex.lex()
    parser = yacc.yacc(debug=False, write_tables=0)

    lexer.lineno = 1
    return parser.parse(data)
parser.py 文件源码 项目:lift 作者: bhuztez 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, filename):
        self.filename = filename
        self.tokens = [ r.upper() for r in self.reserved ] + [ a[2:] for a in dir(self) if a[:2] == 't_' and a[2:].isupper() ]
        self.lexer = lex.lex(module=self, debug=False)
        self.parser = yacc.yacc(
            module=self,
            debug=False,
            write_tables=False,
            picklefile=os.path.splitext(
                sys.modules[self.__class__.__module__].__file__
                )[0]+'.parsetab')
qpathparser.py 文件源码 项目:QTAF 作者: Tencent 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, verbose=False):
        '''????

        :param verbose: ???log??
        :type verbose: boolean
        '''
        if verbose:
            self._logger = None
        else:
            self._logger = yacc.PlyLogger(self._NullStream())
parser.py 文件源码 项目:djangoql 作者: ivelum 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, debug=False, **kwargs):
        self.default_lexer = DjangoQLLexer()
        self.tokens = self.default_lexer.tokens
        kwargs['debug'] = debug
        self.yacc = yacc.yacc(module=self, **kwargs)
parser.py 文件源码 项目:djangoql 作者: ivelum 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def parse(self, input=None, lexer=None, **kwargs):
        lexer = lexer or self.default_lexer
        return self.yacc.parse(input=input, lexer=lexer, **kwargs)
parser.py 文件源码 项目:nml-andythenorth 作者: andythenorth 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self):
        self.lexer = tokens.NMLLexer()
        self.lexer.build()
        self.tokens = self.lexer.tokens
        self.parser = yacc.yacc(debug = False, module = self, write_tables = 0)
Parser.py 文件源码 项目:VM32 作者: gagiel 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def __init__(self):
        self.lexer = Lexer(error_callback=self._lexer_error)
        self.tokens = self.lexer.tokens

        self.parser = yacc.yacc(module=self)
Parser.py 文件源码 项目:VM32 作者: gagiel 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def p_error(self, p):
        next_t = yacc.token()
        raise ParseError("invalid code before %s (at line %s)" % (repr(next_t.value), next_t.lineno))
grammar.py 文件源码 项目:fluiddb 作者: fluidinfo 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def build(self, **kwargs):
        """Build the parser."""
        self._yacc = yacc(**kwargs)
dsl.py 文件源码 项目:praelatus-poc 作者: praelatus 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def compile_q(expr):
    lexer = lex.lex()
    parser = yacc.yacc()
    return parser.parse(expr, lexer=lexer)
parser.py 文件源码 项目:compiladores-python 作者: arthurmbandeira 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def p_error(p):
    last_cr = p.lexer.lexdata.rfind('\n', 0, p.lexer.lexpos)
    column = p.lexer.lexpos - last_cr - 1

    if p:
        print("Erro de sintaxe em {0} na linha {1} coluna {2}".format(p.value, p.lexer.lineno, column))
        # yacc.yacc().errok()
    else:
        print("Erro de sintaxe EOF")
parser.py 文件源码 项目:compiladores-python 作者: arthurmbandeira 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def main(argv):
    try:
        opts, args = getopt.getopt(argv, "hf:", ["file"])
    except getopt.GetoptError:
        print('program.py -f <file>')
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print('program.py -f <file>')
            sys.exit()
        elif opt in ("-f", "--file"):
            f = arg

    input_ = ''
    with open(f, 'r') as file:
        file = open(f, 'r')
        for line in file:
            input_ += line
    file.close()

    # Build the parser
    parser = yacc.yacc()

    program = parser.parse(input_)
    if program:
        program.print_name()
        program.check_node()
        print('Variaveis declaradas', declared_variables)
parser.py 文件源码 项目:ieml 作者: IEMLdev 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self):
        self.t_add_rules()

        self.lexer = get_script_lexer()
        self.parser = yacc.yacc(module=self, errorlog=logging, start='term',
                                debug=False, optimize=True, picklefile=os.path.join(parser_folder, "script_parser.pickle"))
        # rename the parsing method (can't name it directly parse with lru_cache due to ply checking)
        self.parse = self.t_parse
parser.py 文件源码 项目:ieml 作者: IEMLdev 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, dictionary=None):

        self._get_term = partial(term, dictionary=dictionary)

        # Build the lexer and parser
        self.lexer = get_lexer()
        self.parser = yacc.yacc(module=self, errorlog=logging, start='proposition',
                                debug=False, optimize=True, picklefile=os.path.join(parser_folder, "ieml_parser.pickle"))
        self._ieml = None
parser.py 文件源码 项目:ieml 作者: IEMLdev 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def __init__(self):

        # Build the lexer and parser
        self.lexer = get_lexer()
        self.parser = yacc.yacc(module=self, errorlog=logging, start='usl',
                                debug=False, optimize=True, picklefile=os.path.join(parser_folder, "usl_parser.pickle"))
parser.py 文件源码 项目:ieml 作者: IEMLdev 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self):

        # Build the lexer and parser
        self.lexer = get_lexer()
        self.parser = yacc.yacc(module=self, errorlog=logging, start='path',
                                debug=False, optimize=True, picklefile="parser/path_parser.pickle")
        # rename the parsing method (can't name it directly parse with lru_cache due to ply checking)
        self.parse = self.t_parse
c_parser.py 文件源码 项目:xxNet 作者: drzorm 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def p_init_declarator_list_1(self, p):
        """ init_declarator_list    : init_declarator
                                    | init_declarator_list COMMA init_declarator
        """
        p[0] = p[1] + [p[3]] if len(p) == 4 else [p[1]]

    # If the code is declaring a variable that was declared a typedef in an
    # outer scope, yacc will think the name is part of declaration_specifiers,
    # not init_declarator, and will then get confused by EQUALS.  Pass None
    # up in place of declarator, and handle this at a higher level.
    #
c_parser.py 文件源码 项目:xxNet 作者: drzorm 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def p_direct_declarator_5(self, p):
        """ direct_declarator   : direct_declarator LPAREN parameter_type_list RPAREN
                                | direct_declarator LPAREN identifier_list_opt RPAREN
        """
        func = c_ast.FuncDecl(
            args=p[3],
            type=None,
            coord=p[1].coord)

        # To see why _get_yacc_lookahead_token is needed, consider:
        #   typedef char TT;
        #   void foo(int TT) { TT = 10; }
        # Outside the function, TT is a typedef, but inside (starting and
        # ending with the braces) it's a parameter.  The trouble begins with
        # yacc's lookahead token.  We don't know if we're declaring or
        # defining a function until we see LBRACE, but if we wait for yacc to
        # trigger a rule on that token, then TT will have already been read
        # and incorrectly interpreted as TYPEID.  We need to add the
        # parameters to the scope the moment the lexer sees LBRACE.
        #
        if self._get_yacc_lookahead_token().type == "LBRACE":
            if func.args is not None:
                for param in func.args.params:
                    if isinstance(param, c_ast.EllipsisParam): break
                    self._add_identifier(param.name, param.coord)

        p[0] = self._type_modify_decl(decl=p[1], modifier=func)


问题


面经


文章

微信
公众号

扫码关注公众号