Rcc.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. /* Generated By:JavaCC: Do not edit this line. Rcc.java */
  2. /**
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. package com.yahoo.jute.compiler.generated;
  20. import com.yahoo.jute.compiler.*;
  21. import java.util.ArrayList;
  22. import java.util.Hashtable;
  23. import java.util.Iterator;
  24. import java.io.File;
  25. import java.io.FileReader;
  26. import java.io.FileNotFoundException;
  27. import java.io.IOException;
  28. public class Rcc implements RccConstants {
  29. private static String language = "java";
  30. private static ArrayList recFiles = new ArrayList();
  31. private static JFile curFile;
  32. private static Hashtable recTab;
  33. private static String curDir = System.getProperty("user.dir");
  34. private static String curFileName;
  35. private static String curModuleName;
  36. public static void main(String args[]) {
  37. for (int i=0; i<args.length; i++) {
  38. if ("-l".equalsIgnoreCase(args[i]) ||
  39. "--language".equalsIgnoreCase(args[i])) {
  40. language = args[i+1].toLowerCase();
  41. i++;
  42. } else {
  43. recFiles.add(args[i]);
  44. }
  45. }
  46. if (!"c++".equals(language) && !"java".equals(language) && !"c".equals(language)) {
  47. System.out.println("Cannot recognize language:" + language);
  48. System.exit(1);
  49. }
  50. if (recFiles.size() == 0) {
  51. System.out.println("No record files specified. Exiting.");
  52. System.exit(1);
  53. }
  54. for (int i=0; i<recFiles.size(); i++) {
  55. curFileName = (String) recFiles.get(i);
  56. File file = new File(curDir, curFileName);
  57. try {
  58. FileReader reader = new FileReader(file);
  59. Rcc parser = new Rcc(reader);
  60. try {
  61. recTab = new Hashtable();
  62. curFile = parser.Input();
  63. System.out.println((String) recFiles.get(i) +
  64. " Parsed Successfully");
  65. } catch (ParseException e) {
  66. System.out.println(e.toString());
  67. System.exit(1);
  68. }
  69. try {
  70. reader.close();
  71. } catch (IOException e) {
  72. }
  73. } catch (FileNotFoundException e) {
  74. System.out.println("File " + (String) recFiles.get(i) +
  75. " Not found.");
  76. System.exit(1);
  77. }
  78. try {
  79. curFile.genCode(language);
  80. } catch (IOException e) {
  81. System.out.println(e.toString());
  82. System.exit(1);
  83. }
  84. }
  85. }
  86. final public JFile Input() throws ParseException {
  87. ArrayList ilist = new ArrayList();
  88. ArrayList rlist = new ArrayList();
  89. JFile i;
  90. ArrayList l;
  91. label_1:
  92. while (true) {
  93. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  94. case INCLUDE_TKN:
  95. i = Include();
  96. ilist.add(i);
  97. break;
  98. case MODULE_TKN:
  99. l = Module();
  100. rlist.addAll(l);
  101. break;
  102. default:
  103. jj_la1[0] = jj_gen;
  104. jj_consume_token(-1);
  105. throw new ParseException();
  106. }
  107. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  108. case MODULE_TKN:
  109. case INCLUDE_TKN:
  110. ;
  111. break;
  112. default:
  113. jj_la1[1] = jj_gen;
  114. break label_1;
  115. }
  116. }
  117. jj_consume_token(0);
  118. {if (true) return new JFile(curFileName, ilist, rlist);}
  119. throw new Error("Missing return statement in function");
  120. }
  121. final public JFile Include() throws ParseException {
  122. String fname;
  123. Token t;
  124. jj_consume_token(INCLUDE_TKN);
  125. t = jj_consume_token(CSTRING_TKN);
  126. JFile ret = null;
  127. fname = t.image.replaceAll("^\"", "").replaceAll("\"$","");
  128. File file = new File(curDir, fname);
  129. String tmpDir = curDir;
  130. String tmpFile = curFileName;
  131. curDir = file.getParent();
  132. curFileName = file.getName();
  133. try {
  134. FileReader reader = new FileReader(file);
  135. Rcc parser = new Rcc(reader);
  136. try {
  137. ret = parser.Input();
  138. System.out.println(fname + " Parsed Successfully");
  139. } catch (ParseException e) {
  140. System.out.println(e.toString());
  141. System.exit(1);
  142. }
  143. try {
  144. reader.close();
  145. } catch (IOException e) {
  146. }
  147. } catch (FileNotFoundException e) {
  148. System.out.println("File " + fname +
  149. " Not found.");
  150. System.exit(1);
  151. }
  152. curDir = tmpDir;
  153. curFileName = tmpFile;
  154. {if (true) return ret;}
  155. throw new Error("Missing return statement in function");
  156. }
  157. final public ArrayList Module() throws ParseException {
  158. String mName;
  159. ArrayList rlist;
  160. jj_consume_token(MODULE_TKN);
  161. mName = ModuleName();
  162. curModuleName = mName;
  163. jj_consume_token(LBRACE_TKN);
  164. rlist = RecordList();
  165. jj_consume_token(RBRACE_TKN);
  166. {if (true) return rlist;}
  167. throw new Error("Missing return statement in function");
  168. }
  169. final public String ModuleName() throws ParseException {
  170. String name = "";
  171. Token t;
  172. t = jj_consume_token(IDENT_TKN);
  173. name += t.image;
  174. label_2:
  175. while (true) {
  176. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  177. case DOT_TKN:
  178. ;
  179. break;
  180. default:
  181. jj_la1[2] = jj_gen;
  182. break label_2;
  183. }
  184. jj_consume_token(DOT_TKN);
  185. t = jj_consume_token(IDENT_TKN);
  186. name += "." + t.image;
  187. }
  188. {if (true) return name;}
  189. throw new Error("Missing return statement in function");
  190. }
  191. final public ArrayList RecordList() throws ParseException {
  192. ArrayList rlist = new ArrayList();
  193. JRecord r;
  194. label_3:
  195. while (true) {
  196. r = Record();
  197. rlist.add(r);
  198. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  199. case RECORD_TKN:
  200. ;
  201. break;
  202. default:
  203. jj_la1[3] = jj_gen;
  204. break label_3;
  205. }
  206. }
  207. {if (true) return rlist;}
  208. throw new Error("Missing return statement in function");
  209. }
  210. final public JRecord Record() throws ParseException {
  211. String rname;
  212. ArrayList flist = new ArrayList();
  213. Token t;
  214. JField f;
  215. jj_consume_token(RECORD_TKN);
  216. t = jj_consume_token(IDENT_TKN);
  217. rname = t.image;
  218. jj_consume_token(LBRACE_TKN);
  219. label_4:
  220. while (true) {
  221. f = Field();
  222. flist.add(f);
  223. jj_consume_token(SEMICOLON_TKN);
  224. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  225. case BYTE_TKN:
  226. case BOOLEAN_TKN:
  227. case INT_TKN:
  228. case LONG_TKN:
  229. case FLOAT_TKN:
  230. case DOUBLE_TKN:
  231. case USTRING_TKN:
  232. case BUFFER_TKN:
  233. case VECTOR_TKN:
  234. case MAP_TKN:
  235. case IDENT_TKN:
  236. ;
  237. break;
  238. default:
  239. jj_la1[4] = jj_gen;
  240. break label_4;
  241. }
  242. }
  243. jj_consume_token(RBRACE_TKN);
  244. String fqn = curModuleName + "." + rname;
  245. JRecord r = new JRecord(fqn, flist);
  246. recTab.put(fqn, r);
  247. {if (true) return r;}
  248. throw new Error("Missing return statement in function");
  249. }
  250. final public JField Field() throws ParseException {
  251. JType jt;
  252. Token t;
  253. jt = Type();
  254. t = jj_consume_token(IDENT_TKN);
  255. {if (true) return new JField(jt, t.image);}
  256. throw new Error("Missing return statement in function");
  257. }
  258. final public JType Type() throws ParseException {
  259. JType jt;
  260. Token t;
  261. String rname;
  262. switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
  263. case MAP_TKN:
  264. jt = Map();
  265. {if (true) return jt;}
  266. break;
  267. case VECTOR_TKN:
  268. jt = Vector();
  269. {if (true) return jt;}
  270. break;
  271. case BYTE_TKN:
  272. jj_consume_token(BYTE_TKN);
  273. {if (true) return new JByte();}
  274. break;
  275. case BOOLEAN_TKN:
  276. jj_consume_token(BOOLEAN_TKN);
  277. {if (true) return new JBoolean();}
  278. break;
  279. case INT_TKN:
  280. jj_consume_token(INT_TKN);
  281. {if (true) return new JInt();}
  282. break;
  283. case LONG_TKN:
  284. jj_consume_token(LONG_TKN);
  285. {if (true) return new JLong();}
  286. break;
  287. case FLOAT_TKN:
  288. jj_consume_token(FLOAT_TKN);
  289. {if (true) return new JFloat();}
  290. break;
  291. case DOUBLE_TKN:
  292. jj_consume_token(DOUBLE_TKN);
  293. {if (true) return new JDouble();}
  294. break;
  295. case USTRING_TKN:
  296. jj_consume_token(USTRING_TKN);
  297. {if (true) return new JString();}
  298. break;
  299. case BUFFER_TKN:
  300. jj_consume_token(BUFFER_TKN);
  301. {if (true) return new JBuffer();}
  302. break;
  303. case IDENT_TKN:
  304. rname = ModuleName();
  305. if (rname.indexOf('.', 0) < 0) {
  306. rname = curModuleName + "." + rname;
  307. }
  308. JRecord r = (JRecord) recTab.get(rname);
  309. if (r == null) {
  310. System.out.println("Type " + rname + " not known. Exiting.");
  311. System.exit(1);
  312. }
  313. {if (true) return r;}
  314. break;
  315. default:
  316. jj_la1[5] = jj_gen;
  317. jj_consume_token(-1);
  318. throw new ParseException();
  319. }
  320. throw new Error("Missing return statement in function");
  321. }
  322. final public JMap Map() throws ParseException {
  323. JType jt1;
  324. JType jt2;
  325. jj_consume_token(MAP_TKN);
  326. jj_consume_token(LT_TKN);
  327. jt1 = Type();
  328. jj_consume_token(COMMA_TKN);
  329. jt2 = Type();
  330. jj_consume_token(GT_TKN);
  331. {if (true) return new JMap(jt1, jt2);}
  332. throw new Error("Missing return statement in function");
  333. }
  334. final public JVector Vector() throws ParseException {
  335. JType jt;
  336. jj_consume_token(VECTOR_TKN);
  337. jj_consume_token(LT_TKN);
  338. jt = Type();
  339. jj_consume_token(GT_TKN);
  340. {if (true) return new JVector(jt);}
  341. throw new Error("Missing return statement in function");
  342. }
  343. public RccTokenManager token_source;
  344. SimpleCharStream jj_input_stream;
  345. public Token token, jj_nt;
  346. private int jj_ntk;
  347. private int jj_gen;
  348. final private int[] jj_la1 = new int[6];
  349. static private int[] jj_la1_0;
  350. static private int[] jj_la1_1;
  351. static {
  352. jj_la1_0();
  353. jj_la1_1();
  354. }
  355. private static void jj_la1_0() {
  356. jj_la1_0 = new int[] {0x2800,0x2800,0x40000000,0x1000,0xffc000,0xffc000,};
  357. }
  358. private static void jj_la1_1() {
  359. jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x1,0x1,};
  360. }
  361. public Rcc(java.io.InputStream stream) {
  362. this(stream, null);
  363. }
  364. public Rcc(java.io.InputStream stream, String encoding) {
  365. try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
  366. token_source = new RccTokenManager(jj_input_stream);
  367. token = new Token();
  368. jj_ntk = -1;
  369. jj_gen = 0;
  370. for (int i = 0; i < 6; i++) jj_la1[i] = -1;
  371. }
  372. public void ReInit(java.io.InputStream stream) {
  373. ReInit(stream, null);
  374. }
  375. public void ReInit(java.io.InputStream stream, String encoding) {
  376. try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
  377. token_source.ReInit(jj_input_stream);
  378. token = new Token();
  379. jj_ntk = -1;
  380. jj_gen = 0;
  381. for (int i = 0; i < 6; i++) jj_la1[i] = -1;
  382. }
  383. public Rcc(java.io.Reader stream) {
  384. jj_input_stream = new SimpleCharStream(stream, 1, 1);
  385. token_source = new RccTokenManager(jj_input_stream);
  386. token = new Token();
  387. jj_ntk = -1;
  388. jj_gen = 0;
  389. for (int i = 0; i < 6; i++) jj_la1[i] = -1;
  390. }
  391. public void ReInit(java.io.Reader stream) {
  392. jj_input_stream.ReInit(stream, 1, 1);
  393. token_source.ReInit(jj_input_stream);
  394. token = new Token();
  395. jj_ntk = -1;
  396. jj_gen = 0;
  397. for (int i = 0; i < 6; i++) jj_la1[i] = -1;
  398. }
  399. public Rcc(RccTokenManager tm) {
  400. token_source = tm;
  401. token = new Token();
  402. jj_ntk = -1;
  403. jj_gen = 0;
  404. for (int i = 0; i < 6; i++) jj_la1[i] = -1;
  405. }
  406. public void ReInit(RccTokenManager tm) {
  407. token_source = tm;
  408. token = new Token();
  409. jj_ntk = -1;
  410. jj_gen = 0;
  411. for (int i = 0; i < 6; i++) jj_la1[i] = -1;
  412. }
  413. final private Token jj_consume_token(int kind) throws ParseException {
  414. Token oldToken;
  415. if ((oldToken = token).next != null) token = token.next;
  416. else token = token.next = token_source.getNextToken();
  417. jj_ntk = -1;
  418. if (token.kind == kind) {
  419. jj_gen++;
  420. return token;
  421. }
  422. token = oldToken;
  423. jj_kind = kind;
  424. throw generateParseException();
  425. }
  426. final public Token getNextToken() {
  427. if (token.next != null) token = token.next;
  428. else token = token.next = token_source.getNextToken();
  429. jj_ntk = -1;
  430. jj_gen++;
  431. return token;
  432. }
  433. final public Token getToken(int index) {
  434. Token t = token;
  435. for (int i = 0; i < index; i++) {
  436. if (t.next != null) t = t.next;
  437. else t = t.next = token_source.getNextToken();
  438. }
  439. return t;
  440. }
  441. final private int jj_ntk() {
  442. if ((jj_nt=token.next) == null)
  443. return (jj_ntk = (token.next=token_source.getNextToken()).kind);
  444. else
  445. return (jj_ntk = jj_nt.kind);
  446. }
  447. private java.util.Vector jj_expentries = new java.util.Vector();
  448. private int[] jj_expentry;
  449. private int jj_kind = -1;
  450. public ParseException generateParseException() {
  451. jj_expentries.removeAllElements();
  452. boolean[] la1tokens = new boolean[33];
  453. for (int i = 0; i < 33; i++) {
  454. la1tokens[i] = false;
  455. }
  456. if (jj_kind >= 0) {
  457. la1tokens[jj_kind] = true;
  458. jj_kind = -1;
  459. }
  460. for (int i = 0; i < 6; i++) {
  461. if (jj_la1[i] == jj_gen) {
  462. for (int j = 0; j < 32; j++) {
  463. if ((jj_la1_0[i] & (1<<j)) != 0) {
  464. la1tokens[j] = true;
  465. }
  466. if ((jj_la1_1[i] & (1<<j)) != 0) {
  467. la1tokens[32+j] = true;
  468. }
  469. }
  470. }
  471. }
  472. for (int i = 0; i < 33; i++) {
  473. if (la1tokens[i]) {
  474. jj_expentry = new int[1];
  475. jj_expentry[0] = i;
  476. jj_expentries.addElement(jj_expentry);
  477. }
  478. }
  479. int[][] exptokseq = new int[jj_expentries.size()][];
  480. for (int i = 0; i < jj_expentries.size(); i++) {
  481. exptokseq[i] = (int[])jj_expentries.elementAt(i);
  482. }
  483. return new ParseException(token, exptokseq, tokenImage);
  484. }
  485. final public void enable_tracing() {
  486. }
  487. final public void disable_tracing() {
  488. }
  489. }