Concepts of ocamlyacc

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.

    Languages and context-free grammars

    In order for Ocamlyacc to parse a language, it must be described by a context-free grammar.

    From Foraml Rules to Ocamlyacc Input

    A formal grammar is a mathematical construct. To define the language for Ocamlyacc, you must write a file expressing the grammar in Ocamlyacc syntax.

    Semantic values

    A formal grammar is a mathematical construct. To define the language for Ocamlyacc, you must write a file expressing the grammar in Ocamlyacc syntax.

    Semantic actions

    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

    Locations in order to keep track of the textual position, or location, of each syntactic construct.

    Ocamlyacc output

    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.

    Stages in use ocamlyacc

    The actual language-design process using Ocamlyacc, from grammar specification to a working compiler or interpreter, has these parts:

    Overall layout of grammar

    The general form of a Ocamlyacc grammar file is as follows:

comments powered by Disqus