| 1 | <refentry id="productionset.element" revision='EBNF'> |
| 2 | <?dbhtml filename="productionset.html"?> |
| 3 | <refentryinfo> |
| 4 | <pubdate>$Date$</pubdate> |
| 5 | <releaseinfo>$Revision$</releaseinfo> |
| 6 | </refentryinfo> |
| 7 | |
| 8 | <refmeta> |
| 9 | <indexterm><primary>elements</primary> |
| 10 | <secondary>productionset</secondary></indexterm> |
| 11 | <refentrytitle>productionset</refentrytitle> |
| 12 | <refmiscinfo>Element</refmiscinfo> |
| 13 | </refmeta> |
| 14 | <refnamediv> |
| 15 | <refname>productionset</refname> |
| 16 | <refpurpose>&productionset.purpose;</refpurpose> |
| 17 | </refnamediv> |
| 18 | |
| 19 | &productionset.synopsis.gen; |
| 20 | <refsect1 condition='ref.description'><title>Description</title> |
| 21 | |
| 22 | <para>This element is only available if you are using the |
| 23 | <link linkend="ebnf.module">EBNF Module</link>.</para> |
| 24 | |
| 25 | <para>A <sgmltag>ProductionSet</sgmltag> is a collection of |
| 26 | <glossterm>Extended Backus-Naur Form</glossterm> (EBNF) |
| 27 | <sgmltag>Production</sgmltag>s.</para> |
| 28 | |
| 29 | <para>EBNF is a notation for describing the grammar of context-free |
| 30 | languages. Even if you aren't conversant in the programming language |
| 31 | concepts of context-free languages and grammars, it's not really |
| 32 | as hard to understand as it sounds.</para> |
| 33 | |
| 34 | <para>A set of EBNF productions describes the legal arrangements of |
| 35 | tokens in a language. Consider arithmetic expressions as a simple |
| 36 | example.</para> |
| 37 | |
| 38 | <para>The expression |
| 39 | <quote><literal>3 + 4</literal></quote> |
| 40 | is valid and so is |
| 41 | <quote><literal>3 + 4 - 5</literal></quote>, but |
| 42 | <quote><literal>3 - + - 4</literal></quote> is not, nor is |
| 43 | <quote><literal>3 + 4 6</literal></quote>. We can use EBNF to |
| 44 | describe all the possible legal arrangements:</para> |
| 45 | |
| 46 | <productionset><title>Arithemetic Expressions</title> |
| 47 | <production id="ebnf.expression"> |
| 48 | <lhs>Expression</lhs> |
| 49 | <rhs><nonterminal def="ebnf.arith">ArithExpression</nonterminal> | |
| 50 | <nonterminal def="ebnf.mult">MultExpression</nonterminal> |
| 51 | <lineannotation>Does this grammar actually get precedence right? |
| 52 | </lineannotation> |
| 53 | </rhs> |
| 54 | </production> |
| 55 | <production id="ebnf.arith"> |
| 56 | <lhs>ArithExpression</lhs> |
| 57 | <rhs><nonterminal def="ebnf.expression">Expression</nonterminal> |
| 58 | '+' |
| 59 | <nonterminal def="ebnf.mult">MultExpression</nonterminal> | |
| 60 | <nonterminal def="ebnf.expression">Expression</nonterminal> |
| 61 | '-' |
| 62 | <nonterminal def="ebnf.mult">MultExpression</nonterminal> |
| 63 | </rhs> |
| 64 | </production> |
| 65 | <production id="ebnf.mult"> |
| 66 | <lhs>MultExpression</lhs> |
| 67 | <rhs><nonterminal def="ebnf.mult">MultExpression</nonterminal> |
| 68 | '*' |
| 69 | <nonterminal def="ebnf.mult">MultExpression</nonterminal> | |
| 70 | <nonterminal def="ebnf.mult">MultExpression</nonterminal> |
| 71 | '/' |
| 72 | <nonterminal def="ebnf.mult">MultExpression</nonterminal> | |
| 73 | <nonterminal def="ebnf.number">Number</nonterminal> |
| 74 | </rhs> |
| 75 | <constraint linkend="div0"/> |
| 76 | </production> |
| 77 | <production id="ebnf.number"> |
| 78 | <lhs>Number</lhs> |
| 79 | <rhs>[0-9]+</rhs> |
| 80 | </production> |
| 81 | </productionset> |
| 82 | |
| 83 | <constraintdef id="div0" role="Err"> |
| 84 | <title>Division by Zero</title> |
| 85 | <para>Division by zero is an error. Constraints, such as this one, |
| 86 | are used to express conditions that cannot be expressed in the grammar.</para> |
| 87 | </constraintdef> |
| 88 | |
| 89 | <refsect2><title>Processing expectations</title> |
| 90 | <para> |
| 91 | &format.block; The detailed processing expecations with respect to |
| 92 | individual productions, left-hand sides, and right-hand sides are quite |
| 93 | complex. |
| 94 | </para> |
| 95 | <para><sgmltag>Production</sgmltag>s should be numbered.</para> |
| 96 | </refsect2> |
| 97 | |
| 98 | |
| 99 | &productionset.parents.gen; |
| 100 | &productionset.children.gen; |
| 101 | </refsect1> |
| 102 | <refsect1><title>Examples</title> |
| 103 | |
| 104 | <informalexample role="example-source"> |
| 105 | <programlisting>&productionset.example.1.txt;</programlisting> |
| 106 | </informalexample> |
| 107 | |
| 108 | &productionset.example.seealso.gen; |
| 109 | </refsect1> |
| 110 | </refentry> |
| 111 |