blob: 23126c8f890eff77141081dde2fcdd097bd5154a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
package org.grammaticalframework.pgf;
import java.io.*;
import java.util.*;
/** This is the class for PGF grammars.*/
public class PGF {
/** Reads a grammar with the specified file path.
* @param path The path to the file.
* @return an object representing the grammar in memory. */
public static native PGF readPGF(String path) throws FileNotFoundException;
/** Reads a grammar from an input stream.
* @param stream The stream from which to read the grammar
* @return an object representing the grammar in memory. */
public static native PGF readPGF(InputStream stream);
/** Returns the name of the abstract syntax for the grammar */
public native String getAbstractName();
/** Returns a map from a name of a concrete syntax to
* a {@link Concr} object for the syntax. */
public native Map<String,Concr> getLanguages();
/** Returns a list of with all categories in the grammar */
public native List<String> getCategories();
/** The name of the start category for the grammar. This is usually
* specified with 'params startcat=<cat>'.
*/
public native String getStartCat();
/** Returns a list with all functions in the grammar. */
public native List<String> getFunctions();
/** Returns a list with all functions with a given return category.
* @param cat The name of the return category. */
public native List<String> getFunctionsByCat(String cat);
/** Returns the type of the function with the given name.
* @param fun The name of the function.
*/
public native Type getFunctionType(String fun);
/** Returns the negative logarithmic probability of the function
* with the given name.
* @param fun The name of the function.
*/
public native double getFunctionProb(String fun);
/** Returns an iterable over the set of all expression in
* the given category. The expressions are enumerated in decreasing
* probability order.
*/
public Iterable<ExprProb> generateAll(String startCat) {
return new Generator(this, startCat);
}
/** Normalizes an expression to its normal form by using the 'def'
* rules in the grammar.
*
* @param expr the original expression.
* @return the normalized expression.
*/
public native Expr compute(Expr expr);
/** Takes an expression and returns a refined version
* of the expression together with its type */
public native TypedExpr inferExpr(Expr expr) throws TypeError;
/** Takes an expression and checks it agains a type. The returned expression
* is a possibly refined version of the original. */
public native Expr checkExpr(Expr expr, Type ty) throws TypeError;
public native String graphvizAbstractTree(Expr expr);
//////////////////////////////////////////////////////////////////
// private stuff
private Pool pool;
private long ref;
private PGF(long pool, long ref) {
this.pool = new Pool(pool);
this.ref = ref;
}
static {
System.loadLibrary("jpgf");
}
}
|