CHANGES 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407
  1. Version 3.11
  2. ---------------------
  3. 02/15/18 beazley
  4. Fixed some minor bugs related to re flags and token order.
  5. Github pull requests #151 and #153.
  6. 02/15/18 beazley
  7. Added a set_lexpos() method to grammar symbols. Github issue #148.
  8. 04/13/17 beazley
  9. Mostly minor bug fixes and small code cleanups.
  10. Version 3.10
  11. ---------------------
  12. 01/31/17: beazley
  13. Changed grammar signature computation to not involve hashing
  14. functions. Parts are just combined into a big string.
  15. 10/07/16: beazley
  16. Fixed Issue #101: Incorrect shift-reduce conflict resolution with
  17. precedence specifier.
  18. PLY was incorrectly resolving shift-reduce conflicts in certain
  19. cases. For example, in the example/calc/calc.py example, you
  20. could trigger it doing this:
  21. calc > -3 - 4
  22. 1 (correct answer should be -7)
  23. calc >
  24. Issue and suggested patch contributed by https://github.com/RomaVis
  25. Version 3.9
  26. ---------------------
  27. 08/30/16: beazley
  28. Exposed the parser state number as the parser.state attribute
  29. in productions and error functions. For example:
  30. def p_somerule(p):
  31. '''
  32. rule : A B C
  33. '''
  34. print('State:', p.parser.state)
  35. May address issue #65 (publish current state in error callback).
  36. 08/30/16: beazley
  37. Fixed Issue #88. Python3 compatibility with ply/cpp.
  38. 08/30/16: beazley
  39. Fixed Issue #93. Ply can crash if SyntaxError is raised inside
  40. a production. Not actually sure if the original implementation
  41. worked as documented at all. Yacc has been modified to follow
  42. the spec as outlined in the CHANGES noted for 11/27/07 below.
  43. 08/30/16: beazley
  44. Fixed Issue #97. Failure with code validation when the original
  45. source files aren't present. Validation step now ignores
  46. the missing file.
  47. 08/30/16: beazley
  48. Minor fixes to version numbers.
  49. Version 3.8
  50. ---------------------
  51. 10/02/15: beazley
  52. Fixed issues related to Python 3.5. Patch contributed by Barry Warsaw.
  53. Version 3.7
  54. ---------------------
  55. 08/25/15: beazley
  56. Fixed problems when reading table files from pickled data.
  57. 05/07/15: beazley
  58. Fixed regression in handling of table modules if specified as module
  59. objects. See https://github.com/dabeaz/ply/issues/63
  60. Version 3.6
  61. ---------------------
  62. 04/25/15: beazley
  63. If PLY is unable to create the 'parser.out' or 'parsetab.py' files due
  64. to permission issues, it now just issues a warning message and
  65. continues to operate. This could happen if a module using PLY
  66. is installed in a funny way where tables have to be regenerated, but
  67. for whatever reason, the user doesn't have write permission on
  68. the directory where PLY wants to put them.
  69. 04/24/15: beazley
  70. Fixed some issues related to use of packages and table file
  71. modules. Just to emphasize, PLY now generates its special
  72. files such as 'parsetab.py' and 'lextab.py' in the *SAME*
  73. directory as the source file that uses lex() and yacc().
  74. If for some reason, you want to change the name of the table
  75. module, use the tabmodule and lextab options:
  76. lexer = lex.lex(lextab='spamlextab')
  77. parser = yacc.yacc(tabmodule='spamparsetab')
  78. If you specify a simple name as shown, the module will still be
  79. created in the same directory as the file invoking lex() or yacc().
  80. If you want the table files to be placed into a different package,
  81. then give a fully qualified package name. For example:
  82. lexer = lex.lex(lextab='pkgname.files.lextab')
  83. parser = yacc.yacc(tabmodule='pkgname.files.parsetab')
  84. For this to work, 'pkgname.files' must already exist as a valid
  85. Python package (i.e., the directories must already exist and be
  86. set up with the proper __init__.py files, etc.).
  87. Version 3.5
  88. ---------------------
  89. 04/21/15: beazley
  90. Added support for defaulted_states in the parser. A
  91. defaulted_state is a state where the only legal action is a
  92. reduction of a single grammar rule across all valid input
  93. tokens. For such states, the rule is reduced and the
  94. reading of the next lookahead token is delayed until it is
  95. actually needed at a later point in time.
  96. This delay in consuming the next lookahead token is a
  97. potentially important feature in advanced parsing
  98. applications that require tight interaction between the
  99. lexer and the parser. For example, a grammar rule change
  100. modify the lexer state upon reduction and have such changes
  101. take effect before the next input token is read.
  102. *** POTENTIAL INCOMPATIBILITY ***
  103. One potential danger of defaulted_states is that syntax
  104. errors might be deferred to a a later point of processing
  105. than where they were detected in past versions of PLY.
  106. Thus, it's possible that your error handling could change
  107. slightly on the same inputs. defaulted_states do not change
  108. the overall parsing of the input (i.e., the same grammar is
  109. accepted).
  110. If for some reason, you need to disable defaulted states,
  111. you can do this:
  112. parser = yacc.yacc()
  113. parser.defaulted_states = {}
  114. 04/21/15: beazley
  115. Fixed debug logging in the parser. It wasn't properly reporting goto states
  116. on grammar rule reductions.
  117. 04/20/15: beazley
  118. Added actions to be defined to character literals (Issue #32). For example:
  119. literals = [ '{', '}' ]
  120. def t_lbrace(t):
  121. r'\{'
  122. # Some action
  123. t.type = '{'
  124. return t
  125. def t_rbrace(t):
  126. r'\}'
  127. # Some action
  128. t.type = '}'
  129. return t
  130. 04/19/15: beazley
  131. Import of the 'parsetab.py' file is now constrained to only consider the
  132. directory specified by the outputdir argument to yacc(). If not supplied,
  133. the import will only consider the directory in which the grammar is defined.
  134. This should greatly reduce problems with the wrong parsetab.py file being
  135. imported by mistake. For example, if it's found somewhere else on the path
  136. by accident.
  137. *** POTENTIAL INCOMPATIBILITY *** It's possible that this might break some
  138. packaging/deployment setup if PLY was instructed to place its parsetab.py
  139. in a different location. You'll have to specify a proper outputdir= argument
  140. to yacc() to fix this if needed.
  141. 04/19/15: beazley
  142. Changed default output directory to be the same as that in which the
  143. yacc grammar is defined. If your grammar is in a file 'calc.py',
  144. then the parsetab.py and parser.out files should be generated in the
  145. same directory as that file. The destination directory can be changed
  146. using the outputdir= argument to yacc().
  147. 04/19/15: beazley
  148. Changed the parsetab.py file signature slightly so that the parsetab won't
  149. regenerate if created on a different major version of Python (ie., a
  150. parsetab created on Python 2 will work with Python 3).
  151. 04/16/15: beazley
  152. Fixed Issue #44 call_errorfunc() should return the result of errorfunc()
  153. 04/16/15: beazley
  154. Support for versions of Python <2.7 is officially dropped. PLY may work, but
  155. the unit tests requires Python 2.7 or newer.
  156. 04/16/15: beazley
  157. Fixed bug related to calling yacc(start=...). PLY wasn't regenerating the
  158. table file correctly for this case.
  159. 04/16/15: beazley
  160. Added skipped tests for PyPy and Java. Related to use of Python's -O option.
  161. 05/29/13: beazley
  162. Added filter to make unit tests pass under 'python -3'.
  163. Reported by Neil Muller.
  164. 05/29/13: beazley
  165. Fixed CPP_INTEGER regex in ply/cpp.py (Issue 21).
  166. Reported by @vbraun.
  167. 05/29/13: beazley
  168. Fixed yacc validation bugs when from __future__ import unicode_literals
  169. is being used. Reported by Kenn Knowles.
  170. 05/29/13: beazley
  171. Added support for Travis-CI. Contributed by Kenn Knowles.
  172. 05/29/13: beazley
  173. Added a .gitignore file. Suggested by Kenn Knowles.
  174. 05/29/13: beazley
  175. Fixed validation problems for source files that include a
  176. different source code encoding specifier. Fix relies on
  177. the inspect module. Should work on Python 2.6 and newer.
  178. Not sure about older versions of Python.
  179. Contributed by Michael Droettboom
  180. 05/21/13: beazley
  181. Fixed unit tests for yacc to eliminate random failures due to dict hash value
  182. randomization in Python 3.3
  183. Reported by Arfrever
  184. 10/15/12: beazley
  185. Fixed comment whitespace processing bugs in ply/cpp.py.
  186. Reported by Alexei Pososin.
  187. 10/15/12: beazley
  188. Fixed token names in ply/ctokens.py to match rule names.
  189. Reported by Alexei Pososin.
  190. 04/26/12: beazley
  191. Changes to functions available in panic mode error recover. In previous versions
  192. of PLY, the following global functions were available for use in the p_error() rule:
  193. yacc.errok() # Reset error state
  194. yacc.token() # Get the next token
  195. yacc.restart() # Reset the parsing stack
  196. The use of global variables was problematic for code involving multiple parsers
  197. and frankly was a poor design overall. These functions have been moved to methods
  198. of the parser instance created by the yacc() function. You should write code like
  199. this:
  200. def p_error(p):
  201. ...
  202. parser.errok()
  203. parser = yacc.yacc()
  204. *** POTENTIAL INCOMPATIBILITY *** The original global functions now issue a
  205. DeprecationWarning.
  206. 04/19/12: beazley
  207. Fixed some problems with line and position tracking and the use of error
  208. symbols. If you have a grammar rule involving an error rule like this:
  209. def p_assignment_bad(p):
  210. '''assignment : location EQUALS error SEMI'''
  211. ...
  212. You can now do line and position tracking on the error token. For example:
  213. def p_assignment_bad(p):
  214. '''assignment : location EQUALS error SEMI'''
  215. start_line = p.lineno(3)
  216. start_pos = p.lexpos(3)
  217. If the trackng=True option is supplied to parse(), you can additionally get
  218. spans:
  219. def p_assignment_bad(p):
  220. '''assignment : location EQUALS error SEMI'''
  221. start_line, end_line = p.linespan(3)
  222. start_pos, end_pos = p.lexspan(3)
  223. Note that error handling is still a hairy thing in PLY. This won't work
  224. unless your lexer is providing accurate information. Please report bugs.
  225. Suggested by a bug reported by Davis Herring.
  226. 04/18/12: beazley
  227. Change to doc string handling in lex module. Regex patterns are now first
  228. pulled from a function's .regex attribute. If that doesn't exist, then
  229. .doc is checked as a fallback. The @TOKEN decorator now sets the .regex
  230. attribute of a function instead of its doc string.
  231. Changed suggested by Kristoffer Ellersgaard Koch.
  232. 04/18/12: beazley
  233. Fixed issue #1: Fixed _tabversion. It should use __tabversion__ instead of __version__
  234. Reported by Daniele Tricoli
  235. 04/18/12: beazley
  236. Fixed issue #8: Literals empty list causes IndexError
  237. Reported by Walter Nissen.
  238. 04/18/12: beazley
  239. Fixed issue #12: Typo in code snippet in documentation
  240. Reported by florianschanda.
  241. 04/18/12: beazley
  242. Fixed issue #10: Correctly escape t_XOREQUAL pattern.
  243. Reported by Andy Kittner.
  244. Version 3.4
  245. ---------------------
  246. 02/17/11: beazley
  247. Minor patch to make cpp.py compatible with Python 3. Note: This
  248. is an experimental file not currently used by the rest of PLY.
  249. 02/17/11: beazley
  250. Fixed setup.py trove classifiers to properly list PLY as
  251. Python 3 compatible.
  252. 01/02/11: beazley
  253. Migration of repository to github.
  254. Version 3.3
  255. -----------------------------
  256. 08/25/09: beazley
  257. Fixed issue 15 related to the set_lineno() method in yacc. Reported by
  258. mdsherry.
  259. 08/25/09: beazley
  260. Fixed a bug related to regular expression compilation flags not being
  261. properly stored in lextab.py files created by the lexer when running
  262. in optimize mode. Reported by Bruce Frederiksen.
  263. Version 3.2
  264. -----------------------------
  265. 03/24/09: beazley
  266. Added an extra check to not print duplicated warning messages
  267. about reduce/reduce conflicts.
  268. 03/24/09: beazley
  269. Switched PLY over to a BSD-license.
  270. 03/23/09: beazley
  271. Performance optimization. Discovered a few places to make
  272. speedups in LR table generation.
  273. 03/23/09: beazley
  274. New warning message. PLY now warns about rules never
  275. reduced due to reduce/reduce conflicts. Suggested by
  276. Bruce Frederiksen.
  277. 03/23/09: beazley
  278. Some clean-up of warning messages related to reduce/reduce errors.
  279. 03/23/09: beazley
  280. Added a new picklefile option to yacc() to write the parsing
  281. tables to a filename using the pickle module. Here is how
  282. it works:
  283. yacc(picklefile="parsetab.p")
  284. This option can be used if the normal parsetab.py file is
  285. extremely large. For example, on jython, it is impossible
  286. to read parsing tables if the parsetab.py exceeds a certain
  287. threshold.
  288. The filename supplied to the picklefile option is opened
  289. relative to the current working directory of the Python
  290. interpreter. If you need to refer to the file elsewhere,
  291. you will need to supply an absolute or relative path.
  292. For maximum portability, the pickle file is written
  293. using protocol 0.
  294. 03/13/09: beazley
  295. Fixed a bug in parser.out generation where the rule numbers
  296. where off by one.
  297. 03/13/09: beazley
  298. Fixed a string formatting bug with one of the error messages.
  299. Reported by Richard Reitmeyer
  300. Version 3.1
  301. -----------------------------
  302. 02/28/09: beazley
  303. Fixed broken start argument to yacc(). PLY-3.0 broke this
  304. feature by accident.
  305. 02/28/09: beazley
  306. Fixed debugging output. yacc() no longer reports shift/reduce
  307. or reduce/reduce conflicts if debugging is turned off. This
  308. restores similar behavior in PLY-2.5. Reported by Andrew Waters.
  309. Version 3.0
  310. -----------------------------
  311. 02/03/09: beazley
  312. Fixed missing lexer attribute on certain tokens when
  313. invoking the parser p_error() function. Reported by
  314. Bart Whiteley.
  315. 02/02/09: beazley
  316. The lex() command now does all error-reporting and diagonistics
  317. using the logging module interface. Pass in a Logger object
  318. using the errorlog parameter to specify a different logger.
  319. 02/02/09: beazley
  320. Refactored ply.lex to use a more object-oriented and organized
  321. approach to collecting lexer information.
  322. 02/01/09: beazley
  323. Removed the nowarn option from lex(). All output is controlled
  324. by passing in a logger object. Just pass in a logger with a high
  325. level setting to suppress output. This argument was never
  326. documented to begin with so hopefully no one was relying upon it.
  327. 02/01/09: beazley
  328. Discovered and removed a dead if-statement in the lexer. This
  329. resulted in a 6-7% speedup in lexing when I tested it.
  330. 01/13/09: beazley
  331. Minor change to the procedure for signalling a syntax error in a
  332. production rule. A normal SyntaxError exception should be raised
  333. instead of yacc.SyntaxError.
  334. 01/13/09: beazley
  335. Added a new method p.set_lineno(n,lineno) that can be used to set the
  336. line number of symbol n in grammar rules. This simplifies manual
  337. tracking of line numbers.
  338. 01/11/09: beazley
  339. Vastly improved debugging support for yacc.parse(). Instead of passing
  340. debug as an integer, you can supply a Logging object (see the logging
  341. module). Messages will be generated at the ERROR, INFO, and DEBUG
  342. logging levels, each level providing progressively more information.
  343. The debugging trace also shows states, grammar rule, values passed
  344. into grammar rules, and the result of each reduction.
  345. 01/09/09: beazley
  346. The yacc() command now does all error-reporting and diagnostics using
  347. the interface of the logging module. Use the errorlog parameter to
  348. specify a logging object for error messages. Use the debuglog parameter
  349. to specify a logging object for the 'parser.out' output.
  350. 01/09/09: beazley
  351. *HUGE* refactoring of the the ply.yacc() implementation. The high-level
  352. user interface is backwards compatible, but the internals are completely
  353. reorganized into classes. No more global variables. The internals
  354. are also more extensible. For example, you can use the classes to
  355. construct a LALR(1) parser in an entirely different manner than
  356. what is currently the case. Documentation is forthcoming.
  357. 01/07/09: beazley
  358. Various cleanup and refactoring of yacc internals.
  359. 01/06/09: beazley
  360. Fixed a bug with precedence assignment. yacc was assigning the precedence
  361. each rule based on the left-most token, when in fact, it should have been
  362. using the right-most token. Reported by Bruce Frederiksen.
  363. 11/27/08: beazley
  364. Numerous changes to support Python 3.0 including removal of deprecated
  365. statements (e.g., has_key) and the additional of compatibility code
  366. to emulate features from Python 2 that have been removed, but which
  367. are needed. Fixed the unit testing suite to work with Python 3.0.
  368. The code should be backwards compatible with Python 2.
  369. 11/26/08: beazley
  370. Loosened the rules on what kind of objects can be passed in as the
  371. "module" parameter to lex() and yacc(). Previously, you could only use
  372. a module or an instance. Now, PLY just uses dir() to get a list of
  373. symbols on whatever the object is without regard for its type.
  374. 11/26/08: beazley
  375. Changed all except: statements to be compatible with Python2.x/3.x syntax.
  376. 11/26/08: beazley
  377. Changed all raise Exception, value statements to raise Exception(value) for
  378. forward compatibility.
  379. 11/26/08: beazley
  380. Removed all print statements from lex and yacc, using sys.stdout and sys.stderr
  381. directly. Preparation for Python 3.0 support.
  382. 11/04/08: beazley
  383. Fixed a bug with referring to symbols on the the parsing stack using negative
  384. indices.
  385. 05/29/08: beazley
  386. Completely revamped the testing system to use the unittest module for everything.
  387. Added additional tests to cover new errors/warnings.
  388. Version 2.5
  389. -----------------------------
  390. 05/28/08: beazley
  391. Fixed a bug with writing lex-tables in optimized mode and start states.
  392. Reported by Kevin Henry.
  393. Version 2.4
  394. -----------------------------
  395. 05/04/08: beazley
  396. A version number is now embedded in the table file signature so that
  397. yacc can more gracefully accomodate changes to the output format
  398. in the future.
  399. 05/04/08: beazley
  400. Removed undocumented .pushback() method on grammar productions. I'm
  401. not sure this ever worked and can't recall ever using it. Might have
  402. been an abandoned idea that never really got fleshed out. This
  403. feature was never described or tested so removing it is hopefully
  404. harmless.
  405. 05/04/08: beazley
  406. Added extra error checking to yacc() to detect precedence rules defined
  407. for undefined terminal symbols. This allows yacc() to detect a potential
  408. problem that can be really tricky to debug if no warning message or error
  409. message is generated about it.
  410. 05/04/08: beazley
  411. lex() now has an outputdir that can specify the output directory for
  412. tables when running in optimize mode. For example:
  413. lexer = lex.lex(optimize=True, lextab="ltab", outputdir="foo/bar")
  414. The behavior of specifying a table module and output directory are
  415. more aligned with the behavior of yacc().
  416. 05/04/08: beazley
  417. [Issue 9]
  418. Fixed filename bug in when specifying the modulename in lex() and yacc().
  419. If you specified options such as the following:
  420. parser = yacc.yacc(tabmodule="foo.bar.parsetab",outputdir="foo/bar")
  421. yacc would create a file "foo.bar.parsetab.py" in the given directory.
  422. Now, it simply generates a file "parsetab.py" in that directory.
  423. Bug reported by cptbinho.
  424. 05/04/08: beazley
  425. Slight modification to lex() and yacc() to allow their table files
  426. to be loaded from a previously loaded module. This might make
  427. it easier to load the parsing tables from a complicated package
  428. structure. For example:
  429. import foo.bar.spam.parsetab as parsetab
  430. parser = yacc.yacc(tabmodule=parsetab)
  431. Note: lex and yacc will never regenerate the table file if used
  432. in the form---you will get a warning message instead.
  433. This idea suggested by Brian Clapper.
  434. 04/28/08: beazley
  435. Fixed a big with p_error() functions being picked up correctly
  436. when running in yacc(optimize=1) mode. Patch contributed by
  437. Bart Whiteley.
  438. 02/28/08: beazley
  439. Fixed a bug with 'nonassoc' precedence rules. Basically the
  440. non-precedence was being ignored and not producing the correct
  441. run-time behavior in the parser.
  442. 02/16/08: beazley
  443. Slight relaxation of what the input() method to a lexer will
  444. accept as a string. Instead of testing the input to see
  445. if the input is a string or unicode string, it checks to see
  446. if the input object looks like it contains string data.
  447. This change makes it possible to pass string-like objects
  448. in as input. For example, the object returned by mmap.
  449. import mmap, os
  450. data = mmap.mmap(os.open(filename,os.O_RDONLY),
  451. os.path.getsize(filename),
  452. access=mmap.ACCESS_READ)
  453. lexer.input(data)
  454. 11/29/07: beazley
  455. Modification of ply.lex to allow token functions to aliased.
  456. This is subtle, but it makes it easier to create libraries and
  457. to reuse token specifications. For example, suppose you defined
  458. a function like this:
  459. def number(t):
  460. r'\d+'
  461. t.value = int(t.value)
  462. return t
  463. This change would allow you to define a token rule as follows:
  464. t_NUMBER = number
  465. In this case, the token type will be set to 'NUMBER' and use
  466. the associated number() function to process tokens.
  467. 11/28/07: beazley
  468. Slight modification to lex and yacc to grab symbols from both
  469. the local and global dictionaries of the caller. This
  470. modification allows lexers and parsers to be defined using
  471. inner functions and closures.
  472. 11/28/07: beazley
  473. Performance optimization: The lexer.lexmatch and t.lexer
  474. attributes are no longer set for lexer tokens that are not
  475. defined by functions. The only normal use of these attributes
  476. would be in lexer rules that need to perform some kind of
  477. special processing. Thus, it doesn't make any sense to set
  478. them on every token.
  479. *** POTENTIAL INCOMPATIBILITY *** This might break code
  480. that is mucking around with internal lexer state in some
  481. sort of magical way.
  482. 11/27/07: beazley
  483. Added the ability to put the parser into error-handling mode
  484. from within a normal production. To do this, simply raise
  485. a yacc.SyntaxError exception like this:
  486. def p_some_production(p):
  487. 'some_production : prod1 prod2'
  488. ...
  489. raise yacc.SyntaxError # Signal an error
  490. A number of things happen after this occurs:
  491. - The last symbol shifted onto the symbol stack is discarded
  492. and parser state backed up to what it was before the
  493. the rule reduction.
  494. - The current lookahead symbol is saved and replaced by
  495. the 'error' symbol.
  496. - The parser enters error recovery mode where it tries
  497. to either reduce the 'error' rule or it starts
  498. discarding items off of the stack until the parser
  499. resets.
  500. When an error is manually set, the parser does *not* call
  501. the p_error() function (if any is defined).
  502. *** NEW FEATURE *** Suggested on the mailing list
  503. 11/27/07: beazley
  504. Fixed structure bug in examples/ansic. Reported by Dion Blazakis.
  505. 11/27/07: beazley
  506. Fixed a bug in the lexer related to start conditions and ignored
  507. token rules. If a rule was defined that changed state, but
  508. returned no token, the lexer could be left in an inconsistent
  509. state. Reported by
  510. 11/27/07: beazley
  511. Modified setup.py to support Python Eggs. Patch contributed by
  512. Simon Cross.
  513. 11/09/07: beazely
  514. Fixed a bug in error handling in yacc. If a syntax error occurred and the
  515. parser rolled the entire parse stack back, the parser would be left in in
  516. inconsistent state that would cause it to trigger incorrect actions on
  517. subsequent input. Reported by Ton Biegstraaten, Justin King, and others.
  518. 11/09/07: beazley
  519. Fixed a bug when passing empty input strings to yacc.parse(). This
  520. would result in an error message about "No input given". Reported
  521. by Andrew Dalke.
  522. Version 2.3
  523. -----------------------------
  524. 02/20/07: beazley
  525. Fixed a bug with character literals if the literal '.' appeared as the
  526. last symbol of a grammar rule. Reported by Ales Smrcka.
  527. 02/19/07: beazley
  528. Warning messages are now redirected to stderr instead of being printed
  529. to standard output.
  530. 02/19/07: beazley
  531. Added a warning message to lex.py if it detects a literal backslash
  532. character inside the t_ignore declaration. This is to help
  533. problems that might occur if someone accidentally defines t_ignore
  534. as a Python raw string. For example:
  535. t_ignore = r' \t'
  536. The idea for this is from an email I received from David Cimimi who
  537. reported bizarre behavior in lexing as a result of defining t_ignore
  538. as a raw string by accident.
  539. 02/18/07: beazley
  540. Performance improvements. Made some changes to the internal
  541. table organization and LR parser to improve parsing performance.
  542. 02/18/07: beazley
  543. Automatic tracking of line number and position information must now be
  544. enabled by a special flag to parse(). For example:
  545. yacc.parse(data,tracking=True)
  546. In many applications, it's just not that important to have the
  547. parser automatically track all line numbers. By making this an
  548. optional feature, it allows the parser to run significantly faster
  549. (more than a 20% speed increase in many cases). Note: positional
  550. information is always available for raw tokens---this change only
  551. applies to positional information associated with nonterminal
  552. grammar symbols.
  553. *** POTENTIAL INCOMPATIBILITY ***
  554. 02/18/07: beazley
  555. Yacc no longer supports extended slices of grammar productions.
  556. However, it does support regular slices. For example:
  557. def p_foo(p):
  558. '''foo: a b c d e'''
  559. p[0] = p[1:3]
  560. This change is a performance improvement to the parser--it streamlines
  561. normal access to the grammar values since slices are now handled in
  562. a __getslice__() method as opposed to __getitem__().
  563. 02/12/07: beazley
  564. Fixed a bug in the handling of token names when combined with
  565. start conditions. Bug reported by Todd O'Bryan.
  566. Version 2.2
  567. ------------------------------
  568. 11/01/06: beazley
  569. Added lexpos() and lexspan() methods to grammar symbols. These
  570. mirror the same functionality of lineno() and linespan(). For
  571. example:
  572. def p_expr(p):
  573. 'expr : expr PLUS expr'
  574. p.lexpos(1) # Lexing position of left-hand-expression
  575. p.lexpos(1) # Lexing position of PLUS
  576. start,end = p.lexspan(3) # Lexing range of right hand expression
  577. 11/01/06: beazley
  578. Minor change to error handling. The recommended way to skip characters
  579. in the input is to use t.lexer.skip() as shown here:
  580. def t_error(t):
  581. print "Illegal character '%s'" % t.value[0]
  582. t.lexer.skip(1)
  583. The old approach of just using t.skip(1) will still work, but won't
  584. be documented.
  585. 10/31/06: beazley
  586. Discarded tokens can now be specified as simple strings instead of
  587. functions. To do this, simply include the text "ignore_" in the
  588. token declaration. For example:
  589. t_ignore_cppcomment = r'//.*'
  590. Previously, this had to be done with a function. For example:
  591. def t_ignore_cppcomment(t):
  592. r'//.*'
  593. pass
  594. If start conditions/states are being used, state names should appear
  595. before the "ignore_" text.
  596. 10/19/06: beazley
  597. The Lex module now provides support for flex-style start conditions
  598. as described at http://www.gnu.org/software/flex/manual/html_chapter/flex_11.html.
  599. Please refer to this document to understand this change note. Refer to
  600. the PLY documentation for PLY-specific explanation of how this works.
  601. To use start conditions, you first need to declare a set of states in
  602. your lexer file:
  603. states = (
  604. ('foo','exclusive'),
  605. ('bar','inclusive')
  606. )
  607. This serves the same role as the %s and %x specifiers in flex.
  608. One a state has been declared, tokens for that state can be
  609. declared by defining rules of the form t_state_TOK. For example:
  610. t_PLUS = '\+' # Rule defined in INITIAL state
  611. t_foo_NUM = '\d+' # Rule defined in foo state
  612. t_bar_NUM = '\d+' # Rule defined in bar state
  613. t_foo_bar_NUM = '\d+' # Rule defined in both foo and bar
  614. t_ANY_NUM = '\d+' # Rule defined in all states
  615. In addition to defining tokens for each state, the t_ignore and t_error
  616. specifications can be customized for specific states. For example:
  617. t_foo_ignore = " " # Ignored characters for foo state
  618. def t_bar_error(t):
  619. # Handle errors in bar state
  620. With token rules, the following methods can be used to change states
  621. def t_TOKNAME(t):
  622. t.lexer.begin('foo') # Begin state 'foo'
  623. t.lexer.push_state('foo') # Begin state 'foo', push old state
  624. # onto a stack
  625. t.lexer.pop_state() # Restore previous state
  626. t.lexer.current_state() # Returns name of current state
  627. These methods mirror the BEGIN(), yy_push_state(), yy_pop_state(), and
  628. yy_top_state() functions in flex.
  629. The use of start states can be used as one way to write sub-lexers.
  630. For example, the lexer or parser might instruct the lexer to start
  631. generating a different set of tokens depending on the context.
  632. example/yply/ylex.py shows the use of start states to grab C/C++
  633. code fragments out of traditional yacc specification files.
  634. *** NEW FEATURE *** Suggested by Daniel Larraz with whom I also
  635. discussed various aspects of the design.
  636. 10/19/06: beazley
  637. Minor change to the way in which yacc.py was reporting shift/reduce
  638. conflicts. Although the underlying LALR(1) algorithm was correct,
  639. PLY was under-reporting the number of conflicts compared to yacc/bison
  640. when precedence rules were in effect. This change should make PLY
  641. report the same number of conflicts as yacc.
  642. 10/19/06: beazley
  643. Modified yacc so that grammar rules could also include the '-'
  644. character. For example:
  645. def p_expr_list(p):
  646. 'expression-list : expression-list expression'
  647. Suggested by Oldrich Jedlicka.
  648. 10/18/06: beazley
  649. Attribute lexer.lexmatch added so that token rules can access the re
  650. match object that was generated. For example:
  651. def t_FOO(t):
  652. r'some regex'
  653. m = t.lexer.lexmatch
  654. # Do something with m
  655. This may be useful if you want to access named groups specified within
  656. the regex for a specific token. Suggested by Oldrich Jedlicka.
  657. 10/16/06: beazley
  658. Changed the error message that results if an illegal character
  659. is encountered and no default error function is defined in lex.
  660. The exception is now more informative about the actual cause of
  661. the error.
  662. Version 2.1
  663. ------------------------------
  664. 10/02/06: beazley
  665. The last Lexer object built by lex() can be found in lex.lexer.
  666. The last Parser object built by yacc() can be found in yacc.parser.
  667. 10/02/06: beazley
  668. New example added: examples/yply
  669. This example uses PLY to convert Unix-yacc specification files to
  670. PLY programs with the same grammar. This may be useful if you
  671. want to convert a grammar from bison/yacc to use with PLY.
  672. 10/02/06: beazley
  673. Added support for a start symbol to be specified in the yacc
  674. input file itself. Just do this:
  675. start = 'name'
  676. where 'name' matches some grammar rule. For example:
  677. def p_name(p):
  678. 'name : A B C'
  679. ...
  680. This mirrors the functionality of the yacc %start specifier.
  681. 09/30/06: beazley
  682. Some new examples added.:
  683. examples/GardenSnake : A simple indentation based language similar
  684. to Python. Shows how you might handle
  685. whitespace. Contributed by Andrew Dalke.
  686. examples/BASIC : An implementation of 1964 Dartmouth BASIC.
  687. Contributed by Dave against his better
  688. judgement.
  689. 09/28/06: beazley
  690. Minor patch to allow named groups to be used in lex regular
  691. expression rules. For example:
  692. t_QSTRING = r'''(?P<quote>['"]).*?(?P=quote)'''
  693. Patch submitted by Adam Ring.
  694. 09/28/06: beazley
  695. LALR(1) is now the default parsing method. To use SLR, use
  696. yacc.yacc(method="SLR"). Note: there is no performance impact
  697. on parsing when using LALR(1) instead of SLR. However, constructing
  698. the parsing tables will take a little longer.
  699. 09/26/06: beazley
  700. Change to line number tracking. To modify line numbers, modify
  701. the line number of the lexer itself. For example:
  702. def t_NEWLINE(t):
  703. r'\n'
  704. t.lexer.lineno += 1
  705. This modification is both cleanup and a performance optimization.
  706. In past versions, lex was monitoring every token for changes in
  707. the line number. This extra processing is unnecessary for a vast
  708. majority of tokens. Thus, this new approach cleans it up a bit.
  709. *** POTENTIAL INCOMPATIBILITY ***
  710. You will need to change code in your lexer that updates the line
  711. number. For example, "t.lineno += 1" becomes "t.lexer.lineno += 1"
  712. 09/26/06: beazley
  713. Added the lexing position to tokens as an attribute lexpos. This
  714. is the raw index into the input text at which a token appears.
  715. This information can be used to compute column numbers and other
  716. details (e.g., scan backwards from lexpos to the first newline
  717. to get a column position).
  718. 09/25/06: beazley
  719. Changed the name of the __copy__() method on the Lexer class
  720. to clone(). This is used to clone a Lexer object (e.g., if
  721. you're running different lexers at the same time).
  722. 09/21/06: beazley
  723. Limitations related to the use of the re module have been eliminated.
  724. Several users reported problems with regular expressions exceeding
  725. more than 100 named groups. To solve this, lex.py is now capable
  726. of automatically splitting its master regular regular expression into
  727. smaller expressions as needed. This should, in theory, make it
  728. possible to specify an arbitrarily large number of tokens.
  729. 09/21/06: beazley
  730. Improved error checking in lex.py. Rules that match the empty string
  731. are now rejected (otherwise they cause the lexer to enter an infinite
  732. loop). An extra check for rules containing '#' has also been added.
  733. Since lex compiles regular expressions in verbose mode, '#' is interpreted
  734. as a regex comment, it is critical to use '\#' instead.
  735. 09/18/06: beazley
  736. Added a @TOKEN decorator function to lex.py that can be used to
  737. define token rules where the documentation string might be computed
  738. in some way.
  739. digit = r'([0-9])'
  740. nondigit = r'([_A-Za-z])'
  741. identifier = r'(' + nondigit + r'(' + digit + r'|' + nondigit + r')*)'
  742. from ply.lex import TOKEN
  743. @TOKEN(identifier)
  744. def t_ID(t):
  745. # Do whatever
  746. The @TOKEN decorator merely sets the documentation string of the
  747. associated token function as needed for lex to work.
  748. Note: An alternative solution is the following:
  749. def t_ID(t):
  750. # Do whatever
  751. t_ID.__doc__ = identifier
  752. Note: Decorators require the use of Python 2.4 or later. If compatibility
  753. with old versions is needed, use the latter solution.
  754. The need for this feature was suggested by Cem Karan.
  755. 09/14/06: beazley
  756. Support for single-character literal tokens has been added to yacc.
  757. These literals must be enclosed in quotes. For example:
  758. def p_expr(p):
  759. "expr : expr '+' expr"
  760. ...
  761. def p_expr(p):
  762. 'expr : expr "-" expr'
  763. ...
  764. In addition to this, it is necessary to tell the lexer module about
  765. literal characters. This is done by defining the variable 'literals'
  766. as a list of characters. This should be defined in the module that
  767. invokes the lex.lex() function. For example:
  768. literals = ['+','-','*','/','(',')','=']
  769. or simply
  770. literals = '+=*/()='
  771. It is important to note that literals can only be a single character.
  772. When the lexer fails to match a token using its normal regular expression
  773. rules, it will check the current character against the literal list.
  774. If found, it will be returned with a token type set to match the literal
  775. character. Otherwise, an illegal character will be signalled.
  776. 09/14/06: beazley
  777. Modified PLY to install itself as a proper Python package called 'ply'.
  778. This will make it a little more friendly to other modules. This
  779. changes the usage of PLY only slightly. Just do this to import the
  780. modules
  781. import ply.lex as lex
  782. import ply.yacc as yacc
  783. Alternatively, you can do this:
  784. from ply import *
  785. Which imports both the lex and yacc modules.
  786. Change suggested by Lee June.
  787. 09/13/06: beazley
  788. Changed the handling of negative indices when used in production rules.
  789. A negative production index now accesses already parsed symbols on the
  790. parsing stack. For example,
  791. def p_foo(p):
  792. "foo: A B C D"
  793. print p[1] # Value of 'A' symbol
  794. print p[2] # Value of 'B' symbol
  795. print p[-1] # Value of whatever symbol appears before A
  796. # on the parsing stack.
  797. p[0] = some_val # Sets the value of the 'foo' grammer symbol
  798. This behavior makes it easier to work with embedded actions within the
  799. parsing rules. For example, in C-yacc, it is possible to write code like
  800. this:
  801. bar: A { printf("seen an A = %d\n", $1); } B { do_stuff; }
  802. In this example, the printf() code executes immediately after A has been
  803. parsed. Within the embedded action code, $1 refers to the A symbol on
  804. the stack.
  805. To perform this equivalent action in PLY, you need to write a pair
  806. of rules like this:
  807. def p_bar(p):
  808. "bar : A seen_A B"
  809. do_stuff
  810. def p_seen_A(p):
  811. "seen_A :"
  812. print "seen an A =", p[-1]
  813. The second rule "seen_A" is merely a empty production which should be
  814. reduced as soon as A is parsed in the "bar" rule above. The use
  815. of the negative index p[-1] is used to access whatever symbol appeared
  816. before the seen_A symbol.
  817. This feature also makes it possible to support inherited attributes.
  818. For example:
  819. def p_decl(p):
  820. "decl : scope name"
  821. def p_scope(p):
  822. """scope : GLOBAL
  823. | LOCAL"""
  824. p[0] = p[1]
  825. def p_name(p):
  826. "name : ID"
  827. if p[-1] == "GLOBAL":
  828. # ...
  829. else if p[-1] == "LOCAL":
  830. #...
  831. In this case, the name rule is inheriting an attribute from the
  832. scope declaration that precedes it.
  833. *** POTENTIAL INCOMPATIBILITY ***
  834. If you are currently using negative indices within existing grammar rules,
  835. your code will break. This should be extremely rare if non-existent in
  836. most cases. The argument to various grammar rules is not usually not
  837. processed in the same way as a list of items.
  838. Version 2.0
  839. ------------------------------
  840. 09/07/06: beazley
  841. Major cleanup and refactoring of the LR table generation code. Both SLR
  842. and LALR(1) table generation is now performed by the same code base with
  843. only minor extensions for extra LALR(1) processing.
  844. 09/07/06: beazley
  845. Completely reimplemented the entire LALR(1) parsing engine to use the
  846. DeRemer and Pennello algorithm for calculating lookahead sets. This
  847. significantly improves the performance of generating LALR(1) tables
  848. and has the added feature of actually working correctly! If you
  849. experienced weird behavior with LALR(1) in prior releases, this should
  850. hopefully resolve all of those problems. Many thanks to
  851. Andrew Waters and Markus Schoepflin for submitting bug reports
  852. and helping me test out the revised LALR(1) support.
  853. Version 1.8
  854. ------------------------------
  855. 08/02/06: beazley
  856. Fixed a problem related to the handling of default actions in LALR(1)
  857. parsing. If you experienced subtle and/or bizarre behavior when trying
  858. to use the LALR(1) engine, this may correct those problems. Patch
  859. contributed by Russ Cox. Note: This patch has been superceded by
  860. revisions for LALR(1) parsing in Ply-2.0.
  861. 08/02/06: beazley
  862. Added support for slicing of productions in yacc.
  863. Patch contributed by Patrick Mezard.
  864. Version 1.7
  865. ------------------------------
  866. 03/02/06: beazley
  867. Fixed infinite recursion problem ReduceToTerminals() function that
  868. would sometimes come up in LALR(1) table generation. Reported by
  869. Markus Schoepflin.
  870. 03/01/06: beazley
  871. Added "reflags" argument to lex(). For example:
  872. lex.lex(reflags=re.UNICODE)
  873. This can be used to specify optional flags to the re.compile() function
  874. used inside the lexer. This may be necessary for special situations such
  875. as processing Unicode (e.g., if you want escapes like \w and \b to consult
  876. the Unicode character property database). The need for this suggested by
  877. Andreas Jung.
  878. 03/01/06: beazley
  879. Fixed a bug with an uninitialized variable on repeated instantiations of parser
  880. objects when the write_tables=0 argument was used. Reported by Michael Brown.
  881. 03/01/06: beazley
  882. Modified lex.py to accept Unicode strings both as the regular expressions for
  883. tokens and as input. Hopefully this is the only change needed for Unicode support.
  884. Patch contributed by Johan Dahl.
  885. 03/01/06: beazley
  886. Modified the class-based interface to work with new-style or old-style classes.
  887. Patch contributed by Michael Brown (although I tweaked it slightly so it would work
  888. with older versions of Python).
  889. Version 1.6
  890. ------------------------------
  891. 05/27/05: beazley
  892. Incorporated patch contributed by Christopher Stawarz to fix an extremely
  893. devious bug in LALR(1) parser generation. This patch should fix problems
  894. numerous people reported with LALR parsing.
  895. 05/27/05: beazley
  896. Fixed problem with lex.py copy constructor. Reported by Dave Aitel, Aaron Lav,
  897. and Thad Austin.
  898. 05/27/05: beazley
  899. Added outputdir option to yacc() to control output directory. Contributed
  900. by Christopher Stawarz.
  901. 05/27/05: beazley
  902. Added rununit.py test script to run tests using the Python unittest module.
  903. Contributed by Miki Tebeka.
  904. Version 1.5
  905. ------------------------------
  906. 05/26/04: beazley
  907. Major enhancement. LALR(1) parsing support is now working.
  908. This feature was implemented by Elias Ioup (ezioup@alumni.uchicago.edu)
  909. and optimized by David Beazley. To use LALR(1) parsing do
  910. the following:
  911. yacc.yacc(method="LALR")
  912. Computing LALR(1) parsing tables takes about twice as long as
  913. the default SLR method. However, LALR(1) allows you to handle
  914. more complex grammars. For example, the ANSI C grammar
  915. (in example/ansic) has 13 shift-reduce conflicts with SLR, but
  916. only has 1 shift-reduce conflict with LALR(1).
  917. 05/20/04: beazley
  918. Added a __len__ method to parser production lists. Can
  919. be used in parser rules like this:
  920. def p_somerule(p):
  921. """a : B C D
  922. | E F"
  923. if (len(p) == 3):
  924. # Must have been first rule
  925. elif (len(p) == 2):
  926. # Must be second rule
  927. Suggested by Joshua Gerth and others.
  928. Version 1.4
  929. ------------------------------
  930. 04/23/04: beazley
  931. Incorporated a variety of patches contributed by Eric Raymond.
  932. These include:
  933. 0. Cleans up some comments so they don't wrap on an 80-column display.
  934. 1. Directs compiler errors to stderr where they belong.
  935. 2. Implements and documents automatic line counting when \n is ignored.
  936. 3. Changes the way progress messages are dumped when debugging is on.
  937. The new format is both less verbose and conveys more information than
  938. the old, including shift and reduce actions.
  939. 04/23/04: beazley
  940. Added a Python setup.py file to simply installation. Contributed
  941. by Adam Kerrison.
  942. 04/23/04: beazley
  943. Added patches contributed by Adam Kerrison.
  944. - Some output is now only shown when debugging is enabled. This
  945. means that PLY will be completely silent when not in debugging mode.
  946. - An optional parameter "write_tables" can be passed to yacc() to
  947. control whether or not parsing tables are written. By default,
  948. it is true, but it can be turned off if you don't want the yacc
  949. table file. Note: disabling this will cause yacc() to regenerate
  950. the parsing table each time.
  951. 04/23/04: beazley
  952. Added patches contributed by David McNab. This patch addes two
  953. features:
  954. - The parser can be supplied as a class instead of a module.
  955. For an example of this, see the example/classcalc directory.
  956. - Debugging output can be directed to a filename of the user's
  957. choice. Use
  958. yacc(debugfile="somefile.out")
  959. Version 1.3
  960. ------------------------------
  961. 12/10/02: jmdyck
  962. Various minor adjustments to the code that Dave checked in today.
  963. Updated test/yacc_{inf,unused}.exp to reflect today's changes.
  964. 12/10/02: beazley
  965. Incorporated a variety of minor bug fixes to empty production
  966. handling and infinite recursion checking. Contributed by
  967. Michael Dyck.
  968. 12/10/02: beazley
  969. Removed bogus recover() method call in yacc.restart()
  970. Version 1.2
  971. ------------------------------
  972. 11/27/02: beazley
  973. Lexer and parser objects are now available as an attribute
  974. of tokens and slices respectively. For example:
  975. def t_NUMBER(t):
  976. r'\d+'
  977. print t.lexer
  978. def p_expr_plus(t):
  979. 'expr: expr PLUS expr'
  980. print t.lexer
  981. print t.parser
  982. This can be used for state management (if needed).
  983. 10/31/02: beazley
  984. Modified yacc.py to work with Python optimize mode. To make
  985. this work, you need to use
  986. yacc.yacc(optimize=1)
  987. Furthermore, you need to first run Python in normal mode
  988. to generate the necessary parsetab.py files. After that,
  989. you can use python -O or python -OO.
  990. Note: optimized mode turns off a lot of error checking.
  991. Only use when you are sure that your grammar is working.
  992. Make sure parsetab.py is up to date!
  993. 10/30/02: beazley
  994. Added cloning of Lexer objects. For example:
  995. import copy
  996. l = lex.lex()
  997. lc = copy.copy(l)
  998. l.input("Some text")
  999. lc.input("Some other text")
  1000. ...
  1001. This might be useful if the same "lexer" is meant to
  1002. be used in different contexts---or if multiple lexers
  1003. are running concurrently.
  1004. 10/30/02: beazley
  1005. Fixed subtle bug with first set computation and empty productions.
  1006. Patch submitted by Michael Dyck.
  1007. 10/30/02: beazley
  1008. Fixed error messages to use "filename:line: message" instead
  1009. of "filename:line. message". This makes error reporting more
  1010. friendly to emacs. Patch submitted by François Pinard.
  1011. 10/30/02: beazley
  1012. Improvements to parser.out file. Terminals and nonterminals
  1013. are sorted instead of being printed in random order.
  1014. Patch submitted by François Pinard.
  1015. 10/30/02: beazley
  1016. Improvements to parser.out file output. Rules are now printed
  1017. in a way that's easier to understand. Contributed by Russ Cox.
  1018. 10/30/02: beazley
  1019. Added 'nonassoc' associativity support. This can be used
  1020. to disable the chaining of operators like a < b < c.
  1021. To use, simply specify 'nonassoc' in the precedence table
  1022. precedence = (
  1023. ('nonassoc', 'LESSTHAN', 'GREATERTHAN'), # Nonassociative operators
  1024. ('left', 'PLUS', 'MINUS'),
  1025. ('left', 'TIMES', 'DIVIDE'),
  1026. ('right', 'UMINUS'), # Unary minus operator
  1027. )
  1028. Patch contributed by Russ Cox.
  1029. 10/30/02: beazley
  1030. Modified the lexer to provide optional support for Python -O and -OO
  1031. modes. To make this work, Python *first* needs to be run in
  1032. unoptimized mode. This reads the lexing information and creates a
  1033. file "lextab.py". Then, run lex like this:
  1034. # module foo.py
  1035. ...
  1036. ...
  1037. lex.lex(optimize=1)
  1038. Once the lextab file has been created, subsequent calls to
  1039. lex.lex() will read data from the lextab file instead of using
  1040. introspection. In optimized mode (-O, -OO) everything should
  1041. work normally despite the loss of doc strings.
  1042. To change the name of the file 'lextab.py' use the following:
  1043. lex.lex(lextab="footab")
  1044. (this creates a file footab.py)
  1045. Version 1.1 October 25, 2001
  1046. ------------------------------
  1047. 10/25/01: beazley
  1048. Modified the table generator to produce much more compact data.
  1049. This should greatly reduce the size of the parsetab.py[c] file.
  1050. Caveat: the tables still need to be constructed so a little more
  1051. work is done in parsetab on import.
  1052. 10/25/01: beazley
  1053. There may be a possible bug in the cycle detector that reports errors
  1054. about infinite recursion. I'm having a little trouble tracking it
  1055. down, but if you get this problem, you can disable the cycle
  1056. detector as follows:
  1057. yacc.yacc(check_recursion = 0)
  1058. 10/25/01: beazley
  1059. Fixed a bug in lex.py that sometimes caused illegal characters to be
  1060. reported incorrectly. Reported by Sverre Jørgensen.
  1061. 7/8/01 : beazley
  1062. Added a reference to the underlying lexer object when tokens are handled by
  1063. functions. The lexer is available as the 'lexer' attribute. This
  1064. was added to provide better lexing support for languages such as Fortran
  1065. where certain types of tokens can't be conveniently expressed as regular
  1066. expressions (and where the tokenizing function may want to perform a
  1067. little backtracking). Suggested by Pearu Peterson.
  1068. 6/20/01 : beazley
  1069. Modified yacc() function so that an optional starting symbol can be specified.
  1070. For example:
  1071. yacc.yacc(start="statement")
  1072. Normally yacc always treats the first production rule as the starting symbol.
  1073. However, if you are debugging your grammar it may be useful to specify
  1074. an alternative starting symbol. Idea suggested by Rich Salz.
  1075. Version 1.0 June 18, 2001
  1076. --------------------------
  1077. Initial public offering