aboutsummaryrefslogtreecommitdiff
path: root/pycparser/_build_tables.py
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2025-10-14 12:57:38 +0000
committerRichard Qin <richard.qin.x@gmail.com>2025-10-14 12:57:38 +0000
commit275e2ca033a880fe959e7eb4e83268a70318ba57 (patch)
tree312cad2e9d0dbeb608fdd300061b854e4cfa891b /pycparser/_build_tables.py
downloaddatalab2026-275e2ca033a880fe959e7eb4e83268a70318ba57.tar.gz
datalab2026-275e2ca033a880fe959e7eb4e83268a70318ba57.tar.xz
Initial commit
Diffstat (limited to 'pycparser/_build_tables.py')
-rw-r--r--pycparser/_build_tables.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/pycparser/_build_tables.py b/pycparser/_build_tables.py
new file mode 100644
index 0000000..4f37107
--- /dev/null
+++ b/pycparser/_build_tables.py
@@ -0,0 +1,40 @@
+#-----------------------------------------------------------------
+# pycparser: _build_tables.py
+#
+# A dummy for generating the lexing/parsing tables and and
+# compiling them into .pyc for faster execution in optimized mode.
+# Also generates AST code from the configuration file.
+# Should be called from the pycparser directory.
+#
+# Eli Bendersky [https://eli.thegreenplace.net/]
+# License: BSD
+#-----------------------------------------------------------------
+
+# Insert '.' and '..' as first entries to the search path for modules.
+# Restricted environments like embeddable python do not include the
+# current working directory on startup.
+import importlib
+import sys
+sys.path[0:0] = ['.', '..']
+
+# Generate c_ast.py
+from _ast_gen import ASTCodeGenerator
+ast_gen = ASTCodeGenerator('_c_ast.cfg')
+ast_gen.generate(open('c_ast.py', 'w'))
+
+from pycparser import c_parser
+
+# Generates the tables
+#
+c_parser.CParser(
+ lex_optimize=True,
+ yacc_debug=False,
+ yacc_optimize=True)
+
+# Load to compile into .pyc
+#
+importlib.invalidate_caches()
+
+import lextab
+import yacctab
+import c_ast