eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame^] | 1 | <?xml version="1.0" encoding="utf-8" ?>
|
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
| 4 | <head>
|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
| 6 | <meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" />
|
| 7 | <title>pycparser v2.02</title>
|
| 8 | <meta name="author" content="Eli Bendersky" />
|
| 9 | <style type="text/css">
|
| 10 |
|
| 11 | /*
|
| 12 | :Author: David Goodger (goodger@python.org)
|
| 13 | :Id: $Id: html4css1.css 5951 2009-05-18 18:03:10Z milde $
|
| 14 | :Copyright: This stylesheet has been placed in the public domain.
|
| 15 |
|
| 16 | Default cascading style sheet for the HTML output of Docutils.
|
| 17 |
|
| 18 | See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
|
| 19 | customize this style sheet.
|
| 20 | */
|
| 21 |
|
| 22 | /* used to remove borders from tables and images */
|
| 23 | .borderless, table.borderless td, table.borderless th {
|
| 24 | border: 0 }
|
| 25 |
|
| 26 | table.borderless td, table.borderless th {
|
| 27 | /* Override padding for "table.docutils td" with "! important".
|
| 28 | The right padding separates the table cells. */
|
| 29 | padding: 0 0.5em 0 0 ! important }
|
| 30 |
|
| 31 | .first {
|
| 32 | /* Override more specific margin styles with "! important". */
|
| 33 | margin-top: 0 ! important }
|
| 34 |
|
| 35 | .last, .with-subtitle {
|
| 36 | margin-bottom: 0 ! important }
|
| 37 |
|
| 38 | .hidden {
|
| 39 | display: none }
|
| 40 |
|
| 41 | a.toc-backref {
|
| 42 | text-decoration: none ;
|
| 43 | color: black }
|
| 44 |
|
| 45 | blockquote.epigraph {
|
| 46 | margin: 2em 5em ; }
|
| 47 |
|
| 48 | dl.docutils dd {
|
| 49 | margin-bottom: 0.5em }
|
| 50 |
|
| 51 | /* Uncomment (and remove this text!) to get bold-faced definition list terms
|
| 52 | dl.docutils dt {
|
| 53 | font-weight: bold }
|
| 54 | */
|
| 55 |
|
| 56 | div.abstract {
|
| 57 | margin: 2em 5em }
|
| 58 |
|
| 59 | div.abstract p.topic-title {
|
| 60 | font-weight: bold ;
|
| 61 | text-align: center }
|
| 62 |
|
| 63 | div.admonition, div.attention, div.caution, div.danger, div.error,
|
| 64 | div.hint, div.important, div.note, div.tip, div.warning {
|
| 65 | margin: 2em ;
|
| 66 | border: medium outset ;
|
| 67 | padding: 1em }
|
| 68 |
|
| 69 | div.admonition p.admonition-title, div.hint p.admonition-title,
|
| 70 | div.important p.admonition-title, div.note p.admonition-title,
|
| 71 | div.tip p.admonition-title {
|
| 72 | font-weight: bold ;
|
| 73 | font-family: sans-serif }
|
| 74 |
|
| 75 | div.attention p.admonition-title, div.caution p.admonition-title,
|
| 76 | div.danger p.admonition-title, div.error p.admonition-title,
|
| 77 | div.warning p.admonition-title {
|
| 78 | color: red ;
|
| 79 | font-weight: bold ;
|
| 80 | font-family: sans-serif }
|
| 81 |
|
| 82 | /* Uncomment (and remove this text!) to get reduced vertical space in
|
| 83 | compound paragraphs.
|
| 84 | div.compound .compound-first, div.compound .compound-middle {
|
| 85 | margin-bottom: 0.5em }
|
| 86 |
|
| 87 | div.compound .compound-last, div.compound .compound-middle {
|
| 88 | margin-top: 0.5em }
|
| 89 | */
|
| 90 |
|
| 91 | div.dedication {
|
| 92 | margin: 2em 5em ;
|
| 93 | text-align: center ;
|
| 94 | font-style: italic }
|
| 95 |
|
| 96 | div.dedication p.topic-title {
|
| 97 | font-weight: bold ;
|
| 98 | font-style: normal }
|
| 99 |
|
| 100 | div.figure {
|
| 101 | margin-left: 2em ;
|
| 102 | margin-right: 2em }
|
| 103 |
|
| 104 | div.footer, div.header {
|
| 105 | clear: both;
|
| 106 | font-size: smaller }
|
| 107 |
|
| 108 | div.line-block {
|
| 109 | display: block ;
|
| 110 | margin-top: 1em ;
|
| 111 | margin-bottom: 1em }
|
| 112 |
|
| 113 | div.line-block div.line-block {
|
| 114 | margin-top: 0 ;
|
| 115 | margin-bottom: 0 ;
|
| 116 | margin-left: 1.5em }
|
| 117 |
|
| 118 | div.sidebar {
|
| 119 | margin: 0 0 0.5em 1em ;
|
| 120 | border: medium outset ;
|
| 121 | padding: 1em ;
|
| 122 | background-color: #ffffee ;
|
| 123 | width: 40% ;
|
| 124 | float: right ;
|
| 125 | clear: right }
|
| 126 |
|
| 127 | div.sidebar p.rubric {
|
| 128 | font-family: sans-serif ;
|
| 129 | font-size: medium }
|
| 130 |
|
| 131 | div.system-messages {
|
| 132 | margin: 5em }
|
| 133 |
|
| 134 | div.system-messages h1 {
|
| 135 | color: red }
|
| 136 |
|
| 137 | div.system-message {
|
| 138 | border: medium outset ;
|
| 139 | padding: 1em }
|
| 140 |
|
| 141 | div.system-message p.system-message-title {
|
| 142 | color: red ;
|
| 143 | font-weight: bold }
|
| 144 |
|
| 145 | div.topic {
|
| 146 | margin: 2em }
|
| 147 |
|
| 148 | h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
|
| 149 | h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
|
| 150 | margin-top: 0.4em }
|
| 151 |
|
| 152 | h1.title {
|
| 153 | text-align: center }
|
| 154 |
|
| 155 | h2.subtitle {
|
| 156 | text-align: center }
|
| 157 |
|
| 158 | hr.docutils {
|
| 159 | width: 75% }
|
| 160 |
|
| 161 | img.align-left, .figure.align-left{
|
| 162 | clear: left ;
|
| 163 | float: left ;
|
| 164 | margin-right: 1em }
|
| 165 |
|
| 166 | img.align-right, .figure.align-right {
|
| 167 | clear: right ;
|
| 168 | float: right ;
|
| 169 | margin-left: 1em }
|
| 170 |
|
| 171 | .align-left {
|
| 172 | text-align: left }
|
| 173 |
|
| 174 | .align-center {
|
| 175 | clear: both ;
|
| 176 | text-align: center }
|
| 177 |
|
| 178 | .align-right {
|
| 179 | text-align: right }
|
| 180 |
|
| 181 | /* reset inner alignment in figures */
|
| 182 | div.align-right {
|
| 183 | text-align: left }
|
| 184 |
|
| 185 | /* div.align-center * { */
|
| 186 | /* text-align: left } */
|
| 187 |
|
| 188 | ol.simple, ul.simple {
|
| 189 | margin-bottom: 1em }
|
| 190 |
|
| 191 | ol.arabic {
|
| 192 | list-style: decimal }
|
| 193 |
|
| 194 | ol.loweralpha {
|
| 195 | list-style: lower-alpha }
|
| 196 |
|
| 197 | ol.upperalpha {
|
| 198 | list-style: upper-alpha }
|
| 199 |
|
| 200 | ol.lowerroman {
|
| 201 | list-style: lower-roman }
|
| 202 |
|
| 203 | ol.upperroman {
|
| 204 | list-style: upper-roman }
|
| 205 |
|
| 206 | p.attribution {
|
| 207 | text-align: right ;
|
| 208 | margin-left: 50% }
|
| 209 |
|
| 210 | p.caption {
|
| 211 | font-style: italic }
|
| 212 |
|
| 213 | p.credits {
|
| 214 | font-style: italic ;
|
| 215 | font-size: smaller }
|
| 216 |
|
| 217 | p.label {
|
| 218 | white-space: nowrap }
|
| 219 |
|
| 220 | p.rubric {
|
| 221 | font-weight: bold ;
|
| 222 | font-size: larger ;
|
| 223 | color: maroon ;
|
| 224 | text-align: center }
|
| 225 |
|
| 226 | p.sidebar-title {
|
| 227 | font-family: sans-serif ;
|
| 228 | font-weight: bold ;
|
| 229 | font-size: larger }
|
| 230 |
|
| 231 | p.sidebar-subtitle {
|
| 232 | font-family: sans-serif ;
|
| 233 | font-weight: bold }
|
| 234 |
|
| 235 | p.topic-title {
|
| 236 | font-weight: bold }
|
| 237 |
|
| 238 | pre.address {
|
| 239 | margin-bottom: 0 ;
|
| 240 | margin-top: 0 ;
|
| 241 | font: inherit }
|
| 242 |
|
| 243 | pre.literal-block, pre.doctest-block {
|
| 244 | margin-left: 2em ;
|
| 245 | margin-right: 2em }
|
| 246 |
|
| 247 | span.classifier {
|
| 248 | font-family: sans-serif ;
|
| 249 | font-style: oblique }
|
| 250 |
|
| 251 | span.classifier-delimiter {
|
| 252 | font-family: sans-serif ;
|
| 253 | font-weight: bold }
|
| 254 |
|
| 255 | span.interpreted {
|
| 256 | font-family: sans-serif }
|
| 257 |
|
| 258 | span.option {
|
| 259 | white-space: nowrap }
|
| 260 |
|
| 261 | span.pre {
|
| 262 | white-space: pre }
|
| 263 |
|
| 264 | span.problematic {
|
| 265 | color: red }
|
| 266 |
|
| 267 | span.section-subtitle {
|
| 268 | /* font-size relative to parent (h1..h6 element) */
|
| 269 | font-size: 80% }
|
| 270 |
|
| 271 | table.citation {
|
| 272 | border-left: solid 1px gray;
|
| 273 | margin-left: 1px }
|
| 274 |
|
| 275 | table.docinfo {
|
| 276 | margin: 2em 4em }
|
| 277 |
|
| 278 | table.docutils {
|
| 279 | margin-top: 0.5em ;
|
| 280 | margin-bottom: 0.5em }
|
| 281 |
|
| 282 | table.footnote {
|
| 283 | border-left: solid 1px black;
|
| 284 | margin-left: 1px }
|
| 285 |
|
| 286 | table.docutils td, table.docutils th,
|
| 287 | table.docinfo td, table.docinfo th {
|
| 288 | padding-left: 0.5em ;
|
| 289 | padding-right: 0.5em ;
|
| 290 | vertical-align: top }
|
| 291 |
|
| 292 | table.docutils th.field-name, table.docinfo th.docinfo-name {
|
| 293 | font-weight: bold ;
|
| 294 | text-align: left ;
|
| 295 | white-space: nowrap ;
|
| 296 | padding-left: 0 }
|
| 297 |
|
| 298 | h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
|
| 299 | h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
|
| 300 | font-size: 100% }
|
| 301 |
|
| 302 | ul.auto-toc {
|
| 303 | list-style-type: none }
|
| 304 |
|
| 305 | </style>
|
| 306 | </head>
|
| 307 | <body>
|
| 308 | <div class="document" id="pycparser-v2-02">
|
| 309 | <h1 class="title">pycparser v2.02</h1>
|
| 310 | <table class="docinfo" frame="void" rules="none">
|
| 311 | <col class="docinfo-name" />
|
| 312 | <col class="docinfo-content" />
|
| 313 | <tbody valign="top">
|
| 314 | <tr><th class="docinfo-name">Author:</th>
|
| 315 | <td><a class="first reference external" href="http://eli.thegreenplace.net">Eli Bendersky</a></td></tr>
|
| 316 | </tbody>
|
| 317 | </table>
|
| 318 | <div class="contents topic" id="contents">
|
| 319 | <p class="topic-title first">Contents</p>
|
| 320 | <ul class="auto-toc simple">
|
| 321 | <li><a class="reference internal" href="#introduction" id="id2">1 Introduction</a><ul class="auto-toc">
|
| 322 | <li><a class="reference internal" href="#what-is-pycparser" id="id3">1.1 What is pycparser?</a></li>
|
| 323 | <li><a class="reference internal" href="#what-is-it-good-for" id="id4">1.2 What is it good for?</a></li>
|
| 324 | <li><a class="reference internal" href="#which-version-of-c-does-pycparser-support" id="id5">1.3 Which version of C does pycparser support?</a></li>
|
| 325 | <li><a class="reference internal" href="#what-grammar-does-pycparser-follow" id="id6">1.4 What grammar does pycparser follow?</a></li>
|
| 326 | <li><a class="reference internal" href="#what-is-an-ast" id="id7">1.5 What is an AST?</a></li>
|
| 327 | <li><a class="reference internal" href="#how-is-pycparser-licensed" id="id8">1.6 How is pycparser licensed?</a></li>
|
| 328 | <li><a class="reference internal" href="#contact-details" id="id9">1.7 Contact details</a></li>
|
| 329 | </ul>
|
| 330 | </li>
|
| 331 | <li><a class="reference internal" href="#installing" id="id10">2 Installing</a><ul class="auto-toc">
|
| 332 | <li><a class="reference internal" href="#prerequisites" id="id11">2.1 Prerequisites</a></li>
|
| 333 | <li><a class="reference internal" href="#installation-process" id="id12">2.2 Installation process</a></li>
|
| 334 | <li><a class="reference internal" href="#known-problems" id="id13">2.3 Known problems</a></li>
|
| 335 | </ul>
|
| 336 | </li>
|
| 337 | <li><a class="reference internal" href="#using" id="id14">3 Using</a><ul class="auto-toc">
|
| 338 | <li><a class="reference internal" href="#interaction-with-the-c-preprocessor" id="id15">3.1 Interaction with the C preprocessor</a></li>
|
| 339 | <li><a class="reference internal" href="#what-about-the-standard-c-library-headers" id="id16">3.2 What about the standard C library headers?</a></li>
|
| 340 | <li><a class="reference internal" href="#basic-usage" id="id17">3.3 Basic usage</a></li>
|
| 341 | <li><a class="reference internal" href="#advanced-usage" id="id18">3.4 Advanced usage</a></li>
|
| 342 | </ul>
|
| 343 | </li>
|
| 344 | <li><a class="reference internal" href="#modifying" id="id19">4 Modifying</a></li>
|
| 345 | <li><a class="reference internal" href="#package-contents" id="id20">5 Package contents</a></li>
|
| 346 | <li><a class="reference internal" href="#contributors" id="id21">6 Contributors</a></li>
|
| 347 | <li><a class="reference internal" href="#changelog" id="id22">7 Changelog</a></li>
|
| 348 | </ul>
|
| 349 | </div>
|
| 350 | <div class="section" id="introduction">
|
| 351 | <h1>1 Introduction</h1>
|
| 352 | <div class="section" id="what-is-pycparser">
|
| 353 | <h2>1.1 What is pycparser?</h2>
|
| 354 | <p><tt class="docutils literal"><span class="pre">pycparser</span></tt> is a parser for the C language, written in pure Python. It is a module designed to be easily integrated into applications that need to parse C source code.</p>
|
| 355 | </div>
|
| 356 | <div class="section" id="what-is-it-good-for">
|
| 357 | <h2>1.2 What is it good for?</h2>
|
| 358 | <p>Anything that needs C code to be parsed. The following are some uses for <tt class="docutils literal"><span class="pre">pycparser</span></tt>, taken from real user reports:</p>
|
| 359 | <ul class="simple">
|
| 360 | <li>C code obfuscator</li>
|
| 361 | <li>Front-end for various specialized C compilers</li>
|
| 362 | <li>Static code checker</li>
|
| 363 | <li>Automatic unit-test discovery</li>
|
| 364 | <li>Adding specialized extensions to the C language</li>
|
| 365 | </ul>
|
| 366 | <p><tt class="docutils literal"><span class="pre">pycparser</span></tt> is unique in the sense that it's written in pure Python - a very high level language that's easy to experiment with and tweak. To people familiar with Lex and Yacc, <tt class="docutils literal"><span class="pre">pycparser</span></tt>'s code will be simple to understand.</p>
|
| 367 | </div>
|
| 368 | <div class="section" id="which-version-of-c-does-pycparser-support">
|
| 369 | <h2>1.3 Which version of C does pycparser support?</h2>
|
| 370 | <p><tt class="docutils literal"><span class="pre">pycparser</span></tt> aims to support the full C99 language (according to the standard ISO/IEC 9899). This is a new feature in the version 2.x series - earlier versions only supported C89. For more information on the change, read <a class="reference external" href="http://code.google.com/p/pycparser/wiki/C99support">this wiki page</a>.</p>
|
| 371 | <p><tt class="docutils literal"><span class="pre">pycparser</span></tt> doesn't support any GCC extensions.</p>
|
| 372 | </div>
|
| 373 | <div class="section" id="what-grammar-does-pycparser-follow">
|
| 374 | <h2>1.4 What grammar does pycparser follow?</h2>
|
| 375 | <p><tt class="docutils literal"><span class="pre">pycparser</span></tt> very closely follows the C grammar provided in the end of the C99 standard document</p>
|
| 376 | </div>
|
| 377 | <div class="section" id="what-is-an-ast">
|
| 378 | <h2>1.5 What is an AST?</h2>
|
| 379 | <p><a class="reference external" href="http://en.wikipedia.org/wiki/Abstract_syntax_tree">AST</a> - Abstract Syntax Tree. It is a tree representation of the syntax of source code - a convenient hierarchical data structure that's built from the code and is readily suitable for exploration and manipulation.</p>
|
| 380 | </div>
|
| 381 | <div class="section" id="how-is-pycparser-licensed">
|
| 382 | <h2>1.6 How is pycparser licensed?</h2>
|
| 383 | <p><a class="reference external" href="http://www.gnu.org/licenses/lgpl.html">LGPL</a></p>
|
| 384 | </div>
|
| 385 | <div class="section" id="contact-details">
|
| 386 | <h2>1.7 Contact details</h2>
|
| 387 | <p>Drop me an email to <a class="reference external" href="mailto:eliben@gmail.com">eliben@gmail.com</a> for any questions regarding <tt class="docutils literal"><span class="pre">pycparser</span></tt>. For reporting problems with <tt class="docutils literal"><span class="pre">pycparser</span></tt> or submitting feature requests, the best way is to open an issue on the <a class="reference external" href="http://code.google.com/p/pycparser/">pycparser page at Google Code</a>.</p>
|
| 388 | </div>
|
| 389 | </div>
|
| 390 | <div class="section" id="installing">
|
| 391 | <h1>2 Installing</h1>
|
| 392 | <div class="section" id="prerequisites">
|
| 393 | <h2>2.1 Prerequisites</h2>
|
| 394 | <ul class="simple">
|
| 395 | <li><tt class="docutils literal"><span class="pre">pycparser</span></tt> was tested on Python 2.5, 2.6 and 3.1, on both Linux and Windows</li>
|
| 396 | <li><tt class="docutils literal"><span class="pre">pycparser</span></tt> uses the PLY module for the actual lexer and parser construction. Install PLY version 3.3 (earlier versions work at least since 2.5) from <a class="reference external" href="http://www.dabeaz.com/ply/">its website</a>.</li>
|
| 397 | </ul>
|
| 398 | </div>
|
| 399 | <div class="section" id="installation-process">
|
| 400 | <h2>2.2 Installation process</h2>
|
| 401 | <p>Installing <tt class="docutils literal"><span class="pre">pycparser</span></tt> is very simple. Once you download it from its <a class="reference external" href="http://code.google.com/p/pycparser/">website</a> and unzip the package, you just have to execute the standard <tt class="docutils literal"><span class="pre">python</span> <span class="pre">setup.py</span> <span class="pre">install</span></tt>. The setup script will then place the <tt class="docutils literal"><span class="pre">pycparser</span></tt> module into <tt class="docutils literal"><span class="pre">site-packages</span></tt> in your Python's installation library.</p>
|
| 402 | <p>It's recommended to run <tt class="docutils literal"><span class="pre">_build_tables.py</span></tt> in the <tt class="docutils literal"><span class="pre">pycparser</span></tt> code directory after installation to make sure the parsing tables of PLY are pre-generated. This can make your code run faster.</p>
|
| 403 | </div>
|
| 404 | <div class="section" id="known-problems">
|
| 405 | <h2>2.3 Known problems</h2>
|
| 406 | <ul class="simple">
|
| 407 | <li>Some users who've installed a new version of <tt class="docutils literal"><span class="pre">pycparser</span></tt> over an existing version ran into a problem using the newly installed library. This has to do with parse tables staying around as <tt class="docutils literal"><span class="pre">.pyc</span></tt> files from the older version. If you see unexplained errors from <tt class="docutils literal"><span class="pre">pycparser</span></tt> after an upgrade, remove it (by deleting the <tt class="docutils literal"><span class="pre">pycparser</span></tt> directory in your Python's <tt class="docutils literal"><span class="pre">site-packages</span></tt>, or wherever you installed it) and install again.</li>
|
| 408 | </ul>
|
| 409 | </div>
|
| 410 | </div>
|
| 411 | <div class="section" id="using">
|
| 412 | <h1>3 Using</h1>
|
| 413 | <div class="section" id="interaction-with-the-c-preprocessor">
|
| 414 | <h2>3.1 Interaction with the C preprocessor</h2>
|
| 415 | <p>In order to be compilable, C code must be preprocessed by the C preprocessor - <tt class="docutils literal"><span class="pre">cpp</span></tt>. <tt class="docutils literal"><span class="pre">cpp</span></tt> handles preprocessing directives like <tt class="docutils literal"><span class="pre">#include</span></tt> and <tt class="docutils literal"><span class="pre">#define</span></tt>, removes comments, and does other minor tasks that prepare the C code for compilation.</p>
|
| 416 | <p>For all but the most trivial snippets of C code, <tt class="docutils literal"><span class="pre">pycparser</span></tt>, like a C compiler, must receive preprocessed C code in order to function correctly. If you import the top-level <tt class="docutils literal"><span class="pre">parse_file</span></tt> function from the <tt class="docutils literal"><span class="pre">pycparser</span></tt> package, it will interact with <tt class="docutils literal"><span class="pre">cpp</span></tt> for you, as long as it's in your PATH, or you provide a path to it.</p>
|
| 417 | <p>On the vast majority of Linux systems, <tt class="docutils literal"><span class="pre">cpp</span></tt> is installed and is in the PATH. If you're on Windows and don't have <tt class="docutils literal"><span class="pre">cpp</span></tt> somewhere, you can use the one provided in the <tt class="docutils literal"><span class="pre">utils</span></tt> directory in <tt class="docutils literal"><span class="pre">pycparser</span></tt>'s distribution. This <tt class="docutils literal"><span class="pre">cpp</span></tt> executable was compiled from the <a class="reference external" href="http://www.cs.princeton.edu/software/lcc/">LCC distribution</a>, and is provided under LCC's license terms.</p>
|
| 418 | </div>
|
| 419 | <div class="section" id="what-about-the-standard-c-library-headers">
|
| 420 | <h2>3.2 What about the standard C library headers?</h2>
|
| 421 | <p>C code almost always includes various header files from the standard C library, like <tt class="docutils literal"><span class="pre">stdio.h</span></tt>. While, with some effort, <tt class="docutils literal"><span class="pre">pycparser</span></tt> can be made to parse the standard headers from any C compiler, it's much simpler to use the provided "fake" standard in includes in <tt class="docutils literal"><span class="pre">utils/fake_libc_include</span></tt>. These are standard C header files that contain only the bare necessities to allow valid parsing of the files that use them. As a bonus, since they're minimal, it can significantly improve the performance of parsing C files.</p>
|
| 422 | <p>See the <tt class="docutils literal"><span class="pre">using_cpp_libc.py</span></tt> example for more details.</p>
|
| 423 | </div>
|
| 424 | <div class="section" id="basic-usage">
|
| 425 | <h2>3.3 Basic usage</h2>
|
| 426 | <p>Take a look at the <tt class="docutils literal"><span class="pre">examples</span></tt> directory of the distribution for a few examples of using <tt class="docutils literal"><span class="pre">pycparser</span></tt>. These should be enough to get you started.</p>
|
| 427 | </div>
|
| 428 | <div class="section" id="advanced-usage">
|
| 429 | <h2>3.4 Advanced usage</h2>
|
| 430 | <p>The public interface of <tt class="docutils literal"><span class="pre">pycparser</span></tt> is well documented with comments in <tt class="docutils literal"><span class="pre">pycparser/c_parser.py</span></tt>. For a detailed overview of the various AST nodes created by the parser, see <tt class="docutils literal"><span class="pre">pycparser/_c_ast.cfg</span></tt>.</p>
|
| 431 | <p>In any case, you can always drop me an <a class="reference external" href="mailto:eliben@gmail.com">email</a> for help.</p>
|
| 432 | </div>
|
| 433 | </div>
|
| 434 | <div class="section" id="modifying">
|
| 435 | <h1>4 Modifying</h1>
|
| 436 | <p>There are a few points to keep in mind when modifying <tt class="docutils literal"><span class="pre">pycparser</span></tt>:</p>
|
| 437 | <ul class="simple">
|
| 438 | <li>The code for <tt class="docutils literal"><span class="pre">pycparser</span></tt>'s AST nodes is automatically generated from a configuration file - <tt class="docutils literal"><span class="pre">_c_ast.cfg</span></tt>, by <tt class="docutils literal"><span class="pre">_ast_gen.py</span></tt>. If you modify the AST configuration, make sure to re-generate the code.</li>
|
| 439 | <li>Make sure you understand the optimized mode of <tt class="docutils literal"><span class="pre">pycparser</span></tt> - for that you must read the docstring in the constructor of the <tt class="docutils literal"><span class="pre">CParser</span></tt> class. For development you should create the parser without optimizations, so that it will regenerate the Yacc and Lex tables when you change the grammar.</li>
|
| 440 | </ul>
|
| 441 | </div>
|
| 442 | <div class="section" id="package-contents">
|
| 443 | <h1>5 Package contents</h1>
|
| 444 | <p>Once you unzip the <tt class="docutils literal"><span class="pre">pycparser</span></tt> package, you'll see the following files and directories:</p>
|
| 445 | <dl class="docutils">
|
| 446 | <dt>README.txt/html:</dt>
|
| 447 | <dd>This README file.</dd>
|
| 448 | <dt>setup.py:</dt>
|
| 449 | <dd>Installation script</dd>
|
| 450 | <dt>examples/:</dt>
|
| 451 | <dd>A directory with some examples of using <tt class="docutils literal"><span class="pre">pycparser</span></tt></dd>
|
| 452 | <dt>pycparser/:</dt>
|
| 453 | <dd>The <tt class="docutils literal"><span class="pre">pycparser</span></tt> module source code.</dd>
|
| 454 | <dt>tests/:</dt>
|
| 455 | <dd>Unit tests.</dd>
|
| 456 | <dt>utils/cpp.exe:</dt>
|
| 457 | <dd>A Windows executable of the C pre-processor suitable for working with pycparser</dd>
|
| 458 | <dt>utils/fake_libc_include:</dt>
|
| 459 | <dd>Minimal standard C library include files that should allow to parse any C code.</dd>
|
| 460 | <dt>utils/internal/:</dt>
|
| 461 | <dd>Internal utilities for my own use. You probably don't need them.</dd>
|
| 462 | </dl>
|
| 463 | </div>
|
| 464 | <div class="section" id="contributors">
|
| 465 | <h1>6 Contributors</h1>
|
| 466 | <p>Some people have contributed to <tt class="docutils literal"><span class="pre">pycparser</span></tt> by opening issues on bugs they've found and/or submitting patches. The list of contributors is at <a class="reference external" href="http://code.google.com/p/pycparser/wiki/Contributors">this pycparser Wiki page</a>.</p>
|
| 467 | </div>
|
| 468 | <div class="section" id="changelog">
|
| 469 | <h1>7 Changelog</h1>
|
| 470 | <ul class="simple">
|
| 471 | <li>Version 2.02 (10.12.2010)<ul>
|
| 472 | <li>The name of a <tt class="docutils literal"><span class="pre">NamedInitializer</span></tt> node was turned into a sequence of nodes
|
| 473 | instead of an attribute, to make it discoverable by the AST node visitor.</li>
|
| 474 | <li>Documentation updates</li>
|
| 475 | </ul>
|
| 476 | </li>
|
| 477 | <li>Version 2.01 (04.12.2010)<ul>
|
| 478 | <li>Removed dependency on YAML. Parsing of the AST node configuration file is done with a simple parser.</li>
|
| 479 | <li>Fixed issue 12: installation problems</li>
|
| 480 | </ul>
|
| 481 | </li>
|
| 482 | <li>Version 2.00 (31.10.2010)<ul>
|
| 483 | <li>Support for C99 (read <a class="reference external" href="http://code.google.com/p/pycparser/wiki/C99support">this wiki page</a> for more information).</li>
|
| 484 | </ul>
|
| 485 | </li>
|
| 486 | <li>Version 1.08 (09.10.2010)<ul>
|
| 487 | <li>Bug fixes:<ul>
|
| 488 | <li>Correct handling of <tt class="docutils literal"><span class="pre">do{}</span> <span class="pre">...</span> <span class="pre">while</span></tt> statements in some cases</li>
|
| 489 | <li>Issues 6 & 7: Concatenation of string literals</li>
|
| 490 | <li>Issue 9: Support for unnamed bitfields in structs</li>
|
| 491 | </ul>
|
| 492 | </li>
|
| 493 | </ul>
|
| 494 | </li>
|
| 495 | <li>Version 1.07 (18.05.2010)<ul>
|
| 496 | <li>Python 3.1 compatibility: <tt class="docutils literal"><span class="pre">pycparser</span></tt> was modified to run on Python 3.1 as well as 2.6</li>
|
| 497 | </ul>
|
| 498 | </li>
|
| 499 | <li>Version 1.06 (10.04.2010)<ul>
|
| 500 | <li>Bug fixes:<ul>
|
| 501 | <li>coord not propagated to FuncCall nodes</li>
|
| 502 | <li>lexing of the ^= token (XOREQUALS)</li>
|
| 503 | <li>parsing failed on some abstract declarator rules</li>
|
| 504 | </ul>
|
| 505 | </li>
|
| 506 | <li>Linux compatibility: fixed end-of-line and <tt class="docutils literal"><span class="pre">cpp</span></tt> path issues to allow all tests and examples run on Linux</li>
|
| 507 | </ul>
|
| 508 | </li>
|
| 509 | <li>Version 1.05 (16.10.2009)<ul>
|
| 510 | <li>Fixed the <tt class="docutils literal"><span class="pre">parse_file</span></tt> auxiliary function to handle multiple arguments to <tt class="docutils literal"><span class="pre">cpp</span></tt> correctly</li>
|
| 511 | </ul>
|
| 512 | </li>
|
| 513 | <li>Version 1.04 (22.05.2009)<ul>
|
| 514 | <li>Added the <tt class="docutils literal"><span class="pre">fake_libc_include</span></tt> directory to allow parsing of C code that uses standard C library include files without dependency on a real C library.</li>
|
| 515 | <li>Tested with Python 2.6 and PLY 3.2</li>
|
| 516 | </ul>
|
| 517 | </li>
|
| 518 | <li>Version 1.03 (31.01.2009)<ul>
|
| 519 | <li>Accept enumeration lists with a comma after the last item (C99 feature).</li>
|
| 520 | </ul>
|
| 521 | </li>
|
| 522 | <li>Version 1.02 (16.01.2009)<ul>
|
| 523 | <li>Fixed problem of parsing struct/enum/union names that were named similarly to previously defined <tt class="docutils literal"><span class="pre">typedef</span></tt> types.</li>
|
| 524 | </ul>
|
| 525 | </li>
|
| 526 | <li>Version 1.01 (09.01.2009)<ul>
|
| 527 | <li>Fixed subprocess invocation in the helper function parse_file - now it's more portable</li>
|
| 528 | </ul>
|
| 529 | </li>
|
| 530 | <li>Version 1.0 (15.11.2008)<ul>
|
| 531 | <li>Initial release</li>
|
| 532 | <li>Support for ANSI C89</li>
|
| 533 | </ul>
|
| 534 | </li>
|
| 535 | </ul>
|
| 536 | </div>
|
| 537 | </div>
|
| 538 | </body>
|
| 539 | </html>
|