001 002 package railo.runtime.sql.old; 003 004 import java.io.DataInputStream; 005 import java.io.FileInputStream; 006 import java.io.FileNotFoundException; 007 import java.io.InputStream; 008 import java.util.Vector; 009 010 // Referenced classes of package Zql: 011 // ZqlJJParser, ParseException, ZUtils, ZStatement, 012 // ZExp 013 014 public final class ZqlParser 015 { 016 017 public static void main(String args[]) 018 throws ParseException 019 { 020 ZqlParser zqlparser = null; 021 if(args.length < 1) 022 { 023 System.out.println("/* Reading from stdin (exit; to finish) */"); 024 zqlparser = new ZqlParser(System.in); 025 } else 026 { 027 try 028 { 029 zqlparser = new ZqlParser(new DataInputStream(new FileInputStream(args[0]))); 030 } 031 catch(FileNotFoundException filenotfoundexception) 032 { 033 System.out.println("/* File " + args[0] + " not found. Reading from stdin */"); 034 zqlparser = new ZqlParser(System.in); 035 } 036 } 037 if(args.length > 0) 038 System.out.println("/* Reading from " + args[0] + "*/"); 039 for(ZStatement zstatement = null; (zstatement = zqlparser.readStatement()) != null;) 040 System.out.println(zstatement.toString() + ";"); 041 042 System.out.println("exit;"); 043 System.out.println("/* Parse Successful */"); 044 } 045 046 public ZqlParser(InputStream inputstream) 047 { 048 _parser = null; 049 initParser(inputstream); 050 } 051 052 public ZqlParser() 053 { 054 _parser = null; 055 } 056 057 public void initParser(InputStream inputstream) 058 { 059 if(_parser == null) 060 _parser = new ZqlJJParser(inputstream); 061 else 062 _parser.ReInit(inputstream); 063 } 064 065 public void addCustomFunction(String s, int i) 066 { 067 ZUtils.addCustomFunction(s, i); 068 } 069 070 public ZStatement readStatement() 071 throws ParseException 072 { 073 if(_parser == null) 074 throw new ParseException("Parser not initialized: use initParser(InputStream);"); 075 return _parser.SQLStatement(); 076 } 077 078 public Vector readStatements() 079 throws ParseException 080 { 081 if(_parser == null) 082 throw new ParseException("Parser not initialized: use initParser(InputStream);"); 083 return _parser.SQLStatements(); 084 } 085 086 public ZExp readExpression() 087 throws ParseException 088 { 089 if(_parser == null) 090 throw new ParseException("Parser not initialized: use initParser(InputStream);"); 091 return _parser.SQLExpression(); 092 } 093 094 ZqlJJParser _parser; 095 }