webruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (1364) hide show
  1. checksums.yaml +7 -0
  2. data/bin/webruby +36 -0
  3. data/driver/driver.c +50 -0
  4. data/driver/main.c +40 -0
  5. data/lib/webruby/app.rb +13 -0
  6. data/lib/webruby/config.rb +61 -0
  7. data/lib/webruby/environment.rb +32 -0
  8. data/lib/webruby/rake/files.rake +66 -0
  9. data/lib/webruby/rake/general.rake +22 -0
  10. data/lib/webruby/rake/mruby.rake +44 -0
  11. data/lib/webruby/utility.rb +132 -0
  12. data/lib/webruby.rb +10 -0
  13. data/modules/emscripten/AUTHORS +89 -0
  14. data/modules/emscripten/LICENSE +68 -0
  15. data/modules/emscripten/README.markdown +14 -0
  16. data/modules/emscripten/cmake/Platform/Emscripten.cmake +61 -0
  17. data/modules/emscripten/cmake/Platform/Emscripten_unix.cmake +24 -0
  18. data/modules/emscripten/em++ +12 -0
  19. data/modules/emscripten/em++.bat +2 -0
  20. data/modules/emscripten/em-config +24 -0
  21. data/modules/emscripten/em-config.bat +2 -0
  22. data/modules/emscripten/emar +24 -0
  23. data/modules/emscripten/emar.bat +2 -0
  24. data/modules/emscripten/emcc +1744 -0
  25. data/modules/emscripten/emcc.bat +2 -0
  26. data/modules/emscripten/emcc.py +5 -0
  27. data/modules/emscripten/emconfigure +27 -0
  28. data/modules/emscripten/emconfigure.bat +2 -0
  29. data/modules/emscripten/emlibtool +11 -0
  30. data/modules/emscripten/emlibtool.bat +2 -0
  31. data/modules/emscripten/emlink.py +293 -0
  32. data/modules/emscripten/emmake +29 -0
  33. data/modules/emscripten/emmake.bat +2 -0
  34. data/modules/emscripten/emranlib +9 -0
  35. data/modules/emscripten/emranlib.bat +2 -0
  36. data/modules/emscripten/emscons +20 -0
  37. data/modules/emscripten/emscripten.py +835 -0
  38. data/modules/emscripten/patches/README +4 -0
  39. data/modules/emscripten/patches/series +2 -0
  40. data/modules/emscripten/scons-tools/closure.py +28 -0
  41. data/modules/emscripten/scons-tools/emscripten.py +359 -0
  42. data/modules/emscripten/scons-tools/llvm.py +33 -0
  43. data/modules/emscripten/src/analyzer.js +1695 -0
  44. data/modules/emscripten/src/compiler.html +48 -0
  45. data/modules/emscripten/src/compiler.js +298 -0
  46. data/modules/emscripten/src/corruptionCheck.js +98 -0
  47. data/modules/emscripten/src/determinstic.js +20 -0
  48. data/modules/emscripten/src/embind/embind.js +1677 -0
  49. data/modules/emscripten/src/embind/emval.js +283 -0
  50. data/modules/emscripten/src/experimental/allow_loopvars_from_memsetcpy_inasm.diff +97 -0
  51. data/modules/emscripten/src/experimental/batching.diff +44 -0
  52. data/modules/emscripten/src/experimental/functypeopt.diff +113 -0
  53. data/modules/emscripten/src/experimental/multiple_heaps.diff +175 -0
  54. data/modules/emscripten/src/experimental/noncallgraphprofiling.diff +197 -0
  55. data/modules/emscripten/src/experimental/optimize_memcpy_for_ta1.diff +124 -0
  56. data/modules/emscripten/src/experimental/remove__label__s.diff +140 -0
  57. data/modules/emscripten/src/experimental/renderer_cache_hash.diff +99 -0
  58. data/modules/emscripten/src/experimental/sdl_key_forwarding.diff +57 -0
  59. data/modules/emscripten/src/experimental/simplifyGeneratedFunctionsDetection.diff +336 -0
  60. data/modules/emscripten/src/experimental/stringCache.diff +147 -0
  61. data/modules/emscripten/src/fastLong.js +299 -0
  62. data/modules/emscripten/src/framework.js +257 -0
  63. data/modules/emscripten/src/gl-matrix.js +1952 -0
  64. data/modules/emscripten/src/headless.js +904 -0
  65. data/modules/emscripten/src/intertyper.js +1050 -0
  66. data/modules/emscripten/src/jsifier.js +1827 -0
  67. data/modules/emscripten/src/library.js +8270 -0
  68. data/modules/emscripten/src/library_browser.js +911 -0
  69. data/modules/emscripten/src/library_egl.js +491 -0
  70. data/modules/emscripten/src/library_gc.js +236 -0
  71. data/modules/emscripten/src/library_gl.js +4452 -0
  72. data/modules/emscripten/src/library_glfw.js +576 -0
  73. data/modules/emscripten/src/library_glut.js +449 -0
  74. data/modules/emscripten/src/library_jansson.js +320 -0
  75. data/modules/emscripten/src/library_openal.js +602 -0
  76. data/modules/emscripten/src/library_sdl.js +2024 -0
  77. data/modules/emscripten/src/library_strtok_r.c +97 -0
  78. data/modules/emscripten/src/library_xlib.js +23 -0
  79. data/modules/emscripten/src/long.js +1609 -0
  80. data/modules/emscripten/src/modules.js +491 -0
  81. data/modules/emscripten/src/parseTools.js +2474 -0
  82. data/modules/emscripten/src/postamble.js +170 -0
  83. data/modules/emscripten/src/postamble_sharedlib.js +16 -0
  84. data/modules/emscripten/src/preamble.js +914 -0
  85. data/modules/emscripten/src/preamble_sharedlib.js +25 -0
  86. data/modules/emscripten/src/relooper/README.markdown +14 -0
  87. data/modules/emscripten/src/relooper/Relooper.cpp +1236 -0
  88. data/modules/emscripten/src/relooper/Relooper.h +250 -0
  89. data/modules/emscripten/src/relooper/doit.sh +70 -0
  90. data/modules/emscripten/src/relooper/emscripten/glue.js +57 -0
  91. data/modules/emscripten/src/relooper/emscripten/test.js +44 -0
  92. data/modules/emscripten/src/relooper/fuzzer.py +116 -0
  93. data/modules/emscripten/src/relooper/ministring.h +35 -0
  94. data/modules/emscripten/src/relooper/paper.pdf +0 -0
  95. data/modules/emscripten/src/relooper/test.cpp +262 -0
  96. data/modules/emscripten/src/relooper/test.txt +155 -0
  97. data/modules/emscripten/src/relooper/test2.c +44 -0
  98. data/modules/emscripten/src/relooper/test2.txt +12 -0
  99. data/modules/emscripten/src/relooper/test3.c +42 -0
  100. data/modules/emscripten/src/relooper/test3.txt +27 -0
  101. data/modules/emscripten/src/relooper/test4.cpp +40 -0
  102. data/modules/emscripten/src/relooper/test4.txt +23 -0
  103. data/modules/emscripten/src/relooper/test5.cpp +40 -0
  104. data/modules/emscripten/src/relooper/test5.txt +32 -0
  105. data/modules/emscripten/src/relooper/test6.cpp +31 -0
  106. data/modules/emscripten/src/relooper/test6.txt +12 -0
  107. data/modules/emscripten/src/relooper/test_dead.cpp +28 -0
  108. data/modules/emscripten/src/relooper/test_dead.txt +9 -0
  109. data/modules/emscripten/src/relooper/test_debug.cpp +30 -0
  110. data/modules/emscripten/src/relooper/test_debug.txt +128 -0
  111. data/modules/emscripten/src/relooper/test_fuzz1.cpp +52 -0
  112. data/modules/emscripten/src/relooper/test_fuzz1.txt +32 -0
  113. data/modules/emscripten/src/relooper/test_fuzz2.cpp +34 -0
  114. data/modules/emscripten/src/relooper/test_fuzz2.txt +13 -0
  115. data/modules/emscripten/src/relooper/test_fuzz3.cpp +36 -0
  116. data/modules/emscripten/src/relooper/test_fuzz3.txt +9 -0
  117. data/modules/emscripten/src/relooper/test_fuzz4.cpp +38 -0
  118. data/modules/emscripten/src/relooper/test_fuzz4.txt +19 -0
  119. data/modules/emscripten/src/relooper/test_fuzz5.cpp +57 -0
  120. data/modules/emscripten/src/relooper/test_fuzz5.txt +52 -0
  121. data/modules/emscripten/src/relooper/test_fuzz6.cpp +322 -0
  122. data/modules/emscripten/src/relooper/test_fuzz6.txt +108 -0
  123. data/modules/emscripten/src/relooper/test_inf.cpp +813 -0
  124. data/modules/emscripten/src/relooper/test_inf.txt +385 -0
  125. data/modules/emscripten/src/relooper/testit.sh +62 -0
  126. data/modules/emscripten/src/relooper/updateit.sh +17 -0
  127. data/modules/emscripten/src/relooper.js +11516 -0
  128. data/modules/emscripten/src/relooper.js.raw.js +11511 -0
  129. data/modules/emscripten/src/runtime.js +546 -0
  130. data/modules/emscripten/src/settings.js +1284 -0
  131. data/modules/emscripten/src/shell.html +92 -0
  132. data/modules/emscripten/src/shell.js +153 -0
  133. data/modules/emscripten/src/shell_sharedlib.js +12 -0
  134. data/modules/emscripten/src/socket.io.js +3870 -0
  135. data/modules/emscripten/src/utility.js +379 -0
  136. data/modules/emscripten/src/wrtcp.js +821 -0
  137. data/modules/emscripten/system/include/AL/al.h +172 -0
  138. data/modules/emscripten/system/include/AL/alc.h +84 -0
  139. data/modules/emscripten/system/include/EGL/egl.h +329 -0
  140. data/modules/emscripten/system/include/EGL/eglext.h +398 -0
  141. data/modules/emscripten/system/include/EGL/eglplatform.h +141 -0
  142. data/modules/emscripten/system/include/GL/freeglut_std.h +628 -0
  143. data/modules/emscripten/system/include/GL/gl.h +2241 -0
  144. data/modules/emscripten/system/include/GL/glew.h +6 -0
  145. data/modules/emscripten/system/include/GL/glext.h +11127 -0
  146. data/modules/emscripten/system/include/GL/glfw.h +518 -0
  147. data/modules/emscripten/system/include/GL/glu.h +353 -0
  148. data/modules/emscripten/system/include/GL/glut.h +21 -0
  149. data/modules/emscripten/system/include/GLES/gl.h +770 -0
  150. data/modules/emscripten/system/include/GLES/glext.h +1278 -0
  151. data/modules/emscripten/system/include/GLES/glplatform.h +30 -0
  152. data/modules/emscripten/system/include/GLES2/gl2.h +621 -0
  153. data/modules/emscripten/system/include/GLES2/gl2ext.h +803 -0
  154. data/modules/emscripten/system/include/GLES2/gl2platform.h +30 -0
  155. data/modules/emscripten/system/include/KHR/khrplatform.h +277 -0
  156. data/modules/emscripten/system/include/SDL/COPYING +19 -0
  157. data/modules/emscripten/system/include/SDL/SDL.h +162 -0
  158. data/modules/emscripten/system/include/SDL/SDL_assert.h +241 -0
  159. data/modules/emscripten/system/include/SDL/SDL_atomic.h +318 -0
  160. data/modules/emscripten/system/include/SDL/SDL_audio.h +509 -0
  161. data/modules/emscripten/system/include/SDL/SDL_blendmode.h +60 -0
  162. data/modules/emscripten/system/include/SDL/SDL_clipboard.h +75 -0
  163. data/modules/emscripten/system/include/SDL/SDL_compat.h +365 -0
  164. data/modules/emscripten/system/include/SDL/SDL_config.h +48 -0
  165. data/modules/emscripten/system/include/SDL/SDL_config.h.in +297 -0
  166. data/modules/emscripten/system/include/SDL/SDL_config_android.h +133 -0
  167. data/modules/emscripten/system/include/SDL/SDL_config_iphoneos.h +148 -0
  168. data/modules/emscripten/system/include/SDL/SDL_config_macosx.h +172 -0
  169. data/modules/emscripten/system/include/SDL/SDL_config_minimal.h +74 -0
  170. data/modules/emscripten/system/include/SDL/SDL_config_nintendods.h +129 -0
  171. data/modules/emscripten/system/include/SDL/SDL_config_pandora.h +125 -0
  172. data/modules/emscripten/system/include/SDL/SDL_config_windows.h +207 -0
  173. data/modules/emscripten/system/include/SDL/SDL_config_wiz.h +119 -0
  174. data/modules/emscripten/system/include/SDL/SDL_copying.h +20 -0
  175. data/modules/emscripten/system/include/SDL/SDL_cpuinfo.h +150 -0
  176. data/modules/emscripten/system/include/SDL/SDL_endian.h +248 -0
  177. data/modules/emscripten/system/include/SDL/SDL_error.h +77 -0
  178. data/modules/emscripten/system/include/SDL/SDL_events.h +639 -0
  179. data/modules/emscripten/system/include/SDL/SDL_gesture.h +91 -0
  180. data/modules/emscripten/system/include/SDL/SDL_gfxPrimitives.h +246 -0
  181. data/modules/emscripten/system/include/SDL/SDL_haptic.h +1200 -0
  182. data/modules/emscripten/system/include/SDL/SDL_hints.h +206 -0
  183. data/modules/emscripten/system/include/SDL/SDL_image.h +138 -0
  184. data/modules/emscripten/system/include/SDL/SDL_input.h +87 -0
  185. data/modules/emscripten/system/include/SDL/SDL_joystick.h +208 -0
  186. data/modules/emscripten/system/include/SDL/SDL_keyboard.h +169 -0
  187. data/modules/emscripten/system/include/SDL/SDL_keycode.h +344 -0
  188. data/modules/emscripten/system/include/SDL/SDL_loadso.h +85 -0
  189. data/modules/emscripten/system/include/SDL/SDL_log.h +211 -0
  190. data/modules/emscripten/system/include/SDL/SDL_main.h +98 -0
  191. data/modules/emscripten/system/include/SDL/SDL_mixer.h +634 -0
  192. data/modules/emscripten/system/include/SDL/SDL_mouse.h +213 -0
  193. data/modules/emscripten/system/include/SDL/SDL_mutex.h +248 -0
  194. data/modules/emscripten/system/include/SDL/SDL_name.h +11 -0
  195. data/modules/emscripten/system/include/SDL/SDL_opengl.h +11116 -0
  196. data/modules/emscripten/system/include/SDL/SDL_opengles.h +38 -0
  197. data/modules/emscripten/system/include/SDL/SDL_opengles2.h +38 -0
  198. data/modules/emscripten/system/include/SDL/SDL_pixels.h +423 -0
  199. data/modules/emscripten/system/include/SDL/SDL_platform.h +160 -0
  200. data/modules/emscripten/system/include/SDL/SDL_power.h +79 -0
  201. data/modules/emscripten/system/include/SDL/SDL_quit.h +58 -0
  202. data/modules/emscripten/system/include/SDL/SDL_rect.h +136 -0
  203. data/modules/emscripten/system/include/SDL/SDL_render.h +615 -0
  204. data/modules/emscripten/system/include/SDL/SDL_revision.h +2 -0
  205. data/modules/emscripten/system/include/SDL/SDL_revision.h.orig +2 -0
  206. data/modules/emscripten/system/include/SDL/SDL_rotozoom.h +123 -0
  207. data/modules/emscripten/system/include/SDL/SDL_rwops.h +220 -0
  208. data/modules/emscripten/system/include/SDL/SDL_scancode.h +398 -0
  209. data/modules/emscripten/system/include/SDL/SDL_shape.h +147 -0
  210. data/modules/emscripten/system/include/SDL/SDL_stdinc.h +764 -0
  211. data/modules/emscripten/system/include/SDL/SDL_surface.h +499 -0
  212. data/modules/emscripten/system/include/SDL/SDL_syswm.h +241 -0
  213. data/modules/emscripten/system/include/SDL/SDL_thread.h +182 -0
  214. data/modules/emscripten/system/include/SDL/SDL_timer.h +108 -0
  215. data/modules/emscripten/system/include/SDL/SDL_touch.h +124 -0
  216. data/modules/emscripten/system/include/SDL/SDL_ttf.h +249 -0
  217. data/modules/emscripten/system/include/SDL/SDL_types.h +29 -0
  218. data/modules/emscripten/system/include/SDL/SDL_version.h +166 -0
  219. data/modules/emscripten/system/include/SDL/SDL_video.h +820 -0
  220. data/modules/emscripten/system/include/SDL/begin_code.h +135 -0
  221. data/modules/emscripten/system/include/SDL/close_code.h +37 -0
  222. data/modules/emscripten/system/include/X11/X.h +717 -0
  223. data/modules/emscripten/system/include/X11/Xatom.h +79 -0
  224. data/modules/emscripten/system/include/X11/Xfuncproto.h +127 -0
  225. data/modules/emscripten/system/include/X11/Xlib.h +4023 -0
  226. data/modules/emscripten/system/include/X11/Xosdefs.h +116 -0
  227. data/modules/emscripten/system/include/X11/Xutil.h +826 -0
  228. data/modules/emscripten/system/include/X11/keysym.h +73 -0
  229. data/modules/emscripten/system/include/X11/keysymdef.h +2389 -0
  230. data/modules/emscripten/system/include/bsd/float.h +91 -0
  231. data/modules/emscripten/system/include/bsd/readme.txt +2 -0
  232. data/modules/emscripten/system/include/bsd/sys/mman.h +180 -0
  233. data/modules/emscripten/system/include/bsd/sys/utsname.h +70 -0
  234. data/modules/emscripten/system/include/dlfcn.h +31 -0
  235. data/modules/emscripten/system/include/emscripten/bind.h +1210 -0
  236. data/modules/emscripten/system/include/emscripten/emscripten.h +388 -0
  237. data/modules/emscripten/system/include/emscripten/val.h +311 -0
  238. data/modules/emscripten/system/include/emscripten/wire.h +393 -0
  239. data/modules/emscripten/system/include/err.h +95 -0
  240. data/modules/emscripten/system/include/execinfo.h +44 -0
  241. data/modules/emscripten/system/include/features.h +3 -0
  242. data/modules/emscripten/system/include/gc.h +70 -0
  243. data/modules/emscripten/system/include/gfx/png.h +3798 -0
  244. data/modules/emscripten/system/include/gfx/pngconf.h +1665 -0
  245. data/modules/emscripten/system/include/gfx/tiff.h +654 -0
  246. data/modules/emscripten/system/include/gfx/tiffconf.h +104 -0
  247. data/modules/emscripten/system/include/gfx/tiffio.h +526 -0
  248. data/modules/emscripten/system/include/gfx/tiffvers.h +9 -0
  249. data/modules/emscripten/system/include/jansson.h +323 -0
  250. data/modules/emscripten/system/include/jansson_config.h +54 -0
  251. data/modules/emscripten/system/include/libc/_ansi.h +135 -0
  252. data/modules/emscripten/system/include/libc/_syslist.h +40 -0
  253. data/modules/emscripten/system/include/libc/alloca.h +21 -0
  254. data/modules/emscripten/system/include/libc/ar.h +69 -0
  255. data/modules/emscripten/system/include/libc/argz.h +33 -0
  256. data/modules/emscripten/system/include/libc/assert.h +46 -0
  257. data/modules/emscripten/system/include/libc/complex.h +124 -0
  258. data/modules/emscripten/system/include/libc/ctype.h +196 -0
  259. data/modules/emscripten/system/include/libc/dirent.h +16 -0
  260. data/modules/emscripten/system/include/libc/endian.h +3 -0
  261. data/modules/emscripten/system/include/libc/envlock.h +15 -0
  262. data/modules/emscripten/system/include/libc/envz.h +16 -0
  263. data/modules/emscripten/system/include/libc/errno.h +11 -0
  264. data/modules/emscripten/system/include/libc/fastmath.h +13 -0
  265. data/modules/emscripten/system/include/libc/fcntl.h +1 -0
  266. data/modules/emscripten/system/include/libc/fnmatch.h +55 -0
  267. data/modules/emscripten/system/include/libc/getopt.h +196 -0
  268. data/modules/emscripten/system/include/libc/glob.h +89 -0
  269. data/modules/emscripten/system/include/libc/grp.h +94 -0
  270. data/modules/emscripten/system/include/libc/iconv.h +62 -0
  271. data/modules/emscripten/system/include/libc/ieeefp.h +256 -0
  272. data/modules/emscripten/system/include/libc/ifaddrs.h +64 -0
  273. data/modules/emscripten/system/include/libc/inttypes.h +290 -0
  274. data/modules/emscripten/system/include/libc/iso646.h +43 -0
  275. data/modules/emscripten/system/include/libc/langinfo.h +316 -0
  276. data/modules/emscripten/system/include/libc/libgen.h +23 -0
  277. data/modules/emscripten/system/include/libc/limits.h +155 -0
  278. data/modules/emscripten/system/include/libc/locale.h +80 -0
  279. data/modules/emscripten/system/include/libc/machine/_default_types.h +121 -0
  280. data/modules/emscripten/system/include/libc/machine/_types.h +8 -0
  281. data/modules/emscripten/system/include/libc/machine/ansi.h +1 -0
  282. data/modules/emscripten/system/include/libc/machine/endian.h +31 -0
  283. data/modules/emscripten/system/include/libc/machine/fastmath.h +100 -0
  284. data/modules/emscripten/system/include/libc/machine/ieeefp.h +376 -0
  285. data/modules/emscripten/system/include/libc/machine/malloc.h +8 -0
  286. data/modules/emscripten/system/include/libc/machine/param.h +1 -0
  287. data/modules/emscripten/system/include/libc/machine/setjmp-dj.h +43 -0
  288. data/modules/emscripten/system/include/libc/machine/setjmp.h +361 -0
  289. data/modules/emscripten/system/include/libc/machine/stdlib.h +8 -0
  290. data/modules/emscripten/system/include/libc/machine/termios.h +1 -0
  291. data/modules/emscripten/system/include/libc/machine/time.h +19 -0
  292. data/modules/emscripten/system/include/libc/machine/types.h +30 -0
  293. data/modules/emscripten/system/include/libc/malloc.h +169 -0
  294. data/modules/emscripten/system/include/libc/math.h +594 -0
  295. data/modules/emscripten/system/include/libc/newlib.h +2 -0
  296. data/modules/emscripten/system/include/libc/paths.h +7 -0
  297. data/modules/emscripten/system/include/libc/process.h +44 -0
  298. data/modules/emscripten/system/include/libc/pthread.h +362 -0
  299. data/modules/emscripten/system/include/libc/pwd.h +78 -0
  300. data/modules/emscripten/system/include/libc/readme.txt +3 -0
  301. data/modules/emscripten/system/include/libc/reent.h +183 -0
  302. data/modules/emscripten/system/include/libc/regdef.h +7 -0
  303. data/modules/emscripten/system/include/libc/regex.h +102 -0
  304. data/modules/emscripten/system/include/libc/sched.h +97 -0
  305. data/modules/emscripten/system/include/libc/search.h +59 -0
  306. data/modules/emscripten/system/include/libc/setjmp.h +20 -0
  307. data/modules/emscripten/system/include/libc/signal.h +30 -0
  308. data/modules/emscripten/system/include/libc/stdarg.h +50 -0
  309. data/modules/emscripten/system/include/libc/stddef.h +64 -0
  310. data/modules/emscripten/system/include/libc/stdint.h +493 -0
  311. data/modules/emscripten/system/include/libc/stdio.h +694 -0
  312. data/modules/emscripten/system/include/libc/stdlib.h +230 -0
  313. data/modules/emscripten/system/include/libc/string.h +105 -0
  314. data/modules/emscripten/system/include/libc/strings.h +35 -0
  315. data/modules/emscripten/system/include/libc/sys/_default_fcntl.h +223 -0
  316. data/modules/emscripten/system/include/libc/sys/_types.h +93 -0
  317. data/modules/emscripten/system/include/libc/sys/cdefs.h +123 -0
  318. data/modules/emscripten/system/include/libc/sys/config.h +255 -0
  319. data/modules/emscripten/system/include/libc/sys/custom_file.h +2 -0
  320. data/modules/emscripten/system/include/libc/sys/dir.h +10 -0
  321. data/modules/emscripten/system/include/libc/sys/dirent.h +58 -0
  322. data/modules/emscripten/system/include/libc/sys/errno.h +190 -0
  323. data/modules/emscripten/system/include/libc/sys/fcntl.h +4 -0
  324. data/modules/emscripten/system/include/libc/sys/features.h +212 -0
  325. data/modules/emscripten/system/include/libc/sys/file.h +2 -0
  326. data/modules/emscripten/system/include/libc/sys/iconvnls.h +77 -0
  327. data/modules/emscripten/system/include/libc/sys/lock.h +24 -0
  328. data/modules/emscripten/system/include/libc/sys/param.h +25 -0
  329. data/modules/emscripten/system/include/libc/sys/queue.h +471 -0
  330. data/modules/emscripten/system/include/libc/sys/reent.h +843 -0
  331. data/modules/emscripten/system/include/libc/sys/resource.h +59 -0
  332. data/modules/emscripten/system/include/libc/sys/sched.h +67 -0
  333. data/modules/emscripten/system/include/libc/sys/signal.h +314 -0
  334. data/modules/emscripten/system/include/libc/sys/stat.h +222 -0
  335. data/modules/emscripten/system/include/libc/sys/stdio.h +27 -0
  336. data/modules/emscripten/system/include/libc/sys/string.h +2 -0
  337. data/modules/emscripten/system/include/libc/sys/syslimits.h +65 -0
  338. data/modules/emscripten/system/include/libc/sys/termios.h +280 -0
  339. data/modules/emscripten/system/include/libc/sys/time.h +85 -0
  340. data/modules/emscripten/system/include/libc/sys/timeb.h +39 -0
  341. data/modules/emscripten/system/include/libc/sys/times.h +28 -0
  342. data/modules/emscripten/system/include/libc/sys/ttydefaults.h +97 -0
  343. data/modules/emscripten/system/include/libc/sys/types.h +481 -0
  344. data/modules/emscripten/system/include/libc/sys/unistd.h +514 -0
  345. data/modules/emscripten/system/include/libc/sys/utime.h +26 -0
  346. data/modules/emscripten/system/include/libc/sys/wait.h +40 -0
  347. data/modules/emscripten/system/include/libc/tar.h +39 -0
  348. data/modules/emscripten/system/include/libc/termios.h +7 -0
  349. data/modules/emscripten/system/include/libc/time.h +273 -0
  350. data/modules/emscripten/system/include/libc/unctrl.h +46 -0
  351. data/modules/emscripten/system/include/libc/unistd.h +6 -0
  352. data/modules/emscripten/system/include/libc/utime.h +12 -0
  353. data/modules/emscripten/system/include/libc/utmp.h +8 -0
  354. data/modules/emscripten/system/include/libc/wchar.h +194 -0
  355. data/modules/emscripten/system/include/libc/wctype.h +47 -0
  356. data/modules/emscripten/system/include/libc/wordexp.h +53 -0
  357. data/modules/emscripten/system/include/libcxx/CREDITS.TXT +91 -0
  358. data/modules/emscripten/system/include/libcxx/LICENSE.txt +76 -0
  359. data/modules/emscripten/system/include/libcxx/__bit_reference +1268 -0
  360. data/modules/emscripten/system/include/libcxx/__config +485 -0
  361. data/modules/emscripten/system/include/libcxx/__debug +193 -0
  362. data/modules/emscripten/system/include/libcxx/__functional_03 +2130 -0
  363. data/modules/emscripten/system/include/libcxx/__functional_base +437 -0
  364. data/modules/emscripten/system/include/libcxx/__functional_base_03 +1087 -0
  365. data/modules/emscripten/system/include/libcxx/__hash_table +1945 -0
  366. data/modules/emscripten/system/include/libcxx/__locale +1435 -0
  367. data/modules/emscripten/system/include/libcxx/__mutex_base +438 -0
  368. data/modules/emscripten/system/include/libcxx/__split_buffer +654 -0
  369. data/modules/emscripten/system/include/libcxx/__sso_allocator +77 -0
  370. data/modules/emscripten/system/include/libcxx/__std_stream +317 -0
  371. data/modules/emscripten/system/include/libcxx/__tree +2293 -0
  372. data/modules/emscripten/system/include/libcxx/__tuple +305 -0
  373. data/modules/emscripten/system/include/libcxx/__tuple_03 +27 -0
  374. data/modules/emscripten/system/include/libcxx/__undef_min_max +19 -0
  375. data/modules/emscripten/system/include/libcxx/algorithm +5458 -0
  376. data/modules/emscripten/system/include/libcxx/array +341 -0
  377. data/modules/emscripten/system/include/libcxx/atomic +1521 -0
  378. data/modules/emscripten/system/include/libcxx/bitset +1081 -0
  379. data/modules/emscripten/system/include/libcxx/cassert +25 -0
  380. data/modules/emscripten/system/include/libcxx/ccomplex +29 -0
  381. data/modules/emscripten/system/include/libcxx/cctype +164 -0
  382. data/modules/emscripten/system/include/libcxx/cerrno +393 -0
  383. data/modules/emscripten/system/include/libcxx/cfenv +82 -0
  384. data/modules/emscripten/system/include/libcxx/cfloat +78 -0
  385. data/modules/emscripten/system/include/libcxx/chrono +898 -0
  386. data/modules/emscripten/system/include/libcxx/cinttypes +259 -0
  387. data/modules/emscripten/system/include/libcxx/ciso646 +25 -0
  388. data/modules/emscripten/system/include/libcxx/climits +48 -0
  389. data/modules/emscripten/system/include/libcxx/clocale +53 -0
  390. data/modules/emscripten/system/include/libcxx/cmath +1683 -0
  391. data/modules/emscripten/system/include/libcxx/codecvt +547 -0
  392. data/modules/emscripten/system/include/libcxx/complex +1526 -0
  393. data/modules/emscripten/system/include/libcxx/complex.h +35 -0
  394. data/modules/emscripten/system/include/libcxx/condition_variable +256 -0
  395. data/modules/emscripten/system/include/libcxx/csetjmp +52 -0
  396. data/modules/emscripten/system/include/libcxx/csignal +58 -0
  397. data/modules/emscripten/system/include/libcxx/cstdarg +48 -0
  398. data/modules/emscripten/system/include/libcxx/cstdbool +32 -0
  399. data/modules/emscripten/system/include/libcxx/cstddef +103 -0
  400. data/modules/emscripten/system/include/libcxx/cstdint +191 -0
  401. data/modules/emscripten/system/include/libcxx/cstdio +175 -0
  402. data/modules/emscripten/system/include/libcxx/cstdlib +172 -0
  403. data/modules/emscripten/system/include/libcxx/cstring +112 -0
  404. data/modules/emscripten/system/include/libcxx/ctgmath +29 -0
  405. data/modules/emscripten/system/include/libcxx/ctime +72 -0
  406. data/modules/emscripten/system/include/libcxx/cwchar +208 -0
  407. data/modules/emscripten/system/include/libcxx/cwctype +213 -0
  408. data/modules/emscripten/system/include/libcxx/deque +2846 -0
  409. data/modules/emscripten/system/include/libcxx/exception +250 -0
  410. data/modules/emscripten/system/include/libcxx/ext/__hash +46 -0
  411. data/modules/emscripten/system/include/libcxx/ext/hash_map +1003 -0
  412. data/modules/emscripten/system/include/libcxx/ext/hash_set +657 -0
  413. data/modules/emscripten/system/include/libcxx/forward_list +1636 -0
  414. data/modules/emscripten/system/include/libcxx/fstream +1415 -0
  415. data/modules/emscripten/system/include/libcxx/functional +2063 -0
  416. data/modules/emscripten/system/include/libcxx/future +2505 -0
  417. data/modules/emscripten/system/include/libcxx/initializer_list +105 -0
  418. data/modules/emscripten/system/include/libcxx/iomanip +504 -0
  419. data/modules/emscripten/system/include/libcxx/ios +988 -0
  420. data/modules/emscripten/system/include/libcxx/iosfwd +194 -0
  421. data/modules/emscripten/system/include/libcxx/iostream +60 -0
  422. data/modules/emscripten/system/include/libcxx/istream +1713 -0
  423. data/modules/emscripten/system/include/libcxx/iterator +1869 -0
  424. data/modules/emscripten/system/include/libcxx/limits +809 -0
  425. data/modules/emscripten/system/include/libcxx/list +2275 -0
  426. data/modules/emscripten/system/include/libcxx/locale +4591 -0
  427. data/modules/emscripten/system/include/libcxx/map +1924 -0
  428. data/modules/emscripten/system/include/libcxx/memory +5437 -0
  429. data/modules/emscripten/system/include/libcxx/mutex +566 -0
  430. data/modules/emscripten/system/include/libcxx/new +117 -0
  431. data/modules/emscripten/system/include/libcxx/numeric +197 -0
  432. data/modules/emscripten/system/include/libcxx/ostream +1286 -0
  433. data/modules/emscripten/system/include/libcxx/queue +717 -0
  434. data/modules/emscripten/system/include/libcxx/random +6750 -0
  435. data/modules/emscripten/system/include/libcxx/ratio +487 -0
  436. data/modules/emscripten/system/include/libcxx/readme.txt +1 -0
  437. data/modules/emscripten/system/include/libcxx/regex +6439 -0
  438. data/modules/emscripten/system/include/libcxx/scoped_allocator +578 -0
  439. data/modules/emscripten/system/include/libcxx/set +1025 -0
  440. data/modules/emscripten/system/include/libcxx/sstream +888 -0
  441. data/modules/emscripten/system/include/libcxx/stack +292 -0
  442. data/modules/emscripten/system/include/libcxx/stdexcept +162 -0
  443. data/modules/emscripten/system/include/libcxx/streambuf +564 -0
  444. data/modules/emscripten/system/include/libcxx/string +3987 -0
  445. data/modules/emscripten/system/include/libcxx/strstream +400 -0
  446. data/modules/emscripten/system/include/libcxx/support/solaris/floatingpoint.h +5 -0
  447. data/modules/emscripten/system/include/libcxx/support/solaris/wchar.h +38 -0
  448. data/modules/emscripten/system/include/libcxx/support/solaris/xlocale.h +146 -0
  449. data/modules/emscripten/system/include/libcxx/support/win32/limits_win32.h +79 -0
  450. data/modules/emscripten/system/include/libcxx/support/win32/locale_win32.h +116 -0
  451. data/modules/emscripten/system/include/libcxx/support/win32/math_win32.h +113 -0
  452. data/modules/emscripten/system/include/libcxx/support/win32/support.h +115 -0
  453. data/modules/emscripten/system/include/libcxx/system_error +636 -0
  454. data/modules/emscripten/system/include/libcxx/tgmath.h +29 -0
  455. data/modules/emscripten/system/include/libcxx/thread +459 -0
  456. data/modules/emscripten/system/include/libcxx/tuple +1092 -0
  457. data/modules/emscripten/system/include/libcxx/type_traits +3040 -0
  458. data/modules/emscripten/system/include/libcxx/typeindex +103 -0
  459. data/modules/emscripten/system/include/libcxx/typeinfo +124 -0
  460. data/modules/emscripten/system/include/libcxx/unordered_map +1864 -0
  461. data/modules/emscripten/system/include/libcxx/unordered_set +1144 -0
  462. data/modules/emscripten/system/include/libcxx/utility +583 -0
  463. data/modules/emscripten/system/include/libcxx/valarray +4779 -0
  464. data/modules/emscripten/system/include/libcxx/vector +3228 -0
  465. data/modules/emscripten/system/include/memory.h +10 -0
  466. data/modules/emscripten/system/include/mntent.h +23 -0
  467. data/modules/emscripten/system/include/net/arpa/inet.h +32 -0
  468. data/modules/emscripten/system/include/net/arpa/nameser.h +535 -0
  469. data/modules/emscripten/system/include/net/arpa/nameser_compat.h +187 -0
  470. data/modules/emscripten/system/include/net/if.h +87 -0
  471. data/modules/emscripten/system/include/net/netinet/in.h +166 -0
  472. data/modules/emscripten/system/include/net/netinet/tcp.h +246 -0
  473. data/modules/emscripten/system/include/net/resolv.h +389 -0
  474. data/modules/emscripten/system/include/netdb.h +94 -0
  475. data/modules/emscripten/system/include/nl_types.h +19 -0
  476. data/modules/emscripten/system/include/poll.h +3 -0
  477. data/modules/emscripten/system/include/pty.h +6 -0
  478. data/modules/emscripten/system/include/semaphore.h +31 -0
  479. data/modules/emscripten/system/include/spawn.h +105 -0
  480. data/modules/emscripten/system/include/stdbool.h +16 -0
  481. data/modules/emscripten/system/include/sys/bitypes.h +3 -0
  482. data/modules/emscripten/system/include/sys/io.h +14 -0
  483. data/modules/emscripten/system/include/sys/ioctl.h +26 -0
  484. data/modules/emscripten/system/include/sys/poll.h +31 -0
  485. data/modules/emscripten/system/include/sys/select.h +14 -0
  486. data/modules/emscripten/system/include/sys/socket.h +101 -0
  487. data/modules/emscripten/system/include/sys/socketvar.h +3 -0
  488. data/modules/emscripten/system/include/sys/statvfs.h +32 -0
  489. data/modules/emscripten/system/include/sys/sysctl.h +14 -0
  490. data/modules/emscripten/system/include/sys/uio.h +22 -0
  491. data/modules/emscripten/system/include/sys/un.h +66 -0
  492. data/modules/emscripten/system/include/sysexits.h +108 -0
  493. data/modules/emscripten/system/include/unwind.h +154 -0
  494. data/modules/emscripten/system/include/xlocale.h +47 -0
  495. data/modules/emscripten/system/include/zconf.h +428 -0
  496. data/modules/emscripten/system/include/zlib.h +1613 -0
  497. data/modules/emscripten/system/lib/compiler-rt/LICENSE.TXT +97 -0
  498. data/modules/emscripten/system/lib/compiler-rt/divdi3.c +47 -0
  499. data/modules/emscripten/system/lib/compiler-rt/int_endianness.h +116 -0
  500. data/modules/emscripten/system/lib/compiler-rt/int_lib.h +46 -0
  501. data/modules/emscripten/system/lib/compiler-rt/int_math.h +67 -0
  502. data/modules/emscripten/system/lib/compiler-rt/int_types.h +140 -0
  503. data/modules/emscripten/system/lib/compiler-rt/int_util.h +29 -0
  504. data/modules/emscripten/system/lib/compiler-rt/muldi3.c +56 -0
  505. data/modules/emscripten/system/lib/compiler-rt/readme.txt +20 -0
  506. data/modules/emscripten/system/lib/compiler-rt/udivdi3.c +36 -0
  507. data/modules/emscripten/system/lib/compiler-rt/udivmoddi4.c +251 -0
  508. data/modules/emscripten/system/lib/debugging.cpp +24 -0
  509. data/modules/emscripten/system/lib/dlmalloc.c +6299 -0
  510. data/modules/emscripten/system/lib/embind/bind.cpp +63 -0
  511. data/modules/emscripten/system/lib/libc/gen/err.c +49 -0
  512. data/modules/emscripten/system/lib/libc/gen/errx.c +49 -0
  513. data/modules/emscripten/system/lib/libc/gen/verr.c +58 -0
  514. data/modules/emscripten/system/lib/libc/gen/verrx.c +51 -0
  515. data/modules/emscripten/system/lib/libc/gen/vwarn.c +55 -0
  516. data/modules/emscripten/system/lib/libc/gen/vwarnx.c +48 -0
  517. data/modules/emscripten/system/lib/libc/gen/warn.c +49 -0
  518. data/modules/emscripten/system/lib/libc/gen/warnx.c +49 -0
  519. data/modules/emscripten/system/lib/libc/musl/COPYRIGHT +92 -0
  520. data/modules/emscripten/system/lib/libc/musl/readme.txt +1 -0
  521. data/modules/emscripten/system/lib/libc/musl/src/ctype/alpha.h +125 -0
  522. data/modules/emscripten/system/lib/libc/musl/src/ctype/iswalnum.c +7 -0
  523. data/modules/emscripten/system/lib/libc/musl/src/ctype/iswalpha.c +14 -0
  524. data/modules/emscripten/system/lib/libc/musl/src/ctype/iswblank.c +8 -0
  525. data/modules/emscripten/system/lib/libc/musl/src/ctype/iswcntrl.c +10 -0
  526. data/modules/emscripten/system/lib/libc/musl/src/ctype/iswctype.c +63 -0
  527. data/modules/emscripten/system/lib/libc/musl/src/ctype/iswdigit.c +9 -0
  528. data/modules/emscripten/system/lib/libc/musl/src/ctype/iswgraph.c +7 -0
  529. data/modules/emscripten/system/lib/libc/musl/src/ctype/iswlower.c +6 -0
  530. data/modules/emscripten/system/lib/libc/musl/src/ctype/iswprint.c +19 -0
  531. data/modules/emscripten/system/lib/libc/musl/src/ctype/iswpunct.c +12 -0
  532. data/modules/emscripten/system/lib/libc/musl/src/ctype/iswspace.c +19 -0
  533. data/modules/emscripten/system/lib/libc/musl/src/ctype/iswupper.c +6 -0
  534. data/modules/emscripten/system/lib/libc/musl/src/ctype/iswxdigit.c +7 -0
  535. data/modules/emscripten/system/lib/libc/musl/src/ctype/nonspacing.h +62 -0
  536. data/modules/emscripten/system/lib/libc/musl/src/ctype/punct.h +109 -0
  537. data/modules/emscripten/system/lib/libc/musl/src/ctype/towctrans.c +268 -0
  538. data/modules/emscripten/system/lib/libc/musl/src/ctype/wcswidth.c +8 -0
  539. data/modules/emscripten/system/lib/libc/musl/src/ctype/wctrans.c +16 -0
  540. data/modules/emscripten/system/lib/libc/musl/src/ctype/wcwidth.c +29 -0
  541. data/modules/emscripten/system/lib/libc/musl/src/ctype/wide.h +42 -0
  542. data/modules/emscripten/system/lib/libc/musl/src/internal/libc.c +22 -0
  543. data/modules/emscripten/system/lib/libc/musl/src/internal/libc.h +71 -0
  544. data/modules/emscripten/system/lib/libc/musl/src/multibyte/btowc.c +7 -0
  545. data/modules/emscripten/system/lib/libc/musl/src/multibyte/internal.c +38 -0
  546. data/modules/emscripten/system/lib/libc/musl/src/multibyte/internal.h +22 -0
  547. data/modules/emscripten/system/lib/libc/musl/src/multibyte/mblen.c +17 -0
  548. data/modules/emscripten/system/lib/libc/musl/src/multibyte/mbrlen.c +18 -0
  549. data/modules/emscripten/system/lib/libc/musl/src/multibyte/mbrtowc.c +57 -0
  550. data/modules/emscripten/system/lib/libc/musl/src/multibyte/mbsinit.c +17 -0
  551. data/modules/emscripten/system/lib/libc/musl/src/multibyte/mbsnrtowcs.c +65 -0
  552. data/modules/emscripten/system/lib/libc/musl/src/multibyte/mbsrtowcs.c +100 -0
  553. data/modules/emscripten/system/lib/libc/musl/src/multibyte/mbstowcs.c +7 -0
  554. data/modules/emscripten/system/lib/libc/musl/src/multibyte/mbtowc.c +53 -0
  555. data/modules/emscripten/system/lib/libc/musl/src/multibyte/wcrtomb.c +38 -0
  556. data/modules/emscripten/system/lib/libc/musl/src/multibyte/wcsnrtombs.c +52 -0
  557. data/modules/emscripten/system/lib/libc/musl/src/multibyte/wcsrtombs.c +58 -0
  558. data/modules/emscripten/system/lib/libc/musl/src/multibyte/wcstombs.c +7 -0
  559. data/modules/emscripten/system/lib/libc/musl/src/multibyte/wctob.c +8 -0
  560. data/modules/emscripten/system/lib/libc/musl/src/multibyte/wctomb.c +18 -0
  561. data/modules/emscripten/system/lib/libc/musl/src/string/wcpcpy.c +6 -0
  562. data/modules/emscripten/system/lib/libc/musl/src/string/wcpncpy.c +6 -0
  563. data/modules/emscripten/system/lib/libc/musl/src/string/wcscasecmp.c +7 -0
  564. data/modules/emscripten/system/lib/libc/musl/src/string/wcscasecmp_l.c +6 -0
  565. data/modules/emscripten/system/lib/libc/musl/src/string/wcscat.c +7 -0
  566. data/modules/emscripten/system/lib/libc/musl/src/string/wcschr.c +8 -0
  567. data/modules/emscripten/system/lib/libc/musl/src/string/wcscmp.c +7 -0
  568. data/modules/emscripten/system/lib/libc/musl/src/string/wcscpy.c +8 -0
  569. data/modules/emscripten/system/lib/libc/musl/src/string/wcscspn.c +10 -0
  570. data/modules/emscripten/system/lib/libc/musl/src/string/wcsdup.c +11 -0
  571. data/modules/emscripten/system/lib/libc/musl/src/string/wcslen.c +8 -0
  572. data/modules/emscripten/system/lib/libc/musl/src/string/wcsncasecmp.c +9 -0
  573. data/modules/emscripten/system/lib/libc/musl/src/string/wcsncasecmp_l.c +6 -0
  574. data/modules/emscripten/system/lib/libc/musl/src/string/wcsncat.c +10 -0
  575. data/modules/emscripten/system/lib/libc/musl/src/string/wcsncmp.c +7 -0
  576. data/modules/emscripten/system/lib/libc/musl/src/string/wcsncpy.c +9 -0
  577. data/modules/emscripten/system/lib/libc/musl/src/string/wcsnlen.c +8 -0
  578. data/modules/emscripten/system/lib/libc/musl/src/string/wcspbrk.c +7 -0
  579. data/modules/emscripten/system/lib/libc/musl/src/string/wcsrchr.c +8 -0
  580. data/modules/emscripten/system/lib/libc/musl/src/string/wcsspn.c +8 -0
  581. data/modules/emscripten/system/lib/libc/musl/src/string/wcsstr.c +108 -0
  582. data/modules/emscripten/system/lib/libc/musl/src/string/wcstok.c +12 -0
  583. data/modules/emscripten/system/lib/libc/musl/src/string/wcswcs.c +6 -0
  584. data/modules/emscripten/system/lib/libc/musl/src/string/wmemchr.c +8 -0
  585. data/modules/emscripten/system/lib/libc/musl/src/string/wmemcmp.c +8 -0
  586. data/modules/emscripten/system/lib/libc/musl/src/string/wmemcpy.c +9 -0
  587. data/modules/emscripten/system/lib/libc/musl/src/string/wmemmove.c +12 -0
  588. data/modules/emscripten/system/lib/libc/musl/src/string/wmemset.c +9 -0
  589. data/modules/emscripten/system/lib/libc/stdlib/getopt_long.c +511 -0
  590. data/modules/emscripten/system/lib/libc/stdlib/strtod.c +305 -0
  591. data/modules/emscripten/system/lib/libc.symbols +81 -0
  592. data/modules/emscripten/system/lib/libcextra.symbols +61 -0
  593. data/modules/emscripten/system/lib/libcxx/CREDITS.TXT +91 -0
  594. data/modules/emscripten/system/lib/libcxx/LICENSE.txt +76 -0
  595. data/modules/emscripten/system/lib/libcxx/algorithm.cpp +83 -0
  596. data/modules/emscripten/system/lib/libcxx/bind.cpp +30 -0
  597. data/modules/emscripten/system/lib/libcxx/chrono.cpp +132 -0
  598. data/modules/emscripten/system/lib/libcxx/condition_variable.cpp +81 -0
  599. data/modules/emscripten/system/lib/libcxx/debug.cpp +504 -0
  600. data/modules/emscripten/system/lib/libcxx/exception.cpp +226 -0
  601. data/modules/emscripten/system/lib/libcxx/future.cpp +285 -0
  602. data/modules/emscripten/system/lib/libcxx/hash.cpp +564 -0
  603. data/modules/emscripten/system/lib/libcxx/ios.cpp +455 -0
  604. data/modules/emscripten/system/lib/libcxx/iostream.cpp +68 -0
  605. data/modules/emscripten/system/lib/libcxx/locale.cpp +6093 -0
  606. data/modules/emscripten/system/lib/libcxx/memory.cpp +223 -0
  607. data/modules/emscripten/system/lib/libcxx/mutex.cpp +250 -0
  608. data/modules/emscripten/system/lib/libcxx/new.cpp +205 -0
  609. data/modules/emscripten/system/lib/libcxx/random.cpp +48 -0
  610. data/modules/emscripten/system/lib/libcxx/readme.txt +1 -0
  611. data/modules/emscripten/system/lib/libcxx/regex.cpp +325 -0
  612. data/modules/emscripten/system/lib/libcxx/stdexcept.cpp +196 -0
  613. data/modules/emscripten/system/lib/libcxx/string.cpp +687 -0
  614. data/modules/emscripten/system/lib/libcxx/strstream.cpp +329 -0
  615. data/modules/emscripten/system/lib/libcxx/support/solaris/README +4 -0
  616. data/modules/emscripten/system/lib/libcxx/support/solaris/mbsnrtowcs.inc +76 -0
  617. data/modules/emscripten/system/lib/libcxx/support/solaris/wcsnrtombs.inc +93 -0
  618. data/modules/emscripten/system/lib/libcxx/support/solaris/xlocale.c +245 -0
  619. data/modules/emscripten/system/lib/libcxx/support/win32/locale_win32.cpp +94 -0
  620. data/modules/emscripten/system/lib/libcxx/support/win32/support.cpp +70 -0
  621. data/modules/emscripten/system/lib/libcxx/symbols +2927 -0
  622. data/modules/emscripten/system/lib/libcxx/system_error.cpp +201 -0
  623. data/modules/emscripten/system/lib/libcxx/thread.cpp +208 -0
  624. data/modules/emscripten/system/lib/libcxx/typeinfo.cpp +60 -0
  625. data/modules/emscripten/system/lib/libcxx/utility.cpp +17 -0
  626. data/modules/emscripten/system/lib/libcxx/valarray.cpp +54 -0
  627. data/modules/emscripten/system/lib/libcxxabi/CREDITS.TXT +38 -0
  628. data/modules/emscripten/system/lib/libcxxabi/LICENSE.TXT +76 -0
  629. data/modules/emscripten/system/lib/libcxxabi/include/cxa_demangle.h +167 -0
  630. data/modules/emscripten/system/lib/libcxxabi/include/cxxabi.h +175 -0
  631. data/modules/emscripten/system/lib/libcxxabi/lib/buildit +99 -0
  632. data/modules/emscripten/system/lib/libcxxabi/readme.txt +1 -0
  633. data/modules/emscripten/system/lib/libcxxabi/src/abort_message.cpp +50 -0
  634. data/modules/emscripten/system/lib/libcxxabi/src/abort_message.h +33 -0
  635. data/modules/emscripten/system/lib/libcxxabi/src/cxa_aux_runtime.cpp +34 -0
  636. data/modules/emscripten/system/lib/libcxxabi/src/cxa_demangle.cpp +11036 -0
  637. data/modules/emscripten/system/lib/libcxxabi/src/cxa_exception.cpp +622 -0
  638. data/modules/emscripten/system/lib/libcxxabi/src/cxa_exception.hpp +123 -0
  639. data/modules/emscripten/system/lib/libcxxabi/src/cxa_exception_storage.cpp +91 -0
  640. data/modules/emscripten/system/lib/libcxxabi/src/cxa_guard.cpp +231 -0
  641. data/modules/emscripten/system/lib/libcxxabi/src/cxa_handlers.cpp +125 -0
  642. data/modules/emscripten/system/lib/libcxxabi/src/cxa_handlers.hpp +54 -0
  643. data/modules/emscripten/system/lib/libcxxabi/src/cxa_new_delete.cpp +242 -0
  644. data/modules/emscripten/system/lib/libcxxabi/src/cxa_personality.cpp +1055 -0
  645. data/modules/emscripten/system/lib/libcxxabi/src/cxa_unexpected.cpp +27 -0
  646. data/modules/emscripten/system/lib/libcxxabi/src/cxa_vector.cpp +367 -0
  647. data/modules/emscripten/system/lib/libcxxabi/src/cxa_virtual.cpp +31 -0
  648. data/modules/emscripten/system/lib/libcxxabi/src/exception.cpp +41 -0
  649. data/modules/emscripten/system/lib/libcxxabi/src/fallback_malloc.ipp +174 -0
  650. data/modules/emscripten/system/lib/libcxxabi/src/private_typeinfo.cpp +1146 -0
  651. data/modules/emscripten/system/lib/libcxxabi/src/private_typeinfo.h +248 -0
  652. data/modules/emscripten/system/lib/libcxxabi/src/stdexcept.cpp +169 -0
  653. data/modules/emscripten/system/lib/libcxxabi/src/typeinfo.cpp +53 -0
  654. data/modules/emscripten/system/lib/libcxxabi/symbols +236 -0
  655. data/modules/emscripten/system/lib/sdl.cpp +13 -0
  656. data/modules/emscripten/system/lib/sdl.symbols +1 -0
  657. data/modules/emscripten/tests/hello_world.js +92 -0
  658. data/modules/emscripten/third_party/CppHeaderParser/CppHeaderParser/CppHeaderParser.py +2347 -0
  659. data/modules/emscripten/third_party/CppHeaderParser/CppHeaderParser/__init__.py +4 -0
  660. data/modules/emscripten/third_party/CppHeaderParser/CppHeaderParser/doc/CppHeaderParser.html +657 -0
  661. data/modules/emscripten/third_party/CppHeaderParser/CppHeaderParser/examples/SampleClass.h +147 -0
  662. data/modules/emscripten/third_party/CppHeaderParser/CppHeaderParser/examples/readSampleClass.py +74 -0
  663. data/modules/emscripten/third_party/CppHeaderParser/PKG-INFO +249 -0
  664. data/modules/emscripten/third_party/CppHeaderParser/README.html +544 -0
  665. data/modules/emscripten/third_party/CppHeaderParser/README.txt +226 -0
  666. data/modules/emscripten/third_party/CppHeaderParser/setup.py +43 -0
  667. data/modules/emscripten/third_party/ansidecl.h +371 -0
  668. data/modules/emscripten/third_party/closure-compiler/COPYING +202 -0
  669. data/modules/emscripten/third_party/closure-compiler/README +292 -0
  670. data/modules/emscripten/third_party/closure-compiler/compiler.jar +0 -0
  671. data/modules/emscripten/third_party/closure-compiler/readme.txt +3 -0
  672. data/modules/emscripten/third_party/cp-demangle.h +161 -0
  673. data/modules/emscripten/third_party/demangle.h +549 -0
  674. data/modules/emscripten/third_party/demangler.py +49 -0
  675. data/modules/emscripten/third_party/gcc_demangler.c +4226 -0
  676. data/modules/emscripten/third_party/gcc_demangler.js +21282 -0
  677. data/modules/emscripten/third_party/jni/emjvm.cpp +133 -0
  678. data/modules/emscripten/third_party/jni/emjvm.h +8 -0
  679. data/modules/emscripten/third_party/jni/emjvm.js +185 -0
  680. data/modules/emscripten/third_party/jni/jni.h +1154 -0
  681. data/modules/emscripten/third_party/libiberty.h +634 -0
  682. data/modules/emscripten/third_party/lzma.js/README.markdown +37 -0
  683. data/modules/emscripten/third_party/lzma.js/doit.sh +37 -0
  684. data/modules/emscripten/third_party/lzma.js/lzip/AUTHORS +7 -0
  685. data/modules/emscripten/third_party/lzma.js/lzip/COPYING +676 -0
  686. data/modules/emscripten/third_party/lzma.js/lzip/ChangeLog +201 -0
  687. data/modules/emscripten/third_party/lzma.js/lzip/INSTALL +56 -0
  688. data/modules/emscripten/third_party/lzma.js/lzip/Makefile +160 -0
  689. data/modules/emscripten/third_party/lzma.js/lzip/Makefile.in +138 -0
  690. data/modules/emscripten/third_party/lzma.js/lzip/NEWS +22 -0
  691. data/modules/emscripten/third_party/lzma.js/lzip/README +77 -0
  692. data/modules/emscripten/third_party/lzma.js/lzip/arg_parser.cc +204 -0
  693. data/modules/emscripten/third_party/lzma.js/lzip/arg_parser.h +106 -0
  694. data/modules/emscripten/third_party/lzma.js/lzip/configure +192 -0
  695. data/modules/emscripten/third_party/lzma.js/lzip/decoder.cc +252 -0
  696. data/modules/emscripten/third_party/lzma.js/lzip/decoder.h +268 -0
  697. data/modules/emscripten/third_party/lzma.js/lzip/encoder.cc +643 -0
  698. data/modules/emscripten/third_party/lzma.js/lzip/encoder.h +582 -0
  699. data/modules/emscripten/third_party/lzma.js/lzip/fast_encoder.cc +378 -0
  700. data/modules/emscripten/third_party/lzma.js/lzip/fast_encoder.h +171 -0
  701. data/modules/emscripten/third_party/lzma.js/lzip/lzip.h +264 -0
  702. data/modules/emscripten/third_party/lzma.js/lzip/main.cc +545 -0
  703. data/modules/emscripten/third_party/lzma.js/lzma-decoder.js +27 -0
  704. data/modules/emscripten/third_party/lzma.js/lzma-full.js +27 -0
  705. data/modules/emscripten/third_party/lzma.js/native_test.sh +5 -0
  706. data/modules/emscripten/third_party/lzma.js/post.js +13 -0
  707. data/modules/emscripten/third_party/lzma.js/pre.js +13 -0
  708. data/modules/emscripten/third_party/lzma.js/test-decoder.js +39 -0
  709. data/modules/emscripten/third_party/lzma.js/test-full.html +9 -0
  710. data/modules/emscripten/third_party/lzma.js/test-full.js +78 -0
  711. data/modules/emscripten/third_party/ply/ANNOUNCE +40 -0
  712. data/modules/emscripten/third_party/ply/CHANGES +1093 -0
  713. data/modules/emscripten/third_party/ply/PKG-INFO +22 -0
  714. data/modules/emscripten/third_party/ply/README +271 -0
  715. data/modules/emscripten/third_party/ply/TODO +16 -0
  716. data/modules/emscripten/third_party/ply/doc/internal.html +874 -0
  717. data/modules/emscripten/third_party/ply/doc/makedoc.py +194 -0
  718. data/modules/emscripten/third_party/ply/doc/ply.html +3262 -0
  719. data/modules/emscripten/third_party/ply/example/BASIC/README +79 -0
  720. data/modules/emscripten/third_party/ply/example/BASIC/basic.py +71 -0
  721. data/modules/emscripten/third_party/ply/example/BASIC/basiclex.py +74 -0
  722. data/modules/emscripten/third_party/ply/example/BASIC/basiclog.py +79 -0
  723. data/modules/emscripten/third_party/ply/example/BASIC/basinterp.py +441 -0
  724. data/modules/emscripten/third_party/ply/example/BASIC/basparse.py +424 -0
  725. data/modules/emscripten/third_party/ply/example/BASIC/dim.bas +14 -0
  726. data/modules/emscripten/third_party/ply/example/BASIC/func.bas +5 -0
  727. data/modules/emscripten/third_party/ply/example/BASIC/gcd.bas +22 -0
  728. data/modules/emscripten/third_party/ply/example/BASIC/gosub.bas +13 -0
  729. data/modules/emscripten/third_party/ply/example/BASIC/hello.bas +4 -0
  730. data/modules/emscripten/third_party/ply/example/BASIC/linear.bas +17 -0
  731. data/modules/emscripten/third_party/ply/example/BASIC/maxsin.bas +12 -0
  732. data/modules/emscripten/third_party/ply/example/BASIC/powers.bas +13 -0
  733. data/modules/emscripten/third_party/ply/example/BASIC/rand.bas +4 -0
  734. data/modules/emscripten/third_party/ply/example/BASIC/sales.bas +20 -0
  735. data/modules/emscripten/third_party/ply/example/BASIC/sears.bas +18 -0
  736. data/modules/emscripten/third_party/ply/example/BASIC/sqrt1.bas +5 -0
  737. data/modules/emscripten/third_party/ply/example/BASIC/sqrt2.bas +4 -0
  738. data/modules/emscripten/third_party/ply/example/GardenSnake/GardenSnake.py +709 -0
  739. data/modules/emscripten/third_party/ply/example/GardenSnake/README +5 -0
  740. data/modules/emscripten/third_party/ply/example/README +10 -0
  741. data/modules/emscripten/third_party/ply/example/ansic/README +2 -0
  742. data/modules/emscripten/third_party/ply/example/ansic/clex.py +164 -0
  743. data/modules/emscripten/third_party/ply/example/ansic/cparse.py +863 -0
  744. data/modules/emscripten/third_party/ply/example/calc/calc.py +107 -0
  745. data/modules/emscripten/third_party/ply/example/calcdebug/calc.py +113 -0
  746. data/modules/emscripten/third_party/ply/example/classcalc/calc.py +157 -0
  747. data/modules/emscripten/third_party/ply/example/cleanup.sh +2 -0
  748. data/modules/emscripten/third_party/ply/example/closurecalc/calc.py +130 -0
  749. data/modules/emscripten/third_party/ply/example/hedit/hedit.py +48 -0
  750. data/modules/emscripten/third_party/ply/example/newclasscalc/calc.py +160 -0
  751. data/modules/emscripten/third_party/ply/example/optcalc/README +9 -0
  752. data/modules/emscripten/third_party/ply/example/optcalc/calc.py +119 -0
  753. data/modules/emscripten/third_party/ply/example/unicalc/calc.py +117 -0
  754. data/modules/emscripten/third_party/ply/example/yply/README +41 -0
  755. data/modules/emscripten/third_party/ply/example/yply/ylex.py +112 -0
  756. data/modules/emscripten/third_party/ply/example/yply/yparse.py +217 -0
  757. data/modules/emscripten/third_party/ply/example/yply/yply.py +53 -0
  758. data/modules/emscripten/third_party/ply/ply/__init__.py +4 -0
  759. data/modules/emscripten/third_party/ply/ply/cpp.py +898 -0
  760. data/modules/emscripten/third_party/ply/ply/ctokens.py +133 -0
  761. data/modules/emscripten/third_party/ply/ply/lex.py +1058 -0
  762. data/modules/emscripten/third_party/ply/ply/yacc.py +3276 -0
  763. data/modules/emscripten/third_party/ply/setup.py +31 -0
  764. data/modules/emscripten/third_party/ply/test/README +7 -0
  765. data/modules/emscripten/third_party/ply/test/calclex.py +49 -0
  766. data/modules/emscripten/third_party/ply/test/cleanup.sh +4 -0
  767. data/modules/emscripten/third_party/ply/test/lex_closure.py +54 -0
  768. data/modules/emscripten/third_party/ply/test/lex_doc1.py +26 -0
  769. data/modules/emscripten/third_party/ply/test/lex_dup1.py +29 -0
  770. data/modules/emscripten/third_party/ply/test/lex_dup2.py +33 -0
  771. data/modules/emscripten/third_party/ply/test/lex_dup3.py +31 -0
  772. data/modules/emscripten/third_party/ply/test/lex_empty.py +20 -0
  773. data/modules/emscripten/third_party/ply/test/lex_error1.py +24 -0
  774. data/modules/emscripten/third_party/ply/test/lex_error2.py +26 -0
  775. data/modules/emscripten/third_party/ply/test/lex_error3.py +27 -0
  776. data/modules/emscripten/third_party/ply/test/lex_error4.py +27 -0
  777. data/modules/emscripten/third_party/ply/test/lex_hedit.py +47 -0
  778. data/modules/emscripten/third_party/ply/test/lex_ignore.py +31 -0
  779. data/modules/emscripten/third_party/ply/test/lex_ignore2.py +29 -0
  780. data/modules/emscripten/third_party/ply/test/lex_literal1.py +25 -0
  781. data/modules/emscripten/third_party/ply/test/lex_literal2.py +25 -0
  782. data/modules/emscripten/third_party/ply/test/lex_many_tokens.py +27 -0
  783. data/modules/emscripten/third_party/ply/test/lex_module.py +10 -0
  784. data/modules/emscripten/third_party/ply/test/lex_module_import.py +42 -0
  785. data/modules/emscripten/third_party/ply/test/lex_object.py +55 -0
  786. data/modules/emscripten/third_party/ply/test/lex_opt_alias.py +54 -0
  787. data/modules/emscripten/third_party/ply/test/lex_optimize.py +50 -0
  788. data/modules/emscripten/third_party/ply/test/lex_optimize2.py +50 -0
  789. data/modules/emscripten/third_party/ply/test/lex_optimize3.py +52 -0
  790. data/modules/emscripten/third_party/ply/test/lex_re1.py +27 -0
  791. data/modules/emscripten/third_party/ply/test/lex_re2.py +27 -0
  792. data/modules/emscripten/third_party/ply/test/lex_re3.py +29 -0
  793. data/modules/emscripten/third_party/ply/test/lex_rule1.py +27 -0
  794. data/modules/emscripten/third_party/ply/test/lex_rule2.py +29 -0
  795. data/modules/emscripten/third_party/ply/test/lex_rule3.py +27 -0
  796. data/modules/emscripten/third_party/ply/test/lex_state1.py +40 -0
  797. data/modules/emscripten/third_party/ply/test/lex_state2.py +40 -0
  798. data/modules/emscripten/third_party/ply/test/lex_state3.py +42 -0
  799. data/modules/emscripten/third_party/ply/test/lex_state4.py +41 -0
  800. data/modules/emscripten/third_party/ply/test/lex_state5.py +40 -0
  801. data/modules/emscripten/third_party/ply/test/lex_state_noerror.py +39 -0
  802. data/modules/emscripten/third_party/ply/test/lex_state_norule.py +40 -0
  803. data/modules/emscripten/third_party/ply/test/lex_state_try.py +45 -0
  804. data/modules/emscripten/third_party/ply/test/lex_token1.py +19 -0
  805. data/modules/emscripten/third_party/ply/test/lex_token2.py +22 -0
  806. data/modules/emscripten/third_party/ply/test/lex_token3.py +24 -0
  807. data/modules/emscripten/third_party/ply/test/lex_token4.py +26 -0
  808. data/modules/emscripten/third_party/ply/test/lex_token5.py +31 -0
  809. data/modules/emscripten/third_party/ply/test/lex_token_dup.py +29 -0
  810. data/modules/emscripten/third_party/ply/test/testlex.py +606 -0
  811. data/modules/emscripten/third_party/ply/test/testyacc.py +347 -0
  812. data/modules/emscripten/third_party/ply/test/yacc_badargs.py +68 -0
  813. data/modules/emscripten/third_party/ply/test/yacc_badid.py +77 -0
  814. data/modules/emscripten/third_party/ply/test/yacc_badprec.py +64 -0
  815. data/modules/emscripten/third_party/ply/test/yacc_badprec2.py +68 -0
  816. data/modules/emscripten/third_party/ply/test/yacc_badprec3.py +68 -0
  817. data/modules/emscripten/third_party/ply/test/yacc_badrule.py +68 -0
  818. data/modules/emscripten/third_party/ply/test/yacc_badtok.py +68 -0
  819. data/modules/emscripten/third_party/ply/test/yacc_dup.py +68 -0
  820. data/modules/emscripten/third_party/ply/test/yacc_error1.py +68 -0
  821. data/modules/emscripten/third_party/ply/test/yacc_error2.py +68 -0
  822. data/modules/emscripten/third_party/ply/test/yacc_error3.py +67 -0
  823. data/modules/emscripten/third_party/ply/test/yacc_error4.py +72 -0
  824. data/modules/emscripten/third_party/ply/test/yacc_inf.py +56 -0
  825. data/modules/emscripten/third_party/ply/test/yacc_literal.py +69 -0
  826. data/modules/emscripten/third_party/ply/test/yacc_misplaced.py +68 -0
  827. data/modules/emscripten/third_party/ply/test/yacc_missing1.py +68 -0
  828. data/modules/emscripten/third_party/ply/test/yacc_nested.py +33 -0
  829. data/modules/emscripten/third_party/ply/test/yacc_nodoc.py +67 -0
  830. data/modules/emscripten/third_party/ply/test/yacc_noerror.py +66 -0
  831. data/modules/emscripten/third_party/ply/test/yacc_nop.py +68 -0
  832. data/modules/emscripten/third_party/ply/test/yacc_notfunc.py +66 -0
  833. data/modules/emscripten/third_party/ply/test/yacc_notok.py +67 -0
  834. data/modules/emscripten/third_party/ply/test/yacc_prec1.py +68 -0
  835. data/modules/emscripten/third_party/ply/test/yacc_rr.py +72 -0
  836. data/modules/emscripten/third_party/ply/test/yacc_rr_unused.py +30 -0
  837. data/modules/emscripten/third_party/ply/test/yacc_simple.py +68 -0
  838. data/modules/emscripten/third_party/ply/test/yacc_sr.py +63 -0
  839. data/modules/emscripten/third_party/ply/test/yacc_term1.py +68 -0
  840. data/modules/emscripten/third_party/ply/test/yacc_unused.py +77 -0
  841. data/modules/emscripten/third_party/ply/test/yacc_unused_rule.py +72 -0
  842. data/modules/emscripten/third_party/ply/test/yacc_uprec.py +63 -0
  843. data/modules/emscripten/third_party/ply/test/yacc_uprec2.py +63 -0
  844. data/modules/emscripten/third_party/readme.txt +7 -0
  845. data/modules/emscripten/third_party/websockify/CHANGES.txt +23 -0
  846. data/modules/emscripten/third_party/websockify/LICENSE.txt +16 -0
  847. data/modules/emscripten/third_party/websockify/MANIFEST.in +1 -0
  848. data/modules/emscripten/third_party/websockify/Makefile +11 -0
  849. data/modules/emscripten/third_party/websockify/README.md +168 -0
  850. data/modules/emscripten/third_party/websockify/Windows/Windows Service Readme.txt +39 -0
  851. data/modules/emscripten/third_party/websockify/Windows/noVNC Websocket Service Project/Program.cs +24 -0
  852. data/modules/emscripten/third_party/websockify/Windows/noVNC Websocket Service Project/ProjectInstaller.Designer.cs +61 -0
  853. data/modules/emscripten/third_party/websockify/Windows/noVNC Websocket Service Project/ProjectInstaller.cs +19 -0
  854. data/modules/emscripten/third_party/websockify/Windows/noVNC Websocket Service Project/ProjectInstaller.resx +129 -0
  855. data/modules/emscripten/third_party/websockify/Windows/noVNC Websocket Service Project/Properties/AssemblyInfo.cs +36 -0
  856. data/modules/emscripten/third_party/websockify/Windows/noVNC Websocket Service Project/Service1.Designer.cs +37 -0
  857. data/modules/emscripten/third_party/websockify/Windows/noVNC Websocket Service Project/Service1.cs +41 -0
  858. data/modules/emscripten/third_party/websockify/Windows/noVNC Websocket Service Project/noVNC Websocket.csproj +75 -0
  859. data/modules/emscripten/third_party/websockify/Windows/noVNC Websocket Service Project/noVNC Websocket.sln +20 -0
  860. data/modules/emscripten/third_party/websockify/docs/LICENSE.GPL-3 +621 -0
  861. data/modules/emscripten/third_party/websockify/docs/LICENSE.LGPL-3 +165 -0
  862. data/modules/emscripten/third_party/websockify/docs/LICENSE.MPL-2.0 +373 -0
  863. data/modules/emscripten/third_party/websockify/docs/TODO +9 -0
  864. data/modules/emscripten/third_party/websockify/docs/flash_policy.txt +4 -0
  865. data/modules/emscripten/third_party/websockify/docs/latency_results.txt +114 -0
  866. data/modules/emscripten/third_party/websockify/docs/notes +17 -0
  867. data/modules/emscripten/third_party/websockify/docs/release.txt +9 -0
  868. data/modules/emscripten/third_party/websockify/docs/websockify.1 +110 -0
  869. data/modules/emscripten/third_party/websockify/include/VT100.js +919 -0
  870. data/modules/emscripten/third_party/websockify/include/base64.js +114 -0
  871. data/modules/emscripten/third_party/websockify/include/keysym.js +99 -0
  872. data/modules/emscripten/third_party/websockify/include/util.js +359 -0
  873. data/modules/emscripten/third_party/websockify/include/web-socket-js/README.txt +109 -0
  874. data/modules/emscripten/third_party/websockify/include/web-socket-js/WebSocketMain.swf +0 -0
  875. data/modules/emscripten/third_party/websockify/include/web-socket-js/swfobject.js +4 -0
  876. data/modules/emscripten/third_party/websockify/include/web-socket-js/web_socket.js +391 -0
  877. data/modules/emscripten/third_party/websockify/include/websock.js +422 -0
  878. data/modules/emscripten/third_party/websockify/include/webutil.js +216 -0
  879. data/modules/emscripten/third_party/websockify/include/wsirc.js +235 -0
  880. data/modules/emscripten/third_party/websockify/include/wstelnet.js +335 -0
  881. data/modules/emscripten/third_party/websockify/other/Makefile +14 -0
  882. data/modules/emscripten/third_party/websockify/other/README.md +51 -0
  883. data/modules/emscripten/third_party/websockify/other/launch.sh +108 -0
  884. data/modules/emscripten/third_party/websockify/other/project.clj +13 -0
  885. data/modules/emscripten/third_party/websockify/other/websocket.c +802 -0
  886. data/modules/emscripten/third_party/websockify/other/websocket.h +84 -0
  887. data/modules/emscripten/third_party/websockify/other/websocket.rb +456 -0
  888. data/modules/emscripten/third_party/websockify/other/websockify.c +385 -0
  889. data/modules/emscripten/third_party/websockify/other/websockify.clj +233 -0
  890. data/modules/emscripten/third_party/websockify/other/websockify.js +196 -0
  891. data/modules/emscripten/third_party/websockify/other/websockify.rb +171 -0
  892. data/modules/emscripten/third_party/websockify/other/wswrap +22 -0
  893. data/modules/emscripten/third_party/websockify/rebind +18 -0
  894. data/modules/emscripten/third_party/websockify/rebind.c +94 -0
  895. data/modules/emscripten/third_party/websockify/run +5 -0
  896. data/modules/emscripten/third_party/websockify/setup.py +30 -0
  897. data/modules/emscripten/third_party/websockify/tests/b64_vs_utf8.py +29 -0
  898. data/modules/emscripten/third_party/websockify/tests/base64.html +91 -0
  899. data/modules/emscripten/third_party/websockify/tests/base64.js +12 -0
  900. data/modules/emscripten/third_party/websockify/tests/echo.html +148 -0
  901. data/modules/emscripten/third_party/websockify/tests/echo.py +75 -0
  902. data/modules/emscripten/third_party/websockify/tests/echo.rb +62 -0
  903. data/modules/emscripten/third_party/websockify/tests/latency.html +290 -0
  904. data/modules/emscripten/third_party/websockify/tests/latency.py +75 -0
  905. data/modules/emscripten/third_party/websockify/tests/load.html +250 -0
  906. data/modules/emscripten/third_party/websockify/tests/load.py +167 -0
  907. data/modules/emscripten/third_party/websockify/tests/plain_echo.html +168 -0
  908. data/modules/emscripten/third_party/websockify/tests/simple.html +68 -0
  909. data/modules/emscripten/third_party/websockify/tests/utf8-list.py +22 -0
  910. data/modules/emscripten/third_party/websockify/websockify/__init__.py +2 -0
  911. data/modules/emscripten/third_party/websockify/websockify/websocket.py +982 -0
  912. data/modules/emscripten/third_party/websockify/websockify/websocketproxy.py +393 -0
  913. data/modules/emscripten/third_party/websockify/websockify.py +5 -0
  914. data/modules/emscripten/third_party/websockify/wsirc.html +99 -0
  915. data/modules/emscripten/third_party/websockify/wstelnet.html +74 -0
  916. data/modules/emscripten/tools/__init__.py +0 -0
  917. data/modules/emscripten/tools/__init__.pyc +0 -0
  918. data/modules/emscripten/tools/autodebugger.py +289 -0
  919. data/modules/emscripten/tools/autodebugger_c.py +37 -0
  920. data/modules/emscripten/tools/autodebugger_indenter.py +18 -0
  921. data/modules/emscripten/tools/autodebugger_js.py +47 -0
  922. data/modules/emscripten/tools/autodediffer.py +60 -0
  923. data/modules/emscripten/tools/bindings_generator.py +832 -0
  924. data/modules/emscripten/tools/bisect_pair.py +88 -0
  925. data/modules/emscripten/tools/cache.py +198 -0
  926. data/modules/emscripten/tools/cache.pyc +0 -0
  927. data/modules/emscripten/tools/clean_webconsole.py +34 -0
  928. data/modules/emscripten/tools/crunch-worker.js +124 -0
  929. data/modules/emscripten/tools/diff_autodebugger.py +15 -0
  930. data/modules/emscripten/tools/eliminator/asm-eliminator-test-output.js +5129 -0
  931. data/modules/emscripten/tools/eliminator/asm-eliminator-test.js +6861 -0
  932. data/modules/emscripten/tools/eliminator/eliminator-test-output.js +6122 -0
  933. data/modules/emscripten/tools/eliminator/eliminator-test.js +8856 -0
  934. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/README.html +888 -0
  935. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/README.org +463 -0
  936. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/bin/uglifyjs +317 -0
  937. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/docstyle.css +75 -0
  938. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/lib/object-ast.js +75 -0
  939. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/lib/parse-js.js +1363 -0
  940. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/lib/process.js +2005 -0
  941. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/lib/squeeze-more.js +51 -0
  942. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/package.json +22 -0
  943. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/beautify.js +28 -0
  944. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/testparser.js +402 -0
  945. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/array1.js +1 -0
  946. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/array2.js +1 -0
  947. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/array3.js +1 -0
  948. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/array4.js +1 -0
  949. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/assignment.js +1 -0
  950. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/concatstring.js +1 -0
  951. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/const.js +1 -0
  952. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/empty-blocks.js +1 -0
  953. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/forstatement.js +1 -0
  954. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/if.js +1 -0
  955. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/ifreturn.js +1 -0
  956. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/ifreturn2.js +1 -0
  957. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue10.js +1 -0
  958. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue11.js +1 -0
  959. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue13.js +1 -0
  960. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue14.js +1 -0
  961. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue16.js +1 -0
  962. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue17.js +1 -0
  963. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue20.js +1 -0
  964. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue21.js +1 -0
  965. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue25.js +1 -0
  966. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue27.js +1 -0
  967. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue28.js +1 -0
  968. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue29.js +1 -0
  969. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue30.js +1 -0
  970. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue34.js +1 -0
  971. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue4.js +1 -0
  972. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue48.js +1 -0
  973. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue50.js +1 -0
  974. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue53.js +1 -0
  975. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue54.1.js +1 -0
  976. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue68.js +1 -0
  977. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue69.js +1 -0
  978. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/issue9.js +1 -0
  979. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/mangle.js +1 -0
  980. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/strict-equals.js +1 -0
  981. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/var.js +1 -0
  982. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/expected/with.js +1 -0
  983. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/array1.js +3 -0
  984. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/array2.js +4 -0
  985. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/array3.js +4 -0
  986. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/array4.js +6 -0
  987. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/assignment.js +20 -0
  988. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/concatstring.js +3 -0
  989. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/const.js +5 -0
  990. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/empty-blocks.js +4 -0
  991. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/forstatement.js +10 -0
  992. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/if.js +6 -0
  993. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/ifreturn.js +9 -0
  994. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/ifreturn2.js +16 -0
  995. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue10.js +1 -0
  996. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue11.js +3 -0
  997. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue13.js +1 -0
  998. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue14.js +1 -0
  999. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue16.js +1 -0
  1000. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue17.js +4 -0
  1001. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue20.js +1 -0
  1002. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue21.js +6 -0
  1003. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue25.js +7 -0
  1004. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue27.js +1 -0
  1005. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue28.js +3 -0
  1006. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue29.js +1 -0
  1007. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue30.js +3 -0
  1008. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue34.js +3 -0
  1009. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue4.js +3 -0
  1010. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue48.js +1 -0
  1011. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue50.js +9 -0
  1012. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue53.js +1 -0
  1013. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue54.1.js +3 -0
  1014. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue68.js +5 -0
  1015. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue69.js +1 -0
  1016. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/issue9.js +4 -0
  1017. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/mangle.js +5 -0
  1018. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/strict-equals.js +3 -0
  1019. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/var.js +3 -0
  1020. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/compress/test/with.js +2 -0
  1021. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/test/unit/scripts.js +55 -0
  1022. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/tmp/hoist.js +33 -0
  1023. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/tmp/instrument.js +97 -0
  1024. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/tmp/instrument2.js +138 -0
  1025. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/tmp/test.js +16 -0
  1026. data/modules/emscripten/tools/eliminator/node_modules/uglify-js/uglify-js.js +17 -0
  1027. data/modules/emscripten/tools/eliminator/safe-eliminator-test-output.js +85 -0
  1028. data/modules/emscripten/tools/eliminator/safe-eliminator-test.js +103 -0
  1029. data/modules/emscripten/tools/emconfiguren.py +19 -0
  1030. data/modules/emscripten/tools/emmaken.py +230 -0
  1031. data/modules/emscripten/tools/emmakenxx.py +18 -0
  1032. data/modules/emscripten/tools/exec_llvm.py +50 -0
  1033. data/modules/emscripten/tools/file2json.py +49 -0
  1034. data/modules/emscripten/tools/file_packager.py +649 -0
  1035. data/modules/emscripten/tools/find_bigfuncs.py +23 -0
  1036. data/modules/emscripten/tools/find_bigis.py +18 -0
  1037. data/modules/emscripten/tools/fix_closure.py +88 -0
  1038. data/modules/emscripten/tools/ie7_fix.py +14 -0
  1039. data/modules/emscripten/tools/js-optimizer.js +3440 -0
  1040. data/modules/emscripten/tools/js_optimizer.py +341 -0
  1041. data/modules/emscripten/tools/js_optimizer.pyc +0 -0
  1042. data/modules/emscripten/tools/jsrun.py +27 -0
  1043. data/modules/emscripten/tools/jsrun.pyc +0 -0
  1044. data/modules/emscripten/tools/ll-strip.py +56 -0
  1045. data/modules/emscripten/tools/make_file.py +19 -0
  1046. data/modules/emscripten/tools/make_minigzip.py +13 -0
  1047. data/modules/emscripten/tools/namespacer.py +95 -0
  1048. data/modules/emscripten/tools/nativize_llvm.py +34 -0
  1049. data/modules/emscripten/tools/node_modules/source-map/CHANGELOG.md +58 -0
  1050. data/modules/emscripten/tools/node_modules/source-map/LICENSE +28 -0
  1051. data/modules/emscripten/tools/node_modules/source-map/Makefile.dryice.js +166 -0
  1052. data/modules/emscripten/tools/node_modules/source-map/README.md +347 -0
  1053. data/modules/emscripten/tools/node_modules/source-map/build/assert-shim.js +56 -0
  1054. data/modules/emscripten/tools/node_modules/source-map/build/mini-require.js +152 -0
  1055. data/modules/emscripten/tools/node_modules/source-map/build/prefix-source-map.jsm +20 -0
  1056. data/modules/emscripten/tools/node_modules/source-map/build/prefix-utils.jsm +18 -0
  1057. data/modules/emscripten/tools/node_modules/source-map/build/suffix-browser.js +8 -0
  1058. data/modules/emscripten/tools/node_modules/source-map/build/suffix-source-map.jsm +6 -0
  1059. data/modules/emscripten/tools/node_modules/source-map/build/suffix-utils.jsm +21 -0
  1060. data/modules/emscripten/tools/node_modules/source-map/build/test-prefix.js +8 -0
  1061. data/modules/emscripten/tools/node_modules/source-map/build/test-suffix.js +3 -0
  1062. data/modules/emscripten/tools/node_modules/source-map/lib/source-map/array-set.js +96 -0
  1063. data/modules/emscripten/tools/node_modules/source-map/lib/source-map/base64-vlq.js +144 -0
  1064. data/modules/emscripten/tools/node_modules/source-map/lib/source-map/base64.js +42 -0
  1065. data/modules/emscripten/tools/node_modules/source-map/lib/source-map/binary-search.js +81 -0
  1066. data/modules/emscripten/tools/node_modules/source-map/lib/source-map/source-map-consumer.js +430 -0
  1067. data/modules/emscripten/tools/node_modules/source-map/lib/source-map/source-map-generator.js +381 -0
  1068. data/modules/emscripten/tools/node_modules/source-map/lib/source-map/source-node.js +353 -0
  1069. data/modules/emscripten/tools/node_modules/source-map/lib/source-map/util.js +117 -0
  1070. data/modules/emscripten/tools/node_modules/source-map/lib/source-map.js +8 -0
  1071. data/modules/emscripten/tools/node_modules/source-map/node_modules/amdefine/LICENSE +58 -0
  1072. data/modules/emscripten/tools/node_modules/source-map/node_modules/amdefine/README.md +119 -0
  1073. data/modules/emscripten/tools/node_modules/source-map/node_modules/amdefine/amdefine.js +299 -0
  1074. data/modules/emscripten/tools/node_modules/source-map/node_modules/amdefine/package.json +33 -0
  1075. data/modules/emscripten/tools/node_modules/source-map/package.json +74 -0
  1076. data/modules/emscripten/tools/node_modules/source-map/test/run-tests.js +73 -0
  1077. data/modules/emscripten/tools/node_modules/source-map/test/source-map/test-api.js +26 -0
  1078. data/modules/emscripten/tools/node_modules/source-map/test/source-map/test-array-set.js +71 -0
  1079. data/modules/emscripten/tools/node_modules/source-map/test/source-map/test-base64-vlq.js +24 -0
  1080. data/modules/emscripten/tools/node_modules/source-map/test/source-map/test-base64.js +35 -0
  1081. data/modules/emscripten/tools/node_modules/source-map/test/source-map/test-binary-search.js +54 -0
  1082. data/modules/emscripten/tools/node_modules/source-map/test/source-map/test-dog-fooding.js +72 -0
  1083. data/modules/emscripten/tools/node_modules/source-map/test/source-map/test-source-map-consumer.js +306 -0
  1084. data/modules/emscripten/tools/node_modules/source-map/test/source-map/test-source-map-generator.js +391 -0
  1085. data/modules/emscripten/tools/node_modules/source-map/test/source-map/test-source-node.js +282 -0
  1086. data/modules/emscripten/tools/node_modules/source-map/test/source-map/util.js +152 -0
  1087. data/modules/emscripten/tools/reproduceriter.js +216 -0
  1088. data/modules/emscripten/tools/reproduceriter.py +160 -0
  1089. data/modules/emscripten/tools/response_file.py +28 -0
  1090. data/modules/emscripten/tools/response_file.pyc +0 -0
  1091. data/modules/emscripten/tools/scan_js.py +20 -0
  1092. data/modules/emscripten/tools/scan_ll.py +18 -0
  1093. data/modules/emscripten/tools/scons/site_scons/site_tools/emscripten/__init__.py +3 -0
  1094. data/modules/emscripten/tools/scons/site_scons/site_tools/emscripten/emscripten.py +46 -0
  1095. data/modules/emscripten/tools/settings_template_readonly.py +47 -0
  1096. data/modules/emscripten/tools/shared.py +1437 -0
  1097. data/modules/emscripten/tools/shared.pyc +0 -0
  1098. data/modules/emscripten/tools/source-maps/sourcemap2json.js +15 -0
  1099. data/modules/emscripten/tools/source-maps/sourcemapper.js +177 -0
  1100. data/modules/emscripten/tools/split.py +97 -0
  1101. data/modules/emscripten/tools/tempfiles.py +40 -0
  1102. data/modules/emscripten/tools/tempfiles.pyc +0 -0
  1103. data/modules/emscripten/tools/test-js-optimizer-asm-last-output.js +75 -0
  1104. data/modules/emscripten/tools/test-js-optimizer-asm-last.js +91 -0
  1105. data/modules/emscripten/tools/test-js-optimizer-asm-outline-output.js +570 -0
  1106. data/modules/emscripten/tools/test-js-optimizer-asm-outline.js +606 -0
  1107. data/modules/emscripten/tools/test-js-optimizer-asm-pre-output.js +540 -0
  1108. data/modules/emscripten/tools/test-js-optimizer-asm-pre.js +550 -0
  1109. data/modules/emscripten/tools/test-js-optimizer-asm-regs-min-output.js +36 -0
  1110. data/modules/emscripten/tools/test-js-optimizer-asm-regs-min.js +37 -0
  1111. data/modules/emscripten/tools/test-js-optimizer-asm-regs-output.js +106 -0
  1112. data/modules/emscripten/tools/test-js-optimizer-asm-regs.js +110 -0
  1113. data/modules/emscripten/tools/test-js-optimizer-asm-relocate-output.js +9 -0
  1114. data/modules/emscripten/tools/test-js-optimizer-asm-relocate.js +12 -0
  1115. data/modules/emscripten/tools/test-js-optimizer-output.js +291 -0
  1116. data/modules/emscripten/tools/test-js-optimizer-regs-output.js +232 -0
  1117. data/modules/emscripten/tools/test-js-optimizer-regs.js +237 -0
  1118. data/modules/emscripten/tools/test-js-optimizer-t2-output.js +91 -0
  1119. data/modules/emscripten/tools/test-js-optimizer-t2.js +92 -0
  1120. data/modules/emscripten/tools/test-js-optimizer-t2c-output.js +17 -0
  1121. data/modules/emscripten/tools/test-js-optimizer-t2c.js +18 -0
  1122. data/modules/emscripten/tools/test-js-optimizer-t3-output.js +49 -0
  1123. data/modules/emscripten/tools/test-js-optimizer-t3.js +50 -0
  1124. data/modules/emscripten/tools/test-js-optimizer.js +401 -0
  1125. data/modules/mruby/AUTHORS +18 -0
  1126. data/modules/mruby/CONTRIBUTING.md +65 -0
  1127. data/modules/mruby/ChangeLog +15 -0
  1128. data/modules/mruby/INSTALL +29 -0
  1129. data/modules/mruby/LEGAL +6 -0
  1130. data/modules/mruby/MITL +20 -0
  1131. data/modules/mruby/Makefile +18 -0
  1132. data/modules/mruby/NEWS +13 -0
  1133. data/modules/mruby/README.md +116 -0
  1134. data/modules/mruby/Rakefile +114 -0
  1135. data/modules/mruby/TODO +11 -0
  1136. data/modules/mruby/benchmark/ao-render.rb +315 -0
  1137. data/modules/mruby/benchmark/bm_so_lists.rb +47 -0
  1138. data/modules/mruby/benchmark/fib39.rb +8 -0
  1139. data/modules/mruby/build_config.rb +88 -0
  1140. data/modules/mruby/doc/compile/README.md +376 -0
  1141. data/modules/mruby/doc/mrbgems/README.md +254 -0
  1142. data/modules/mruby/examples/mrbgems/c_and_ruby_extension_example/README.md +4 -0
  1143. data/modules/mruby/examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake +23 -0
  1144. data/modules/mruby/examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb +5 -0
  1145. data/modules/mruby/examples/mrbgems/c_and_ruby_extension_example/src/example.c +20 -0
  1146. data/modules/mruby/examples/mrbgems/c_and_ruby_extension_example/test/example.rb +7 -0
  1147. data/modules/mruby/examples/mrbgems/c_extension_example/README.md +4 -0
  1148. data/modules/mruby/examples/mrbgems/c_extension_example/mrbgem.rake +23 -0
  1149. data/modules/mruby/examples/mrbgems/c_extension_example/src/example.c +20 -0
  1150. data/modules/mruby/examples/mrbgems/c_extension_example/test/example.c +7 -0
  1151. data/modules/mruby/examples/mrbgems/c_extension_example/test/example.rb +3 -0
  1152. data/modules/mruby/examples/mrbgems/ruby_extension_example/README.md +4 -0
  1153. data/modules/mruby/examples/mrbgems/ruby_extension_example/mrbgem.rake +23 -0
  1154. data/modules/mruby/examples/mrbgems/ruby_extension_example/mrblib/example.rb +5 -0
  1155. data/modules/mruby/examples/mrbgems/ruby_extension_example/test/example.rb +3 -0
  1156. data/modules/mruby/examples/targets/ArduinoDue.rb +65 -0
  1157. data/modules/mruby/examples/targets/chipKitMax32.rb +68 -0
  1158. data/modules/mruby/include/mrbconf.h +87 -0
  1159. data/modules/mruby/include/mruby/array.h +63 -0
  1160. data/modules/mruby/include/mruby/class.h +75 -0
  1161. data/modules/mruby/include/mruby/compile.h +176 -0
  1162. data/modules/mruby/include/mruby/data.h +53 -0
  1163. data/modules/mruby/include/mruby/dump.h +151 -0
  1164. data/modules/mruby/include/mruby/gc.h +17 -0
  1165. data/modules/mruby/include/mruby/hash.h +54 -0
  1166. data/modules/mruby/include/mruby/irep.h +40 -0
  1167. data/modules/mruby/include/mruby/khash.h +257 -0
  1168. data/modules/mruby/include/mruby/numeric.h +32 -0
  1169. data/modules/mruby/include/mruby/proc.h +62 -0
  1170. data/modules/mruby/include/mruby/range.h +35 -0
  1171. data/modules/mruby/include/mruby/string.h +78 -0
  1172. data/modules/mruby/include/mruby/value.h +483 -0
  1173. data/modules/mruby/include/mruby/variable.h +78 -0
  1174. data/modules/mruby/include/mruby.h +388 -0
  1175. data/modules/mruby/minirake +477 -0
  1176. data/modules/mruby/mrbgems/default.gembox +61 -0
  1177. data/modules/mruby/mrbgems/full-core.gembox +9 -0
  1178. data/modules/mruby/mrbgems/mruby-array-ext/mrbgem.rake +4 -0
  1179. data/modules/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +204 -0
  1180. data/modules/mruby/mrbgems/mruby-array-ext/src/array.c +140 -0
  1181. data/modules/mruby/mrbgems/mruby-array-ext/test/array.rb +109 -0
  1182. data/modules/mruby/mrbgems/mruby-bin-mirb/mrbgem.rake +5 -0
  1183. data/modules/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +365 -0
  1184. data/modules/mruby/mrbgems/mruby-bin-mruby/mrbgem.rake +5 -0
  1185. data/modules/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +243 -0
  1186. data/modules/mruby/mrbgems/mruby-enum-ext/mrbgem.rake +4 -0
  1187. data/modules/mruby/mrbgems/mruby-enum-ext/mrblib/enum.rb +164 -0
  1188. data/modules/mruby/mrbgems/mruby-enum-ext/test/enum.rb +44 -0
  1189. data/modules/mruby/mrbgems/mruby-eval/mrbgem.rake +4 -0
  1190. data/modules/mruby/mrbgems/mruby-eval/src/eval.c +23 -0
  1191. data/modules/mruby/mrbgems/mruby-fiber/mrbgem.rake +4 -0
  1192. data/modules/mruby/mrbgems/mruby-fiber/src/fiber.c +251 -0
  1193. data/modules/mruby/mrbgems/mruby-fiber/test/fiber.rb +64 -0
  1194. data/modules/mruby/mrbgems/mruby-hash-ext/mrbgem.rake +4 -0
  1195. data/modules/mruby/mrbgems/mruby-hash-ext/mrblib/hash.rb +13 -0
  1196. data/modules/mruby/mrbgems/mruby-hash-ext/src/hash-ext.c +62 -0
  1197. data/modules/mruby/mrbgems/mruby-hash-ext/test/hash.rb +26 -0
  1198. data/modules/mruby/mrbgems/mruby-math/mrbgem.rake +4 -0
  1199. data/modules/mruby/mrbgems/mruby-math/src/math.c +685 -0
  1200. data/modules/mruby/mrbgems/mruby-math/test/math.rb +136 -0
  1201. data/modules/mruby/mrbgems/mruby-numeric-ext/mrbgem.rake +4 -0
  1202. data/modules/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +31 -0
  1203. data/modules/mruby/mrbgems/mruby-numeric-ext/test/numeric.rb +10 -0
  1204. data/modules/mruby/mrbgems/mruby-object-ext/mrbgem.rake +4 -0
  1205. data/modules/mruby/mrbgems/mruby-object-ext/src/object.c +108 -0
  1206. data/modules/mruby/mrbgems/mruby-object-ext/test/nil.rb +11 -0
  1207. data/modules/mruby/mrbgems/mruby-object-ext/test/object.rb +9 -0
  1208. data/modules/mruby/mrbgems/mruby-objectspace/mrbgem.rake +4 -0
  1209. data/modules/mruby/mrbgems/mruby-objectspace/src/mruby_objectspace.c +117 -0
  1210. data/modules/mruby/mrbgems/mruby-objectspace/test/objectspace.rb +38 -0
  1211. data/modules/mruby/mrbgems/mruby-print/mrbgem.rake +4 -0
  1212. data/modules/mruby/mrbgems/mruby-print/mrblib/print.rb +64 -0
  1213. data/modules/mruby/mrbgems/mruby-print/src/print.c +44 -0
  1214. data/modules/mruby/mrbgems/mruby-proc-ext/mrbgem.rake +4 -0
  1215. data/modules/mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb +40 -0
  1216. data/modules/mruby/mrbgems/mruby-proc-ext/src/proc.c +97 -0
  1217. data/modules/mruby/mrbgems/mruby-proc-ext/test/proc.rb +41 -0
  1218. data/modules/mruby/mrbgems/mruby-random/mrbgem.rake +4 -0
  1219. data/modules/mruby/mrbgems/mruby-random/src/mt19937ar.c +193 -0
  1220. data/modules/mruby/mrbgems/mruby-random/src/mt19937ar.h +48 -0
  1221. data/modules/mruby/mrbgems/mruby-random/src/random.c +231 -0
  1222. data/modules/mruby/mrbgems/mruby-random/src/random.h +12 -0
  1223. data/modules/mruby/mrbgems/mruby-random/test/random.rb +32 -0
  1224. data/modules/mruby/mrbgems/mruby-range-ext/mrbgem.rake +4 -0
  1225. data/modules/mruby/mrbgems/mruby-range-ext/src/range.c +141 -0
  1226. data/modules/mruby/mrbgems/mruby-range-ext/test/range.rb +20 -0
  1227. data/modules/mruby/mrbgems/mruby-sprintf/mrbgem.rake +4 -0
  1228. data/modules/mruby/mrbgems/mruby-sprintf/src/kernel.c +30 -0
  1229. data/modules/mruby/mrbgems/mruby-sprintf/src/sprintf.c +1102 -0
  1230. data/modules/mruby/mrbgems/mruby-sprintf/test/sprintf.rb +3 -0
  1231. data/modules/mruby/mrbgems/mruby-string-ext/mrbgem.rake +4 -0
  1232. data/modules/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +52 -0
  1233. data/modules/mruby/mrbgems/mruby-string-ext/src/string.c +175 -0
  1234. data/modules/mruby/mrbgems/mruby-string-ext/test/string.rb +112 -0
  1235. data/modules/mruby/mrbgems/mruby-struct/mrbgem.rake +4 -0
  1236. data/modules/mruby/mrbgems/mruby-struct/mrblib/struct.rb +50 -0
  1237. data/modules/mruby/mrbgems/mruby-struct/src/struct.c +818 -0
  1238. data/modules/mruby/mrbgems/mruby-struct/test/struct.rb +77 -0
  1239. data/modules/mruby/mrbgems/mruby-symbol-ext/mrbgem.rake +4 -0
  1240. data/modules/mruby/mrbgems/mruby-symbol-ext/mrblib/symbol.rb +9 -0
  1241. data/modules/mruby/mrbgems/mruby-symbol-ext/src/symbol.c +55 -0
  1242. data/modules/mruby/mrbgems/mruby-symbol-ext/test/symbol.rb +12 -0
  1243. data/modules/mruby/mrbgems/mruby-time/mrbgem.rake +4 -0
  1244. data/modules/mruby/mrbgems/mruby-time/src/time.c +749 -0
  1245. data/modules/mruby/mrbgems/mruby-time/test/time.rb +201 -0
  1246. data/modules/mruby/mrbgems/mruby-toplevel-ext/mrbgem.rake +4 -0
  1247. data/modules/mruby/mrbgems/mruby-toplevel-ext/mrblib/toplevel.rb +11 -0
  1248. data/modules/mruby/mrbgems/mruby-toplevel-ext/test/toplevel.rb +24 -0
  1249. data/modules/mruby/mrblib/array.rb +111 -0
  1250. data/modules/mruby/mrblib/class.rb +26 -0
  1251. data/modules/mruby/mrblib/compar.rb +104 -0
  1252. data/modules/mruby/mrblib/enum.rb +398 -0
  1253. data/modules/mruby/mrblib/error.rb +66 -0
  1254. data/modules/mruby/mrblib/hash.rb +193 -0
  1255. data/modules/mruby/mrblib/init_mrblib.c +14 -0
  1256. data/modules/mruby/mrblib/kernel.rb +46 -0
  1257. data/modules/mruby/mrblib/mrblib.rake +18 -0
  1258. data/modules/mruby/mrblib/numeric.rb +101 -0
  1259. data/modules/mruby/mrblib/print.rb +18 -0
  1260. data/modules/mruby/mrblib/range.rb +40 -0
  1261. data/modules/mruby/mrblib/string.rb +145 -0
  1262. data/modules/mruby/src/array.c +1150 -0
  1263. data/modules/mruby/src/backtrace.c +73 -0
  1264. data/modules/mruby/src/class.c +1942 -0
  1265. data/modules/mruby/src/codegen.c +2864 -0
  1266. data/modules/mruby/src/compar.c +13 -0
  1267. data/modules/mruby/src/crc.c +38 -0
  1268. data/modules/mruby/src/dump.c +542 -0
  1269. data/modules/mruby/src/enum.c +14 -0
  1270. data/modules/mruby/src/error.c +454 -0
  1271. data/modules/mruby/src/error.h +18 -0
  1272. data/modules/mruby/src/etc.c +204 -0
  1273. data/modules/mruby/src/gc.c +1542 -0
  1274. data/modules/mruby/src/hash.c +1261 -0
  1275. data/modules/mruby/src/init.c +62 -0
  1276. data/modules/mruby/src/kernel.c +1105 -0
  1277. data/modules/mruby/src/keywords +50 -0
  1278. data/modules/mruby/src/lex.def +212 -0
  1279. data/modules/mruby/src/load.c +629 -0
  1280. data/modules/mruby/src/mruby_core.rake +28 -0
  1281. data/modules/mruby/src/node.h +117 -0
  1282. data/modules/mruby/src/numeric.c +1418 -0
  1283. data/modules/mruby/src/object.c +593 -0
  1284. data/modules/mruby/src/opcode.h +160 -0
  1285. data/modules/mruby/src/parse.y +6050 -0
  1286. data/modules/mruby/src/pool.c +190 -0
  1287. data/modules/mruby/src/print.c +71 -0
  1288. data/modules/mruby/src/proc.c +209 -0
  1289. data/modules/mruby/src/range.c +442 -0
  1290. data/modules/mruby/src/re.h +13 -0
  1291. data/modules/mruby/src/state.c +200 -0
  1292. data/modules/mruby/src/string.c +2580 -0
  1293. data/modules/mruby/src/symbol.c +456 -0
  1294. data/modules/mruby/src/value_array.h +27 -0
  1295. data/modules/mruby/src/variable.c +1147 -0
  1296. data/modules/mruby/src/vm.c +2129 -0
  1297. data/modules/mruby/tasks/libmruby.rake +18 -0
  1298. data/modules/mruby/tasks/mrbgem_spec.rake +297 -0
  1299. data/modules/mruby/tasks/mrbgems.rake +85 -0
  1300. data/modules/mruby/tasks/mrbgems_test.rake +88 -0
  1301. data/modules/mruby/tasks/mruby_build.rake +211 -0
  1302. data/modules/mruby/tasks/mruby_build_commands.rake +287 -0
  1303. data/modules/mruby/tasks/mruby_build_gem.rake +67 -0
  1304. data/modules/mruby/tasks/ruby_ext.rake +70 -0
  1305. data/modules/mruby/tasks/toolchains/androideabi.rake +126 -0
  1306. data/modules/mruby/tasks/toolchains/clang.rake +8 -0
  1307. data/modules/mruby/tasks/toolchains/gcc.rake +21 -0
  1308. data/modules/mruby/tasks/toolchains/vs2010.rake +3 -0
  1309. data/modules/mruby/tasks/toolchains/vs2012.rake +44 -0
  1310. data/modules/mruby/test/README.md +7 -0
  1311. data/modules/mruby/test/assert.rb +238 -0
  1312. data/modules/mruby/test/driver.c +118 -0
  1313. data/modules/mruby/test/init_mrbtest.c +24 -0
  1314. data/modules/mruby/test/mrbtest.rake +47 -0
  1315. data/modules/mruby/test/report.rb +4 -0
  1316. data/modules/mruby/test/t/argumenterror.rb +21 -0
  1317. data/modules/mruby/test/t/array.rb +309 -0
  1318. data/modules/mruby/test/t/basicobject.rb +11 -0
  1319. data/modules/mruby/test/t/bs_block.rb +489 -0
  1320. data/modules/mruby/test/t/bs_literal.rb +38 -0
  1321. data/modules/mruby/test/t/class.rb +219 -0
  1322. data/modules/mruby/test/t/comparable.rb +72 -0
  1323. data/modules/mruby/test/t/enumerable.rb +108 -0
  1324. data/modules/mruby/test/t/exception.rb +337 -0
  1325. data/modules/mruby/test/t/false.rb +33 -0
  1326. data/modules/mruby/test/t/float.rb +145 -0
  1327. data/modules/mruby/test/t/gc.rb +45 -0
  1328. data/modules/mruby/test/t/hash.rb +310 -0
  1329. data/modules/mruby/test/t/indexerror.rb +10 -0
  1330. data/modules/mruby/test/t/integer.rb +222 -0
  1331. data/modules/mruby/test/t/kernel.rb +425 -0
  1332. data/modules/mruby/test/t/literals.rb +287 -0
  1333. data/modules/mruby/test/t/localjumperror.rb +13 -0
  1334. data/modules/mruby/test/t/methods.rb +109 -0
  1335. data/modules/mruby/test/t/module.rb +344 -0
  1336. data/modules/mruby/test/t/nameerror.rb +32 -0
  1337. data/modules/mruby/test/t/nil.rb +29 -0
  1338. data/modules/mruby/test/t/nomethoderror.rb +13 -0
  1339. data/modules/mruby/test/t/numeric.rb +29 -0
  1340. data/modules/mruby/test/t/object.rb +11 -0
  1341. data/modules/mruby/test/t/proc.rb +56 -0
  1342. data/modules/mruby/test/t/range.rb +82 -0
  1343. data/modules/mruby/test/t/rangeerror.rb +10 -0
  1344. data/modules/mruby/test/t/regexperror.rb +4 -0
  1345. data/modules/mruby/test/t/runtimeerror.rb +6 -0
  1346. data/modules/mruby/test/t/standarderror.rb +10 -0
  1347. data/modules/mruby/test/t/string.rb +483 -0
  1348. data/modules/mruby/test/t/symbol.rb +27 -0
  1349. data/modules/mruby/test/t/syntax.rb +67 -0
  1350. data/modules/mruby/test/t/true.rb +33 -0
  1351. data/modules/mruby/test/t/typeerror.rb +11 -0
  1352. data/modules/mruby/tools/mrbc/mrbc.c +318 -0
  1353. data/modules/mruby/tools/mrbc/mrbc.rake +14 -0
  1354. data/modules/mruby/travis_config.rb +6 -0
  1355. data/modules/mrubymix/LICENSE +21 -0
  1356. data/modules/mrubymix/README.md +6 -0
  1357. data/modules/mrubymix/bin/mrubymix +29 -0
  1358. data/modules/mrubymix/lib/mrubymix.rb +93 -0
  1359. data/modules/mrubymix/mrubymix.gemspec +13 -0
  1360. data/scripts/gen_gems_config.rb +185 -0
  1361. data/scripts/gen_post.rb +104 -0
  1362. data/templates/minimal/Rakefile +36 -0
  1363. data/templates/minimal/app/app.rb +3 -0
  1364. metadata +1408 -0
