Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 8de1f55ea6a1a64d0f3f3ea116288458 > files > 102

happy-1.17-3mdv2009.0.i586.rpm

<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 6. Syntax of Grammar Files</title><link rel="stylesheet" href="fptools.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="Happy User Guide"><link rel="up" href="index.html" title="Happy User Guide"><link rel="prev" href="sec-invoking.html" title="Chapter 5. Invoking Happy"><link rel="next" href="sec-module-header.html" title="6.2. Module Header"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 6. Syntax of Grammar Files</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="sec-invoking.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="sec-module-header.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="sec-grammar-files"></a>Chapter 6. Syntax of Grammar Files</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="sec-grammar-files.html#sec-lexical-rules">6.1. Lexical Rules</a></span></dt><dt><span class="sect1"><a href="sec-module-header.html">6.2. Module Header</a></span></dt><dt><span class="sect1"><a href="sec-directives.html">6.3. Directives</a></span></dt><dd><dl><dt><span class="sect2"><a href="sec-directives.html#sec-token-type">6.3.1. Token Type</a></span></dt><dt><span class="sect2"><a href="sec-directives.html#sec-tokens">6.3.2. Tokens</a></span></dt><dt><span class="sect2"><a href="sec-directives.html#sec-parser-name">6.3.3. Parser Name</a></span></dt><dt><span class="sect2"><a href="sec-directives.html#sec-partial-parsers">6.3.4. Partial Parsers</a></span></dt><dt><span class="sect2"><a href="sec-directives.html#sec-monad-decl">6.3.5. Monad Directive</a></span></dt><dt><span class="sect2"><a href="sec-directives.html#sec-lexer-decl">6.3.6. Lexical Analyser</a></span></dt><dt><span class="sect2"><a href="sec-directives.html#sec-prec-decls">6.3.7. Precedence declarations</a></span></dt><dt><span class="sect2"><a href="sec-directives.html#sec-expect">6.3.8. Expect declarations</a></span></dt><dt><span class="sect2"><a href="sec-directives.html#sec-error-directive">6.3.9. Error declaration</a></span></dt><dt><span class="sect2"><a href="sec-directives.html#sec-attributes">6.3.10. Attribute Type Declaration</a></span></dt><dt><span class="sect2"><a href="sec-directives.html#sec-attribute">6.3.11. Attribute declaration</a></span></dt></dl></dd><dt><span class="sect1"><a href="sec-grammar.html">6.4. Grammar</a></span></dt><dt><span class="sect1"><a href="sec-module-trailer.html">6.5. Module Trailer</a></span></dt></dl></div><p>The input to <span class="application">Happy</span> is a text file containing
    the grammar of the language you want to parse, together with some
    annotations that help the parser generator make a legal Haskell
    module that can be included in your program.  This section gives
    the exact syntax of grammar files. </p><p>The overall format of the grammar file is given below:</p><pre class="programlisting">
&lt;optional module header&gt;
&lt;directives&gt;
%%
&lt;grammar&gt;
&lt;optional module trailer&gt;
</pre><a class="indexterm" name="id2549776"></a><a class="indexterm" name="id2549788"></a><p>If the name of the grammar file ends in <code class="literal">.ly</code>, then
    it is assumed to be a literate script.  All lines except those
    beginning with a <code class="literal">&gt;</code> will be ignored, and the
    <code class="literal">&gt;</code> will be stripped from the beginning of all the code
    lines.  There must be a blank line between each code section
    (lines beginning with <code class="literal">&gt;</code>) and comment section.
    Grammars not using the literate notation must be in a file with
    the <code class="literal">.y</code> suffix.</p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec-lexical-rules"></a>6.1. Lexical Rules</h2></div></div></div><p>Identifiers in <span class="application">Happy</span> grammar files must take the following form (using
the BNF syntax from the Haskell Report):</p><pre class="programlisting">
        id      ::= alpha { idchar }
                  | ' { any{^'} | \' } '
                  | " { any{^"} | \" } "

        alpha   ::= A | B | ... | Z
                  | a | b | ... | z

        idchar  ::= alpha
                  | 0 | 1 | ... | 9
                  | _
</pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sec-invoking.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="sec-module-header.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 5. Invoking <span class="application">Happy</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 6.2. Module Header</td></tr></table></div></body></html>