govern the sentence structure of a language • Syntax refers only to the structure of a sentence; not the meaning, or “semantics” • A formal description of a language’s syntax is called a “grammar” Thursday, August 1, 13
define the syntax of a language • A formal grammar can be generative or analytic • Generative grammars define how to form valid sentences • Analytic grammars define how to recognize valid sentences Thursday, August 1, 13
structure • Turns a linear sequence of characters into an explicit structure • Output is typically a tree structure • Usually a component of a compiler or interpreter (or parser generator) Thursday, August 1, 13
generates a parser • The input is a formal description of the language to parse • That formal description is a grammar • The parser generator starts by parsing the grammar Thursday, August 1, 13
• Treetop and Citrus are pretty basic and don’t handle left-recursion • ANTLR for Ruby is slow and doesn’t handle left-recursion • Ragel is not really designed for syntactic analysis Thursday, August 1, 13
Require a separate token grammar • Difficult to debug • Difficult to produce useful error messages • Generative grammars tend to be ambiguous Thursday, August 1, 13
and maybe even fun! • Experimenting should be encouraged • Common parsing problems should be easy to solve • Write expressive grammars, let Rattler optimize the parser Thursday, August 1, 13