parser, lexer の参照
#!/usr/bin/env python import ply.lex as lex tokens = ( 'A', 'B', 'C', ) def t_A(t): r'A' print t.lexer return t t_B = r'B' t_C = r'C' t_ignore = " \t" def t_error(t): print "Illegal character '%s'" % t.value[0] t.lexer.skip(1) lex.lex() import ply.yacc as yacc def p_input(p): 'input : A B C' print p.parser print p.lexer def p_error(p): print "Syntax error at '%s'" % p.value yacc.yacc() while 1: try: s = raw_input('input > ') except EOFError: break if not s: continue yacc.parse(s)
で、
input > A B C <ply.lex.Lexer instance at 0x4022064c> <ply.yacc.Parser instance at 0x40243fac> <ply.lex.Lexer instance at 0x4022064c>