001 // This file is part of the Attempto Java Packages.
002 // Copyright 2008, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch).
003 //
004 // The Attempto Java Packages is free software: you can redistribute it and/or modify it under the
005 // terms of the GNU Lesser General Public License as published by the Free Software Foundation,
006 // either version 3 of the License, or (at your option) any later version.
007 //
008 // The Attempto Java Packages is distributed in the hope that it will be useful, but WITHOUT ANY
009 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
010 // PURPOSE. See the GNU Lesser General Public License for more details.
011 //
012 // You should have received a copy of the GNU Lesser General Public License along with the Attempto
013 // Java Packages. If not, see http://www.gnu.org/licenses/.
014
015 package ch.uzh.ifi.attempto.preditor.example;
016
017 import ch.uzh.ifi.attempto.chartparser.Grammar;
018 import ch.uzh.ifi.attempto.chartparser.Nonterminal;
019 import ch.uzh.ifi.attempto.chartparser.Rule;
020 import ch.uzh.ifi.attempto.chartparser.Terminal;
021
022 /**
023 * This class is an examplary implementation of a grammar. See the
024 * <a href="{@docRoot}/src-html/ch/uzh/ifi/attempto/preditor/example/ExampleGrammar.html#line.1">source code</a>.
025 *
026 * @author Tobias Kuhn
027 */
028 public class ExampleGrammar extends Grammar {
029
030 /**
031 * Creates a new grammar instance.
032 */
033 public ExampleGrammar() {
034 // "text" is the start symbol
035 super("text");
036
037 // Now the grammar rules are added. The comment lines show how the rules would be expressed in ACGN.
038
039 // text => [].
040 addRule(new Rule(new Nonterminal("text"), true));
041
042 // text => s, ['.'], text.
043 addRule(new Rule(new Nonterminal("text"), true, new Nonterminal("s"), new Terminal("."), new Nonterminal("text")));
044
045 // s => exist_np, vp.
046 addRule(new Rule(new Nonterminal("s"), true, new Nonterminal("exist_np"), new Nonterminal("vp")));
047
048 // s ~> univ_np, vp.
049 addRule(new Rule(new Nonterminal("s"), false, new Nonterminal("univ_np"), new Nonterminal("vp")));
050
051 // univ_np => [every, 'N'], var.
052 addRule(new Rule(new Nonterminal("univ_np"), true, new Terminal("every"), new Terminal("N"), new Nonterminal("var")));
053
054 // univ_np => [no, 'N'], var.
055 addRule(new Rule(new Nonterminal("univ_np"), true, new Terminal("no"), new Terminal("N"), new Nonterminal("var")));
056
057 // exist_np => [a, 'N'], var.
058 addRule(new Rule(new Nonterminal("exist_np"), true, new Terminal("a"), new Terminal("N"), new Nonterminal("var")));
059
060 // exist_np => ['PN'].
061 addRule(new Rule(new Nonterminal("exist_np"), true, new Terminal("PN")));
062
063 // exist_np => ['REF'].
064 addRule(new Rule(new Nonterminal("exist_np"), true, new Terminal("REF")));
065
066 // var => [].
067 addRule(new Rule(new Nonterminal("var"), true));
068
069 // var => ['VAR'].
070 addRule(new Rule(new Nonterminal("var"), true, new Terminal("VAR")));
071
072 // vp => ['IV'].
073 addRule(new Rule(new Nonterminal("vp"), true, new Terminal("IV")));
074
075 // vp => ['TV'], exist_np.
076 addRule(new Rule(new Nonterminal("vp"), true, new Terminal("TV"), new Nonterminal("exist_np")));
077
078 // vp ~> ['TV'], univ_np.
079 addRule(new Rule(new Nonterminal("vp"), false, new Terminal("TV"), new Nonterminal("univ_np")));
080
081 }
082
083 }