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" />
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 6 | <meta name="generator" content="Docutils 0.9: http://docutils.sourceforge.net/" />
|
| 7 | <title>pycparser v2.05</title>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 8 | <meta name="author" content="Eli Bendersky" />
|
| 9 | <style type="text/css">
|
| 10 |
|
| 11 | /*
|
| 12 | :Author: David Goodger (goodger@python.org)
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 13 | :Id: $Id: html4css1.css 7056 2011-06-17 10:50:48Z milde $
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 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 |
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 51 | object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
|
| 52 | overflow: hidden;
|
| 53 | }
|
| 54 |
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 55 | /* Uncomment (and remove this text!) to get bold-faced definition list terms
|
| 56 | dl.docutils dt {
|
| 57 | font-weight: bold }
|
| 58 | */
|
| 59 |
|
| 60 | div.abstract {
|
| 61 | margin: 2em 5em }
|
| 62 |
|
| 63 | div.abstract p.topic-title {
|
| 64 | font-weight: bold ;
|
| 65 | text-align: center }
|
| 66 |
|
| 67 | div.admonition, div.attention, div.caution, div.danger, div.error,
|
| 68 | div.hint, div.important, div.note, div.tip, div.warning {
|
| 69 | margin: 2em ;
|
| 70 | border: medium outset ;
|
| 71 | padding: 1em }
|
| 72 |
|
| 73 | div.admonition p.admonition-title, div.hint p.admonition-title,
|
| 74 | div.important p.admonition-title, div.note p.admonition-title,
|
| 75 | div.tip p.admonition-title {
|
| 76 | font-weight: bold ;
|
| 77 | font-family: sans-serif }
|
| 78 |
|
| 79 | div.attention p.admonition-title, div.caution p.admonition-title,
|
| 80 | div.danger p.admonition-title, div.error p.admonition-title,
|
| 81 | div.warning p.admonition-title {
|
| 82 | color: red ;
|
| 83 | font-weight: bold ;
|
| 84 | font-family: sans-serif }
|
| 85 |
|
| 86 | /* Uncomment (and remove this text!) to get reduced vertical space in
|
| 87 | compound paragraphs.
|
| 88 | div.compound .compound-first, div.compound .compound-middle {
|
| 89 | margin-bottom: 0.5em }
|
| 90 |
|
| 91 | div.compound .compound-last, div.compound .compound-middle {
|
| 92 | margin-top: 0.5em }
|
| 93 | */
|
| 94 |
|
| 95 | div.dedication {
|
| 96 | margin: 2em 5em ;
|
| 97 | text-align: center ;
|
| 98 | font-style: italic }
|
| 99 |
|
| 100 | div.dedication p.topic-title {
|
| 101 | font-weight: bold ;
|
| 102 | font-style: normal }
|
| 103 |
|
| 104 | div.figure {
|
| 105 | margin-left: 2em ;
|
| 106 | margin-right: 2em }
|
| 107 |
|
| 108 | div.footer, div.header {
|
| 109 | clear: both;
|
| 110 | font-size: smaller }
|
| 111 |
|
| 112 | div.line-block {
|
| 113 | display: block ;
|
| 114 | margin-top: 1em ;
|
| 115 | margin-bottom: 1em }
|
| 116 |
|
| 117 | div.line-block div.line-block {
|
| 118 | margin-top: 0 ;
|
| 119 | margin-bottom: 0 ;
|
| 120 | margin-left: 1.5em }
|
| 121 |
|
| 122 | div.sidebar {
|
| 123 | margin: 0 0 0.5em 1em ;
|
| 124 | border: medium outset ;
|
| 125 | padding: 1em ;
|
| 126 | background-color: #ffffee ;
|
| 127 | width: 40% ;
|
| 128 | float: right ;
|
| 129 | clear: right }
|
| 130 |
|
| 131 | div.sidebar p.rubric {
|
| 132 | font-family: sans-serif ;
|
| 133 | font-size: medium }
|
| 134 |
|
| 135 | div.system-messages {
|
| 136 | margin: 5em }
|
| 137 |
|
| 138 | div.system-messages h1 {
|
| 139 | color: red }
|
| 140 |
|
| 141 | div.system-message {
|
| 142 | border: medium outset ;
|
| 143 | padding: 1em }
|
| 144 |
|
| 145 | div.system-message p.system-message-title {
|
| 146 | color: red ;
|
| 147 | font-weight: bold }
|
| 148 |
|
| 149 | div.topic {
|
| 150 | margin: 2em }
|
| 151 |
|
| 152 | h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
|
| 153 | h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
|
| 154 | margin-top: 0.4em }
|
| 155 |
|
| 156 | h1.title {
|
| 157 | text-align: center }
|
| 158 |
|
| 159 | h2.subtitle {
|
| 160 | text-align: center }
|
| 161 |
|
| 162 | hr.docutils {
|
| 163 | width: 75% }
|
| 164 |
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 165 | img.align-left, .figure.align-left, object.align-left {
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 166 | clear: left ;
|
| 167 | float: left ;
|
| 168 | margin-right: 1em }
|
| 169 |
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 170 | img.align-right, .figure.align-right, object.align-right {
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 171 | clear: right ;
|
| 172 | float: right ;
|
| 173 | margin-left: 1em }
|
| 174 |
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 175 | img.align-center, .figure.align-center, object.align-center {
|
| 176 | display: block;
|
| 177 | margin-left: auto;
|
| 178 | margin-right: auto;
|
| 179 | }
|
| 180 |
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 181 | .align-left {
|
| 182 | text-align: left }
|
| 183 |
|
| 184 | .align-center {
|
| 185 | clear: both ;
|
| 186 | text-align: center }
|
| 187 |
|
| 188 | .align-right {
|
| 189 | text-align: right }
|
| 190 |
|
| 191 | /* reset inner alignment in figures */
|
| 192 | div.align-right {
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 193 | text-align: inherit }
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 194 |
|
| 195 | /* div.align-center * { */
|
| 196 | /* text-align: left } */
|
| 197 |
|
| 198 | ol.simple, ul.simple {
|
| 199 | margin-bottom: 1em }
|
| 200 |
|
| 201 | ol.arabic {
|
| 202 | list-style: decimal }
|
| 203 |
|
| 204 | ol.loweralpha {
|
| 205 | list-style: lower-alpha }
|
| 206 |
|
| 207 | ol.upperalpha {
|
| 208 | list-style: upper-alpha }
|
| 209 |
|
| 210 | ol.lowerroman {
|
| 211 | list-style: lower-roman }
|
| 212 |
|
| 213 | ol.upperroman {
|
| 214 | list-style: upper-roman }
|
| 215 |
|
| 216 | p.attribution {
|
| 217 | text-align: right ;
|
| 218 | margin-left: 50% }
|
| 219 |
|
| 220 | p.caption {
|
| 221 | font-style: italic }
|
| 222 |
|
| 223 | p.credits {
|
| 224 | font-style: italic ;
|
| 225 | font-size: smaller }
|
| 226 |
|
| 227 | p.label {
|
| 228 | white-space: nowrap }
|
| 229 |
|
| 230 | p.rubric {
|
| 231 | font-weight: bold ;
|
| 232 | font-size: larger ;
|
| 233 | color: maroon ;
|
| 234 | text-align: center }
|
| 235 |
|
| 236 | p.sidebar-title {
|
| 237 | font-family: sans-serif ;
|
| 238 | font-weight: bold ;
|
| 239 | font-size: larger }
|
| 240 |
|
| 241 | p.sidebar-subtitle {
|
| 242 | font-family: sans-serif ;
|
| 243 | font-weight: bold }
|
| 244 |
|
| 245 | p.topic-title {
|
| 246 | font-weight: bold }
|
| 247 |
|
| 248 | pre.address {
|
| 249 | margin-bottom: 0 ;
|
| 250 | margin-top: 0 ;
|
| 251 | font: inherit }
|
| 252 |
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 253 | pre.literal-block, pre.doctest-block, pre.math {
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 254 | margin-left: 2em ;
|
| 255 | margin-right: 2em }
|
| 256 |
|
| 257 | span.classifier {
|
| 258 | font-family: sans-serif ;
|
| 259 | font-style: oblique }
|
| 260 |
|
| 261 | span.classifier-delimiter {
|
| 262 | font-family: sans-serif ;
|
| 263 | font-weight: bold }
|
| 264 |
|
| 265 | span.interpreted {
|
| 266 | font-family: sans-serif }
|
| 267 |
|
| 268 | span.option {
|
| 269 | white-space: nowrap }
|
| 270 |
|
| 271 | span.pre {
|
| 272 | white-space: pre }
|
| 273 |
|
| 274 | span.problematic {
|
| 275 | color: red }
|
| 276 |
|
| 277 | span.section-subtitle {
|
| 278 | /* font-size relative to parent (h1..h6 element) */
|
| 279 | font-size: 80% }
|
| 280 |
|
| 281 | table.citation {
|
| 282 | border-left: solid 1px gray;
|
| 283 | margin-left: 1px }
|
| 284 |
|
| 285 | table.docinfo {
|
| 286 | margin: 2em 4em }
|
| 287 |
|
| 288 | table.docutils {
|
| 289 | margin-top: 0.5em ;
|
| 290 | margin-bottom: 0.5em }
|
| 291 |
|
| 292 | table.footnote {
|
| 293 | border-left: solid 1px black;
|
| 294 | margin-left: 1px }
|
| 295 |
|
| 296 | table.docutils td, table.docutils th,
|
| 297 | table.docinfo td, table.docinfo th {
|
| 298 | padding-left: 0.5em ;
|
| 299 | padding-right: 0.5em ;
|
| 300 | vertical-align: top }
|
| 301 |
|
| 302 | table.docutils th.field-name, table.docinfo th.docinfo-name {
|
| 303 | font-weight: bold ;
|
| 304 | text-align: left ;
|
| 305 | white-space: nowrap ;
|
| 306 | padding-left: 0 }
|
| 307 |
|
| 308 | h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
|
| 309 | h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
|
| 310 | font-size: 100% }
|
| 311 |
|
| 312 | ul.auto-toc {
|
| 313 | list-style-type: none }
|
| 314 |
|
| 315 | </style>
|
| 316 | </head>
|
| 317 | <body>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 318 | <div class="document" id="pycparser-v2-05">
|
| 319 | <h1 class="title">pycparser v2.05</h1>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 320 | <table class="docinfo" frame="void" rules="none">
|
| 321 | <col class="docinfo-name" />
|
| 322 | <col class="docinfo-content" />
|
| 323 | <tbody valign="top">
|
| 324 | <tr><th class="docinfo-name">Author:</th>
|
| 325 | <td><a class="first reference external" href="http://eli.thegreenplace.net">Eli Bendersky</a></td></tr>
|
| 326 | </tbody>
|
| 327 | </table>
|
| 328 | <div class="contents topic" id="contents">
|
| 329 | <p class="topic-title first">Contents</p>
|
| 330 | <ul class="auto-toc simple">
|
| 331 | <li><a class="reference internal" href="#introduction" id="id2">1 Introduction</a><ul class="auto-toc">
|
| 332 | <li><a class="reference internal" href="#what-is-pycparser" id="id3">1.1 What is pycparser?</a></li>
|
| 333 | <li><a class="reference internal" href="#what-is-it-good-for" id="id4">1.2 What is it good for?</a></li>
|
| 334 | <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>
|
| 335 | <li><a class="reference internal" href="#what-grammar-does-pycparser-follow" id="id6">1.4 What grammar does pycparser follow?</a></li>
|
eli.bendersky | 40d218b | 2011-02-10 07:04:47 +0200 | [diff] [blame] | 336 | <li><a class="reference internal" href="#how-is-pycparser-licensed" id="id7">1.5 How is pycparser licensed?</a></li>
|
| 337 | <li><a class="reference internal" href="#contact-details" id="id8">1.6 Contact details</a></li>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 338 | </ul>
|
| 339 | </li>
|
eli.bendersky | 40d218b | 2011-02-10 07:04:47 +0200 | [diff] [blame] | 340 | <li><a class="reference internal" href="#installing" id="id9">2 Installing</a><ul class="auto-toc">
|
| 341 | <li><a class="reference internal" href="#prerequisites" id="id10">2.1 Prerequisites</a></li>
|
| 342 | <li><a class="reference internal" href="#installation-process" id="id11">2.2 Installation process</a></li>
|
| 343 | <li><a class="reference internal" href="#known-problems" id="id12">2.3 Known problems</a></li>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 344 | </ul>
|
| 345 | </li>
|
eli.bendersky | 40d218b | 2011-02-10 07:04:47 +0200 | [diff] [blame] | 346 | <li><a class="reference internal" href="#using" id="id13">3 Using</a><ul class="auto-toc">
|
| 347 | <li><a class="reference internal" href="#interaction-with-the-c-preprocessor" id="id14">3.1 Interaction with the C preprocessor</a></li>
|
| 348 | <li><a class="reference internal" href="#what-about-the-standard-c-library-headers" id="id15">3.2 What about the standard C library headers?</a></li>
|
| 349 | <li><a class="reference internal" href="#basic-usage" id="id16">3.3 Basic usage</a></li>
|
| 350 | <li><a class="reference internal" href="#advanced-usage" id="id17">3.4 Advanced usage</a></li>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 351 | </ul>
|
| 352 | </li>
|
eli.bendersky | 40d218b | 2011-02-10 07:04:47 +0200 | [diff] [blame] | 353 | <li><a class="reference internal" href="#modifying" id="id18">4 Modifying</a></li>
|
| 354 | <li><a class="reference internal" href="#package-contents" id="id19">5 Package contents</a></li>
|
| 355 | <li><a class="reference internal" href="#contributors" id="id20">6 Contributors</a></li>
|
| 356 | <li><a class="reference internal" href="#changelog" id="id21">7 Changelog</a></li>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 357 | </ul>
|
| 358 | </div>
|
| 359 | <div class="section" id="introduction">
|
| 360 | <h1>1 Introduction</h1>
|
| 361 | <div class="section" id="what-is-pycparser">
|
| 362 | <h2>1.1 What is pycparser?</h2>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 363 | <p><tt class="docutils literal">pycparser</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>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 364 | </div>
|
| 365 | <div class="section" id="what-is-it-good-for">
|
| 366 | <h2>1.2 What is it good for?</h2>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 367 | <p>Anything that needs C code to be parsed. The following are some uses for <tt class="docutils literal">pycparser</tt>, taken from real user reports:</p>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 368 | <ul class="simple">
|
| 369 | <li>C code obfuscator</li>
|
| 370 | <li>Front-end for various specialized C compilers</li>
|
| 371 | <li>Static code checker</li>
|
| 372 | <li>Automatic unit-test discovery</li>
|
| 373 | <li>Adding specialized extensions to the C language</li>
|
| 374 | </ul>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 375 | <p><tt class="docutils literal">pycparser</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">pycparser</tt>'s code will be simple to understand.</p>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 376 | </div>
|
| 377 | <div class="section" id="which-version-of-c-does-pycparser-support">
|
| 378 | <h2>1.3 Which version of C does pycparser support?</h2>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 379 | <p><tt class="docutils literal">pycparser</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>
|
| 380 | <p><tt class="docutils literal">pycparser</tt> doesn't support any GCC extensions.</p>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 381 | </div>
|
| 382 | <div class="section" id="what-grammar-does-pycparser-follow">
|
| 383 | <h2>1.4 What grammar does pycparser follow?</h2>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 384 | <p><tt class="docutils literal">pycparser</tt> very closely follows the C grammar provided in the end of the C99 standard document</p>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 385 | </div>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 386 | <div class="section" id="how-is-pycparser-licensed">
|
eli.bendersky | 40d218b | 2011-02-10 07:04:47 +0200 | [diff] [blame] | 387 | <h2>1.5 How is pycparser licensed?</h2>
|
eli.bendersky | 15cb270 | 2011-04-29 09:01:33 +0300 | [diff] [blame] | 388 | <p><a class="reference external" href="http://www.opensource.org/licenses/bsd-license.php">New BSD License</a></p>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 389 | </div>
|
| 390 | <div class="section" id="contact-details">
|
eli.bendersky | 40d218b | 2011-02-10 07:04:47 +0200 | [diff] [blame] | 391 | <h2>1.6 Contact details</h2>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 392 | <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">pycparser</tt>. For reporting problems with <tt class="docutils literal">pycparser</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>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 393 | </div>
|
| 394 | </div>
|
| 395 | <div class="section" id="installing">
|
| 396 | <h1>2 Installing</h1>
|
| 397 | <div class="section" id="prerequisites">
|
| 398 | <h2>2.1 Prerequisites</h2>
|
| 399 | <ul class="simple">
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 400 | <li><tt class="docutils literal">pycparser</tt> was tested on Python 2.6 and 3.2, on both Linux and Windows. It should work on any later version (in both the 2.x and 3.x lines) as well.</li>
|
| 401 | <li><tt class="docutils literal">pycparser</tt> uses the PLY module for the actual lexer and parser construction. Install PLY from <a class="reference external" href="http://www.dabeaz.com/ply/">its website</a>.</li>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 402 | </ul>
|
| 403 | </div>
|
| 404 | <div class="section" id="installation-process">
|
| 405 | <h2>2.2 Installation process</h2>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 406 | <p>Installing <tt class="docutils literal">pycparser</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">python setup.py install</tt>. The setup script will then place the <tt class="docutils literal">pycparser</tt> module into <tt class="docutils literal"><span class="pre">site-packages</span></tt> in your Python's installation library.</p>
|
| 407 | <p>Alternatively, since <tt class="docutils literal">pycparser</tt> is listed in the <a class="reference external" href="http://pypi.python.org/pypi/pycparser">Python Package Index</a> (PyPI), you can install it using your favorite Python packaging/distribution tool, for example with:</p>
|
| 408 | <pre class="literal-block">
|
| 409 | > pip install pycparser
|
| 410 | </pre>
|
| 411 | <p>It's recommended to run <tt class="docutils literal">_build_tables.py</tt> in the <tt class="docutils literal">pycparser</tt> code directory after installation to make sure the parsing tables of PLY are pre-generated. This can make your code run faster.</p>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 412 | </div>
|
| 413 | <div class="section" id="known-problems">
|
| 414 | <h2>2.3 Known problems</h2>
|
| 415 | <ul class="simple">
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 416 | <li>Some users who've installed a new version of <tt class="docutils literal">pycparser</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">.pyc</tt> files from the older version. If you see unexplained errors from <tt class="docutils literal">pycparser</tt> after an upgrade, remove it (by deleting the <tt class="docutils literal">pycparser</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>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 417 | </ul>
|
| 418 | </div>
|
| 419 | </div>
|
| 420 | <div class="section" id="using">
|
| 421 | <h1>3 Using</h1>
|
| 422 | <div class="section" id="interaction-with-the-c-preprocessor">
|
| 423 | <h2>3.1 Interaction with the C preprocessor</h2>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 424 | <p>In order to be compilable, C code must be preprocessed by the C preprocessor - <tt class="docutils literal">cpp</tt>. <tt class="docutils literal">cpp</tt> handles preprocessing directives like <tt class="docutils literal">#include</tt> and <tt class="docutils literal">#define</tt>, removes comments, and does other minor tasks that prepare the C code for compilation.</p>
|
| 425 | <p>For all but the most trivial snippets of C code, <tt class="docutils literal">pycparser</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">parse_file</tt> function from the <tt class="docutils literal">pycparser</tt> package, it will interact with <tt class="docutils literal">cpp</tt> for you, as long as it's in your PATH, or you provide a path to it.</p>
|
| 426 | <p>On the vast majority of Linux systems, <tt class="docutils literal">cpp</tt> is installed and is in the PATH. If you're on Windows and don't have <tt class="docutils literal">cpp</tt> somewhere, you can use the one provided in the <tt class="docutils literal">utils</tt> directory in <tt class="docutils literal">pycparser</tt>'s distribution. This <tt class="docutils literal">cpp</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>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 427 | </div>
|
| 428 | <div class="section" id="what-about-the-standard-c-library-headers">
|
| 429 | <h2>3.2 What about the standard C library headers?</h2>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 430 | <p>C code almost always includes various header files from the standard C library, like <tt class="docutils literal">stdio.h</tt>. While, with some effort, <tt class="docutils literal">pycparser</tt> can be made to parse the standard headers from any C compiler, it's much simpler to use the provided "fake" standard includes in <tt class="docutils literal">utils/fake_libc_include</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>
|
| 431 | <p>See the <tt class="docutils literal">using_cpp_libc.py</tt> example for more details.</p>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 432 | </div>
|
| 433 | <div class="section" id="basic-usage">
|
| 434 | <h2>3.3 Basic usage</h2>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 435 | <p>Take a look at the <tt class="docutils literal">examples</tt> directory of the distribution for a few examples of using <tt class="docutils literal">pycparser</tt>. These should be enough to get you started.</p>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 436 | </div>
|
| 437 | <div class="section" id="advanced-usage">
|
| 438 | <h2>3.4 Advanced usage</h2>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 439 | <p>The public interface of <tt class="docutils literal">pycparser</tt> is well documented with comments in <tt class="docutils literal">pycparser/c_parser.py</tt>. For a detailed overview of the various AST nodes created by the parser, see <tt class="docutils literal">pycparser/_c_ast.cfg</tt>.</p>
|
eli.bendersky | 40d218b | 2011-02-10 07:04:47 +0200 | [diff] [blame] | 440 | <p>There's also a <a class="reference external" href="http://code.google.com/p/pycparser/wiki/FAQ">FAQ available here</a>. In any case, you can always drop me an <a class="reference external" href="mailto:eliben@gmail.com">email</a> for help.</p>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 441 | </div>
|
| 442 | </div>
|
| 443 | <div class="section" id="modifying">
|
| 444 | <h1>4 Modifying</h1>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 445 | <p>There are a few points to keep in mind when modifying <tt class="docutils literal">pycparser</tt>:</p>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 446 | <ul class="simple">
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 447 | <li>The code for <tt class="docutils literal">pycparser</tt>'s AST nodes is automatically generated from a configuration file - <tt class="docutils literal">_c_ast.cfg</tt>, by <tt class="docutils literal">_ast_gen.py</tt>. If you modify the AST configuration, make sure to re-generate the code.</li>
|
| 448 | <li>Make sure you understand the optimized mode of <tt class="docutils literal">pycparser</tt> - for that you must read the docstring in the constructor of the <tt class="docutils literal">CParser</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>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 449 | </ul>
|
| 450 | </div>
|
| 451 | <div class="section" id="package-contents">
|
| 452 | <h1>5 Package contents</h1>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 453 | <p>Once you unzip the <tt class="docutils literal">pycparser</tt> package, you'll see the following files and directories:</p>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 454 | <dl class="docutils">
|
| 455 | <dt>README.txt/html:</dt>
|
| 456 | <dd>This README file.</dd>
|
| 457 | <dt>setup.py:</dt>
|
| 458 | <dd>Installation script</dd>
|
| 459 | <dt>examples/:</dt>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 460 | <dd>A directory with some examples of using <tt class="docutils literal">pycparser</tt></dd>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 461 | <dt>pycparser/:</dt>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 462 | <dd>The <tt class="docutils literal">pycparser</tt> module source code.</dd>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 463 | <dt>tests/:</dt>
|
| 464 | <dd>Unit tests.</dd>
|
| 465 | <dt>utils/cpp.exe:</dt>
|
| 466 | <dd>A Windows executable of the C pre-processor suitable for working with pycparser</dd>
|
| 467 | <dt>utils/fake_libc_include:</dt>
|
| 468 | <dd>Minimal standard C library include files that should allow to parse any C code.</dd>
|
| 469 | <dt>utils/internal/:</dt>
|
| 470 | <dd>Internal utilities for my own use. You probably don't need them.</dd>
|
| 471 | </dl>
|
| 472 | </div>
|
| 473 | <div class="section" id="contributors">
|
| 474 | <h1>6 Contributors</h1>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 475 | <p>Some people have contributed to <tt class="docutils literal">pycparser</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>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 476 | </div>
|
| 477 | <div class="section" id="changelog">
|
| 478 | <h1>7 Changelog</h1>
|
| 479 | <ul class="simple">
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 480 | <li>Version 2.05 (16.10.2011)<ul>
|
| 481 | <li>Added support for the C99 <tt class="docutils literal">_Bool</tt> type and <tt class="docutils literal">stdbool.h</tt> header file</li>
|
| 482 | <li>Expanded <tt class="docutils literal">examples/explore_ast.py</tt> with more details on working with the
|
| 483 | AST</li>
|
| 484 | <li>Relaxed the rules on parsing unnamed struct members (helps parse <tt class="docutils literal">windows.h</tt>)</li>
|
| 485 | <li>Bug fixes:<ul>
|
| 486 | <li>Fixed spacing issue for some type declarations</li>
|
| 487 | <li>Issue 47: display empty statements (lone ';') correctly after parsing</li>
|
| 488 | </ul>
|
| 489 | </li>
|
| 490 | </ul>
|
| 491 | </li>
|
eli.bendersky | 851dbfb | 2011-05-21 09:30:05 +0300 | [diff] [blame] | 492 | <li>Version 2.04 (21.05.2011)<ul>
|
| 493 | <li>License changed from LGPL to BSD</li>
|
| 494 | <li>Bug fixes:<ul>
|
| 495 | <li>Issue 31: constraining the scope of typedef definitions</li>
|
| 496 | <li>Issues 33, 35: fixes for the c-to-c.py example</li>
|
| 497 | </ul>
|
| 498 | </li>
|
| 499 | <li>Added C99 integer types to fake headers</li>
|
| 500 | <li>Added unit tests for the c-to-c.py example</li>
|
| 501 | </ul>
|
| 502 | </li>
|
eli.bendersky | b56e8f8 | 2011-03-06 07:56:55 +0200 | [diff] [blame] | 503 | <li>Version 2.03 (06.03.2011)<ul>
|
| 504 | <li>Bug fixes:<ul>
|
| 505 | <li>Issue 17: empty file-level declarations</li>
|
| 506 | <li>Issue 18: empty statements and declarations in functions</li>
|
| 507 | <li>Issue 19: anonymous structs & union fields</li>
|
| 508 | <li>Issue 23: fix coordinates of Cast nodes</li>
|
| 509 | </ul>
|
| 510 | </li>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 511 | <li>New example added (<tt class="docutils literal"><span class="pre">examples/c-to-c.py</span></tt>) for translating ASTs generated by <tt class="docutils literal">pycparser</tt> back into C code.</li>
|
| 512 | <li><tt class="docutils literal">pycparser</tt> is now on PyPI (Python Package Index)</li>
|
| 513 | <li>Created <a class="reference external" href="http://code.google.com/p/pycparser/wiki/FAQ">FAQ</a> on the <tt class="docutils literal">pycparser</tt> project page</li>
|
| 514 | <li>Removed support for Python 2.5. <tt class="docutils literal">pycparser</tt> supports Python 2 from 2.6 and on, and Python 3.</li>
|
eli.bendersky | b56e8f8 | 2011-03-06 07:56:55 +0200 | [diff] [blame] | 515 | </ul>
|
| 516 | </li>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 517 | <li>Version 2.02 (10.12.2010)<ul>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 518 | <li>The name of a <tt class="docutils literal">NamedInitializer</tt> node was turned into a sequence of nodes
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 519 | instead of an attribute, to make it discoverable by the AST node visitor.</li>
|
| 520 | <li>Documentation updates</li>
|
| 521 | </ul>
|
| 522 | </li>
|
| 523 | <li>Version 2.01 (04.12.2010)<ul>
|
| 524 | <li>Removed dependency on YAML. Parsing of the AST node configuration file is done with a simple parser.</li>
|
| 525 | <li>Fixed issue 12: installation problems</li>
|
| 526 | </ul>
|
| 527 | </li>
|
| 528 | <li>Version 2.00 (31.10.2010)<ul>
|
| 529 | <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>
|
| 530 | </ul>
|
| 531 | </li>
|
| 532 | <li>Version 1.08 (09.10.2010)<ul>
|
| 533 | <li>Bug fixes:<ul>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 534 | <li>Correct handling of <tt class="docutils literal">do{} ... while</tt> statements in some cases</li>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 535 | <li>Issues 6 & 7: Concatenation of string literals</li>
|
| 536 | <li>Issue 9: Support for unnamed bitfields in structs</li>
|
| 537 | </ul>
|
| 538 | </li>
|
| 539 | </ul>
|
| 540 | </li>
|
| 541 | <li>Version 1.07 (18.05.2010)<ul>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 542 | <li>Python 3.1 compatibility: <tt class="docutils literal">pycparser</tt> was modified to run on Python 3.1 as well as 2.6</li>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 543 | </ul>
|
| 544 | </li>
|
| 545 | <li>Version 1.06 (10.04.2010)<ul>
|
| 546 | <li>Bug fixes:<ul>
|
| 547 | <li>coord not propagated to FuncCall nodes</li>
|
| 548 | <li>lexing of the ^= token (XOREQUALS)</li>
|
| 549 | <li>parsing failed on some abstract declarator rules</li>
|
| 550 | </ul>
|
| 551 | </li>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 552 | <li>Linux compatibility: fixed end-of-line and <tt class="docutils literal">cpp</tt> path issues to allow all tests and examples run on Linux</li>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 553 | </ul>
|
| 554 | </li>
|
| 555 | <li>Version 1.05 (16.10.2009)<ul>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 556 | <li>Fixed the <tt class="docutils literal">parse_file</tt> auxiliary function to handle multiple arguments to <tt class="docutils literal">cpp</tt> correctly</li>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 557 | </ul>
|
| 558 | </li>
|
| 559 | <li>Version 1.04 (22.05.2009)<ul>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 560 | <li>Added the <tt class="docutils literal">fake_libc_include</tt> directory to allow parsing of C code that uses standard C library include files without dependency on a real C library.</li>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 561 | <li>Tested with Python 2.6 and PLY 3.2</li>
|
| 562 | </ul>
|
| 563 | </li>
|
| 564 | <li>Version 1.03 (31.01.2009)<ul>
|
| 565 | <li>Accept enumeration lists with a comma after the last item (C99 feature).</li>
|
| 566 | </ul>
|
| 567 | </li>
|
| 568 | <li>Version 1.02 (16.01.2009)<ul>
|
eli.bendersky | e91008a | 2011-10-16 06:21:59 +0200 | [diff] [blame] | 569 | <li>Fixed problem of parsing struct/enum/union names that were named similarly to previously defined <tt class="docutils literal">typedef</tt> types.</li>
|
eli.bendersky | 347497d | 2010-12-10 15:17:28 +0200 | [diff] [blame] | 570 | </ul>
|
| 571 | </li>
|
| 572 | <li>Version 1.01 (09.01.2009)<ul>
|
| 573 | <li>Fixed subprocess invocation in the helper function parse_file - now it's more portable</li>
|
| 574 | </ul>
|
| 575 | </li>
|
| 576 | <li>Version 1.0 (15.11.2008)<ul>
|
| 577 | <li>Initial release</li>
|
| 578 | <li>Support for ANSI C89</li>
|
| 579 | </ul>
|
| 580 | </li>
|
| 581 | </ul>
|
| 582 | </div>
|
| 583 | </div>
|
| 584 | </body>
|
| 585 | </html>
|