License is MIT
Note: this is a work in progress. Tutorial so far is in parser.c
A parser interprets an input and produces a tree representing its structure.
For example, the arithmetic expression
(+ 3 (* 2 7))
The above expression states that
You could achieve this in a variety of ways, such as writing a parser that first looked for the "high priority" expressions first (multiplication), working its way down the priority chain.
The rules describing the structure of a document to parse is called a grammar, and you are going to learn how to create a parser that is 'programmed' by a grammar you can read from a text file.
So let's get started.
We will describe grammars with s-expressions. Not only are they easy to parse, it's easy to extend them to include more complex logic.
For example, a grammar for arithmetic expressions can be expressed as:
(:rule 'expression (:option (:sequence 'expression 'operand
'expression)
'integer))
(:rule 'operand (:option "*" "/" "+" "-"))
(:rule 'integer (:one-or-more (:character-range "0" "9")))
Here an 'expression is either a sequence of [ 'expression, 'operand, 'expression ], or a 'integer.
An 'operand is either a "*", "/", "+" or "-" character.
An 'integer is one or more characters from the range of "0"-"9".