pacc logo
pacc v0.3: Rules

Next: , Previous: , Up: Top   [Contents][Index]


5 Rules

Here’s where we’ve got to:

Start <- "yes" {1} / "oui" {1} / "non" {0} / "no" {0}

We can improve this by splitting things up and removing the repetition.

Start <- Yes → 1 / No → 0
Yes :: void <- "yes" / "oui"
No <- "non" / "no"

Don’t, at the moment, worry about ‘:: void’ on the second line—we’ll explain what this means shortly. The important point to notice is that a grammar can have more than one rule. The first rule is always the start rule, where parsing begins.

Each rule has a name, in this grammar there are 3 rules named ‘Start’, ‘Yes’, and ‘No’. Rule names are formed in the same way as C identifiers: they must start with a letter or underscore, and continue with letters, underscores, or digits. I often follow the convention of starting rule names with capital letters as it helps them to stand out, but you don’t have to.

The fundamental building blocks of pacc are called matchers. We’ve already met one kind of matcher: a literal string like ‘"yes"’. A matcher occurs in the definition of a rule, and it matches something in the input. In the case of a literal string, it matches just that one string.

Another kind of matcher is a call matcher. One rule can call another rule, simply by naming the called rule in its definition. As you might expect, when you call a rule by name, that matches whatever the called rule matches. The definition of the ‘Start’ rule contains two call matchers: the first calls the rule ‘Yes’ and the second calls the rule ‘No’. You can call a rule before it has been defined, so long as the definition occurs in the same pacc grammar.

There are only two other kinds of matcher, which we’ll get to soon.


Next: , Previous: , Up: Top   [Contents][Index]

Last updated: 2016-08-03 21:39:50 UTC

News

Porting and packaging

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...

Release relief

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...

See more news articles

feed