diff options
| author | Andrei Aiordachioaie <a.aiordachioaie@jacobs-university.de> | 2009-06-08 17:49:13 +0200 |
|---|---|---|
| committer | Andrei Aiordachioaie <a.aiordachioaie@jacobs-university.de> | 2009-07-07 10:55:14 +0200 |
| commit | d2b0e006273d55c170ed6cd56f9509bc1eaa90eb (patch) | |
| tree | b778bcbf3211d2ff5d5a0dee8daaad480095aa8c /src/wcps/server/cli/f_grammar.java | |
| parent | e60efdbfb39124b6a36465e17fe2ad349580c18b (diff) | |
Implemented Condense Expression and Constant Coverage Expression. WCPS Grammar modified
Diffstat (limited to 'src/wcps/server/cli/f_grammar.java')
| -rw-r--r-- | src/wcps/server/cli/f_grammar.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/wcps/server/cli/f_grammar.java b/src/wcps/server/cli/f_grammar.java new file mode 100644 index 0000000..6468767 --- /dev/null +++ b/src/wcps/server/cli/f_grammar.java @@ -0,0 +1,66 @@ +package wcps.server.cli; + +import grammar.*; +import grammar.wcpsParser.*; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import org.antlr.runtime.ANTLRInputStream; +import org.antlr.runtime.CommonTokenStream; +import org.antlr.runtime.RecognitionException; +import org.apache.commons.io.FileUtils; + +/** Test the WCPS grammar parser (generated by ANTLR). + * Input the path that contains an Abstract Syntax query. + * Outputs the corresponding XML tree. + * + * @author Andrei Aiordachioaie + */ +public class f_grammar { + + private static String query; + private static String path; + + public static void main(String[] args) throws RecognitionException, IOException + { + if (args.length != 1) + { + System.err.println("AbstractGrammarGen: no parameter to specify input file !"); + path = "test/test-tmp/29.test"; + query = FileUtils.readFileToString(new File(path)); + } + else + { + path = args[0]; + query = FileUtils.readFileToString(new File(path)); + } + + System.out.println("Running with the following query: " + query); + + String xmlString = runQuery(query); + System.out.println("Output XML: \n****************\n" + xmlString); + + System.exit(0); + + } + + public static String runQuery(String query) throws IOException, RecognitionException + { + 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; + + String result = request.toXML(); + return result; + } + +} |
