Next: Character classes, Previous: Rules, Up: Top [Contents][Index]
Every pacc rule has a type, which can be almost any C type. The type of a rule appears in its definition, directly after the name introduced by ‘::’. (In many ways, I would have preferred to prefix types to names like C itself, but then we’d have to terminate rules, say with semicolons, and that appealed even less.)
The rules for types are as follows.
Rule 3 explains how we have got away so far without explicit type declarations—in their absence, everything defaults to ‘int’. Let’s revisit our example yet again.
Start :: int <- Yes → 1 / No → 0 Yes :: void <- "yes" / "oui" No <- "non" / "no"
The first rule ‘Start’ has type ‘int’, this time we’ve made that explicit. The second rule ‘Yes’ has type ‘void’, again by explicit declaration. The third rule ‘No’ has no explicit type, so by rule 2 its type is ‘void’.
|
Arguably this is unfortunate (perhaps there should be a ‘strict’ mode where every rule must have an explicit type?) but in practice most pacc grammars have only a few different types, so implicit typing saves a lot of, errm, typing.
Any C type that can be constructed with words and the ‘*’ character can be used as a pacc type. This includes pointers, structures, and unions, but not vectors (arrays) or function types. You could use a ‘typedef’ for those if you really wanted to, and include it (directly or more likely by ‘#include’) in the pacc preamble.
Next: Character classes, Previous: Rules, Up: Top [Contents][Index]
Last updated: 2016-08-03 21:39:50 UTC
One thing pacc needs is more users. And, perhaps, one way to get more users is to reduce the friction in getting started with pacc. An obvious lubricant is packaging. Read More...
Looking at _pacc_coords(), I noticed that it seemed to have the same realloc() bug that I'd just fixed in _pacc_result(). However, the "list of arrays" trick really wasn't going to work here. Read More...