pacc logo
pacc v0.3: Pacc basics

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


3 Pacc basics

A pacc grammar consists of one or more rules. Let’s look at our first example again.

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

There’s just one rule in this tiny grammar. Every rule starts with a name, and the name of this rule is ‘Start’.

After the name, a left arrow introduces the definition of the rule. In this case, we’ve made a left arrow out of two old-fashioned ASCII symbols, ‘<’ and ‘-’, but it’s also permitted to use the Unicode character ‘←’ (U+2190 LEFTWARDS ARROW). You can also use a plain old equals sign ‘=’ if you prefer.

A pacc parser works by matching the input to the rules in the grammar. The process starts with the first rule (in this case it’s the only rule), and the first thing in the definition of that first rule. In the case of ‘Start’, the first thing in the definition is ‘"yes"’. The quote marks mean that this is a literal string. For a successful match, the input must be exactly the same characters as are in the literal.

Let’s suppose that on this occasion the input is ‘no’. So the parser can’t match the input against ‘"yes"’ in the rule. But in this rule there is an alternative, and the parser will try to match that next. The ‘/’ character separates alternatives, so the next alternative starts with another literal string: ‘"no"’. This does match our example input.

So having matched ‘"no"’ the parser then finds ‘{0}’. The braces indicate that this is a semantic expression: a hunk of C code (albeit a very tiny one in this case!). Because it is in the alternative that matched, it will be evaluated to give a value to the rule. And the value of the start rule is the overall value of the parse.


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