This chapter introduces many of the basic concepts without which the details of Ocamlyacc will not make sense. If you do not already know how to use Ocamlyacc, we suggest you start by reading this chapter carefully.
In order for Ocamlyacc to parse a language, it must be described by a context-free grammar.
A formal grammar is a mathematical construct. To define the language for Ocamlyacc, you must write a file expressing the grammar in Ocamlyacc syntax.
A formal grammar is a mathematical construct. To define the language for Ocamlyacc, you must write a file expressing the grammar in Ocamlyacc syntax.
A grammar rule can have an action made up of Ocaml statements. Each time the parser recognizes a match for that rule, the action is executed.
Locations in order to keep track of the textual position, or location, of each syntactic construct.
When you run Ocamlyacc, you give it a Ocamlyacc grammar file as input. The output is a Ocaml source file that parses the language described by the grammar.
The actual language-design process using Ocamlyacc, from grammar specification to a working compiler or interpreter, has these parts:
The general form of a Ocamlyacc grammar file is as follows: