Previous Contents Next

Chapter Structure

This chapter introduces the tools of the Objective CAML distribution for lexical analysis and parsing. The latter normally supposes that the former has already taken place. In the first section, we introduce a simple tool for lexical analysis provided by module Genlex. Next we give details about the definition of sets of lexical units by introducing the formalism of regular expressions. We illustrate their behavior within module Str and the ocamllex tool. In section two we define grammars and give details about sentence production rules for a language to introduce two types of parsing: bottom-up and top-down. They are further illustrated by using Stream and the ocamlyacc tool. These examples use context-free grammars. We then show how to carry out contextual analysis with Streams. In the third section we go back to the example of a BASIC interpreter from page ??, using ocamllex and ocamlyacc to implement the lexical analysis and parsing functions.


Previous Contents Next