diff options
Diffstat (limited to 'src/wcps/server/cli/grammar.java')
| -rw-r--r-- | src/wcps/server/cli/grammar.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/wcps/server/cli/grammar.java b/src/wcps/server/cli/grammar.java new file mode 100644 index 0000000..879b814 --- /dev/null +++ b/src/wcps/server/cli/grammar.java @@ -0,0 +1,53 @@ +package wcps.server.cli; + +import grammar.*; +import grammar.wcpsParser.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import org.antlr.runtime.ANTLRInputStream; +import org.antlr.runtime.CommonTokenStream; +import org.antlr.runtime.RecognitionException; + +/** Test the WCPS grammar parser (generated by ANTLR). + * Input a Abstract Syntax query. + * Outputs the corresponding XML tree. + * + * @author Andrei Aiordachioaie + */ +public class grammar { + + static String query; + + public static void main(String[] args) throws RecognitionException, IOException + { + if (args.length != 1) + { + System.err.println("AbstractGrammarGen: no query as parameter !"); + // What is the meaning of AxisIterator variable and axis type? Query 15, 16 + // Query 4: cast should not be this greedy! (float)a + b != (float) (a+b) + query = "for s in ( rgb, rgb, rgb ), r in ( rgb ) return count( ((s.0-s.1)/(s.0+s.1) > 0.6) * r )"; + } + else + query = args[0]; + + System.out.println("Running with the following query: " + query); + + InputStream stream = new ByteArrayInputStream(query.getBytes()); // defaults to ISO-1 + ANTLRInputStream inputStream = new ANTLRInputStream(stream); +// wcpsLexer lexer = new wcpsLexer( inputStream ); + wcpsLexer lexer = new wcpsLexer( inputStream ); + + CommonTokenStream tokenStream = new CommonTokenStream(lexer); +// wcpsParser parser = new wcpsParser(tokenStream); + wcpsParser parser = new wcpsParser(tokenStream); + + wcpsRequest_return rrequest = parser.wcpsRequest(); + WCPSRequest request = rrequest.value; + System.out.println("Output XML: \n****************\n" + request.toXML()); + + System.exit(0); + + } + +} |
