View Javadoc

1   /*
2    * #%L
3    * prolobjectlink-jpi-jtrolog
4    * %%
5    * Copyright (C) 2012 - 2018 WorkLogic Project
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as
9    * published by the Free Software Foundation, either version 2.1 of the
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
20   * #L%
21   */
22  /*
23   * tuProlog - Copyright (C) 2001-2002  aliCE team at deis.unibo.it
24   *
25   * This library is free software; you can redistribute it and/or
26   * modify it under the terms of the GNU Lesser General Public
27   * License as published by the Free Software Foundation; either
28   * version 2.1 of the License, or (at your option) any later version.
29   *
30   * This library is distributed in the hope that it will be useful,
31   * but WITHOUT ANY WARRANTY; without even the implied warranty of
32   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
33   * Lesser General Public License for more details.
34   *
35   * You should have received a copy of the GNU Lesser General Public
36   * License along with this library; if not, write to the Free Software
37   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
38   */
39  package jTrolog.lib;
40  
41  /**
42   * Library for managing DCGs. Library/Theory dependency: BasicLibrary
43   */
44  @SuppressWarnings("serial")
45  public class DCGLibrary extends Library {
46  
47  	public DCGLibrary() {
48  	}
49  
50  	public String getTheory() {
51  		return ":- op(1200, xfx, '-->').  " + ":- op(200, xfx, '\\').  " +
52  
53  		"phrase(Category,String,Left, SyntaxTree) :- dcg_parse(Category,String\\Left, SyntaxTree). " + "phrase(Category,[H|T], SyntaxTree) :- dcg_parse(Category,[H|T]\\[], SyntaxTree). " +
54  
55  		"dcg_parse(A,Tokens,  A < SubTree) :- " + "not list(A), " + "(A --> B), " + "dcg_parse(B,Tokens, SubTree). " + "dcg_parse((A,B),(Tokens \\ Xs), [SubTreeA|SubTreeB]) :- "
56  				+ "dcg_parse(A,(Tokens \\ Tokens1), SubTreeA), " + "dcg_parse(B,(Tokens1 \\ Xs), SubTreeB). " + "dcg_parse(A, Tokens, A) :- " + "list(A), " + "dcg_connect(A,Tokens). "
57  				+ "dcg_parse({A},(Xs \\ Xs), []) :- A. " +
58  
59  				"dcg_connect([],(Xs \\ Xs)). " + "dcg_connect([W|Ws],([W|Xs] \\ Ys)) :- dcg_connect(Ws,(Xs \\ Ys)). ";
60  	}
61  }