@@ -0,0 +1,3262 @@
1
+ <html>
2
+ <head>
3
+ <title>PLY (Python Lex-Yacc)</title>
4
+ </head>
5
+ <body bgcolor="#ffffff">
6
+
7
+ <h1>PLY (Python Lex-Yacc)</h1>
8
+
9
+ <b>
10
+ David M. Beazley <br>
11
+ dave@dabeaz.com<br>
12
+ </b>
13
+
14
+ <p>
15
+ <b>PLY Version: 3.4</b>
16
+ <p>
17
+
18
+ <!-- INDEX -->
19
+ <div class="sectiontoc">
20
+ <ul>
21
+ <li><a href="#ply_nn1">Preface and Requirements</a>
22
+ <li><a href="#ply_nn1">Introduction</a>
23
+ <li><a href="#ply_nn2">PLY Overview</a>
24
+ <li><a href="#ply_nn3">Lex</a>
25
+ <ul>
26
+ <li><a href="#ply_nn4">Lex Example</a>
27
+ <li><a href="#ply_nn5">The tokens list</a>
28
+ <li><a href="#ply_nn6">Specification of tokens</a>
29
+ <li><a href="#ply_nn7">Token values</a>
30
+ <li><a href="#ply_nn8">Discarded tokens</a>
31
+ <li><a href="#ply_nn9">Line numbers and positional information</a>
32
+ <li><a href="#ply_nn10">Ignored characters</a>
33
+ <li><a href="#ply_nn11">Literal characters</a>
34
+ <li><a href="#ply_nn12">Error handling</a>
35
+ <li><a href="#ply_nn13">Building and using the lexer</a>
36
+ <li><a href="#ply_nn14">The @TOKEN decorator</a>
37
+ <li><a href="#ply_nn15">Optimized mode</a>
38
+ <li><a href="#ply_nn16">Debugging</a>
39
+ <li><a href="#ply_nn17">Alternative specification of lexers</a>
40
+ <li><a href="#ply_nn18">Maintaining state</a>
41
+ <li><a href="#ply_nn19">Lexer cloning</a>
42
+ <li><a href="#ply_nn20">Internal lexer state</a>
43
+ <li><a href="#ply_nn21">Conditional lexing and start conditions</a>
44
+ <li><a href="#ply_nn21">Miscellaneous Issues</a>
45
+ </ul>
46
+ <li><a href="#ply_nn22">Parsing basics</a>
47
+ <li><a href="#ply_nn23">Yacc</a>
48
+ <ul>
49
+ <li><a href="#ply_nn24">An example</a>
50
+ <li><a href="#ply_nn25">Combining Grammar Rule Functions</a>
51
+ <li><a href="#ply_nn26">Character Literals</a>
52
+ <li><a href="#ply_nn26">Empty Productions</a>
53
+ <li><a href="#ply_nn28">Changing the starting symbol</a>
54
+ <li><a href="#ply_nn27">Dealing With Ambiguous Grammars</a>
55
+ <li><a href="#ply_nn28">The parser.out file</a>
56
+ <li><a href="#ply_nn29">Syntax Error Handling</a>
57
+ <ul>
58
+ <li><a href="#ply_nn30">Recovery and resynchronization with error rules</a>
59
+ <li><a href="#ply_nn31">Panic mode recovery</a>
60
+ <li><a href="#ply_nn35">Signaling an error from a production</a>
61
+ <li><a href="#ply_nn32">General comments on error handling</a>
62
+ </ul>
63
+ <li><a href="#ply_nn33">Line Number and Position Tracking</a>
64
+ <li><a href="#ply_nn34">AST Construction</a>
65
+ <li><a href="#ply_nn35">Embedded Actions</a>
66
+ <li><a href="#ply_nn36">Miscellaneous Yacc Notes</a>
67
+ </ul>
68
+ <li><a href="#ply_nn37">Multiple Parsers and Lexers</a>
69
+ <li><a href="#ply_nn38">Using Python's Optimized Mode</a>
70
+ <li><a href="#ply_nn44">Advanced Debugging</a>
71
+ <ul>
72
+ <li><a href="#ply_nn45">Debugging the lex() and yacc() commands</a>
73
+ <li><a href="#ply_nn46">Run-time Debugging</a>
74
+ </ul>
75
+ <li><a href="#ply_nn39">Where to go from here?</a>
76
+ </ul>
77
+ </div>
78
+ <!-- INDEX -->
79
+
80
+
81
+
82
+ <H2><a name="ply_nn1"></a>1. Preface and Requirements</H2>
83
+
84
+
85
+ <p>
86
+ This document provides an overview of lexing and parsing with PLY.
87
+ Given the intrinsic complexity of parsing, I would strongly advise
88
+ that you read (or at least skim) this entire document before jumping
89
+ into a big development project with PLY.
90
+ </p>
91
+
92
+ <p>
93
+ PLY-3.0 is compatible with both Python 2 and Python 3. Be aware that
94
+ Python 3 support is new and has not been extensively tested (although
95
+ all of the examples and unit tests pass under Python 3.0). If you are
96
+ using Python 2, you should try to use Python 2.4 or newer. Although PLY
97
+ works with versions as far back as Python 2.2, some of its optional features
98
+ require more modern library modules.
99
+ </p>
100
+
101
+ <H2><a name="ply_nn1"></a>2. Introduction</H2>
102
+
103
+
104
+ PLY is a pure-Python implementation of the popular compiler
105
+ construction tools lex and yacc. The main goal of PLY is to stay
106
+ fairly faithful to the way in which traditional lex/yacc tools work.
107
+ This includes supporting LALR(1) parsing as well as providing
108
+ extensive input validation, error reporting, and diagnostics. Thus,
109
+ if you've used yacc in another programming language, it should be
110
+ relatively straightforward to use PLY.
111
+
112
+ <p>
113
+ Early versions of PLY were developed to support an Introduction to
114
+ Compilers Course I taught in 2001 at the University of Chicago. In this course,
115
+ students built a fully functional compiler for a simple Pascal-like
116
+ language. Their compiler, implemented entirely in Python, had to
117
+ include lexical analysis, parsing, type checking, type inference,
118
+ nested scoping, and code generation for the SPARC processor.
119
+ Approximately 30 different compiler implementations were completed in
120
+ this course. Most of PLY's interface and operation has been influenced by common
121
+ usability problems encountered by students. Since 2001, PLY has
122
+ continued to be improved as feedback has been received from users.
123
+ PLY-3.0 represents a major refactoring of the original implementation
124
+ with an eye towards future enhancements.
125
+
126
+ <p>
127
+ Since PLY was primarily developed as an instructional tool, you will
128
+ find it to be fairly picky about token and grammar rule
129
+ specification. In part, this
130
+ added formality is meant to catch common programming mistakes made by
131
+ novice users. However, advanced users will also find such features to
132
+ be useful when building complicated grammars for real programming
133
+ languages. It should also be noted that PLY does not provide much in
134
+ the way of bells and whistles (e.g., automatic construction of
135
+ abstract syntax trees, tree traversal, etc.). Nor would I consider it
136
+ to be a parsing framework. Instead, you will find a bare-bones, yet
137
+ fully capable lex/yacc implementation written entirely in Python.
138
+
139
+ <p>
140
+ The rest of this document assumes that you are somewhat familar with
141
+ parsing theory, syntax directed translation, and the use of compiler
142
+ construction tools such as lex and yacc in other programming
143
+ languages. If you are unfamilar with these topics, you will probably
144
+ want to consult an introductory text such as "Compilers: Principles,
145
+ Techniques, and Tools", by Aho, Sethi, and Ullman. O'Reilly's "Lex
146
+ and Yacc" by John Levine may also be handy. In fact, the O'Reilly book can be
147
+ used as a reference for PLY as the concepts are virtually identical.
148
+
149
+ <H2><a name="ply_nn2"></a>3. PLY Overview</H2>
150
+
151
+
152
+ PLY consists of two separate modules; <tt>lex.py</tt> and
153
+ <tt>yacc.py</tt>, both of which are found in a Python package
154
+ called <tt>ply</tt>. The <tt>lex.py</tt> module is used to break input text into a
155
+ collection of tokens specified by a collection of regular expression
156
+ rules. <tt>yacc.py</tt> is used to recognize language syntax that has
157
+ been specified in the form of a context free grammar. <tt>yacc.py</tt> uses LR parsing and generates its parsing tables
158
+ using either the LALR(1) (the default) or SLR table generation algorithms.
159
+
160
+ <p>
161
+ The two tools are meant to work together. Specifically,
162
+ <tt>lex.py</tt> provides an external interface in the form of a
163
+ <tt>token()</tt> function that returns the next valid token on the
164
+ input stream. <tt>yacc.py</tt> calls this repeatedly to retrieve
165
+ tokens and invoke grammar rules. The output of <tt>yacc.py</tt> is
166
+ often an Abstract Syntax Tree (AST). However, this is entirely up to
167
+ the user. If desired, <tt>yacc.py</tt> can also be used to implement
168
+ simple one-pass compilers.
169
+
170
+ <p>
171
+ Like its Unix counterpart, <tt>yacc.py</tt> provides most of the
172
+ features you expect including extensive error checking, grammar
173
+ validation, support for empty productions, error tokens, and ambiguity
174
+ resolution via precedence rules. In fact, everything that is possible in traditional yacc
175
+ should be supported in PLY.
176
+
177
+ <p>
178
+ The primary difference between
179
+ <tt>yacc.py</tt> and Unix <tt>yacc</tt> is that <tt>yacc.py</tt>
180
+ doesn't involve a separate code-generation process.
181
+ Instead, PLY relies on reflection (introspection)
182
+ to build its lexers and parsers. Unlike traditional lex/yacc which
183
+ require a special input file that is converted into a separate source
184
+ file, the specifications given to PLY <em>are</em> valid Python
185
+ programs. This means that there are no extra source files nor is
186
+ there a special compiler construction step (e.g., running yacc to
187
+ generate Python code for the compiler). Since the generation of the
188
+ parsing tables is relatively expensive, PLY caches the results and
189
+ saves them to a file. If no changes are detected in the input source,
190
+ the tables are read from the cache. Otherwise, they are regenerated.
191
+
192
+ <H2><a name="ply_nn3"></a>4. Lex</H2>
193
+
194
+
195
+ <tt>lex.py</tt> is used to tokenize an input string. For example, suppose
196
+ you're writing a programming language and a user supplied the following input string:
197
+
198
+ <blockquote>
199
+ <pre>
200
+ x = 3 + 42 * (s - t)
201
+ </pre>
202
+ </blockquote>
203
+
204
+ A tokenizer splits the string into individual tokens
205
+
206
+ <blockquote>
207
+ <pre>
208
+ 'x','=', '3', '+', '42', '*', '(', 's', '-', 't', ')'
209
+ </pre>
210
+ </blockquote>
211
+
212
+ Tokens are usually given names to indicate what they are. For example:
213
+
214
+ <blockquote>
215
+ <pre>
216
+ 'ID','EQUALS','NUMBER','PLUS','NUMBER','TIMES',
217
+ 'LPAREN','ID','MINUS','ID','RPAREN'
218
+ </pre>
219
+ </blockquote>
220
+
221
+ More specifically, the input is broken into pairs of token types and values. For example:
222
+
223
+ <blockquote>
224
+ <pre>
225
+ ('ID','x'), ('EQUALS','='), ('NUMBER','3'),
226
+ ('PLUS','+'), ('NUMBER','42), ('TIMES','*'),
227
+ ('LPAREN','('), ('ID','s'), ('MINUS','-'),
228
+ ('ID','t'), ('RPAREN',')'
229
+ </pre>
230
+ </blockquote>
231
+
232
+ The identification of tokens is typically done by writing a series of regular expression
233
+ rules. The next section shows how this is done using <tt>lex.py</tt>.
234
+
235
+ <H3><a name="ply_nn4"></a>4.1 Lex Example</H3>
236
+
237
+
238
+ The following example shows how <tt>lex.py</tt> is used to write a simple tokenizer.
239
+
240
+ <blockquote>
241
+ <pre>
242
+ # ------------------------------------------------------------
243
+ # calclex.py
244
+ #
245
+ # tokenizer for a simple expression evaluator for
246
+ # numbers and +,-,*,/
247
+ # ------------------------------------------------------------
248
+ import ply.lex as lex
249
+
250
+ # List of token names. This is always required
251
+ tokens = (
252
+ 'NUMBER',
253
+ 'PLUS',
254
+ 'MINUS',
255
+ 'TIMES',
256
+ 'DIVIDE',
257
+ 'LPAREN',
258
+ 'RPAREN',
259
+ )
260
+
261
+ # Regular expression rules for simple tokens
262
+ t_PLUS = r'\+'
263
+ t_MINUS = r'-'
264
+ t_TIMES = r'\*'
265
+ t_DIVIDE = r'/'
266
+ t_LPAREN = r'\('
267
+ t_RPAREN = r'\)'
268
+
269
+ # A regular expression rule with some action code
270
+ def t_NUMBER(t):
271
+ r'\d+'
272
+ t.value = int(t.value)
273
+ return t
274
+
275
+ # Define a rule so we can track line numbers
276
+ def t_newline(t):
277
+ r'\n+'
278
+ t.lexer.lineno += len(t.value)
279
+
280
+ # A string containing ignored characters (spaces and tabs)
281
+ t_ignore = ' \t'
282
+
283
+ # Error handling rule
284
+ def t_error(t):
285
+ print "Illegal character '%s'" % t.value[0]
286
+ t.lexer.skip(1)
287
+
288
+ # Build the lexer
289
+ lexer = lex.lex()
290
+
291
+ </pre>
292
+ </blockquote>
293
+ To use the lexer, you first need to feed it some input text using
294
+ its <tt>input()</tt> method. After that, repeated calls
295
+ to <tt>token()</tt> produce tokens. The following code shows how this
296
+ works:
297
+
298
+ <blockquote>
299
+ <pre>
300
+
301
+ # Test it out
302
+ data = '''
303
+ 3 + 4 * 10
304
+ + -20 *2
305
+ '''
306
+
307
+ # Give the lexer some input
308
+ lexer.input(data)
309
+
310
+ # Tokenize
311
+ while True:
312
+ tok = lexer.token()
313
+ if not tok: break # No more input
314
+ print tok
315
+ </pre>
316
+ </blockquote>
317
+
318
+ When executed, the example will produce the following output:
319
+
320
+ <blockquote>
321
+ <pre>
322
+ $ python example.py
323
+ LexToken(NUMBER,3,2,1)
324
+ LexToken(PLUS,'+',2,3)
325
+ LexToken(NUMBER,4,2,5)
326
+ LexToken(TIMES,'*',2,7)
327
+ LexToken(NUMBER,10,2,10)
328
+ LexToken(PLUS,'+',3,14)
329
+ LexToken(MINUS,'-',3,16)
330
+ LexToken(NUMBER,20,3,18)
331
+ LexToken(TIMES,'*',3,20)
332
+ LexToken(NUMBER,2,3,21)
333
+ </pre>
334
+ </blockquote>
335
+
336
+ Lexers also support the iteration protocol. So, you can write the above loop as follows:
337
+
338
+ <blockquote>
339
+ <pre>
340
+ for tok in lexer:
341
+ print tok
342
+ </pre>
343
+ </blockquote>
344
+
345
+ The tokens returned by <tt>lexer.token()</tt> are instances
346
+ of <tt>LexToken</tt>. This object has
347
+ attributes <tt>tok.type</tt>, <tt>tok.value</tt>,
348
+ <tt>tok.lineno</tt>, and <tt>tok.lexpos</tt>. The following code shows an example of
349
+ accessing these attributes:
350
+
351
+ <blockquote>
352
+ <pre>
353
+ # Tokenize
354
+ while True:
355
+ tok = lexer.token()
356
+ if not tok: break # No more input
357
+ print tok.type, tok.value, tok.line, tok.lexpos
358
+ </pre>
359
+ </blockquote>
360
+
361
+ The <tt>tok.type</tt> and <tt>tok.value</tt> attributes contain the
362
+ type and value of the token itself.
363
+ <tt>tok.line</tt> and <tt>tok.lexpos</tt> contain information about
364
+ the location of the token. <tt>tok.lexpos</tt> is the index of the
365
+ token relative to the start of the input text.
366
+
367
+ <H3><a name="ply_nn5"></a>4.2 The tokens list</H3>
368
+
369
+
370
+ All lexers must provide a list <tt>tokens</tt> that defines all of the possible token
371
+ names that can be produced by the lexer. This list is always required
372
+ and is used to perform a variety of validation checks. The tokens list is also used by the
373
+ <tt>yacc.py</tt> module to identify terminals.
374
+
375
+ <p>
376
+ In the example, the following code specified the token names:
377
+
378
+ <blockquote>
379
+ <pre>
380
+ tokens = (
381
+ 'NUMBER',
382
+ 'PLUS',
383
+ 'MINUS',
384
+ 'TIMES',
385
+ 'DIVIDE',
386
+ 'LPAREN',
387
+ 'RPAREN',
388
+ )
389
+ </pre>
390
+ </blockquote>
391
+
392
+ <H3><a name="ply_nn6"></a>4.3 Specification of tokens</H3>
393
+
394
+
395
+ Each token is specified by writing a regular expression rule. Each of these rules are
396
+ are defined by making declarations with a special prefix <tt>t_</tt> to indicate that it
397
+ defines a token. For simple tokens, the regular expression can
398
+ be specified as strings such as this (note: Python raw strings are used since they are the
399
+ most convenient way to write regular expression strings):
400
+
401
+ <blockquote>
402
+ <pre>
403
+ t_PLUS = r'\+'
404
+ </pre>
405
+ </blockquote>
406
+
407
+ In this case, the name following the <tt>t_</tt> must exactly match one of the
408
+ names supplied in <tt>tokens</tt>. If some kind of action needs to be performed,
409
+ a token rule can be specified as a function. For example, this rule matches numbers and
410
+ converts the string into a Python integer.
411
+
412
+ <blockquote>
413
+ <pre>
414
+ def t_NUMBER(t):
415
+ r'\d+'
416
+ t.value = int(t.value)
417
+ return t
418
+ </pre>
419
+ </blockquote>
420
+
421
+ When a function is used, the regular expression rule is specified in the function documentation string.
422
+ The function always takes a single argument which is an instance of
423
+ <tt>LexToken</tt>. This object has attributes of <tt>t.type</tt> which is the token type (as a string),
424
+ <tt>t.value</tt> which is the lexeme (the actual text matched), <tt>t.lineno</tt> which is the current line number, and <tt>t.lexpos</tt> which
425
+ is the position of the token relative to the beginning of the input text.
426
+ By default, <tt>t.type</tt> is set to the name following the <tt>t_</tt> prefix. The action
427
+ function can modify the contents of the <tt>LexToken</tt> object as appropriate. However,
428
+ when it is done, the resulting token should be returned. If no value is returned by the action
429
+ function, the token is simply discarded and the next token read.
430
+
431
+ <p>
432
+ Internally, <tt>lex.py</tt> uses the <tt>re</tt> module to do its patten matching. When building the master regular expression,
433
+ rules are added in the following order:
434
+ <p>
435
+ <ol>
436
+ <li>All tokens defined by functions are added in the same order as they appear in the lexer file.
437
+ <li>Tokens defined by strings are added next by sorting them in order of decreasing regular expression length (longer expressions
438
+ are added first).
439
+ </ol>
440
+ <p>
441
+ Without this ordering, it can be difficult to correctly match certain types of tokens. For example, if you
442
+ wanted to have separate tokens for "=" and "==", you need to make sure that "==" is checked first. By sorting regular
443
+ expressions in order of decreasing length, this problem is solved for rules defined as strings. For functions,
444
+ the order can be explicitly controlled since rules appearing first are checked first.
445
+
446
+ <p>
447
+ To handle reserved words, you should write a single rule to match an
448
+ identifier and do a special name lookup in a function like this:
449
+
450
+ <blockquote>
451
+ <pre>
452
+ reserved = {
453
+ 'if' : 'IF',
454
+ 'then' : 'THEN',
455
+ 'else' : 'ELSE',
456
+ 'while' : 'WHILE',
457
+ ...
458
+ }
459
+
460
+ tokens = ['LPAREN','RPAREN',...,'ID'] + list(reserved.values())
461
+
462
+ def t_ID(t):
463
+ r'[a-zA-Z_][a-zA-Z_0-9]*'
464
+ t.type = reserved.get(t.value,'ID') # Check for reserved words
465
+ return t
466
+ </pre>
467
+ </blockquote>
468
+
469
+ This approach greatly reduces the number of regular expression rules and is likely to make things a little faster.
470
+
471
+ <p>
472
+ <b>Note:</b> You should avoid writing individual rules for reserved words. For example, if you write rules like this,
473
+
474
+ <blockquote>
475
+ <pre>
476
+ t_FOR = r'for'
477
+ t_PRINT = r'print'
478
+ </pre>
479
+ </blockquote>
480
+
481
+ those rules will be triggered for identifiers that include those words as a prefix such as "forget" or "printed". This is probably not
482
+ what you want.
483
+
484
+ <H3><a name="ply_nn7"></a>4.4 Token values</H3>
485
+
486
+
487
+ When tokens are returned by lex, they have a value that is stored in the <tt>value</tt> attribute. Normally, the value is the text
488
+ that was matched. However, the value can be assigned to any Python object. For instance, when lexing identifiers, you may
489
+ want to return both the identifier name and information from some sort of symbol table. To do this, you might write a rule like this:
490
+
491
+ <blockquote>
492
+ <pre>
493
+ def t_ID(t):
494
+ ...
495
+ # Look up symbol table information and return a tuple
496
+ t.value = (t.value, symbol_lookup(t.value))
497
+ ...
498
+ return t
499
+ </pre>
500
+ </blockquote>
501
+
502
+ It is important to note that storing data in other attribute names is <em>not</em> recommended. The <tt>yacc.py</tt> module only exposes the
503
+ contents of the <tt>value</tt> attribute. Thus, accessing other attributes may be unnecessarily awkward. If you
504
+ need to store multiple values on a token, assign a tuple, dictionary, or instance to <tt>value</tt>.
505
+
506
+ <H3><a name="ply_nn8"></a>4.5 Discarded tokens</H3>
507
+
508
+
509
+ To discard a token, such as a comment, simply define a token rule that returns no value. For example:
510
+
511
+ <blockquote>
512
+ <pre>
513
+ def t_COMMENT(t):
514
+ r'\#.*'
515
+ pass
516
+ # No return value. Token discarded
517
+ </pre>
518
+ </blockquote>
519
+
520
+ Alternatively, you can include the prefix "ignore_" in the token declaration to force a token to be ignored. For example:
521
+
522
+ <blockquote>
523
+ <pre>
524
+ t_ignore_COMMENT = r'\#.*'
525
+ </pre>
526
+ </blockquote>
527
+
528
+ Be advised that if you are ignoring many different kinds of text, you may still want to use functions since these provide more precise
529
+ control over the order in which regular expressions are matched (i.e., functions are matched in order of specification whereas strings are
530
+ sorted by regular expression length).
531
+
532
+ <H3><a name="ply_nn9"></a>4.6 Line numbers and positional information</H3>
533
+
534
+
535
+ <p>By default, <tt>lex.py</tt> knows nothing about line numbers. This is because <tt>lex.py</tt> doesn't know anything
536
+ about what constitutes a "line" of input (e.g., the newline character or even if the input is textual data).
537
+ To update this information, you need to write a special rule. In the example, the <tt>t_newline()</tt> rule shows how to do this.
538
+
539
+ <blockquote>
540
+ <pre>
541
+ # Define a rule so we can track line numbers
542
+ def t_newline(t):
543
+ r'\n+'
544
+ t.lexer.lineno += len(t.value)
545
+ </pre>
546
+ </blockquote>
547
+ Within the rule, the <tt>lineno</tt> attribute of the underlying lexer <tt>t.lexer</tt> is updated.
548
+ After the line number is updated, the token is simply discarded since nothing is returned.
549
+
550
+ <p>
551
+ <tt>lex.py</tt> does not perform and kind of automatic column tracking. However, it does record positional
552
+ information related to each token in the <tt>lexpos</tt> attribute. Using this, it is usually possible to compute
553
+ column information as a separate step. For instance, just count backwards until you reach a newline.
554
+
555
+ <blockquote>
556
+ <pre>
557
+ # Compute column.
558
+ # input is the input text string
559
+ # token is a token instance
560
+ def find_column(input,token):
561
+ last_cr = input.rfind('\n',0,token.lexpos)
562
+ if last_cr < 0:
563
+ last_cr = 0
564
+ column = (token.lexpos - last_cr) + 1
565
+ return column
566
+ </pre>
567
+ </blockquote>
568
+
569
+ Since column information is often only useful in the context of error handling, calculating the column
570
+ position can be performed when needed as opposed to doing it for each token.
571
+
572
+ <H3><a name="ply_nn10"></a>4.7 Ignored characters</H3>
573
+
574
+
575
+ <p>
576
+ The special <tt>t_ignore</tt> rule is reserved by <tt>lex.py</tt> for characters
577
+ that should be completely ignored in the input stream.
578
+ Usually this is used to skip over whitespace and other non-essential characters.
579
+ Although it is possible to define a regular expression rule for whitespace in a manner
580
+ similar to <tt>t_newline()</tt>, the use of <tt>t_ignore</tt> provides substantially better
581
+ lexing performance because it is handled as a special case and is checked in a much
582
+ more efficient manner than the normal regular expression rules.
583
+
584
+ <H3><a name="ply_nn11"></a>4.8 Literal characters</H3>
585
+
586
+
587
+ <p>
588
+ Literal characters can be specified by defining a variable <tt>literals</tt> in your lexing module. For example:
589
+
590
+ <blockquote>
591
+ <pre>
592
+ literals = [ '+','-','*','/' ]
593
+ </pre>
594
+ </blockquote>
595
+
596
+ or alternatively
597
+
598
+ <blockquote>
599
+ <pre>
600
+ literals = "+-*/"
601
+ </pre>
602
+ </blockquote>
603
+
604
+ A literal character is simply a single character that is returned "as is" when encountered by the lexer. Literals are checked
605
+ after all of the defined regular expression rules. Thus, if a rule starts with one of the literal characters, it will always
606
+ take precedence.
607
+ <p>
608
+ When a literal token is returned, both its <tt>type</tt> and <tt>value</tt> attributes are set to the character itself. For example, <tt>'+'</tt>.
609
+
610
+ <H3><a name="ply_nn12"></a>4.9 Error handling</H3>
611
+
612
+
613
+ <p>
614
+ Finally, the <tt>t_error()</tt>
615
+ function is used to handle lexing errors that occur when illegal
616
+ characters are detected. In this case, the <tt>t.value</tt> attribute contains the
617
+ rest of the input string that has not been tokenized. In the example, the error function
618
+ was defined as follows:
619
+
620
+ <blockquote>
621
+ <pre>
622
+ # Error handling rule
623
+ def t_error(t):
624
+ print "Illegal character '%s'" % t.value[0]
625
+ t.lexer.skip(1)
626
+ </pre>
627
+ </blockquote>
628
+
629
+ In this case, we simply print the offending character and skip ahead one character by calling <tt>t.lexer.skip(1)</tt>.
630
+
631
+ <H3><a name="ply_nn13"></a>4.10 Building and using the lexer</H3>
632
+
633
+
634
+ <p>
635
+ To build the lexer, the function <tt>lex.lex()</tt> is used. This function
636
+ uses Python reflection (or introspection) to read the the regular expression rules
637
+ out of the calling context and build the lexer. Once the lexer has been built, two methods can
638
+ be used to control the lexer.
639
+
640
+ <ul>
641
+ <li><tt>lexer.input(data)</tt>. Reset the lexer and store a new input string.
642
+ <li><tt>lexer.token()</tt>. Return the next token. Returns a special <tt>LexToken</tt> instance on success or
643
+ None if the end of the input text has been reached.
644
+ </ul>
645
+
646
+ The preferred way to use PLY is to invoke the above methods directly on the lexer object returned by the
647
+ <tt>lex()</tt> function. The legacy interface to PLY involves module-level functions <tt>lex.input()</tt> and <tt>lex.token()</tt>.
648
+ For example:
649
+
650
+ <blockquote>
651
+ <pre>
652
+ lex.lex()
653
+ lex.input(sometext)
654
+ while 1:
655
+ tok = lex.token()
656
+ if not tok: break
657
+ print tok
658
+ </pre>
659
+ </blockquote>
660
+
661
+ <p>
662
+ In this example, the module-level functions <tt>lex.input()</tt> and <tt>lex.token()</tt> are bound to the <tt>input()</tt>
663
+ and <tt>token()</tt> methods of the last lexer created by the lex module. This interface may go away at some point so
664
+ it's probably best not to use it.
665
+
666
+ <H3><a name="ply_nn14"></a>4.11 The @TOKEN decorator</H3>
667
+
668
+
669
+ In some applications, you may want to define build tokens from as a series of
670
+ more complex regular expression rules. For example:
671
+
672
+ <blockquote>
673
+ <pre>
674
+ digit = r'([0-9])'
675
+ nondigit = r'([_A-Za-z])'
676
+ identifier = r'(' + nondigit + r'(' + digit + r'|' + nondigit + r')*)'
677
+
678
+ def t_ID(t):
679
+ # want docstring to be identifier above. ?????
680
+ ...
681
+ </pre>
682
+ </blockquote>
683
+
684
+ In this case, we want the regular expression rule for <tt>ID</tt> to be one of the variables above. However, there is no
685
+ way to directly specify this using a normal documentation string. To solve this problem, you can use the <tt>@TOKEN</tt>
686
+ decorator. For example:
687
+
688
+ <blockquote>
689
+ <pre>
690
+ from ply.lex import TOKEN
691
+
692
+ @TOKEN(identifier)
693
+ def t_ID(t):
694
+ ...
695
+ </pre>
696
+ </blockquote>
697
+
698
+ This will attach <tt>identifier</tt> to the docstring for <tt>t_ID()</tt> allowing <tt>lex.py</tt> to work normally. An alternative
699
+ approach this problem is to set the docstring directly like this:
700
+
701
+ <blockquote>
702
+ <pre>
703
+ def t_ID(t):
704
+ ...
705
+
706
+ t_ID.__doc__ = identifier
707
+ </pre>
708
+ </blockquote>
709
+
710
+ <b>NOTE:</b> Use of <tt>@TOKEN</tt> requires Python-2.4 or newer. If you're concerned about backwards compatibility with older
711
+ versions of Python, use the alternative approach of setting the docstring directly.
712
+
713
+ <H3><a name="ply_nn15"></a>4.12 Optimized mode</H3>
714
+
715
+
716
+ For improved performance, it may be desirable to use Python's
717
+ optimized mode (e.g., running Python with the <tt>-O</tt>
718
+ option). However, doing so causes Python to ignore documentation
719
+ strings. This presents special problems for <tt>lex.py</tt>. To
720
+ handle this case, you can create your lexer using
721
+ the <tt>optimize</tt> option as follows:
722
+
723
+ <blockquote>
724
+ <pre>
725
+ lexer = lex.lex(optimize=1)
726
+ </pre>
727
+ </blockquote>
728
+
729
+ Next, run Python in its normal operating mode. When you do
730
+ this, <tt>lex.py</tt> will write a file called <tt>lextab.py</tt> to
731
+ the current directory. This file contains all of the regular
732
+ expression rules and tables used during lexing. On subsequent
733
+ executions,
734
+ <tt>lextab.py</tt> will simply be imported to build the lexer. This
735
+ approach substantially improves the startup time of the lexer and it
736
+ works in Python's optimized mode.
737
+
738
+ <p>
739
+ To change the name of the lexer-generated file, use the <tt>lextab</tt> keyword argument. For example:
740
+
741
+ <blockquote>
742
+ <pre>
743
+ lexer = lex.lex(optimize=1,lextab="footab")
744
+ </pre>
745
+ </blockquote>
746
+
747
+ When running in optimized mode, it is important to note that lex disables most error checking. Thus, this is really only recommended
748
+ if you're sure everything is working correctly and you're ready to start releasing production code.
749
+
750
+ <H3><a name="ply_nn16"></a>4.13 Debugging</H3>
751
+
752
+
753
+ For the purpose of debugging, you can run <tt>lex()</tt> in a debugging mode as follows:
754
+
755
+ <blockquote>
756
+ <pre>
757
+ lexer = lex.lex(debug=1)
758
+ </pre>
759
+ </blockquote>
760
+
761
+ <p>
762
+ This will produce various sorts of debugging information including all of the added rules,
763
+ the master regular expressions used by the lexer, and tokens generating during lexing.
764
+ </p>
765
+
766
+ <p>
767
+ In addition, <tt>lex.py</tt> comes with a simple main function which
768
+ will either tokenize input read from standard input or from a file specified
769
+ on the command line. To use it, simply put this in your lexer:
770
+ </p>
771
+
772
+ <blockquote>
773
+ <pre>
774
+ if __name__ == '__main__':
775
+ lex.runmain()
776
+ </pre>
777
+ </blockquote>
778
+
779
+ Please refer to the "Debugging" section near the end for some more advanced details
780
+ of debugging.
781
+
782
+ <H3><a name="ply_nn17"></a>4.14 Alternative specification of lexers</H3>
783
+
784
+
785
+ As shown in the example, lexers are specified all within one Python module. If you want to
786
+ put token rules in a different module from the one in which you invoke <tt>lex()</tt>, use the
787
+ <tt>module</tt> keyword argument.
788
+
789
+ <p>
790
+ For example, you might have a dedicated module that just contains
791
+ the token rules:
792
+
793
+ <blockquote>
794
+ <pre>
795
+ # module: tokrules.py
796
+ # This module just contains the lexing rules
797
+
798
+ # List of token names. This is always required
799
+ tokens = (
800
+ 'NUMBER',
801
+ 'PLUS',
802
+ 'MINUS',
803
+ 'TIMES',
804
+ 'DIVIDE',
805
+ 'LPAREN',
806
+ 'RPAREN',
807
+ )
808
+
809
+ # Regular expression rules for simple tokens
810
+ t_PLUS = r'\+'
811
+ t_MINUS = r'-'
812
+ t_TIMES = r'\*'
813
+ t_DIVIDE = r'/'
814
+ t_LPAREN = r'\('
815
+ t_RPAREN = r'\)'
816
+
817
+ # A regular expression rule with some action code
818
+ def t_NUMBER(t):
819
+ r'\d+'
820
+ t.value = int(t.value)
821
+ return t
822
+
823
+ # Define a rule so we can track line numbers
824
+ def t_newline(t):
825
+ r'\n+'
826
+ t.lexer.lineno += len(t.value)
827
+
828
+ # A string containing ignored characters (spaces and tabs)
829
+ t_ignore = ' \t'
830
+
831
+ # Error handling rule
832
+ def t_error(t):
833
+ print "Illegal character '%s'" % t.value[0]
834
+ t.lexer.skip(1)
835
+ </pre>
836
+ </blockquote>
837
+
838
+ Now, if you wanted to build a tokenizer from these rules from within a different module, you would do the following (shown for Python interactive mode):
839
+
840
+ <blockquote>
841
+ <pre>
842
+ >>> import tokrules
843
+ >>> <b>lexer = lex.lex(module=tokrules)</b>
844
+ >>> lexer.input("3 + 4")
845
+ >>> lexer.token()
846
+ LexToken(NUMBER,3,1,1,0)
847
+ >>> lexer.token()
848
+ LexToken(PLUS,'+',1,2)
849
+ >>> lexer.token()
850
+ LexToken(NUMBER,4,1,4)
851
+ >>> lexer.token()
852
+ None
853
+ >>>
854
+ </pre>
855
+ </blockquote>
856
+
857
+ The <tt>module</tt> option can also be used to define lexers from instances of a class. For example:
858
+
859
+ <blockquote>
860
+ <pre>
861
+ import ply.lex as lex
862
+
863
+ class MyLexer:
864
+ # List of token names. This is always required
865
+ tokens = (
866
+ 'NUMBER',
867
+ 'PLUS',
868
+ 'MINUS',
869
+ 'TIMES',
870
+ 'DIVIDE',
871
+ 'LPAREN',
872
+ 'RPAREN',
873
+ )
874
+
875
+ # Regular expression rules for simple tokens
876
+ t_PLUS = r'\+'
877
+ t_MINUS = r'-'
878
+ t_TIMES = r'\*'
879
+ t_DIVIDE = r'/'
880
+ t_LPAREN = r'\('
881
+ t_RPAREN = r'\)'
882
+
883
+ # A regular expression rule with some action code
884
+ # Note addition of self parameter since we're in a class
885
+ def t_NUMBER(self,t):
886
+ r'\d+'
887
+ t.value = int(t.value)
888
+ return t
889
+
890
+ # Define a rule so we can track line numbers
891
+ def t_newline(self,t):
892
+ r'\n+'
893
+ t.lexer.lineno += len(t.value)
894
+
895
+ # A string containing ignored characters (spaces and tabs)
896
+ t_ignore = ' \t'
897
+
898
+ # Error handling rule
899
+ def t_error(self,t):
900
+ print "Illegal character '%s'" % t.value[0]
901
+ t.lexer.skip(1)
902
+
903
+ <b># Build the lexer
904
+ def build(self,**kwargs):
905
+ self.lexer = lex.lex(module=self, **kwargs)</b>
906
+
907
+ # Test it output
908
+ def test(self,data):
909
+ self.lexer.input(data)
910
+ while True:
911
+ tok = lexer.token()
912
+ if not tok: break
913
+ print tok
914
+
915
+ # Build the lexer and try it out
916
+ m = MyLexer()
917
+ m.build() # Build the lexer
918
+ m.test("3 + 4") # Test it
919
+ </pre>
920
+ </blockquote>
921
+
922
+
923
+ When building a lexer from class, <em>you should construct the lexer from
924
+ an instance of the class</em>, not the class object itself. This is because
925
+ PLY only works properly if the lexer actions are defined by bound-methods.
926
+
927
+ <p>
928
+ When using the <tt>module</tt> option to <tt>lex()</tt>, PLY collects symbols
929
+ from the underlying object using the <tt>dir()</tt> function. There is no
930
+ direct access to the <tt>__dict__</tt> attribute of the object supplied as a
931
+ module value.
932
+
933
+ <P>
934
+ Finally, if you want to keep things nicely encapsulated, but don't want to use a
935
+ full-fledged class definition, lexers can be defined using closures. For example:
936
+
937
+ <blockquote>
938
+ <pre>
939
+ import ply.lex as lex
940
+
941
+ # List of token names. This is always required
942
+ tokens = (
943
+ 'NUMBER',
944
+ 'PLUS',
945
+ 'MINUS',
946
+ 'TIMES',
947
+ 'DIVIDE',
948
+ 'LPAREN',
949
+ 'RPAREN',
950
+ )
951
+
952
+ def MyLexer():
953
+ # Regular expression rules for simple tokens
954
+ t_PLUS = r'\+'
955
+ t_MINUS = r'-'
956
+ t_TIMES = r'\*'
957
+ t_DIVIDE = r'/'
958
+ t_LPAREN = r'\('
959
+ t_RPAREN = r'\)'
960
+
961
+ # A regular expression rule with some action code
962
+ def t_NUMBER(t):
963
+ r'\d+'
964
+ t.value = int(t.value)
965
+ return t
966
+
967
+ # Define a rule so we can track line numbers
968
+ def t_newline(t):
969
+ r'\n+'
970
+ t.lexer.lineno += len(t.value)
971
+
972
+ # A string containing ignored characters (spaces and tabs)
973
+ t_ignore = ' \t'
974
+
975
+ # Error handling rule
976
+ def t_error(t):
977
+ print "Illegal character '%s'" % t.value[0]
978
+ t.lexer.skip(1)
979
+
980
+ # Build the lexer from my environment and return it
981
+ return lex.lex()
982
+ </pre>
983
+ </blockquote>
984
+
985
+
986
+ <H3><a name="ply_nn18"></a>4.15 Maintaining state</H3>
987
+
988
+
989
+ In your lexer, you may want to maintain a variety of state
990
+ information. This might include mode settings, symbol tables, and
991
+ other details. As an example, suppose that you wanted to keep
992
+ track of how many NUMBER tokens had been encountered.
993
+
994
+ <p>
995
+ One way to do this is to keep a set of global variables in the module
996
+ where you created the lexer. For example:
997
+
998
+ <blockquote>
999
+ <pre>
1000
+ num_count = 0
1001
+ def t_NUMBER(t):
1002
+ r'\d+'
1003
+ global num_count
1004
+ num_count += 1
1005
+ t.value = int(t.value)
1006
+ return t
1007
+ </pre>
1008
+ </blockquote>
1009
+
1010
+ If you don't like the use of a global variable, another place to store
1011
+ information is inside the Lexer object created by <tt>lex()</tt>.
1012
+ To this, you can use the <tt>lexer</tt> attribute of tokens passed to
1013
+ the various rules. For example:
1014
+
1015
+ <blockquote>
1016
+ <pre>
1017
+ def t_NUMBER(t):
1018
+ r'\d+'
1019
+ t.lexer.num_count += 1 # Note use of lexer attribute
1020
+ t.value = int(t.value)
1021
+ return t
1022
+
1023
+ lexer = lex.lex()
1024
+ lexer.num_count = 0 # Set the initial count
1025
+ </pre>
1026
+ </blockquote>
1027
+
1028
+ This latter approach has the advantage of being simple and working
1029
+ correctly in applications where multiple instantiations of a given
1030
+ lexer exist in the same application. However, this might also feel
1031
+ like a gross violation of encapsulation to OO purists.
1032
+ Just to put your mind at some ease, all
1033
+ internal attributes of the lexer (with the exception of <tt>lineno</tt>) have names that are prefixed
1034
+ by <tt>lex</tt> (e.g., <tt>lexdata</tt>,<tt>lexpos</tt>, etc.). Thus,
1035
+ it is perfectly safe to store attributes in the lexer that
1036
+ don't have names starting with that prefix or a name that conlicts with one of the
1037
+ predefined methods (e.g., <tt>input()</tt>, <tt>token()</tt>, etc.).
1038
+
1039
+ <p>
1040
+ If you don't like assigning values on the lexer object, you can define your lexer as a class as
1041
+ shown in the previous section:
1042
+
1043
+ <blockquote>
1044
+ <pre>
1045
+ class MyLexer:
1046
+ ...
1047
+ def t_NUMBER(self,t):
1048
+ r'\d+'
1049
+ self.num_count += 1
1050
+ t.value = int(t.value)
1051
+ return t
1052
+
1053
+ def build(self, **kwargs):
1054
+ self.lexer = lex.lex(object=self,**kwargs)
1055
+
1056
+ def __init__(self):
1057
+ self.num_count = 0
1058
+ </pre>
1059
+ </blockquote>
1060
+
1061
+ The class approach may be the easiest to manage if your application is
1062
+ going to be creating multiple instances of the same lexer and you need
1063
+ to manage a lot of state.
1064
+
1065
+ <p>
1066
+ State can also be managed through closures. For example, in Python 3:
1067
+
1068
+ <blockquote>
1069
+ <pre>
1070
+ def MyLexer():
1071
+ num_count = 0
1072
+ ...
1073
+ def t_NUMBER(t):
1074
+ r'\d+'
1075
+ nonlocal num_count
1076
+ num_count += 1
1077
+ t.value = int(t.value)
1078
+ return t
1079
+ ...
1080
+ </pre>
1081
+ </blockquote>
1082
+
1083
+ <H3><a name="ply_nn19"></a>4.16 Lexer cloning</H3>
1084
+
1085
+
1086
+ <p>
1087
+ If necessary, a lexer object can be duplicated by invoking its <tt>clone()</tt> method. For example:
1088
+
1089
+ <blockquote>
1090
+ <pre>
1091
+ lexer = lex.lex()
1092
+ ...
1093
+ newlexer = lexer.clone()
1094
+ </pre>
1095
+ </blockquote>
1096
+
1097
+ When a lexer is cloned, the copy is exactly identical to the original lexer
1098
+ including any input text and internal state. However, the clone allows a
1099
+ different set of input text to be supplied which may be processed separately.
1100
+ This may be useful in situations when you are writing a parser/compiler that
1101
+ involves recursive or reentrant processing. For instance, if you
1102
+ needed to scan ahead in the input for some reason, you could create a
1103
+ clone and use it to look ahead. Or, if you were implementing some kind of preprocessor,
1104
+ cloned lexers could be used to handle different input files.
1105
+
1106
+ <p>
1107
+ Creating a clone is different than calling <tt>lex.lex()</tt> in that
1108
+ PLY doesn't regenerate any of the internal tables or regular expressions. So,
1109
+
1110
+ <p>
1111
+ Special considerations need to be made when cloning lexers that also
1112
+ maintain their own internal state using classes or closures. Namely,
1113
+ you need to be aware that the newly created lexers will share all of
1114
+ this state with the original lexer. For example, if you defined a
1115
+ lexer as a class and did this:
1116
+
1117
+ <blockquote>
1118
+ <pre>
1119
+ m = MyLexer()
1120
+ a = lex.lex(object=m) # Create a lexer
1121
+
1122
+ b = a.clone() # Clone the lexer
1123
+ </pre>
1124
+ </blockquote>
1125
+
1126
+ Then both <tt>a</tt> and <tt>b</tt> are going to be bound to the same
1127
+ object <tt>m</tt> and any changes to <tt>m</tt> will be reflected in both lexers. It's
1128
+ important to emphasize that <tt>clone()</tt> is only meant to create a new lexer
1129
+ that reuses the regular expressions and environment of another lexer. If you
1130
+ need to make a totally new copy of a lexer, then call <tt>lex()</tt> again.
1131
+
1132
+ <H3><a name="ply_nn20"></a>4.17 Internal lexer state</H3>
1133
+
1134
+
1135
+ A Lexer object <tt>lexer</tt> has a number of internal attributes that may be useful in certain
1136
+ situations.
1137
+
1138
+ <p>
1139
+ <tt>lexer.lexpos</tt>
1140
+ <blockquote>
1141
+ This attribute is an integer that contains the current position within the input text. If you modify
1142
+ the value, it will change the result of the next call to <tt>token()</tt>. Within token rule functions, this points
1143
+ to the first character <em>after</em> the matched text. If the value is modified within a rule, the next returned token will be
1144
+ matched at the new position.
1145
+ </blockquote>
1146
+
1147
+ <p>
1148
+ <tt>lexer.lineno</tt>
1149
+ <blockquote>
1150
+ The current value of the line number attribute stored in the lexer. PLY only specifies that the attribute
1151
+ exists---it never sets, updates, or performs any processing with it. If you want to track line numbers,
1152
+ you will need to add code yourself (see the section on line numbers and positional information).
1153
+ </blockquote>
1154
+
1155
+ <p>
1156
+ <tt>lexer.lexdata</tt>
1157
+ <blockquote>
1158
+ The current input text stored in the lexer. This is the string passed with the <tt>input()</tt> method. It
1159
+ would probably be a bad idea to modify this unless you really know what you're doing.
1160
+ </blockquote>
1161
+
1162
+ <P>
1163
+ <tt>lexer.lexmatch</tt>
1164
+ <blockquote>
1165
+ This is the raw <tt>Match</tt> object returned by the Python <tt>re.match()</tt> function (used internally by PLY) for the
1166
+ current token. If you have written a regular expression that contains named groups, you can use this to retrieve those values.
1167
+ Note: This attribute is only updated when tokens are defined and processed by functions.
1168
+ </blockquote>
1169
+
1170
+ <H3><a name="ply_nn21"></a>4.18 Conditional lexing and start conditions</H3>
1171
+
1172
+
1173
+ In advanced parsing applications, it may be useful to have different
1174
+ lexing states. For instance, you may want the occurrence of a certain
1175
+ token or syntactic construct to trigger a different kind of lexing.
1176
+ PLY supports a feature that allows the underlying lexer to be put into
1177
+ a series of different states. Each state can have its own tokens,
1178
+ lexing rules, and so forth. The implementation is based largely on
1179
+ the "start condition" feature of GNU flex. Details of this can be found
1180
+ at <a
1181
+ href="http://www.gnu.org/software/flex/manual/html_chapter/flex_11.html">http://www.gnu.org/software/flex/manual/html_chapter/flex_11.html.</a>.
1182
+
1183
+ <p>
1184
+ To define a new lexing state, it must first be declared. This is done by including a "states" declaration in your
1185
+ lex file. For example:
1186
+
1187
+ <blockquote>
1188
+ <pre>
1189
+ states = (
1190
+ ('foo','exclusive'),
1191
+ ('bar','inclusive'),
1192
+ )
1193
+ </pre>
1194
+ </blockquote>
1195
+
1196
+ This declaration declares two states, <tt>'foo'</tt>
1197
+ and <tt>'bar'</tt>. States may be of two types; <tt>'exclusive'</tt>
1198
+ and <tt>'inclusive'</tt>. An exclusive state completely overrides the
1199
+ default behavior of the lexer. That is, lex will only return tokens
1200
+ and apply rules defined specifically for that state. An inclusive
1201
+ state adds additional tokens and rules to the default set of rules.
1202
+ Thus, lex will return both the tokens defined by default in addition
1203
+ to those defined for the inclusive state.
1204
+
1205
+ <p>
1206
+ Once a state has been declared, tokens and rules are declared by including the
1207
+ state name in token/rule declaration. For example:
1208
+
1209
+ <blockquote>
1210
+ <pre>
1211
+ t_foo_NUMBER = r'\d+' # Token 'NUMBER' in state 'foo'
1212
+ t_bar_ID = r'[a-zA-Z_][a-zA-Z0-9_]*' # Token 'ID' in state 'bar'
1213
+
1214
+ def t_foo_newline(t):
1215
+ r'\n'
1216
+ t.lexer.lineno += 1
1217
+ </pre>
1218
+ </blockquote>
1219
+
1220
+ A token can be declared in multiple states by including multiple state names in the declaration. For example:
1221
+
1222
+ <blockquote>
1223
+ <pre>
1224
+ t_foo_bar_NUMBER = r'\d+' # Defines token 'NUMBER' in both state 'foo' and 'bar'
1225
+ </pre>
1226
+ </blockquote>
1227
+
1228
+ Alternative, a token can be declared in all states using the 'ANY' in the name.
1229
+
1230
+ <blockquote>
1231
+ <pre>
1232
+ t_ANY_NUMBER = r'\d+' # Defines a token 'NUMBER' in all states
1233
+ </pre>
1234
+ </blockquote>
1235
+
1236
+ If no state name is supplied, as is normally the case, the token is associated with a special state <tt>'INITIAL'</tt>. For example,
1237
+ these two declarations are identical:
1238
+
1239
+ <blockquote>
1240
+ <pre>
1241
+ t_NUMBER = r'\d+'
1242
+ t_INITIAL_NUMBER = r'\d+'
1243
+ </pre>
1244
+ </blockquote>
1245
+
1246
+ <p>
1247
+ States are also associated with the special <tt>t_ignore</tt> and <tt>t_error()</tt> declarations. For example, if a state treats
1248
+ these differently, you can declare:
1249
+
1250
+ <blockquote>
1251
+ <pre>
1252
+ t_foo_ignore = " \t\n" # Ignored characters for state 'foo'
1253
+
1254
+ def t_bar_error(t): # Special error handler for state 'bar'
1255
+ pass
1256
+ </pre>
1257
+ </blockquote>
1258
+
1259
+ By default, lexing operates in the <tt>'INITIAL'</tt> state. This state includes all of the normally defined tokens.
1260
+ For users who aren't using different states, this fact is completely transparent. If, during lexing or parsing, you want to change
1261
+ the lexing state, use the <tt>begin()</tt> method. For example:
1262
+
1263
+ <blockquote>
1264
+ <pre>
1265
+ def t_begin_foo(t):
1266
+ r'start_foo'
1267
+ t.lexer.begin('foo') # Starts 'foo' state
1268
+ </pre>
1269
+ </blockquote>
1270
+
1271
+ To get out of a state, you use <tt>begin()</tt> to switch back to the initial state. For example:
1272
+
1273
+ <blockquote>
1274
+ <pre>
1275
+ def t_foo_end(t):
1276
+ r'end_foo'
1277
+ t.lexer.begin('INITIAL') # Back to the initial state
1278
+ </pre>
1279
+ </blockquote>
1280
+
1281
+ The management of states can also be done with a stack. For example:
1282
+
1283
+ <blockquote>
1284
+ <pre>
1285
+ def t_begin_foo(t):
1286
+ r'start_foo'
1287
+ t.lexer.push_state('foo') # Starts 'foo' state
1288
+
1289
+ def t_foo_end(t):
1290
+ r'end_foo'
1291
+ t.lexer.pop_state() # Back to the previous state
1292
+ </pre>
1293
+ </blockquote>
1294
+
1295
+ <p>
1296
+ The use of a stack would be useful in situations where there are many ways of entering a new lexing state and you merely want to go back
1297
+ to the previous state afterwards.
1298
+
1299
+ <P>
1300
+ An example might help clarify. Suppose you were writing a parser and you wanted to grab sections of arbitrary C code enclosed by
1301
+ curly braces. That is, whenever you encounter a starting brace '{', you want to read all of the enclosed code up to the ending brace '}'
1302
+ and return it as a string. Doing this with a normal regular expression rule is nearly (if not actually) impossible. This is because braces can
1303
+ be nested and can be included in comments and strings. Thus, simply matching up to the first matching '}' character isn't good enough. Here is how
1304
+ you might use lexer states to do this:
1305
+
1306
+ <blockquote>
1307
+ <pre>
1308
+ # Declare the state
1309
+ states = (
1310
+ ('ccode','exclusive'),
1311
+ )
1312
+
1313
+ # Match the first {. Enter ccode state.
1314
+ def t_ccode(t):
1315
+ r'\{'
1316
+ t.lexer.code_start = t.lexer.lexpos # Record the starting position
1317
+ t.lexer.level = 1 # Initial brace level
1318
+ t.lexer.begin('ccode') # Enter 'ccode' state
1319
+
1320
+ # Rules for the ccode state
1321
+ def t_ccode_lbrace(t):
1322
+ r'\{'
1323
+ t.lexer.level +=1
1324
+
1325
+ def t_ccode_rbrace(t):
1326
+ r'\}'
1327
+ t.lexer.level -=1
1328
+
1329
+ # If closing brace, return the code fragment
1330
+ if t.lexer.level == 0:
1331
+ t.value = t.lexer.lexdata[t.lexer.code_start:t.lexer.lexpos+1]
1332
+ t.type = "CCODE"
1333
+ t.lexer.lineno += t.value.count('\n')
1334
+ t.lexer.begin('INITIAL')
1335
+ return t
1336
+
1337
+ # C or C++ comment (ignore)
1338
+ def t_ccode_comment(t):
1339
+ r'(/\*(.|\n)*?*/)|(//.*)'
1340
+ pass
1341
+
1342
+ # C string
1343
+ def t_ccode_string(t):
1344
+ r'\"([^\\\n]|(\\.))*?\"'
1345
+
1346
+ # C character literal
1347
+ def t_ccode_char(t):
1348
+ r'\'([^\\\n]|(\\.))*?\''
1349
+
1350
+ # Any sequence of non-whitespace characters (not braces, strings)
1351
+ def t_ccode_nonspace(t):
1352
+ r'[^\s\{\}\'\"]+'
1353
+
1354
+ # Ignored characters (whitespace)
1355
+ t_ccode_ignore = " \t\n"
1356
+
1357
+ # For bad characters, we just skip over it
1358
+ def t_ccode_error(t):
1359
+ t.lexer.skip(1)
1360
+ </pre>
1361
+ </blockquote>
1362
+
1363
+ In this example, the occurrence of the first '{' causes the lexer to record the starting position and enter a new state <tt>'ccode'</tt>. A collection of rules then match
1364
+ various parts of the input that follow (comments, strings, etc.). All of these rules merely discard the token (by not returning a value).
1365
+ However, if the closing right brace is encountered, the rule <tt>t_ccode_rbrace</tt> collects all of the code (using the earlier recorded starting
1366
+ position), stores it, and returns a token 'CCODE' containing all of that text. When returning the token, the lexing state is restored back to its
1367
+ initial state.
1368
+
1369
+ <H3><a name="ply_nn21"></a>4.19 Miscellaneous Issues</H3>
1370
+
1371
+
1372
+ <P>
1373
+ <li>The lexer requires input to be supplied as a single input string. Since most machines have more than enough memory, this
1374
+ rarely presents a performance concern. However, it means that the lexer currently can't be used with streaming data
1375
+ such as open files or sockets. This limitation is primarily a side-effect of using the <tt>re</tt> module.
1376
+
1377
+ <p>
1378
+ <li>The lexer should work properly with both Unicode strings given as token and pattern matching rules as
1379
+ well as for input text.
1380
+
1381
+ <p>
1382
+ <li>If you need to supply optional flags to the re.compile() function, use the reflags option to lex. For example:
1383
+
1384
+ <blockquote>
1385
+ <pre>
1386
+ lex.lex(reflags=re.UNICODE)
1387
+ </pre>
1388
+ </blockquote>
1389
+
1390
+ <p>
1391
+ <li>Since the lexer is written entirely in Python, its performance is
1392
+ largely determined by that of the Python <tt>re</tt> module. Although
1393
+ the lexer has been written to be as efficient as possible, it's not
1394
+ blazingly fast when used on very large input files. If
1395
+ performance is concern, you might consider upgrading to the most
1396
+ recent version of Python, creating a hand-written lexer, or offloading
1397
+ the lexer into a C extension module.
1398
+
1399
+ <p>
1400
+ If you are going to create a hand-written lexer and you plan to use it with <tt>yacc.py</tt>,
1401
+ it only needs to conform to the following requirements:
1402
+
1403
+ <ul>
1404
+ <li>It must provide a <tt>token()</tt> method that returns the next token or <tt>None</tt> if no more
1405
+ tokens are available.
1406
+ <li>The <tt>token()</tt> method must return an object <tt>tok</tt> that has <tt>type</tt> and <tt>value</tt> attributes. If
1407
+ line number tracking is being used, then the token should also define a <tt>lineno</tt> attribute.
1408
+ </ul>
1409
+
1410
+ <H2><a name="ply_nn22"></a>5. Parsing basics</H2>
1411
+
1412
+
1413
+ <tt>yacc.py</tt> is used to parse language syntax. Before showing an
1414
+ example, there are a few important bits of background that must be
1415
+ mentioned. First, <em>syntax</em> is usually specified in terms of a BNF grammar.
1416
+ For example, if you wanted to parse
1417
+ simple arithmetic expressions, you might first write an unambiguous
1418
+ grammar specification like this:
1419
+
1420
+ <blockquote>
1421
+ <pre>
1422
+ expression : expression + term
1423
+ | expression - term
1424
+ | term
1425
+
1426
+ term : term * factor
1427
+ | term / factor
1428
+ | factor
1429
+
1430
+ factor : NUMBER
1431
+ | ( expression )
1432
+ </pre>
1433
+ </blockquote>
1434
+
1435
+ In the grammar, symbols such as <tt>NUMBER</tt>, <tt>+</tt>, <tt>-</tt>, <tt>*</tt>, and <tt>/</tt> are known
1436
+ as <em>terminals</em> and correspond to raw input tokens. Identifiers such as <tt>term</tt> and <tt>factor</tt> refer to
1437
+ grammar rules comprised of a collection of terminals and other rules. These identifiers are known as <em>non-terminals</em>.
1438
+ <P>
1439
+
1440
+ The semantic behavior of a language is often specified using a
1441
+ technique known as syntax directed translation. In syntax directed
1442
+ translation, attributes are attached to each symbol in a given grammar
1443
+ rule along with an action. Whenever a particular grammar rule is
1444
+ recognized, the action describes what to do. For example, given the
1445
+ expression grammar above, you might write the specification for a
1446
+ simple calculator like this:
1447
+
1448
+ <blockquote>
1449
+ <pre>
1450
+ Grammar Action
1451
+ -------------------------------- --------------------------------------------
1452
+ expression0 : expression1 + term expression0.val = expression1.val + term.val
1453
+ | expression1 - term expression0.val = expression1.val - term.val
1454
+ | term expression0.val = term.val
1455
+
1456
+ term0 : term1 * factor term0.val = term1.val * factor.val
1457
+ | term1 / factor term0.val = term1.val / factor.val
1458
+ | factor term0.val = factor.val
1459
+
1460
+ factor : NUMBER factor.val = int(NUMBER.lexval)
1461
+ | ( expression ) factor.val = expression.val
1462
+ </pre>
1463
+ </blockquote>
1464
+
1465
+ A good way to think about syntax directed translation is to
1466
+ view each symbol in the grammar as a kind of object. Associated
1467
+ with each symbol is a value representing its "state" (for example, the
1468
+ <tt>val</tt> attribute above). Semantic
1469
+ actions are then expressed as a collection of functions or methods
1470
+ that operate on the symbols and associated values.
1471
+
1472
+ <p>
1473
+ Yacc uses a parsing technique known as LR-parsing or shift-reduce parsing. LR parsing is a
1474
+ bottom up technique that tries to recognize the right-hand-side of various grammar rules.
1475
+ Whenever a valid right-hand-side is found in the input, the appropriate action code is triggered and the
1476
+ grammar symbols are replaced by the grammar symbol on the left-hand-side.
1477
+
1478
+ <p>
1479
+ LR parsing is commonly implemented by shifting grammar symbols onto a
1480
+ stack and looking at the stack and the next input token for patterns that
1481
+ match one of the grammar rules.
1482
+ The details of the algorithm can be found in a compiler textbook, but the
1483
+ following example illustrates the steps that are performed if you
1484
+ wanted to parse the expression
1485
+ <tt>3 + 5 * (10 - 20)</tt> using the grammar defined above. In the example,
1486
+ the special symbol <tt>$</tt> represents the end of input.
1487
+
1488
+
1489
+ <blockquote>
1490
+ <pre>
1491
+ Step Symbol Stack Input Tokens Action
1492
+ ---- --------------------- --------------------- -------------------------------
1493
+ 1 3 + 5 * ( 10 - 20 )$ Shift 3
1494
+ 2 3 + 5 * ( 10 - 20 )$ Reduce factor : NUMBER
1495
+ 3 factor + 5 * ( 10 - 20 )$ Reduce term : factor
1496
+ 4 term + 5 * ( 10 - 20 )$ Reduce expr : term
1497
+ 5 expr + 5 * ( 10 - 20 )$ Shift +
1498
+ 6 expr + 5 * ( 10 - 20 )$ Shift 5
1499
+ 7 expr + 5 * ( 10 - 20 )$ Reduce factor : NUMBER
1500
+ 8 expr + factor * ( 10 - 20 )$ Reduce term : factor
1501
+ 9 expr + term * ( 10 - 20 )$ Shift *
1502
+ 10 expr + term * ( 10 - 20 )$ Shift (
1503
+ 11 expr + term * ( 10 - 20 )$ Shift 10
1504
+ 12 expr + term * ( 10 - 20 )$ Reduce factor : NUMBER
1505
+ 13 expr + term * ( factor - 20 )$ Reduce term : factor
1506
+ 14 expr + term * ( term - 20 )$ Reduce expr : term
1507
+ 15 expr + term * ( expr - 20 )$ Shift -
1508
+ 16 expr + term * ( expr - 20 )$ Shift 20
1509
+ 17 expr + term * ( expr - 20 )$ Reduce factor : NUMBER
1510
+ 18 expr + term * ( expr - factor )$ Reduce term : factor
1511
+ 19 expr + term * ( expr - term )$ Reduce expr : expr - term
1512
+ 20 expr + term * ( expr )$ Shift )
1513
+ 21 expr + term * ( expr ) $ Reduce factor : (expr)
1514
+ 22 expr + term * factor $ Reduce term : term * factor
1515
+ 23 expr + term $ Reduce expr : expr + term
1516
+ 24 expr $ Reduce expr
1517
+ 25 $ Success!
1518
+ </pre>
1519
+ </blockquote>
1520
+
1521
+ When parsing the expression, an underlying state machine and the
1522
+ current input token determine what happens next. If the next token
1523
+ looks like part of a valid grammar rule (based on other items on the
1524
+ stack), it is generally shifted onto the stack. If the top of the
1525
+ stack contains a valid right-hand-side of a grammar rule, it is
1526
+ usually "reduced" and the symbols replaced with the symbol on the
1527
+ left-hand-side. When this reduction occurs, the appropriate action is
1528
+ triggered (if defined). If the input token can't be shifted and the
1529
+ top of stack doesn't match any grammar rules, a syntax error has
1530
+ occurred and the parser must take some kind of recovery step (or bail
1531
+ out). A parse is only successful if the parser reaches a state where
1532
+ the symbol stack is empty and there are no more input tokens.
1533
+
1534
+ <p>
1535
+ It is important to note that the underlying implementation is built
1536
+ around a large finite-state machine that is encoded in a collection of
1537
+ tables. The construction of these tables is non-trivial and
1538
+ beyond the scope of this discussion. However, subtle details of this
1539
+ process explain why, in the example above, the parser chooses to shift
1540
+ a token onto the stack in step 9 rather than reducing the
1541
+ rule <tt>expr : expr + term</tt>.
1542
+
1543
+ <H2><a name="ply_nn23"></a>6. Yacc</H2>
1544
+
1545
+
1546
+ The <tt>ply.yacc</tt> module implements the parsing component of PLY.
1547
+ The name "yacc" stands for "Yet Another Compiler Compiler" and is
1548
+ borrowed from the Unix tool of the same name.
1549
+
1550
+ <H3><a name="ply_nn24"></a>6.1 An example</H3>
1551
+
1552
+
1553
+ Suppose you wanted to make a grammar for simple arithmetic expressions as previously described. Here is
1554
+ how you would do it with <tt>yacc.py</tt>:
1555
+
1556
+ <blockquote>
1557
+ <pre>
1558
+ # Yacc example
1559
+
1560
+ import ply.yacc as yacc
1561
+
1562
+ # Get the token map from the lexer. This is required.
1563
+ from calclex import tokens
1564
+
1565
+ def p_expression_plus(p):
1566
+ 'expression : expression PLUS term'
1567
+ p[0] = p[1] + p[3]
1568
+
1569
+ def p_expression_minus(p):
1570
+ 'expression : expression MINUS term'
1571
+ p[0] = p[1] - p[3]
1572
+
1573
+ def p_expression_term(p):
1574
+ 'expression : term'
1575
+ p[0] = p[1]
1576
+
1577
+ def p_term_times(p):
1578
+ 'term : term TIMES factor'
1579
+ p[0] = p[1] * p[3]
1580
+
1581
+ def p_term_div(p):
1582
+ 'term : term DIVIDE factor'
1583
+ p[0] = p[1] / p[3]
1584
+
1585
+ def p_term_factor(p):
1586
+ 'term : factor'
1587
+ p[0] = p[1]
1588
+
1589
+ def p_factor_num(p):
1590
+ 'factor : NUMBER'
1591
+ p[0] = p[1]
1592
+
1593
+ def p_factor_expr(p):
1594
+ 'factor : LPAREN expression RPAREN'
1595
+ p[0] = p[2]
1596
+
1597
+ # Error rule for syntax errors
1598
+ def p_error(p):
1599
+ print "Syntax error in input!"
1600
+
1601
+ # Build the parser
1602
+ parser = yacc.yacc()
1603
+
1604
+ while True:
1605
+ try:
1606
+ s = raw_input('calc > ')
1607
+ except EOFError:
1608
+ break
1609
+ if not s: continue
1610
+ result = parser.parse(s)
1611
+ print result
1612
+ </pre>
1613
+ </blockquote>
1614
+
1615
+ In this example, each grammar rule is defined by a Python function
1616
+ where the docstring to that function contains the appropriate
1617
+ context-free grammar specification. The statements that make up the
1618
+ function body implement the semantic actions of the rule. Each function
1619
+ accepts a single argument <tt>p</tt> that is a sequence containing the
1620
+ values of each grammar symbol in the corresponding rule. The values
1621
+ of <tt>p[i]</tt> are mapped to grammar symbols as shown here:
1622
+
1623
+ <blockquote>
1624
+ <pre>
1625
+ def p_expression_plus(p):
1626
+ 'expression : expression PLUS term'
1627
+ # ^ ^ ^ ^
1628
+ # p[0] p[1] p[2] p[3]
1629
+
1630
+ p[0] = p[1] + p[3]
1631
+ </pre>
1632
+ </blockquote>
1633
+
1634
+ <p>
1635
+ For tokens, the "value" of the corresponding <tt>p[i]</tt> is the
1636
+ <em>same</em> as the <tt>p.value</tt> attribute assigned in the lexer
1637
+ module. For non-terminals, the value is determined by whatever is
1638
+ placed in <tt>p[0]</tt> when rules are reduced. This value can be
1639
+ anything at all. However, it probably most common for the value to be
1640
+ a simple Python type, a tuple, or an instance. In this example, we
1641
+ are relying on the fact that the <tt>NUMBER</tt> token stores an
1642
+ integer value in its value field. All of the other rules simply
1643
+ perform various types of integer operations and propagate the result.
1644
+ </p>
1645
+
1646
+ <p>
1647
+ Note: The use of negative indices have a special meaning in
1648
+ yacc---specially <tt>p[-1]</tt> does not have the same value
1649
+ as <tt>p[3]</tt> in this example. Please see the section on "Embedded
1650
+ Actions" for further details.
1651
+ </p>
1652
+
1653
+ <p>
1654
+ The first rule defined in the yacc specification determines the
1655
+ starting grammar symbol (in this case, a rule for <tt>expression</tt>
1656
+ appears first). Whenever the starting rule is reduced by the parser
1657
+ and no more input is available, parsing stops and the final value is
1658
+ returned (this value will be whatever the top-most rule placed
1659
+ in <tt>p[0]</tt>). Note: an alternative starting symbol can be
1660
+ specified using the <tt>start</tt> keyword argument to
1661
+ <tt>yacc()</tt>.
1662
+
1663
+ <p>The <tt>p_error(p)</tt> rule is defined to catch syntax errors.
1664
+ See the error handling section below for more detail.
1665
+
1666
+ <p>
1667
+ To build the parser, call the <tt>yacc.yacc()</tt> function. This
1668
+ function looks at the module and attempts to construct all of the LR
1669
+ parsing tables for the grammar you have specified. The first
1670
+ time <tt>yacc.yacc()</tt> is invoked, you will get a message such as
1671
+ this:
1672
+
1673
+ <blockquote>
1674
+ <pre>
1675
+ $ python calcparse.py
1676
+ Generating LALR tables
1677
+ calc >
1678
+ </pre>
1679
+ </blockquote>
1680
+
1681
+ Since table construction is relatively expensive (especially for large
1682
+ grammars), the resulting parsing table is written to the current
1683
+ directory in a file called <tt>parsetab.py</tt>. In addition, a
1684
+ debugging file called <tt>parser.out</tt> is created. On subsequent
1685
+ executions, <tt>yacc</tt> will reload the table from
1686
+ <tt>parsetab.py</tt> unless it has detected a change in the underlying
1687
+ grammar (in which case the tables and <tt>parsetab.py</tt> file are
1688
+ regenerated). Note: The names of parser output files can be changed
1689
+ if necessary. See the <a href="reference.html">PLY Reference</a> for details.
1690
+
1691
+ <p>
1692
+ If any errors are detected in your grammar specification, <tt>yacc.py</tt> will produce
1693
+ diagnostic messages and possibly raise an exception. Some of the errors that can be detected include:
1694
+
1695
+ <ul>
1696
+ <li>Duplicated function names (if more than one rule function have the same name in the grammar file).
1697
+ <li>Shift/reduce and reduce/reduce conflicts generated by ambiguous grammars.
1698
+ <li>Badly specified grammar rules.
1699
+ <li>Infinite recursion (rules that can never terminate).
1700
+ <li>Unused rules and tokens
1701
+ <li>Undefined rules and tokens
1702
+ </ul>
1703
+
1704
+ The next few sections discuss grammar specification in more detail.
1705
+
1706
+ <p>
1707
+ The final part of the example shows how to actually run the parser
1708
+ created by
1709
+ <tt>yacc()</tt>. To run the parser, you simply have to call
1710
+ the <tt>parse()</tt> with a string of input text. This will run all
1711
+ of the grammar rules and return the result of the entire parse. This
1712
+ result return is the value assigned to <tt>p[0]</tt> in the starting
1713
+ grammar rule.
1714
+
1715
+ <H3><a name="ply_nn25"></a>6.2 Combining Grammar Rule Functions</H3>
1716
+
1717
+
1718
+ When grammar rules are similar, they can be combined into a single function.
1719
+ For example, consider the two rules in our earlier example:
1720
+
1721
+ <blockquote>
1722
+ <pre>
1723
+ def p_expression_plus(p):
1724
+ 'expression : expression PLUS term'
1725
+ p[0] = p[1] + p[3]
1726
+
1727
+ def p_expression_minus(t):
1728
+ 'expression : expression MINUS term'
1729
+ p[0] = p[1] - p[3]
1730
+ </pre>
1731
+ </blockquote>
1732
+
1733
+ Instead of writing two functions, you might write a single function like this:
1734
+
1735
+ <blockquote>
1736
+ <pre>
1737
+ def p_expression(p):
1738
+ '''expression : expression PLUS term
1739
+ | expression MINUS term'''
1740
+ if p[2] == '+':
1741
+ p[0] = p[1] + p[3]
1742
+ elif p[2] == '-':
1743
+ p[0] = p[1] - p[3]
1744
+ </pre>
1745
+ </blockquote>
1746
+
1747
+ In general, the doc string for any given function can contain multiple grammar rules. So, it would
1748
+ have also been legal (although possibly confusing) to write this:
1749
+
1750
+ <blockquote>
1751
+ <pre>
1752
+ def p_binary_operators(p):
1753
+ '''expression : expression PLUS term
1754
+ | expression MINUS term
1755
+ term : term TIMES factor
1756
+ | term DIVIDE factor'''
1757
+ if p[2] == '+':
1758
+ p[0] = p[1] + p[3]
1759
+ elif p[2] == '-':
1760
+ p[0] = p[1] - p[3]
1761
+ elif p[2] == '*':
1762
+ p[0] = p[1] * p[3]
1763
+ elif p[2] == '/':
1764
+ p[0] = p[1] / p[3]
1765
+ </pre>
1766
+ </blockquote>
1767
+
1768
+ When combining grammar rules into a single function, it is usually a good idea for all of the rules to have
1769
+ a similar structure (e.g., the same number of terms). Otherwise, the corresponding action code may be more
1770
+ complicated than necessary. However, it is possible to handle simple cases using len(). For example:
1771
+
1772
+ <blockquote>
1773
+ <pre>
1774
+ def p_expressions(p):
1775
+ '''expression : expression MINUS expression
1776
+ | MINUS expression'''
1777
+ if (len(p) == 4):
1778
+ p[0] = p[1] - p[3]
1779
+ elif (len(p) == 3):
1780
+ p[0] = -p[2]
1781
+ </pre>
1782
+ </blockquote>
1783
+
1784
+ If parsing performance is a concern, you should resist the urge to put
1785
+ too much conditional processing into a single grammar rule as shown in
1786
+ these examples. When you add checks to see which grammar rule is
1787
+ being handled, you are actually duplicating the work that the parser
1788
+ has already performed (i.e., the parser already knows exactly what rule it
1789
+ matched). You can eliminate this overhead by using a
1790
+ separate <tt>p_rule()</tt> function for each grammar rule.
1791
+
1792
+ <H3><a name="ply_nn26"></a>6.3 Character Literals</H3>
1793
+
1794
+
1795
+ If desired, a grammar may contain tokens defined as single character literals. For example:
1796
+
1797
+ <blockquote>
1798
+ <pre>
1799
+ def p_binary_operators(p):
1800
+ '''expression : expression '+' term
1801
+ | expression '-' term
1802
+ term : term '*' factor
1803
+ | term '/' factor'''
1804
+ if p[2] == '+':
1805
+ p[0] = p[1] + p[3]
1806
+ elif p[2] == '-':
1807
+ p[0] = p[1] - p[3]
1808
+ elif p[2] == '*':
1809
+ p[0] = p[1] * p[3]
1810
+ elif p[2] == '/':
1811
+ p[0] = p[1] / p[3]
1812
+ </pre>
1813
+ </blockquote>
1814
+
1815
+ A character literal must be enclosed in quotes such as <tt>'+'</tt>. In addition, if literals are used, they must be declared in the
1816
+ corresponding <tt>lex</tt> file through the use of a special <tt>literals</tt> declaration.
1817
+
1818
+ <blockquote>
1819
+ <pre>
1820
+ # Literals. Should be placed in module given to lex()
1821
+ literals = ['+','-','*','/' ]
1822
+ </pre>
1823
+ </blockquote>
1824
+
1825
+ <b>Character literals are limited to a single character</b>. Thus, it is not legal to specify literals such as <tt>'&lt;='</tt> or <tt>'=='</tt>. For this, use
1826
+ the normal lexing rules (e.g., define a rule such as <tt>t_EQ = r'=='</tt>).
1827
+
1828
+ <H3><a name="ply_nn26"></a>6.4 Empty Productions</H3>
1829
+
1830
+
1831
+ <tt>yacc.py</tt> can handle empty productions by defining a rule like this:
1832
+
1833
+ <blockquote>
1834
+ <pre>
1835
+ def p_empty(p):
1836
+ 'empty :'
1837
+ pass
1838
+ </pre>
1839
+ </blockquote>
1840
+
1841
+ Now to use the empty production, simply use 'empty' as a symbol. For example:
1842
+
1843
+ <blockquote>
1844
+ <pre>
1845
+ def p_optitem(p):
1846
+ 'optitem : item'
1847
+ ' | empty'
1848
+ ...
1849
+ </pre>
1850
+ </blockquote>
1851
+
1852
+ Note: You can write empty rules anywhere by simply specifying an empty
1853
+ right hand side. However, I personally find that writing an "empty"
1854
+ rule and using "empty" to denote an empty production is easier to read
1855
+ and more clearly states your intentions.
1856
+
1857
+ <H3><a name="ply_nn28"></a>6.5 Changing the starting symbol</H3>
1858
+
1859
+
1860
+ Normally, the first rule found in a yacc specification defines the starting grammar rule (top level rule). To change this, simply
1861
+ supply a <tt>start</tt> specifier in your file. For example:
1862
+
1863
+ <blockquote>
1864
+ <pre>
1865
+ start = 'foo'
1866
+
1867
+ def p_bar(p):
1868
+ 'bar : A B'
1869
+
1870
+ # This is the starting rule due to the start specifier above
1871
+ def p_foo(p):
1872
+ 'foo : bar X'
1873
+ ...
1874
+ </pre>
1875
+ </blockquote>
1876
+
1877
+ The use of a <tt>start</tt> specifier may be useful during debugging
1878
+ since you can use it to have yacc build a subset of a larger grammar.
1879
+ For this purpose, it is also possible to specify a starting symbol as
1880
+ an argument to <tt>yacc()</tt>. For example:
1881
+
1882
+ <blockquote>
1883
+ <pre>
1884
+ yacc.yacc(start='foo')
1885
+ </pre>
1886
+ </blockquote>
1887
+
1888
+ <H3><a name="ply_nn27"></a>6.6 Dealing With Ambiguous Grammars</H3>
1889
+
1890
+
1891
+ The expression grammar given in the earlier example has been written
1892
+ in a special format to eliminate ambiguity. However, in many
1893
+ situations, it is extremely difficult or awkward to write grammars in
1894
+ this format. A much more natural way to express the grammar is in a
1895
+ more compact form like this:
1896
+
1897
+ <blockquote>
1898
+ <pre>
1899
+ expression : expression PLUS expression
1900
+ | expression MINUS expression
1901
+ | expression TIMES expression
1902
+ | expression DIVIDE expression
1903
+ | LPAREN expression RPAREN
1904
+ | NUMBER
1905
+ </pre>
1906
+ </blockquote>
1907
+
1908
+ Unfortunately, this grammar specification is ambiguous. For example,
1909
+ if you are parsing the string "3 * 4 + 5", there is no way to tell how
1910
+ the operators are supposed to be grouped. For example, does the
1911
+ expression mean "(3 * 4) + 5" or is it "3 * (4+5)"?
1912
+
1913
+ <p>
1914
+ When an ambiguous grammar is given to <tt>yacc.py</tt> it will print
1915
+ messages about "shift/reduce conflicts" or "reduce/reduce conflicts".
1916
+ A shift/reduce conflict is caused when the parser generator can't
1917
+ decide whether or not to reduce a rule or shift a symbol on the
1918
+ parsing stack. For example, consider the string "3 * 4 + 5" and the
1919
+ internal parsing stack:
1920
+
1921
+ <blockquote>
1922
+ <pre>
1923
+ Step Symbol Stack Input Tokens Action
1924
+ ---- --------------------- --------------------- -------------------------------
1925
+ 1 $ 3 * 4 + 5$ Shift 3
1926
+ 2 $ 3 * 4 + 5$ Reduce : expression : NUMBER
1927
+ 3 $ expr * 4 + 5$ Shift *
1928
+ 4 $ expr * 4 + 5$ Shift 4
1929
+ 5 $ expr * 4 + 5$ Reduce: expression : NUMBER
1930
+ 6 $ expr * expr + 5$ SHIFT/REDUCE CONFLICT ????
1931
+ </pre>
1932
+ </blockquote>
1933
+
1934
+ In this case, when the parser reaches step 6, it has two options. One
1935
+ is to reduce the rule <tt>expr : expr * expr</tt> on the stack. The
1936
+ other option is to shift the token <tt>+</tt> on the stack. Both
1937
+ options are perfectly legal from the rules of the
1938
+ context-free-grammar.
1939
+
1940
+ <p>
1941
+ By default, all shift/reduce conflicts are resolved in favor of
1942
+ shifting. Therefore, in the above example, the parser will always
1943
+ shift the <tt>+</tt> instead of reducing. Although this strategy
1944
+ works in many cases (for example, the case of
1945
+ "if-then" versus "if-then-else"), it is not enough for arithmetic expressions. In fact,
1946
+ in the above example, the decision to shift <tt>+</tt> is completely
1947
+ wrong---we should have reduced <tt>expr * expr</tt> since
1948
+ multiplication has higher mathematical precedence than addition.
1949
+
1950
+ <p>To resolve ambiguity, especially in expression
1951
+ grammars, <tt>yacc.py</tt> allows individual tokens to be assigned a
1952
+ precedence level and associativity. This is done by adding a variable
1953
+ <tt>precedence</tt> to the grammar file like this:
1954
+
1955
+ <blockquote>
1956
+ <pre>
1957
+ precedence = (
1958
+ ('left', 'PLUS', 'MINUS'),
1959
+ ('left', 'TIMES', 'DIVIDE'),
1960
+ )
1961
+ </pre>
1962
+ </blockquote>
1963
+
1964
+ This declaration specifies that <tt>PLUS</tt>/<tt>MINUS</tt> have the
1965
+ same precedence level and are left-associative and that
1966
+ <tt>TIMES</tt>/<tt>DIVIDE</tt> have the same precedence and are
1967
+ left-associative. Within the <tt>precedence</tt> declaration, tokens
1968
+ are ordered from lowest to highest precedence. Thus, this declaration
1969
+ specifies that <tt>TIMES</tt>/<tt>DIVIDE</tt> have higher precedence
1970
+ than <tt>PLUS</tt>/<tt>MINUS</tt> (since they appear later in the
1971
+ precedence specification).
1972
+
1973
+ <p>
1974
+ The precedence specification works by associating a numerical
1975
+ precedence level value and associativity direction to the listed
1976
+ tokens. For example, in the above example you get:
1977
+
1978
+ <blockquote>
1979
+ <pre>
1980
+ PLUS : level = 1, assoc = 'left'
1981
+ MINUS : level = 1, assoc = 'left'
1982
+ TIMES : level = 2, assoc = 'left'
1983
+ DIVIDE : level = 2, assoc = 'left'
1984
+ </pre>
1985
+ </blockquote>
1986
+
1987
+ These values are then used to attach a numerical precedence value and
1988
+ associativity direction to each grammar rule. <em>This is always
1989
+ determined by looking at the precedence of the right-most terminal
1990
+ symbol.</em> For example:
1991
+
1992
+ <blockquote>
1993
+ <pre>
1994
+ expression : expression PLUS expression # level = 1, left
1995
+ | expression MINUS expression # level = 1, left
1996
+ | expression TIMES expression # level = 2, left
1997
+ | expression DIVIDE expression # level = 2, left
1998
+ | LPAREN expression RPAREN # level = None (not specified)
1999
+ | NUMBER # level = None (not specified)
2000
+ </pre>
2001
+ </blockquote>
2002
+
2003
+ When shift/reduce conflicts are encountered, the parser generator resolves the conflict by
2004
+ looking at the precedence rules and associativity specifiers.
2005
+
2006
+ <p>
2007
+ <ol>
2008
+ <li>If the current token has higher precedence than the rule on the stack, it is shifted.
2009
+ <li>If the grammar rule on the stack has higher precedence, the rule is reduced.
2010
+ <li>If the current token and the grammar rule have the same precedence, the
2011
+ rule is reduced for left associativity, whereas the token is shifted for right associativity.
2012
+ <li>If nothing is known about the precedence, shift/reduce conflicts are resolved in
2013
+ favor of shifting (the default).
2014
+ </ol>
2015
+
2016
+ For example, if "expression PLUS expression" has been parsed and the
2017
+ next token is "TIMES", the action is going to be a shift because
2018
+ "TIMES" has a higher precedence level than "PLUS". On the other hand,
2019
+ if "expression TIMES expression" has been parsed and the next token is
2020
+ "PLUS", the action is going to be reduce because "PLUS" has a lower
2021
+ precedence than "TIMES."
2022
+
2023
+ <p>
2024
+ When shift/reduce conflicts are resolved using the first three
2025
+ techniques (with the help of precedence rules), <tt>yacc.py</tt> will
2026
+ report no errors or conflicts in the grammar (although it will print
2027
+ some information in the <tt>parser.out</tt> debugging file).
2028
+
2029
+ <p>
2030
+ One problem with the precedence specifier technique is that it is
2031
+ sometimes necessary to change the precedence of an operator in certain
2032
+ contexts. For example, consider a unary-minus operator in "3 + 4 *
2033
+ -5". Mathematically, the unary minus is normally given a very high
2034
+ precedence--being evaluated before the multiply. However, in our
2035
+ precedence specifier, MINUS has a lower precedence than TIMES. To
2036
+ deal with this, precedence rules can be given for so-called "fictitious tokens"
2037
+ like this:
2038
+
2039
+ <blockquote>
2040
+ <pre>
2041
+ precedence = (
2042
+ ('left', 'PLUS', 'MINUS'),
2043
+ ('left', 'TIMES', 'DIVIDE'),
2044
+ ('right', 'UMINUS'), # Unary minus operator
2045
+ )
2046
+ </pre>
2047
+ </blockquote>
2048
+
2049
+ Now, in the grammar file, we can write our unary minus rule like this:
2050
+
2051
+ <blockquote>
2052
+ <pre>
2053
+ def p_expr_uminus(p):
2054
+ 'expression : MINUS expression %prec UMINUS'
2055
+ p[0] = -p[2]
2056
+ </pre>
2057
+ </blockquote>
2058
+
2059
+ In this case, <tt>%prec UMINUS</tt> overrides the default rule precedence--setting it to that
2060
+ of UMINUS in the precedence specifier.
2061
+
2062
+ <p>
2063
+ At first, the use of UMINUS in this example may appear very confusing.
2064
+ UMINUS is not an input token or a grammer rule. Instead, you should
2065
+ think of it as the name of a special marker in the precedence table. When you use the <tt>%prec</tt> qualifier, you're simply
2066
+ telling yacc that you want the precedence of the expression to be the same as for this special marker instead of the usual precedence.
2067
+
2068
+ <p>
2069
+ It is also possible to specify non-associativity in the <tt>precedence</tt> table. This would
2070
+ be used when you <em>don't</em> want operations to chain together. For example, suppose
2071
+ you wanted to support comparison operators like <tt>&lt;</tt> and <tt>&gt;</tt> but you didn't want to allow
2072
+ combinations like <tt>a &lt; b &lt; c</tt>. To do this, simply specify a rule like this:
2073
+
2074
+ <blockquote>
2075
+ <pre>
2076
+ precedence = (
2077
+ ('nonassoc', 'LESSTHAN', 'GREATERTHAN'), # Nonassociative operators
2078
+ ('left', 'PLUS', 'MINUS'),
2079
+ ('left', 'TIMES', 'DIVIDE'),
2080
+ ('right', 'UMINUS'), # Unary minus operator
2081
+ )
2082
+ </pre>
2083
+ </blockquote>
2084
+
2085
+ <p>
2086
+ If you do this, the occurrence of input text such as <tt> a &lt; b &lt; c</tt> will result in a syntax error. However, simple
2087
+ expressions such as <tt>a &lt; b</tt> will still be fine.
2088
+
2089
+ <p>
2090
+ Reduce/reduce conflicts are caused when there are multiple grammar
2091
+ rules that can be applied to a given set of symbols. This kind of
2092
+ conflict is almost always bad and is always resolved by picking the
2093
+ rule that appears first in the grammar file. Reduce/reduce conflicts
2094
+ are almost always caused when different sets of grammar rules somehow
2095
+ generate the same set of symbols. For example:
2096
+
2097
+ <blockquote>
2098
+ <pre>
2099
+ assignment : ID EQUALS NUMBER
2100
+ | ID EQUALS expression
2101
+
2102
+ expression : expression PLUS expression
2103
+ | expression MINUS expression
2104
+ | expression TIMES expression
2105
+ | expression DIVIDE expression
2106
+ | LPAREN expression RPAREN
2107
+ | NUMBER
2108
+ </pre>
2109
+ </blockquote>
2110
+
2111
+ In this case, a reduce/reduce conflict exists between these two rules:
2112
+
2113
+ <blockquote>
2114
+ <pre>
2115
+ assignment : ID EQUALS NUMBER
2116
+ expression : NUMBER
2117
+ </pre>
2118
+ </blockquote>
2119
+
2120
+ For example, if you wrote "a = 5", the parser can't figure out if this
2121
+ is supposed to be reduced as <tt>assignment : ID EQUALS NUMBER</tt> or
2122
+ whether it's supposed to reduce the 5 as an expression and then reduce
2123
+ the rule <tt>assignment : ID EQUALS expression</tt>.
2124
+
2125
+ <p>
2126
+ It should be noted that reduce/reduce conflicts are notoriously
2127
+ difficult to spot simply looking at the input grammer. When a
2128
+ reduce/reduce conflict occurs, <tt>yacc()</tt> will try to help by
2129
+ printing a warning message such as this:
2130
+
2131
+ <blockquote>
2132
+ <pre>
2133
+ WARNING: 1 reduce/reduce conflict
2134
+ WARNING: reduce/reduce conflict in state 15 resolved using rule (assignment -> ID EQUALS NUMBER)
2135
+ WARNING: rejected rule (expression -> NUMBER)
2136
+ </pre>
2137
+ </blockquote>
2138
+
2139
+ This message identifies the two rules that are in conflict. However,
2140
+ it may not tell you how the parser arrived at such a state. To try
2141
+ and figure it out, you'll probably have to look at your grammar and
2142
+ the contents of the
2143
+ <tt>parser.out</tt> debugging file with an appropriately high level of
2144
+ caffeination.
2145
+
2146
+ <H3><a name="ply_nn28"></a>6.7 The parser.out file</H3>
2147
+
2148
+
2149
+ Tracking down shift/reduce and reduce/reduce conflicts is one of the finer pleasures of using an LR
2150
+ parsing algorithm. To assist in debugging, <tt>yacc.py</tt> creates a debugging file called
2151
+ 'parser.out' when it generates the parsing table. The contents of this file look like the following:
2152
+
2153
+ <blockquote>
2154
+ <pre>
2155
+ Unused terminals:
2156
+
2157
+
2158
+ Grammar
2159
+
2160
+ Rule 1 expression -> expression PLUS expression
2161
+ Rule 2 expression -> expression MINUS expression
2162
+ Rule 3 expression -> expression TIMES expression
2163
+ Rule 4 expression -> expression DIVIDE expression
2164
+ Rule 5 expression -> NUMBER
2165
+ Rule 6 expression -> LPAREN expression RPAREN
2166
+
2167
+ Terminals, with rules where they appear
2168
+
2169
+ TIMES : 3
2170
+ error :
2171
+ MINUS : 2
2172
+ RPAREN : 6
2173
+ LPAREN : 6
2174
+ DIVIDE : 4
2175
+ PLUS : 1
2176
+ NUMBER : 5
2177
+
2178
+ Nonterminals, with rules where they appear
2179
+
2180
+ expression : 1 1 2 2 3 3 4 4 6 0
2181
+
2182
+
2183
+ Parsing method: LALR
2184
+
2185
+
2186
+ state 0
2187
+
2188
+ S' -> . expression
2189
+ expression -> . expression PLUS expression
2190
+ expression -> . expression MINUS expression
2191
+ expression -> . expression TIMES expression
2192
+ expression -> . expression DIVIDE expression
2193
+ expression -> . NUMBER
2194
+ expression -> . LPAREN expression RPAREN
2195
+
2196
+ NUMBER shift and go to state 3
2197
+ LPAREN shift and go to state 2
2198
+
2199
+
2200
+ state 1
2201
+
2202
+ S' -> expression .
2203
+ expression -> expression . PLUS expression
2204
+ expression -> expression . MINUS expression
2205
+ expression -> expression . TIMES expression
2206
+ expression -> expression . DIVIDE expression
2207
+
2208
+ PLUS shift and go to state 6
2209
+ MINUS shift and go to state 5
2210
+ TIMES shift and go to state 4
2211
+ DIVIDE shift and go to state 7
2212
+
2213
+
2214
+ state 2
2215
+
2216
+ expression -> LPAREN . expression RPAREN
2217
+ expression -> . expression PLUS expression
2218
+ expression -> . expression MINUS expression
2219
+ expression -> . expression TIMES expression
2220
+ expression -> . expression DIVIDE expression
2221
+ expression -> . NUMBER
2222
+ expression -> . LPAREN expression RPAREN
2223
+
2224
+ NUMBER shift and go to state 3
2225
+ LPAREN shift and go to state 2
2226
+
2227
+
2228
+ state 3
2229
+
2230
+ expression -> NUMBER .
2231
+
2232
+ $ reduce using rule 5
2233
+ PLUS reduce using rule 5
2234
+ MINUS reduce using rule 5
2235
+ TIMES reduce using rule 5
2236
+ DIVIDE reduce using rule 5
2237
+ RPAREN reduce using rule 5
2238
+
2239
+
2240
+ state 4
2241
+
2242
+ expression -> expression TIMES . expression
2243
+ expression -> . expression PLUS expression
2244
+ expression -> . expression MINUS expression
2245
+ expression -> . expression TIMES expression
2246
+ expression -> . expression DIVIDE expression
2247
+ expression -> . NUMBER
2248
+ expression -> . LPAREN expression RPAREN
2249
+
2250
+ NUMBER shift and go to state 3
2251
+ LPAREN shift and go to state 2
2252
+
2253
+
2254
+ state 5
2255
+
2256
+ expression -> expression MINUS . expression
2257
+ expression -> . expression PLUS expression
2258
+ expression -> . expression MINUS expression
2259
+ expression -> . expression TIMES expression
2260
+ expression -> . expression DIVIDE expression
2261
+ expression -> . NUMBER
2262
+ expression -> . LPAREN expression RPAREN
2263
+
2264
+ NUMBER shift and go to state 3
2265
+ LPAREN shift and go to state 2
2266
+
2267
+
2268
+ state 6
2269
+
2270
+ expression -> expression PLUS . expression
2271
+ expression -> . expression PLUS expression
2272
+ expression -> . expression MINUS expression
2273
+ expression -> . expression TIMES expression
2274
+ expression -> . expression DIVIDE expression
2275
+ expression -> . NUMBER
2276
+ expression -> . LPAREN expression RPAREN
2277
+
2278
+ NUMBER shift and go to state 3
2279
+ LPAREN shift and go to state 2
2280
+
2281
+
2282
+ state 7
2283
+
2284
+ expression -> expression DIVIDE . expression
2285
+ expression -> . expression PLUS expression
2286
+ expression -> . expression MINUS expression
2287
+ expression -> . expression TIMES expression
2288
+ expression -> . expression DIVIDE expression
2289
+ expression -> . NUMBER
2290
+ expression -> . LPAREN expression RPAREN
2291
+
2292
+ NUMBER shift and go to state 3
2293
+ LPAREN shift and go to state 2
2294
+
2295
+
2296
+ state 8
2297
+
2298
+ expression -> LPAREN expression . RPAREN
2299
+ expression -> expression . PLUS expression
2300
+ expression -> expression . MINUS expression
2301
+ expression -> expression . TIMES expression
2302
+ expression -> expression . DIVIDE expression
2303
+
2304
+ RPAREN shift and go to state 13
2305
+ PLUS shift and go to state 6
2306
+ MINUS shift and go to state 5
2307
+ TIMES shift and go to state 4
2308
+ DIVIDE shift and go to state 7
2309
+
2310
+
2311
+ state 9
2312
+
2313
+ expression -> expression TIMES expression .
2314
+ expression -> expression . PLUS expression
2315
+ expression -> expression . MINUS expression
2316
+ expression -> expression . TIMES expression
2317
+ expression -> expression . DIVIDE expression
2318
+
2319
+ $ reduce using rule 3
2320
+ PLUS reduce using rule 3
2321
+ MINUS reduce using rule 3
2322
+ TIMES reduce using rule 3
2323
+ DIVIDE reduce using rule 3
2324
+ RPAREN reduce using rule 3
2325
+
2326
+ ! PLUS [ shift and go to state 6 ]
2327
+ ! MINUS [ shift and go to state 5 ]
2328
+ ! TIMES [ shift and go to state 4 ]
2329
+ ! DIVIDE [ shift and go to state 7 ]
2330
+
2331
+ state 10
2332
+
2333
+ expression -> expression MINUS expression .
2334
+ expression -> expression . PLUS expression
2335
+ expression -> expression . MINUS expression
2336
+ expression -> expression . TIMES expression
2337
+ expression -> expression . DIVIDE expression
2338
+
2339
+ $ reduce using rule 2
2340
+ PLUS reduce using rule 2
2341
+ MINUS reduce using rule 2
2342
+ RPAREN reduce using rule 2
2343
+ TIMES shift and go to state 4
2344
+ DIVIDE shift and go to state 7
2345
+
2346
+ ! TIMES [ reduce using rule 2 ]
2347
+ ! DIVIDE [ reduce using rule 2 ]
2348
+ ! PLUS [ shift and go to state 6 ]
2349
+ ! MINUS [ shift and go to state 5 ]
2350
+
2351
+ state 11
2352
+
2353
+ expression -> expression PLUS expression .
2354
+ expression -> expression . PLUS expression
2355
+ expression -> expression . MINUS expression
2356
+ expression -> expression . TIMES expression
2357
+ expression -> expression . DIVIDE expression
2358
+
2359
+ $ reduce using rule 1
2360
+ PLUS reduce using rule 1
2361
+ MINUS reduce using rule 1
2362
+ RPAREN reduce using rule 1
2363
+ TIMES shift and go to state 4
2364
+ DIVIDE shift and go to state 7
2365
+
2366
+ ! TIMES [ reduce using rule 1 ]
2367
+ ! DIVIDE [ reduce using rule 1 ]
2368
+ ! PLUS [ shift and go to state 6 ]
2369
+ ! MINUS [ shift and go to state 5 ]
2370
+
2371
+ state 12
2372
+
2373
+ expression -> expression DIVIDE expression .
2374
+ expression -> expression . PLUS expression
2375
+ expression -> expression . MINUS expression
2376
+ expression -> expression . TIMES expression
2377
+ expression -> expression . DIVIDE expression
2378
+
2379
+ $ reduce using rule 4
2380
+ PLUS reduce using rule 4
2381
+ MINUS reduce using rule 4
2382
+ TIMES reduce using rule 4
2383
+ DIVIDE reduce using rule 4
2384
+ RPAREN reduce using rule 4
2385
+
2386
+ ! PLUS [ shift and go to state 6 ]
2387
+ ! MINUS [ shift and go to state 5 ]
2388
+ ! TIMES [ shift and go to state 4 ]
2389
+ ! DIVIDE [ shift and go to state 7 ]
2390
+
2391
+ state 13
2392
+
2393
+ expression -> LPAREN expression RPAREN .
2394
+
2395
+ $ reduce using rule 6
2396
+ PLUS reduce using rule 6
2397
+ MINUS reduce using rule 6
2398
+ TIMES reduce using rule 6
2399
+ DIVIDE reduce using rule 6
2400
+ RPAREN reduce using rule 6
2401
+ </pre>
2402
+ </blockquote>
2403
+
2404
+ The different states that appear in this file are a representation of
2405
+ every possible sequence of valid input tokens allowed by the grammar.
2406
+ When receiving input tokens, the parser is building up a stack and
2407
+ looking for matching rules. Each state keeps track of the grammar
2408
+ rules that might be in the process of being matched at that point. Within each
2409
+ rule, the "." character indicates the current location of the parse
2410
+ within that rule. In addition, the actions for each valid input token
2411
+ are listed. When a shift/reduce or reduce/reduce conflict arises,
2412
+ rules <em>not</em> selected are prefixed with an !. For example:
2413
+
2414
+ <blockquote>
2415
+ <pre>
2416
+ ! TIMES [ reduce using rule 2 ]
2417
+ ! DIVIDE [ reduce using rule 2 ]
2418
+ ! PLUS [ shift and go to state 6 ]
2419
+ ! MINUS [ shift and go to state 5 ]
2420
+ </pre>
2421
+ </blockquote>
2422
+
2423
+ By looking at these rules (and with a little practice), you can usually track down the source
2424
+ of most parsing conflicts. It should also be stressed that not all shift-reduce conflicts are
2425
+ bad. However, the only way to be sure that they are resolved correctly is to look at <tt>parser.out</tt>.
2426
+
2427
+ <H3><a name="ply_nn29"></a>6.8 Syntax Error Handling</H3>
2428
+
2429
+
2430
+ If you are creating a parser for production use, the handling of
2431
+ syntax errors is important. As a general rule, you don't want a
2432
+ parser to simply throw up its hands and stop at the first sign of
2433
+ trouble. Instead, you want it to report the error, recover if possible, and
2434
+ continue parsing so that all of the errors in the input get reported
2435
+ to the user at once. This is the standard behavior found in compilers
2436
+ for languages such as C, C++, and Java.
2437
+
2438
+ In PLY, when a syntax error occurs during parsing, the error is immediately
2439
+ detected (i.e., the parser does not read any more tokens beyond the
2440
+ source of the error). However, at this point, the parser enters a
2441
+ recovery mode that can be used to try and continue further parsing.
2442
+ As a general rule, error recovery in LR parsers is a delicate
2443
+ topic that involves ancient rituals and black-magic. The recovery mechanism
2444
+ provided by <tt>yacc.py</tt> is comparable to Unix yacc so you may want
2445
+ consult a book like O'Reilly's "Lex and Yacc" for some of the finer details.
2446
+
2447
+ <p>
2448
+ When a syntax error occurs, <tt>yacc.py</tt> performs the following steps:
2449
+
2450
+ <ol>
2451
+ <li>On the first occurrence of an error, the user-defined <tt>p_error()</tt> function
2452
+ is called with the offending token as an argument. However, if the syntax error is due to
2453
+ reaching the end-of-file, <tt>p_error()</tt> is called with an argument of <tt>None</tt>.
2454
+ Afterwards, the parser enters
2455
+ an "error-recovery" mode in which it will not make future calls to <tt>p_error()</tt> until it
2456
+ has successfully shifted at least 3 tokens onto the parsing stack.
2457
+
2458
+ <p>
2459
+ <li>If no recovery action is taken in <tt>p_error()</tt>, the offending lookahead token is replaced
2460
+ with a special <tt>error</tt> token.
2461
+
2462
+ <p>
2463
+ <li>If the offending lookahead token is already set to <tt>error</tt>, the top item of the parsing stack is
2464
+ deleted.
2465
+
2466
+ <p>
2467
+ <li>If the entire parsing stack is unwound, the parser enters a restart state and attempts to start
2468
+ parsing from its initial state.
2469
+
2470
+ <p>
2471
+ <li>If a grammar rule accepts <tt>error</tt> as a token, it will be
2472
+ shifted onto the parsing stack.
2473
+
2474
+ <p>
2475
+ <li>If the top item of the parsing stack is <tt>error</tt>, lookahead tokens will be discarded until the
2476
+ parser can successfully shift a new symbol or reduce a rule involving <tt>error</tt>.
2477
+ </ol>
2478
+
2479
+ <H4><a name="ply_nn30"></a>6.8.1 Recovery and resynchronization with error rules</H4>
2480
+
2481
+
2482
+ The most well-behaved approach for handling syntax errors is to write grammar rules that include the <tt>error</tt>
2483
+ token. For example, suppose your language had a grammar rule for a print statement like this:
2484
+
2485
+ <blockquote>
2486
+ <pre>
2487
+ def p_statement_print(p):
2488
+ 'statement : PRINT expr SEMI'
2489
+ ...
2490
+ </pre>
2491
+ </blockquote>
2492
+
2493
+ To account for the possibility of a bad expression, you might write an additional grammar rule like this:
2494
+
2495
+ <blockquote>
2496
+ <pre>
2497
+ def p_statement_print_error(p):
2498
+ 'statement : PRINT error SEMI'
2499
+ print "Syntax error in print statement. Bad expression"
2500
+
2501
+ </pre>
2502
+ </blockquote>
2503
+
2504
+ In this case, the <tt>error</tt> token will match any sequence of
2505
+ tokens that might appear up to the first semicolon that is
2506
+ encountered. Once the semicolon is reached, the rule will be
2507
+ invoked and the <tt>error</tt> token will go away.
2508
+
2509
+ <p>
2510
+ This type of recovery is sometimes known as parser resynchronization.
2511
+ The <tt>error</tt> token acts as a wildcard for any bad input text and
2512
+ the token immediately following <tt>error</tt> acts as a
2513
+ synchronization token.
2514
+
2515
+ <p>
2516
+ It is important to note that the <tt>error</tt> token usually does not appear as the last token
2517
+ on the right in an error rule. For example:
2518
+
2519
+ <blockquote>
2520
+ <pre>
2521
+ def p_statement_print_error(p):
2522
+ 'statement : PRINT error'
2523
+ print "Syntax error in print statement. Bad expression"
2524
+ </pre>
2525
+ </blockquote>
2526
+
2527
+ This is because the first bad token encountered will cause the rule to
2528
+ be reduced--which may make it difficult to recover if more bad tokens
2529
+ immediately follow.
2530
+
2531
+ <H4><a name="ply_nn31"></a>6.8.2 Panic mode recovery</H4>
2532
+
2533
+
2534
+ An alternative error recovery scheme is to enter a panic mode recovery in which tokens are
2535
+ discarded to a point where the parser might be able to recover in some sensible manner.
2536
+
2537
+ <p>
2538
+ Panic mode recovery is implemented entirely in the <tt>p_error()</tt> function. For example, this
2539
+ function starts discarding tokens until it reaches a closing '}'. Then, it restarts the
2540
+ parser in its initial state.
2541
+
2542
+ <blockquote>
2543
+ <pre>
2544
+ def p_error(p):
2545
+ print "Whoa. You are seriously hosed."
2546
+ # Read ahead looking for a closing '}'
2547
+ while 1:
2548
+ tok = yacc.token() # Get the next token
2549
+ if not tok or tok.type == 'RBRACE': break
2550
+ yacc.restart()
2551
+ </pre>
2552
+ </blockquote>
2553
+
2554
+ <p>
2555
+ This function simply discards the bad token and tells the parser that the error was ok.
2556
+
2557
+ <blockquote>
2558
+ <pre>
2559
+ def p_error(p):
2560
+ print "Syntax error at token", p.type
2561
+ # Just discard the token and tell the parser it's okay.
2562
+ yacc.errok()
2563
+ </pre>
2564
+ </blockquote>
2565
+
2566
+ <P>
2567
+ Within the <tt>p_error()</tt> function, three functions are available to control the behavior
2568
+ of the parser:
2569
+ <p>
2570
+ <ul>
2571
+ <li><tt>yacc.errok()</tt>. This resets the parser state so it doesn't think it's in error-recovery
2572
+ mode. This will prevent an <tt>error</tt> token from being generated and will reset the internal
2573
+ error counters so that the next syntax error will call <tt>p_error()</tt> again.
2574
+
2575
+ <p>
2576
+ <li><tt>yacc.token()</tt>. This returns the next token on the input stream.
2577
+
2578
+ <p>
2579
+ <li><tt>yacc.restart()</tt>. This discards the entire parsing stack and resets the parser
2580
+ to its initial state.
2581
+ </ul>
2582
+
2583
+ Note: these functions are only available when invoking <tt>p_error()</tt> and are not available
2584
+ at any other time.
2585
+
2586
+ <p>
2587
+ To supply the next lookahead token to the parser, <tt>p_error()</tt> can return a token. This might be
2588
+ useful if trying to synchronize on special characters. For example:
2589
+
2590
+ <blockquote>
2591
+ <pre>
2592
+ def p_error(p):
2593
+ # Read ahead looking for a terminating ";"
2594
+ while 1:
2595
+ tok = yacc.token() # Get the next token
2596
+ if not tok or tok.type == 'SEMI': break
2597
+ yacc.errok()
2598
+
2599
+ # Return SEMI to the parser as the next lookahead token
2600
+ return tok
2601
+ </pre>
2602
+ </blockquote>
2603
+
2604
+ <H4><a name="ply_nn35"></a>6.8.3 Signaling an error from a production</H4>
2605
+
2606
+
2607
+ If necessary, a production rule can manually force the parser to enter error recovery. This
2608
+ is done by raising the <tt>SyntaxError</tt> exception like this:
2609
+
2610
+ <blockquote>
2611
+ <pre>
2612
+ def p_production(p):
2613
+ 'production : some production ...'
2614
+ raise SyntaxError
2615
+ </pre>
2616
+ </blockquote>
2617
+
2618
+ The effect of raising <tt>SyntaxError</tt> is the same as if the last symbol shifted onto the
2619
+ parsing stack was actually a syntax error. Thus, when you do this, the last symbol shifted is popped off
2620
+ of the parsing stack and the current lookahead token is set to an <tt>error</tt> token. The parser
2621
+ then enters error-recovery mode where it tries to reduce rules that can accept <tt>error</tt> tokens.
2622
+ The steps that follow from this point are exactly the same as if a syntax error were detected and
2623
+ <tt>p_error()</tt> were called.
2624
+
2625
+ <P>
2626
+ One important aspect of manually setting an error is that the <tt>p_error()</tt> function will <b>NOT</b> be
2627
+ called in this case. If you need to issue an error message, make sure you do it in the production that
2628
+ raises <tt>SyntaxError</tt>.
2629
+
2630
+ <P>
2631
+ Note: This feature of PLY is meant to mimic the behavior of the YYERROR macro in yacc.
2632
+
2633
+
2634
+ <H4><a name="ply_nn32"></a>6.8.4 General comments on error handling</H4>
2635
+
2636
+
2637
+ For normal types of languages, error recovery with error rules and resynchronization characters is probably the most reliable
2638
+ technique. This is because you can instrument the grammar to catch errors at selected places where it is relatively easy
2639
+ to recover and continue parsing. Panic mode recovery is really only useful in certain specialized applications where you might want
2640
+ to discard huge portions of the input text to find a valid restart point.
2641
+
2642
+ <H3><a name="ply_nn33"></a>6.9 Line Number and Position Tracking</H3>
2643
+
2644
+
2645
+ Position tracking is often a tricky problem when writing compilers.
2646
+ By default, PLY tracks the line number and position of all tokens.
2647
+ This information is available using the following functions:
2648
+
2649
+ <ul>
2650
+ <li><tt>p.lineno(num)</tt>. Return the line number for symbol <em>num</em>
2651
+ <li><tt>p.lexpos(num)</tt>. Return the lexing position for symbol <em>num</em>
2652
+ </ul>
2653
+
2654
+ For example:
2655
+
2656
+ <blockquote>
2657
+ <pre>
2658
+ def p_expression(p):
2659
+ 'expression : expression PLUS expression'
2660
+ line = p.lineno(2) # line number of the PLUS token
2661
+ index = p.lexpos(2) # Position of the PLUS token
2662
+ </pre>
2663
+ </blockquote>
2664
+
2665
+ As an optional feature, <tt>yacc.py</tt> can automatically track line
2666
+ numbers and positions for all of the grammar symbols as well.
2667
+ However, this extra tracking requires extra processing and can
2668
+ significantly slow down parsing. Therefore, it must be enabled by
2669
+ passing the
2670
+ <tt>tracking=True</tt> option to <tt>yacc.parse()</tt>. For example:
2671
+
2672
+ <blockquote>
2673
+ <pre>
2674
+ yacc.parse(data,tracking=True)
2675
+ </pre>
2676
+ </blockquote>
2677
+
2678
+ Once enabled, the <tt>lineno()</tt> and <tt>lexpos()</tt> methods work
2679
+ for all grammar symbols. In addition, two additional methods can be
2680
+ used:
2681
+
2682
+ <ul>
2683
+ <li><tt>p.linespan(num)</tt>. Return a tuple (startline,endline) with the starting and ending line number for symbol <em>num</em>.
2684
+ <li><tt>p.lexspan(num)</tt>. Return a tuple (start,end) with the starting and ending positions for symbol <em>num</em>.
2685
+ </ul>
2686
+
2687
+ For example:
2688
+
2689
+ <blockquote>
2690
+ <pre>
2691
+ def p_expression(p):
2692
+ 'expression : expression PLUS expression'
2693
+ p.lineno(1) # Line number of the left expression
2694
+ p.lineno(2) # line number of the PLUS operator
2695
+ p.lineno(3) # line number of the right expression
2696
+ ...
2697
+ start,end = p.linespan(3) # Start,end lines of the right expression
2698
+ starti,endi = p.lexspan(3) # Start,end positions of right expression
2699
+
2700
+ </pre>
2701
+ </blockquote>
2702
+
2703
+ Note: The <tt>lexspan()</tt> function only returns the range of values up to the start of the last grammar symbol.
2704
+
2705
+ <p>
2706
+ Although it may be convenient for PLY to track position information on
2707
+ all grammar symbols, this is often unnecessary. For example, if you
2708
+ are merely using line number information in an error message, you can
2709
+ often just key off of a specific token in the grammar rule. For
2710
+ example:
2711
+
2712
+ <blockquote>
2713
+ <pre>
2714
+ def p_bad_func(p):
2715
+ 'funccall : fname LPAREN error RPAREN'
2716
+ # Line number reported from LPAREN token
2717
+ print "Bad function call at line", p.lineno(2)
2718
+ </pre>
2719
+ </blockquote>
2720
+
2721
+ <p>
2722
+ Similarly, you may get better parsing performance if you only
2723
+ selectively propagate line number information where it's needed using
2724
+ the <tt>p.set_lineno()</tt> method. For example:
2725
+
2726
+ <blockquote>
2727
+ <pre>
2728
+ def p_fname(p):
2729
+ 'fname : ID'
2730
+ p[0] = p[1]
2731
+ p.set_lineno(0,p.lineno(1))
2732
+ </pre>
2733
+ </blockquote>
2734
+
2735
+ PLY doesn't retain line number information from rules that have already been
2736
+ parsed. If you are building an abstract syntax tree and need to have line numbers,
2737
+ you should make sure that the line numbers appear in the tree itself.
2738
+
2739
+ <H3><a name="ply_nn34"></a>6.10 AST Construction</H3>
2740
+
2741
+
2742
+ <tt>yacc.py</tt> provides no special functions for constructing an
2743
+ abstract syntax tree. However, such construction is easy enough to do
2744
+ on your own.
2745
+
2746
+ <p>A minimal way to construct a tree is to simply create and
2747
+ propagate a tuple or list in each grammar rule function. There
2748
+ are many possible ways to do this, but one example would be something
2749
+ like this:
2750
+
2751
+ <blockquote>
2752
+ <pre>
2753
+ def p_expression_binop(p):
2754
+ '''expression : expression PLUS expression
2755
+ | expression MINUS expression
2756
+ | expression TIMES expression
2757
+ | expression DIVIDE expression'''
2758
+
2759
+ p[0] = ('binary-expression',p[2],p[1],p[3])
2760
+
2761
+ def p_expression_group(p):
2762
+ 'expression : LPAREN expression RPAREN'
2763
+ p[0] = ('group-expression',p[2])
2764
+
2765
+ def p_expression_number(p):
2766
+ 'expression : NUMBER'
2767
+ p[0] = ('number-expression',p[1])
2768
+ </pre>
2769
+ </blockquote>
2770
+
2771
+ <p>
2772
+ Another approach is to create a set of data structure for different
2773
+ kinds of abstract syntax tree nodes and assign nodes to <tt>p[0]</tt>
2774
+ in each rule. For example:
2775
+
2776
+ <blockquote>
2777
+ <pre>
2778
+ class Expr: pass
2779
+
2780
+ class BinOp(Expr):
2781
+ def __init__(self,left,op,right):
2782
+ self.type = "binop"
2783
+ self.left = left
2784
+ self.right = right
2785
+ self.op = op
2786
+
2787
+ class Number(Expr):
2788
+ def __init__(self,value):
2789
+ self.type = "number"
2790
+ self.value = value
2791
+
2792
+ def p_expression_binop(p):
2793
+ '''expression : expression PLUS expression
2794
+ | expression MINUS expression
2795
+ | expression TIMES expression
2796
+ | expression DIVIDE expression'''
2797
+
2798
+ p[0] = BinOp(p[1],p[2],p[3])
2799
+
2800
+ def p_expression_group(p):
2801
+ 'expression : LPAREN expression RPAREN'
2802
+ p[0] = p[2]
2803
+
2804
+ def p_expression_number(p):
2805
+ 'expression : NUMBER'
2806
+ p[0] = Number(p[1])
2807
+ </pre>
2808
+ </blockquote>
2809
+
2810
+ The advantage to this approach is that it may make it easier to attach more complicated
2811
+ semantics, type checking, code generation, and other features to the node classes.
2812
+
2813
+ <p>
2814
+ To simplify tree traversal, it may make sense to pick a very generic
2815
+ tree structure for your parse tree nodes. For example:
2816
+
2817
+ <blockquote>
2818
+ <pre>
2819
+ class Node:
2820
+ def __init__(self,type,children=None,leaf=None):
2821
+ self.type = type
2822
+ if children:
2823
+ self.children = children
2824
+ else:
2825
+ self.children = [ ]
2826
+ self.leaf = leaf
2827
+
2828
+ def p_expression_binop(p):
2829
+ '''expression : expression PLUS expression
2830
+ | expression MINUS expression
2831
+ | expression TIMES expression
2832
+ | expression DIVIDE expression'''
2833
+
2834
+ p[0] = Node("binop", [p[1],p[3]], p[2])
2835
+ </pre>
2836
+ </blockquote>
2837
+
2838
+ <H3><a name="ply_nn35"></a>6.11 Embedded Actions</H3>
2839
+
2840
+
2841
+ The parsing technique used by yacc only allows actions to be executed at the end of a rule. For example,
2842
+ suppose you have a rule like this:
2843
+
2844
+ <blockquote>
2845
+ <pre>
2846
+ def p_foo(p):
2847
+ "foo : A B C D"
2848
+ print "Parsed a foo", p[1],p[2],p[3],p[4]
2849
+ </pre>
2850
+ </blockquote>
2851
+
2852
+ <p>
2853
+ In this case, the supplied action code only executes after all of the
2854
+ symbols <tt>A</tt>, <tt>B</tt>, <tt>C</tt>, and <tt>D</tt> have been
2855
+ parsed. Sometimes, however, it is useful to execute small code
2856
+ fragments during intermediate stages of parsing. For example, suppose
2857
+ you wanted to perform some action immediately after <tt>A</tt> has
2858
+ been parsed. To do this, write an empty rule like this:
2859
+
2860
+ <blockquote>
2861
+ <pre>
2862
+ def p_foo(p):
2863
+ "foo : A seen_A B C D"
2864
+ print "Parsed a foo", p[1],p[3],p[4],p[5]
2865
+ print "seen_A returned", p[2]
2866
+
2867
+ def p_seen_A(p):
2868
+ "seen_A :"
2869
+ print "Saw an A = ", p[-1] # Access grammar symbol to left
2870
+ p[0] = some_value # Assign value to seen_A
2871
+
2872
+ </pre>
2873
+ </blockquote>
2874
+
2875
+ <p>
2876
+ In this example, the empty <tt>seen_A</tt> rule executes immediately
2877
+ after <tt>A</tt> is shifted onto the parsing stack. Within this
2878
+ rule, <tt>p[-1]</tt> refers to the symbol on the stack that appears
2879
+ immediately to the left of the <tt>seen_A</tt> symbol. In this case,
2880
+ it would be the value of <tt>A</tt> in the <tt>foo</tt> rule
2881
+ immediately above. Like other rules, a value can be returned from an
2882
+ embedded action by simply assigning it to <tt>p[0]</tt>
2883
+
2884
+ <p>
2885
+ The use of embedded actions can sometimes introduce extra shift/reduce conflicts. For example,
2886
+ this grammar has no conflicts:
2887
+
2888
+ <blockquote>
2889
+ <pre>
2890
+ def p_foo(p):
2891
+ """foo : abcd
2892
+ | abcx"""
2893
+
2894
+ def p_abcd(p):
2895
+ "abcd : A B C D"
2896
+
2897
+ def p_abcx(p):
2898
+ "abcx : A B C X"
2899
+ </pre>
2900
+ </blockquote>
2901
+
2902
+ However, if you insert an embedded action into one of the rules like this,
2903
+
2904
+ <blockquote>
2905
+ <pre>
2906
+ def p_foo(p):
2907
+ """foo : abcd
2908
+ | abcx"""
2909
+
2910
+ def p_abcd(p):
2911
+ "abcd : A B C D"
2912
+
2913
+ def p_abcx(p):
2914
+ "abcx : A B seen_AB C X"
2915
+
2916
+ def p_seen_AB(p):
2917
+ "seen_AB :"
2918
+ </pre>
2919
+ </blockquote>
2920
+
2921
+ an extra shift-reduce conflict will be introduced. This conflict is
2922
+ caused by the fact that the same symbol <tt>C</tt> appears next in
2923
+ both the <tt>abcd</tt> and <tt>abcx</tt> rules. The parser can either
2924
+ shift the symbol (<tt>abcd</tt> rule) or reduce the empty
2925
+ rule <tt>seen_AB</tt> (<tt>abcx</tt> rule).
2926
+
2927
+ <p>
2928
+ A common use of embedded rules is to control other aspects of parsing
2929
+ such as scoping of local variables. For example, if you were parsing C code, you might
2930
+ write code like this:
2931
+
2932
+ <blockquote>
2933
+ <pre>
2934
+ def p_statements_block(p):
2935
+ "statements: LBRACE new_scope statements RBRACE"""
2936
+ # Action code
2937
+ ...
2938
+ pop_scope() # Return to previous scope
2939
+
2940
+ def p_new_scope(p):
2941
+ "new_scope :"
2942
+ # Create a new scope for local variables
2943
+ s = new_scope()
2944
+ push_scope(s)
2945
+ ...
2946
+ </pre>
2947
+ </blockquote>
2948
+
2949
+ In this case, the embedded action <tt>new_scope</tt> executes
2950
+ immediately after a <tt>LBRACE</tt> (<tt>{</tt>) symbol is parsed.
2951
+ This might adjust internal symbol tables and other aspects of the
2952
+ parser. Upon completion of the rule <tt>statements_block</tt>, code
2953
+ might undo the operations performed in the embedded action
2954
+ (e.g., <tt>pop_scope()</tt>).
2955
+
2956
+ <H3><a name="ply_nn36"></a>6.12 Miscellaneous Yacc Notes</H3>
2957
+
2958
+
2959
+ <ul>
2960
+ <li>The default parsing method is LALR. To use SLR instead, run yacc() as follows:
2961
+
2962
+ <blockquote>
2963
+ <pre>
2964
+ yacc.yacc(method="SLR")
2965
+ </pre>
2966
+ </blockquote>
2967
+ Note: LALR table generation takes approximately twice as long as SLR table generation. There is no
2968
+ difference in actual parsing performance---the same code is used in both cases. LALR is preferred when working
2969
+ with more complicated grammars since it is more powerful.
2970
+
2971
+ <p>
2972
+
2973
+ <li>By default, <tt>yacc.py</tt> relies on <tt>lex.py</tt> for tokenizing. However, an alternative tokenizer
2974
+ can be supplied as follows:
2975
+
2976
+ <blockquote>
2977
+ <pre>
2978
+ yacc.parse(lexer=x)
2979
+ </pre>
2980
+ </blockquote>
2981
+ in this case, <tt>x</tt> must be a Lexer object that minimally has a <tt>x.token()</tt> method for retrieving the next
2982
+ token. If an input string is given to <tt>yacc.parse()</tt>, the lexer must also have an <tt>x.input()</tt> method.
2983
+
2984
+ <p>
2985
+ <li>By default, the yacc generates tables in debugging mode (which produces the parser.out file and other output).
2986
+ To disable this, use
2987
+
2988
+ <blockquote>
2989
+ <pre>
2990
+ yacc.yacc(debug=0)
2991
+ </pre>
2992
+ </blockquote>
2993
+
2994
+ <p>
2995
+ <li>To change the name of the <tt>parsetab.py</tt> file, use:
2996
+
2997
+ <blockquote>
2998
+ <pre>
2999
+ yacc.yacc(tabmodule="foo")
3000
+ </pre>
3001
+ </blockquote>
3002
+
3003
+ <p>
3004
+ <li>To change the directory in which the <tt>parsetab.py</tt> file (and other output files) are written, use:
3005
+ <blockquote>
3006
+ <pre>
3007
+ yacc.yacc(tabmodule="foo",outputdir="somedirectory")
3008
+ </pre>
3009
+ </blockquote>
3010
+
3011
+ <p>
3012
+ <li>To prevent yacc from generating any kind of parser table file, use:
3013
+ <blockquote>
3014
+ <pre>
3015
+ yacc.yacc(write_tables=0)
3016
+ </pre>
3017
+ </blockquote>
3018
+
3019
+ Note: If you disable table generation, yacc() will regenerate the parsing tables
3020
+ each time it runs (which may take awhile depending on how large your grammar is).
3021
+
3022
+ <P>
3023
+ <li>To print copious amounts of debugging during parsing, use:
3024
+
3025
+ <blockquote>
3026
+ <pre>
3027
+ yacc.parse(debug=1)
3028
+ </pre>
3029
+ </blockquote>
3030
+
3031
+ <p>
3032
+ <li>The <tt>yacc.yacc()</tt> function really returns a parser object. If you want to support multiple
3033
+ parsers in the same application, do this:
3034
+
3035
+ <blockquote>
3036
+ <pre>
3037
+ p = yacc.yacc()
3038
+ ...
3039
+ p.parse()
3040
+ </pre>
3041
+ </blockquote>
3042
+
3043
+ Note: The function <tt>yacc.parse()</tt> is bound to the last parser that was generated.
3044
+
3045
+ <p>
3046
+ <li>Since the generation of the LALR tables is relatively expensive, previously generated tables are
3047
+ cached and reused if possible. The decision to regenerate the tables is determined by taking an MD5
3048
+ checksum of all grammar rules and precedence rules. Only in the event of a mismatch are the tables regenerated.
3049
+
3050
+ <p>
3051
+ It should be noted that table generation is reasonably efficient, even for grammars that involve around a 100 rules
3052
+ and several hundred states. For more complex languages such as C, table generation may take 30-60 seconds on a slow
3053
+ machine. Please be patient.
3054
+
3055
+ <p>
3056
+ <li>Since LR parsing is driven by tables, the performance of the parser is largely independent of the
3057
+ size of the grammar. The biggest bottlenecks will be the lexer and the complexity of the code in your grammar rules.
3058
+ </ul>
3059
+
3060
+ <H2><a name="ply_nn37"></a>7. Multiple Parsers and Lexers</H2>
3061
+
3062
+
3063
+ In advanced parsing applications, you may want to have multiple
3064
+ parsers and lexers.
3065
+
3066
+ <p>
3067
+ As a general rules this isn't a problem. However, to make it work,
3068
+ you need to carefully make sure everything gets hooked up correctly.
3069
+ First, make sure you save the objects returned by <tt>lex()</tt> and
3070
+ <tt>yacc()</tt>. For example:
3071
+
3072
+ <blockquote>
3073
+ <pre>
3074
+ lexer = lex.lex() # Return lexer object
3075
+ parser = yacc.yacc() # Return parser object
3076
+ </pre>
3077
+ </blockquote>
3078
+
3079
+ Next, when parsing, make sure you give the <tt>parse()</tt> function a reference to the lexer it
3080
+ should be using. For example:
3081
+
3082
+ <blockquote>
3083
+ <pre>
3084
+ parser.parse(text,lexer=lexer)
3085
+ </pre>
3086
+ </blockquote>
3087
+
3088
+ If you forget to do this, the parser will use the last lexer
3089
+ created--which is not always what you want.
3090
+
3091
+ <p>
3092
+ Within lexer and parser rule functions, these objects are also
3093
+ available. In the lexer, the "lexer" attribute of a token refers to
3094
+ the lexer object that triggered the rule. For example:
3095
+
3096
+ <blockquote>
3097
+ <pre>
3098
+ def t_NUMBER(t):
3099
+ r'\d+'
3100
+ ...
3101
+ print t.lexer # Show lexer object
3102
+ </pre>
3103
+ </blockquote>
3104
+
3105
+ In the parser, the "lexer" and "parser" attributes refer to the lexer
3106
+ and parser objects respectively.
3107
+
3108
+ <blockquote>
3109
+ <pre>
3110
+ def p_expr_plus(p):
3111
+ 'expr : expr PLUS expr'
3112
+ ...
3113
+ print p.parser # Show parser object
3114
+ print p.lexer # Show lexer object
3115
+ </pre>
3116
+ </blockquote>
3117
+
3118
+ If necessary, arbitrary attributes can be attached to the lexer or parser object.
3119
+ For example, if you wanted to have different parsing modes, you could attach a mode
3120
+ attribute to the parser object and look at it later.
3121
+
3122
+ <H2><a name="ply_nn38"></a>8. Using Python's Optimized Mode</H2>
3123
+
3124
+
3125
+ Because PLY uses information from doc-strings, parsing and lexing
3126
+ information must be gathered while running the Python interpreter in
3127
+ normal mode (i.e., not with the -O or -OO options). However, if you
3128
+ specify optimized mode like this:
3129
+
3130
+ <blockquote>
3131
+ <pre>
3132
+ lex.lex(optimize=1)
3133
+ yacc.yacc(optimize=1)
3134
+ </pre>
3135
+ </blockquote>
3136
+
3137
+ then PLY can later be used when Python runs in optimized mode. To make this work,
3138
+ make sure you first run Python in normal mode. Once the lexing and parsing tables
3139
+ have been generated the first time, run Python in optimized mode. PLY will use
3140
+ the tables without the need for doc strings.
3141
+
3142
+ <p>
3143
+ Beware: running PLY in optimized mode disables a lot of error
3144
+ checking. You should only do this when your project has stabilized
3145
+ and you don't need to do any debugging. One of the purposes of
3146
+ optimized mode is to substantially decrease the startup time of
3147
+ your compiler (by assuming that everything is already properly
3148
+ specified and works).
3149
+
3150
+ <H2><a name="ply_nn44"></a>9. Advanced Debugging</H2>
3151
+
3152
+
3153
+ <p>
3154
+ Debugging a compiler is typically not an easy task. PLY provides some
3155
+ advanced diagonistic capabilities through the use of Python's
3156
+ <tt>logging</tt> module. The next two sections describe this:
3157
+
3158
+ <H3><a name="ply_nn45"></a>9.1 Debugging the lex() and yacc() commands</H3>
3159
+
3160
+
3161
+ <p>
3162
+ Both the <tt>lex()</tt> and <tt>yacc()</tt> commands have a debugging
3163
+ mode that can be enabled using the <tt>debug</tt> flag. For example:
3164
+
3165
+ <blockquote>
3166
+ <pre>
3167
+ lex.lex(debug=True)
3168
+ yacc.yacc(debug=True)
3169
+ </pre>
3170
+ </blockquote>
3171
+
3172
+ Normally, the output produced by debugging is routed to either
3173
+ standard error or, in the case of <tt>yacc()</tt>, to a file
3174
+ <tt>parser.out</tt>. This output can be more carefully controlled
3175
+ by supplying a logging object. Here is an example that adds
3176
+ information about where different debugging messages are coming from:
3177
+
3178
+ <blockquote>
3179
+ <pre>
3180
+ # Set up a logging object
3181
+ import logging
3182
+ logging.basicConfig(
3183
+ level = logging.DEBUG,
3184
+ filename = "parselog.txt",
3185
+ filemode = "w",
3186
+ format = "%(filename)10s:%(lineno)4d:%(message)s"
3187
+ )
3188
+ log = logging.getLogger()
3189
+
3190
+ lex.lex(debug=True,debuglog=log)
3191
+ yacc.yacc(debug=True,debuglog=log)
3192
+ </pre>
3193
+ </blockquote>
3194
+
3195
+ If you supply a custom logger, the amount of debugging
3196
+ information produced can be controlled by setting the logging level.
3197
+ Typically, debugging messages are either issued at the <tt>DEBUG</tt>,
3198
+ <tt>INFO</tt>, or <tt>WARNING</tt> levels.
3199
+
3200
+ <p>
3201
+ PLY's error messages and warnings are also produced using the logging
3202
+ interface. This can be controlled by passing a logging object
3203
+ using the <tt>errorlog</tt> parameter.
3204
+
3205
+ <blockquote>
3206
+ <pre>
3207
+ lex.lex(errorlog=log)
3208
+ yacc.yacc(errorlog=log)
3209
+ </pre>
3210
+ </blockquote>
3211
+
3212
+ If you want to completely silence warnings, you can either pass in a
3213
+ logging object with an appropriate filter level or use the <tt>NullLogger</tt>
3214
+ object defined in either <tt>lex</tt> or <tt>yacc</tt>. For example:
3215
+
3216
+ <blockquote>
3217
+ <pre>
3218
+ yacc.yacc(errorlog=yacc.NullLogger())
3219
+ </pre>
3220
+ </blockquote>
3221
+
3222
+ <H3><a name="ply_nn46"></a>9.2 Run-time Debugging</H3>
3223
+
3224
+
3225
+ <p>
3226
+ To enable run-time debugging of a parser, use the <tt>debug</tt> option to parse. This
3227
+ option can either be an integer (which simply turns debugging on or off) or an instance
3228
+ of a logger object. For example:
3229
+
3230
+ <blockquote>
3231
+ <pre>
3232
+ log = logging.getLogger()
3233
+ parser.parse(input,debug=log)
3234
+ </pre>
3235
+ </blockquote>
3236
+
3237
+ If a logging object is passed, you can use its filtering level to control how much
3238
+ output gets generated. The <tt>INFO</tt> level is used to produce information
3239
+ about rule reductions. The <tt>DEBUG</tt> level will show information about the
3240
+ parsing stack, token shifts, and other details. The <tt>ERROR</tt> level shows information
3241
+ related to parsing errors.
3242
+
3243
+ <p>
3244
+ For very complicated problems, you should pass in a logging object that
3245
+ redirects to a file where you can more easily inspect the output after
3246
+ execution.
3247
+
3248
+ <H2><a name="ply_nn39"></a>10. Where to go from here?</H2>
3249
+
3250
+
3251
+ The <tt>examples</tt> directory of the PLY distribution contains several simple examples. Please consult a
3252
+ compilers textbook for the theory and underlying implementation details or LR parsing.
3253
+
3254
+ </body>
3255
+ </html>
3256
+
3257
+
3258
+
3259
+
3260
+
3261
+
3262
+