_build_tables.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #-----------------------------------------------------------------
  2. # pycparser: _build_tables.py
  3. #
  4. # A dummy for generating the lexing/parsing tables and and
  5. # compiling them into .pyc for faster execution in optimized mode.
  6. # Also generates AST code from the configuration file.
  7. # Should be called from the pycparser directory.
  8. #
  9. # Eli Bendersky [https://eli.thegreenplace.net/]
  10. # License: BSD
  11. #-----------------------------------------------------------------
  12. # Insert '.' and '..' as first entries to the search path for modules.
  13. # Restricted environments like embeddable python do not include the
  14. # current working directory on startup.
  15. import importlib
  16. import sys
  17. sys.path[0:0] = ['.', '..']
  18. # Generate c_ast.py
  19. from _ast_gen import ASTCodeGenerator
  20. ast_gen = ASTCodeGenerator('_c_ast.cfg')
  21. ast_gen.generate(open('c_ast.py', 'w'))
  22. from pycparser import c_parser
  23. # Generates the tables
  24. #
  25. c_parser.CParser(
  26. lex_optimize=True,
  27. yacc_debug=False,
  28. yacc_optimize=True)
  29. # Load to compile into .pyc
  30. #
  31. importlib.invalidate_caches()
  32. import lextab
  33. import yacctab
  34. import c_ast