PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/antlr-2.7.5/examples/java/pascal/SymtabPhase.java

https://github.com/boo/boo-lang
Java | 3444 lines | 3165 code | 268 blank | 11 comment | 261 complexity | 226618818a4452794493c5101c0be2c4 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. // $ANTLR 2.7.2: "expandedsymtab.g" -> "SymtabPhase.java"$
  2. import antlr.TreeParser;
  3. import antlr.Token;
  4. import antlr.collections.AST;
  5. import antlr.RecognitionException;
  6. import antlr.ANTLRException;
  7. import antlr.NoViableAltException;
  8. import antlr.MismatchedTokenException;
  9. import antlr.SemanticException;
  10. import antlr.collections.impl.BitSet;
  11. import antlr.ASTPair;
  12. import antlr.collections.impl.ASTArray;
  13. import java.util.*;
  14. import java.io.*;
  15. public class SymtabPhase extends antlr.TreeParser implements SymtabPhaseTokenTypes
  16. {
  17. Stack scopes = new Stack();
  18. Stack usesScopes = new Stack();
  19. //public static File thisUnit;
  20. public File thisUnit;
  21. public SymtabPhase() {
  22. tokenNames = _tokenNames;
  23. }
  24. public final void program(AST _t) throws RecognitionException {
  25. PascalAST program_AST_in = (PascalAST)_t;
  26. try { // for error handling
  27. programHeading(_t);
  28. _t = _retTree;
  29. block(_t);
  30. _t = _retTree;
  31. System.out.println(scopes.peek());
  32. }
  33. catch (RecognitionException ex) {
  34. reportError(ex);
  35. if (_t!=null) {_t = _t.getNextSibling();}
  36. }
  37. _retTree = _t;
  38. }
  39. public final void programHeading(AST _t) throws RecognitionException {
  40. PascalAST programHeading_AST_in = (PascalAST)_t;
  41. try { // for error handling
  42. if (_t==null) _t=ASTNULL;
  43. switch ( _t.getType()) {
  44. case PROGRAM:
  45. {
  46. AST __t3 = _t;
  47. PascalAST tmp1_AST_in = (PascalAST)_t;
  48. match(_t,PROGRAM);
  49. _t = _t.getFirstChild();
  50. PascalAST tmp2_AST_in = (PascalAST)_t;
  51. match(_t,IDENT);
  52. _t = _t.getNextSibling();
  53. identifierList(_t);
  54. _t = _retTree;
  55. _t = __t3;
  56. _t = _t.getNextSibling();
  57. Scope root = new Scope(null);
  58. scopes.push(root);
  59. break;
  60. }
  61. case UNIT:
  62. {
  63. AST __t4 = _t;
  64. PascalAST tmp3_AST_in = (PascalAST)_t;
  65. match(_t,UNIT);
  66. _t = _t.getFirstChild();
  67. PascalAST tmp4_AST_in = (PascalAST)_t;
  68. match(_t,IDENT);
  69. _t = _t.getNextSibling();
  70. _t = __t4;
  71. _t = _t.getNextSibling();
  72. Scope root = new Scope(null); // create new scope
  73. scopes.push(root); // enter new scope :)
  74. root.addSymbol(new Unit(tmp4_AST_in.getText())); // create unit symbol entry
  75. String tUnit = new String (tmp4_AST_in.getText());
  76. tUnit = tUnit.concat(".sym");
  77. thisUnit = new File (PascalParser.translateFilePath, tUnit);
  78. break;
  79. }
  80. default:
  81. {
  82. throw new NoViableAltException(_t);
  83. }
  84. }
  85. }
  86. catch (RecognitionException ex) {
  87. reportError(ex);
  88. if (_t!=null) {_t = _t.getNextSibling();}
  89. }
  90. _retTree = _t;
  91. }
  92. public final void block(AST _t) throws RecognitionException {
  93. PascalAST block_AST_in = (PascalAST)_t;
  94. try { // for error handling
  95. {
  96. _loop7:
  97. do {
  98. if (_t==null) _t=ASTNULL;
  99. switch ( _t.getType()) {
  100. case LABEL:
  101. {
  102. labelDeclarationPart(_t);
  103. _t = _retTree;
  104. break;
  105. }
  106. case CONST:
  107. {
  108. constantDefinitionPart(_t);
  109. _t = _retTree;
  110. break;
  111. }
  112. case TYPE:
  113. {
  114. typeDefinitionPart(_t);
  115. _t = _retTree;
  116. break;
  117. }
  118. case VAR:
  119. {
  120. variableDeclarationPart(_t);
  121. _t = _retTree;
  122. break;
  123. }
  124. case FUNCTION:
  125. case PROCEDURE:
  126. {
  127. procedureAndFunctionDeclarationPart(_t);
  128. _t = _retTree;
  129. break;
  130. }
  131. case USES:
  132. {
  133. usesUnitsPart(_t);
  134. _t = _retTree;
  135. break;
  136. }
  137. case IMPLEMENTATION:
  138. {
  139. PascalAST tmp5_AST_in = (PascalAST)_t;
  140. match(_t,IMPLEMENTATION);
  141. _t = _t.getNextSibling();
  142. System.out.println(scopes.peek());
  143. //write symbol table and exit when currentFileName != translateFileName
  144. if (PascalParser.currentFileName.compareTo(PascalParser.translateFileName) != 0) {
  145. try{
  146. ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(thisUnit));
  147. oos.writeObject(scopes);
  148. oos.close();
  149. }
  150. catch (IOException e) {
  151. System.err.println("IOexception: "+e); }
  152. _t = null;
  153. throw new RecognitionException();
  154. }
  155. break;
  156. }
  157. default:
  158. {
  159. break _loop7;
  160. }
  161. }
  162. } while (true);
  163. }
  164. compoundStatement(_t);
  165. _t = _retTree;
  166. }
  167. catch (RecognitionException ex) {
  168. reportError(ex);
  169. if (_t!=null) {_t = _t.getNextSibling();}
  170. }
  171. _retTree = _t;
  172. }
  173. public final Vector identifierList(AST _t) throws RecognitionException {
  174. Vector ids=new Vector();
  175. PascalAST identifierList_AST_in = (PascalAST)_t;
  176. try { // for error handling
  177. AST __t38 = _t;
  178. PascalAST tmp6_AST_in = (PascalAST)_t;
  179. match(_t,IDLIST);
  180. _t = _t.getFirstChild();
  181. {
  182. int _cnt40=0;
  183. _loop40:
  184. do {
  185. if (_t==null) _t=ASTNULL;
  186. if ((_t.getType()==IDENT)) {
  187. PascalAST tmp7_AST_in = (PascalAST)_t;
  188. match(_t,IDENT);
  189. _t = _t.getNextSibling();
  190. ids.addElement(tmp7_AST_in.getText());
  191. }
  192. else {
  193. if ( _cnt40>=1 ) { break _loop40; } else {throw new NoViableAltException(_t);}
  194. }
  195. _cnt40++;
  196. } while (true);
  197. }
  198. _t = __t38;
  199. _t = _t.getNextSibling();
  200. }
  201. catch (RecognitionException ex) {
  202. reportError(ex);
  203. if (_t!=null) {_t = _t.getNextSibling();}
  204. }
  205. _retTree = _t;
  206. return ids;
  207. }
  208. public final void labelDeclarationPart(AST _t) throws RecognitionException {
  209. PascalAST labelDeclarationPart_AST_in = (PascalAST)_t;
  210. try { // for error handling
  211. AST __t47 = _t;
  212. PascalAST tmp8_AST_in = (PascalAST)_t;
  213. match(_t,LABEL);
  214. _t = _t.getFirstChild();
  215. {
  216. int _cnt49=0;
  217. _loop49:
  218. do {
  219. if (_t==null) _t=ASTNULL;
  220. if ((_t.getType()==NUM_INT)) {
  221. label(_t);
  222. _t = _retTree;
  223. }
  224. else {
  225. if ( _cnt49>=1 ) { break _loop49; } else {throw new NoViableAltException(_t);}
  226. }
  227. _cnt49++;
  228. } while (true);
  229. }
  230. _t = __t47;
  231. _t = _t.getNextSibling();
  232. }
  233. catch (RecognitionException ex) {
  234. reportError(ex);
  235. if (_t!=null) {_t = _t.getNextSibling();}
  236. }
  237. _retTree = _t;
  238. }
  239. public final void constantDefinitionPart(AST _t) throws RecognitionException {
  240. PascalAST constantDefinitionPart_AST_in = (PascalAST)_t;
  241. try { // for error handling
  242. AST __t52 = _t;
  243. PascalAST tmp9_AST_in = (PascalAST)_t;
  244. match(_t,CONST);
  245. _t = _t.getFirstChild();
  246. {
  247. int _cnt54=0;
  248. _loop54:
  249. do {
  250. if (_t==null) _t=ASTNULL;
  251. if ((_t.getType()==EQUAL)) {
  252. constantDefinition(_t);
  253. _t = _retTree;
  254. }
  255. else {
  256. if ( _cnt54>=1 ) { break _loop54; } else {throw new NoViableAltException(_t);}
  257. }
  258. _cnt54++;
  259. } while (true);
  260. }
  261. _t = __t52;
  262. _t = _t.getNextSibling();
  263. }
  264. catch (RecognitionException ex) {
  265. reportError(ex);
  266. if (_t!=null) {_t = _t.getNextSibling();}
  267. }
  268. _retTree = _t;
  269. }
  270. public final void typeDefinitionPart(AST _t) throws RecognitionException {
  271. PascalAST typeDefinitionPart_AST_in = (PascalAST)_t;
  272. try { // for error handling
  273. AST __t57 = _t;
  274. PascalAST tmp10_AST_in = (PascalAST)_t;
  275. match(_t,TYPE);
  276. _t = _t.getFirstChild();
  277. {
  278. int _cnt59=0;
  279. _loop59:
  280. do {
  281. if (_t==null) _t=ASTNULL;
  282. if ((_t.getType()==TYPEDECL)) {
  283. typeDefinition(_t);
  284. _t = _retTree;
  285. }
  286. else {
  287. if ( _cnt59>=1 ) { break _loop59; } else {throw new NoViableAltException(_t);}
  288. }
  289. _cnt59++;
  290. } while (true);
  291. }
  292. _t = __t57;
  293. _t = _t.getNextSibling();
  294. }
  295. catch (RecognitionException ex) {
  296. reportError(ex);
  297. if (_t!=null) {_t = _t.getNextSibling();}
  298. }
  299. _retTree = _t;
  300. }
  301. public final void variableDeclarationPart(AST _t) throws RecognitionException {
  302. PascalAST variableDeclarationPart_AST_in = (PascalAST)_t;
  303. try { // for error handling
  304. AST __t95 = _t;
  305. PascalAST tmp11_AST_in = (PascalAST)_t;
  306. match(_t,VAR);
  307. _t = _t.getFirstChild();
  308. {
  309. int _cnt97=0;
  310. _loop97:
  311. do {
  312. if (_t==null) _t=ASTNULL;
  313. if ((_t.getType()==VARDECL)) {
  314. variableDeclaration(_t);
  315. _t = _retTree;
  316. }
  317. else {
  318. if ( _cnt97>=1 ) { break _loop97; } else {throw new NoViableAltException(_t);}
  319. }
  320. _cnt97++;
  321. } while (true);
  322. }
  323. _t = __t95;
  324. _t = _t.getNextSibling();
  325. }
  326. catch (RecognitionException ex) {
  327. reportError(ex);
  328. if (_t!=null) {_t = _t.getNextSibling();}
  329. }
  330. _retTree = _t;
  331. }
  332. public final void procedureAndFunctionDeclarationPart(AST _t) throws RecognitionException {
  333. PascalAST procedureAndFunctionDeclarationPart_AST_in = (PascalAST)_t;
  334. try { // for error handling
  335. procedureOrFunctionDeclaration(_t);
  336. _t = _retTree;
  337. }
  338. catch (RecognitionException ex) {
  339. reportError(ex);
  340. if (_t!=null) {_t = _t.getNextSibling();}
  341. }
  342. _retTree = _t;
  343. }
  344. public final void usesUnitsPart(AST _t) throws RecognitionException {
  345. PascalAST usesUnitsPart_AST_in = (PascalAST)_t;
  346. PascalAST usesList = null;
  347. String usesFile, usesSymtab;
  348. String oldUsesFile;
  349. File f, symFile;
  350. Object readSymtab = new Stack();
  351. try { // for error handling
  352. AST __t9 = _t;
  353. PascalAST tmp12_AST_in = (PascalAST)_t;
  354. match(_t,USES);
  355. _t = _t.getFirstChild();
  356. usesList = _t==ASTNULL ? null : (PascalAST)_t;
  357. identifierList(_t);
  358. _t = _retTree;
  359. _t = __t9;
  360. _t = _t.getNextSibling();
  361. usesList = (PascalAST) usesList.getFirstChild();
  362. oldUsesFile = PascalParser.currentFileName;
  363. while (usesList !=null) {
  364. // make symboltable for usesFile
  365. usesFile = usesList.getText();
  366. usesFile = usesFile.concat(".pas");
  367. usesSymtab = usesList.getText();
  368. usesSymtab = usesSymtab.concat(".sym");
  369. f = new File(PascalParser.translateFilePath,usesFile);
  370. symFile = new File(PascalParser.translateFilePath,usesSymtab);
  371. // we have to build the symbol table when ...
  372. if (( !(symFile.exists() ) )
  373. // this .sym file (usesSymtyb) does not exist or ...
  374. || ((f.lastModified()) > (symFile.lastModified()) ) ){
  375. // the date of this .sym file (usesSymtyb) is older than the .pas file (usesFile)
  376. try {
  377. PascalParser.parseFile(f.getName(),new FileInputStream(f));
  378. }
  379. catch (Exception e) {
  380. System.err.println("parser exception: "+e);
  381. e.printStackTrace(); // so we can get stack trace
  382. }
  383. }
  384. // read serialized symbol table and add to symbol table "usesScopes"
  385. File symTab = new File (PascalParser.translateFilePath , usesSymtab);
  386. try {
  387. ObjectInputStream ois = new ObjectInputStream(new FileInputStream(symTab));
  388. readSymtab = ois.readObject();
  389. ois.close();
  390. }
  391. catch (ClassNotFoundException cnfe) {
  392. System.err.println("parser exception: "+cnfe);
  393. cnfe.printStackTrace(); // so we can get stack trace
  394. }
  395. catch (FileNotFoundException e) {
  396. System.err.println("parser exception: "+e);
  397. e.printStackTrace(); // so we can get stack trace
  398. }
  399. catch (IOException e) {
  400. System.err.println("parser exception: "+e);
  401. e.printStackTrace(); // so we can get stack trace
  402. }
  403. Stack symTabToPop = (Stack) readSymtab;
  404. // add uses symbol table "readSymtab" to symboltable "usesScopes"
  405. while (!(symTabToPop.empty())) {
  406. usesScopes.push(symTabToPop.pop());
  407. }
  408. usesList = (PascalAST) usesList.getNextSibling();
  409. }
  410. PascalParser.currentFileName = oldUsesFile;
  411. }
  412. catch (RecognitionException ex) {
  413. reportError(ex);
  414. if (_t!=null) {_t = _t.getNextSibling();}
  415. }
  416. _retTree = _t;
  417. }
  418. public final void compoundStatement(AST _t) throws RecognitionException {
  419. PascalAST compoundStatement_AST_in = (PascalAST)_t;
  420. try { // for error handling
  421. statements(_t);
  422. _t = _retTree;
  423. }
  424. catch (RecognitionException ex) {
  425. reportError(ex);
  426. if (_t!=null) {_t = _t.getNextSibling();}
  427. }
  428. _retTree = _t;
  429. }
  430. public final void constantDefinition(AST _t) throws RecognitionException {
  431. PascalAST constantDefinition_AST_in = (PascalAST)_t;
  432. PascalAST r = null;
  433. Constant c = null;
  434. try { // for error handling
  435. AST __t11 = _t;
  436. r = _t==ASTNULL ? null :(PascalAST)_t;
  437. match(_t,EQUAL);
  438. _t = _t.getFirstChild();
  439. PascalAST tmp13_AST_in = (PascalAST)_t;
  440. match(_t,IDENT);
  441. _t = _t.getNextSibling();
  442. c=constant(_t);
  443. _t = _retTree;
  444. _t = __t11;
  445. _t = _t.getNextSibling();
  446. if ( c!=null ) {
  447. Scope sc = (Scope)scopes.peek();
  448. c.setName(tmp13_AST_in.getText());
  449. sc.addSymbol(c);
  450. r.symbol = c; // AST def root points to symbol table entry now
  451. }
  452. }
  453. catch (RecognitionException ex) {
  454. reportError(ex);
  455. if (_t!=null) {_t = _t.getNextSibling();}
  456. }
  457. _retTree = _t;
  458. }
  459. public final Constant constant(AST _t) throws RecognitionException {
  460. Constant c=null;
  461. PascalAST constant_AST_in = (PascalAST)_t;
  462. try { // for error handling
  463. if (_t==null) _t=ASTNULL;
  464. switch ( _t.getType()) {
  465. case NUM_INT:
  466. {
  467. PascalAST tmp14_AST_in = (PascalAST)_t;
  468. match(_t,NUM_INT);
  469. _t = _t.getNextSibling();
  470. c = new IntegerConstant(tmp14_AST_in.getText());
  471. break;
  472. }
  473. case NUM_REAL:
  474. {
  475. PascalAST tmp15_AST_in = (PascalAST)_t;
  476. match(_t,NUM_REAL);
  477. _t = _t.getNextSibling();
  478. c = new RealConstant(tmp15_AST_in.getText());
  479. break;
  480. }
  481. case PLUS:
  482. {
  483. AST __t13 = _t;
  484. PascalAST tmp16_AST_in = (PascalAST)_t;
  485. match(_t,PLUS);
  486. _t = _t.getFirstChild();
  487. {
  488. if (_t==null) _t=ASTNULL;
  489. switch ( _t.getType()) {
  490. case NUM_INT:
  491. {
  492. PascalAST tmp17_AST_in = (PascalAST)_t;
  493. match(_t,NUM_INT);
  494. _t = _t.getNextSibling();
  495. c = new IntegerConstant(tmp17_AST_in.getText());
  496. break;
  497. }
  498. case NUM_REAL:
  499. {
  500. PascalAST tmp18_AST_in = (PascalAST)_t;
  501. match(_t,NUM_REAL);
  502. _t = _t.getNextSibling();
  503. c = new RealConstant(tmp18_AST_in.getText());
  504. break;
  505. }
  506. case IDENT:
  507. {
  508. PascalAST tmp19_AST_in = (PascalAST)_t;
  509. match(_t,IDENT);
  510. _t = _t.getNextSibling();
  511. break;
  512. }
  513. default:
  514. {
  515. throw new NoViableAltException(_t);
  516. }
  517. }
  518. }
  519. _t = __t13;
  520. _t = _t.getNextSibling();
  521. break;
  522. }
  523. case MINUS:
  524. {
  525. AST __t15 = _t;
  526. PascalAST tmp20_AST_in = (PascalAST)_t;
  527. match(_t,MINUS);
  528. _t = _t.getFirstChild();
  529. {
  530. if (_t==null) _t=ASTNULL;
  531. switch ( _t.getType()) {
  532. case NUM_INT:
  533. {
  534. PascalAST tmp21_AST_in = (PascalAST)_t;
  535. match(_t,NUM_INT);
  536. _t = _t.getNextSibling();
  537. c = new IntegerConstant(tmp21_AST_in.getText());
  538. break;
  539. }
  540. case NUM_REAL:
  541. {
  542. PascalAST tmp22_AST_in = (PascalAST)_t;
  543. match(_t,NUM_REAL);
  544. _t = _t.getNextSibling();
  545. c = new RealConstant(tmp22_AST_in.getText());
  546. break;
  547. }
  548. case IDENT:
  549. {
  550. PascalAST tmp23_AST_in = (PascalAST)_t;
  551. match(_t,IDENT);
  552. _t = _t.getNextSibling();
  553. break;
  554. }
  555. default:
  556. {
  557. throw new NoViableAltException(_t);
  558. }
  559. }
  560. }
  561. _t = __t15;
  562. _t = _t.getNextSibling();
  563. break;
  564. }
  565. case IDENT:
  566. {
  567. PascalAST tmp24_AST_in = (PascalAST)_t;
  568. match(_t,IDENT);
  569. _t = _t.getNextSibling();
  570. break;
  571. }
  572. case STRING_LITERAL:
  573. {
  574. PascalAST tmp25_AST_in = (PascalAST)_t;
  575. match(_t,STRING_LITERAL);
  576. _t = _t.getNextSibling();
  577. break;
  578. }
  579. case CHR:
  580. {
  581. AST __t17 = _t;
  582. PascalAST tmp26_AST_in = (PascalAST)_t;
  583. match(_t,CHR);
  584. _t = _t.getFirstChild();
  585. {
  586. if (_t==null) _t=ASTNULL;
  587. switch ( _t.getType()) {
  588. case NUM_INT:
  589. {
  590. PascalAST tmp27_AST_in = (PascalAST)_t;
  591. match(_t,NUM_INT);
  592. _t = _t.getNextSibling();
  593. break;
  594. }
  595. case NUM_REAL:
  596. {
  597. PascalAST tmp28_AST_in = (PascalAST)_t;
  598. match(_t,NUM_REAL);
  599. _t = _t.getNextSibling();
  600. break;
  601. }
  602. default:
  603. {
  604. throw new NoViableAltException(_t);
  605. }
  606. }
  607. }
  608. _t = __t17;
  609. _t = _t.getNextSibling();
  610. break;
  611. }
  612. default:
  613. {
  614. throw new NoViableAltException(_t);
  615. }
  616. }
  617. }
  618. catch (RecognitionException ex) {
  619. reportError(ex);
  620. if (_t!=null) {_t = _t.getNextSibling();}
  621. }
  622. _retTree = _t;
  623. return c;
  624. }
  625. public final void typeDefinition(AST _t) throws RecognitionException {
  626. PascalAST typeDefinition_AST_in = (PascalAST)_t;
  627. PascalAST r = null;
  628. TypeSpecifier t=null;
  629. try { // for error handling
  630. AST __t20 = _t;
  631. PascalAST tmp29_AST_in = (PascalAST)_t;
  632. match(_t,TYPEDECL);
  633. _t = _t.getFirstChild();
  634. PascalAST tmp30_AST_in = (PascalAST)_t;
  635. match(_t,IDENT);
  636. _t = _t.getNextSibling();
  637. {
  638. if (_t==null) _t=ASTNULL;
  639. switch ( _t.getType()) {
  640. case SCALARTYPE:
  641. case IDENT:
  642. case DOTDOT:
  643. case CHAR:
  644. case BOOLEAN:
  645. case INTEGER:
  646. case REAL:
  647. case STRING:
  648. case PACKED:
  649. case ARRAY:
  650. case RECORD:
  651. case SET:
  652. case FILE:
  653. case POINTER:
  654. {
  655. type(_t);
  656. _t = _retTree;
  657. break;
  658. }
  659. case FUNCTION:
  660. {
  661. AST __t22 = _t;
  662. r = _t==ASTNULL ? null :(PascalAST)_t;
  663. match(_t,FUNCTION);
  664. _t = _t.getFirstChild();
  665. {
  666. if (_t==null) _t=ASTNULL;
  667. switch ( _t.getType()) {
  668. case ARGDECLS:
  669. {
  670. formalParameterList(_t);
  671. _t = _retTree;
  672. break;
  673. }
  674. case IDENT:
  675. case CHAR:
  676. case BOOLEAN:
  677. case INTEGER:
  678. case REAL:
  679. case STRING:
  680. {
  681. break;
  682. }
  683. default:
  684. {
  685. throw new NoViableAltException(_t);
  686. }
  687. }
  688. }
  689. t=resultType(_t);
  690. _t = _retTree;
  691. _t = __t22;
  692. _t = _t.getNextSibling();
  693. if ( t!=null ) {r.symbol = t;}
  694. break;
  695. }
  696. case PROCEDURE:
  697. {
  698. AST __t24 = _t;
  699. PascalAST tmp31_AST_in = (PascalAST)_t;
  700. match(_t,PROCEDURE);
  701. _t = _t.getFirstChild();
  702. {
  703. if (_t==null) _t=ASTNULL;
  704. switch ( _t.getType()) {
  705. case ARGDECLS:
  706. {
  707. formalParameterList(_t);
  708. _t = _retTree;
  709. break;
  710. }
  711. case 3:
  712. {
  713. break;
  714. }
  715. default:
  716. {
  717. throw new NoViableAltException(_t);
  718. }
  719. }
  720. }
  721. _t = __t24;
  722. _t = _t.getNextSibling();
  723. break;
  724. }
  725. default:
  726. {
  727. throw new NoViableAltException(_t);
  728. }
  729. }
  730. }
  731. _t = __t20;
  732. _t = _t.getNextSibling();
  733. }
  734. catch (RecognitionException ex) {
  735. reportError(ex);
  736. if (_t!=null) {_t = _t.getNextSibling();}
  737. }
  738. _retTree = _t;
  739. }
  740. public final TypeSpecifier type(AST _t) throws RecognitionException {
  741. TypeSpecifier ts=null;
  742. PascalAST type_AST_in = (PascalAST)_t;
  743. try { // for error handling
  744. if (_t==null) _t=ASTNULL;
  745. switch ( _t.getType()) {
  746. case SCALARTYPE:
  747. {
  748. AST __t27 = _t;
  749. PascalAST tmp32_AST_in = (PascalAST)_t;
  750. match(_t,SCALARTYPE);
  751. _t = _t.getFirstChild();
  752. identifierList(_t);
  753. _t = _retTree;
  754. _t = __t27;
  755. _t = _t.getNextSibling();
  756. break;
  757. }
  758. case DOTDOT:
  759. {
  760. AST __t28 = _t;
  761. PascalAST tmp33_AST_in = (PascalAST)_t;
  762. match(_t,DOTDOT);
  763. _t = _t.getFirstChild();
  764. constant(_t);
  765. _t = _retTree;
  766. constant(_t);
  767. _t = _retTree;
  768. _t = __t28;
  769. _t = _t.getNextSibling();
  770. break;
  771. }
  772. case IDENT:
  773. case CHAR:
  774. case BOOLEAN:
  775. case INTEGER:
  776. case REAL:
  777. case STRING:
  778. {
  779. ts=typeIdentifier(_t);
  780. _t = _retTree;
  781. break;
  782. }
  783. case PACKED:
  784. case ARRAY:
  785. case RECORD:
  786. case SET:
  787. case FILE:
  788. {
  789. structuredType(_t);
  790. _t = _retTree;
  791. break;
  792. }
  793. case POINTER:
  794. {
  795. AST __t29 = _t;
  796. PascalAST tmp34_AST_in = (PascalAST)_t;
  797. match(_t,POINTER);
  798. _t = _t.getFirstChild();
  799. typeIdentifier(_t);
  800. _t = _retTree;
  801. _t = __t29;
  802. _t = _t.getNextSibling();
  803. break;
  804. }
  805. default:
  806. {
  807. throw new NoViableAltException(_t);
  808. }
  809. }
  810. }
  811. catch (RecognitionException ex) {
  812. reportError(ex);
  813. if (_t!=null) {_t = _t.getNextSibling();}
  814. }
  815. _retTree = _t;
  816. return ts;
  817. }
  818. public final void formalParameterList(AST _t) throws RecognitionException {
  819. PascalAST formalParameterList_AST_in = (PascalAST)_t;
  820. try { // for error handling
  821. AST __t104 = _t;
  822. PascalAST tmp35_AST_in = (PascalAST)_t;
  823. match(_t,ARGDECLS);
  824. _t = _t.getFirstChild();
  825. {
  826. int _cnt106=0;
  827. _loop106:
  828. do {
  829. if (_t==null) _t=ASTNULL;
  830. if ((_tokenSet_0.member(_t.getType()))) {
  831. formalParameterSection(_t);
  832. _t = _retTree;
  833. }
  834. else {
  835. if ( _cnt106>=1 ) { break _loop106; } else {throw new NoViableAltException(_t);}
  836. }
  837. _cnt106++;
  838. } while (true);
  839. }
  840. _t = __t104;
  841. _t = _t.getNextSibling();
  842. }
  843. catch (RecognitionException ex) {
  844. reportError(ex);
  845. if (_t!=null) {_t = _t.getNextSibling();}
  846. }
  847. _retTree = _t;
  848. }
  849. public final TypeSpecifier resultType(AST _t) throws RecognitionException {
  850. TypeSpecifier ts=null;
  851. PascalAST resultType_AST_in = (PascalAST)_t;
  852. try { // for error handling
  853. ts=typeIdentifier(_t);
  854. _t = _retTree;
  855. }
  856. catch (RecognitionException ex) {
  857. reportError(ex);
  858. if (_t!=null) {_t = _t.getNextSibling();}
  859. }
  860. _retTree = _t;
  861. return ts;
  862. }
  863. public final TypeSpecifier typeIdentifier(AST _t) throws RecognitionException {
  864. TypeSpecifier ts=null;
  865. PascalAST typeIdentifier_AST_in = (PascalAST)_t;
  866. try { // for error handling
  867. if (_t==null) _t=ASTNULL;
  868. switch ( _t.getType()) {
  869. case IDENT:
  870. {
  871. PascalAST tmp36_AST_in = (PascalAST)_t;
  872. match(_t,IDENT);
  873. _t = _t.getNextSibling();
  874. break;
  875. }
  876. case CHAR:
  877. {
  878. PascalAST tmp37_AST_in = (PascalAST)_t;
  879. match(_t,CHAR);
  880. _t = _t.getNextSibling();
  881. break;
  882. }
  883. case BOOLEAN:
  884. {
  885. PascalAST tmp38_AST_in = (PascalAST)_t;
  886. match(_t,BOOLEAN);
  887. _t = _t.getNextSibling();
  888. break;
  889. }
  890. case INTEGER:
  891. {
  892. PascalAST tmp39_AST_in = (PascalAST)_t;
  893. match(_t,INTEGER);
  894. _t = _t.getNextSibling();
  895. ts=PascalParser.symbolTable.getPredefinedType("integer");
  896. break;
  897. }
  898. case REAL:
  899. {
  900. PascalAST tmp40_AST_in = (PascalAST)_t;
  901. match(_t,REAL);
  902. _t = _t.getNextSibling();
  903. ts=PascalParser.symbolTable.getPredefinedType("real");
  904. break;
  905. }
  906. case STRING:
  907. {
  908. AST __t31 = _t;
  909. PascalAST tmp41_AST_in = (PascalAST)_t;
  910. match(_t,STRING);
  911. _t = _t.getFirstChild();
  912. {
  913. if (_t==null) _t=ASTNULL;
  914. switch ( _t.getType()) {
  915. case IDENT:
  916. {
  917. PascalAST tmp42_AST_in = (PascalAST)_t;
  918. match(_t,IDENT);
  919. _t = _t.getNextSibling();
  920. break;
  921. }
  922. case NUM_INT:
  923. {
  924. PascalAST tmp43_AST_in = (PascalAST)_t;
  925. match(_t,NUM_INT);
  926. _t = _t.getNextSibling();
  927. break;
  928. }
  929. case NUM_REAL:
  930. {
  931. PascalAST tmp44_AST_in = (PascalAST)_t;
  932. match(_t,NUM_REAL);
  933. _t = _t.getNextSibling();
  934. break;
  935. }
  936. case 3:
  937. {
  938. break;
  939. }
  940. default:
  941. {
  942. throw new NoViableAltException(_t);
  943. }
  944. }
  945. }
  946. _t = __t31;
  947. _t = _t.getNextSibling();
  948. break;
  949. }
  950. default:
  951. {
  952. throw new NoViableAltException(_t);
  953. }
  954. }
  955. }
  956. catch (RecognitionException ex) {
  957. reportError(ex);
  958. if (_t!=null) {_t = _t.getNextSibling();}
  959. }
  960. _retTree = _t;
  961. return ts;
  962. }
  963. public final void structuredType(AST _t) throws RecognitionException {
  964. PascalAST structuredType_AST_in = (PascalAST)_t;
  965. try { // for error handling
  966. if (_t==null) _t=ASTNULL;
  967. switch ( _t.getType()) {
  968. case PACKED:
  969. {
  970. AST __t61 = _t;
  971. PascalAST tmp45_AST_in = (PascalAST)_t;
  972. match(_t,PACKED);
  973. _t = _t.getFirstChild();
  974. unpackedStructuredType(_t);
  975. _t = _retTree;
  976. _t = __t61;
  977. _t = _t.getNextSibling();
  978. break;
  979. }
  980. case ARRAY:
  981. case RECORD:
  982. case SET:
  983. case FILE:
  984. {
  985. unpackedStructuredType(_t);
  986. _t = _retTree;
  987. break;
  988. }
  989. default:
  990. {
  991. throw new NoViableAltException(_t);
  992. }
  993. }
  994. }
  995. catch (RecognitionException ex) {
  996. reportError(ex);
  997. if (_t!=null) {_t = _t.getNextSibling();}
  998. }
  999. _retTree = _t;
  1000. }
  1001. public final void variableDeclaration(AST _t) throws RecognitionException {
  1002. PascalAST variableDeclaration_AST_in = (PascalAST)_t;
  1003. PascalAST r = null;
  1004. Vector ids=null;
  1005. TypeSpecifier t=null;
  1006. try { // for error handling
  1007. AST __t34 = _t;
  1008. r = _t==ASTNULL ? null :(PascalAST)_t;
  1009. match(_t,VARDECL);
  1010. _t = _t.getFirstChild();
  1011. ids=identifierList(_t);
  1012. _t = _retTree;
  1013. t=type(_t);
  1014. _t = _retTree;
  1015. _t = __t34;
  1016. _t = _t.getNextSibling();
  1017. // walk list of identifiers, creating variable syms and setting types
  1018. if ( t!=null ) {
  1019. Scope sc = (Scope)scopes.peek();
  1020. for (int i=0; ids!=null && i<ids.size(); i++) {
  1021. String id = (String)ids.elementAt(i);
  1022. Variable v = new Variable(id,t);
  1023. sc.addSymbol(v);
  1024. r.symbol = t; // AST def root points to symbol table entry now
  1025. }
  1026. }
  1027. }
  1028. catch (RecognitionException ex) {
  1029. reportError(ex);
  1030. if (_t!=null) {_t = _t.getNextSibling();}
  1031. }
  1032. _retTree = _t;
  1033. }
  1034. public final void parameterGroup(AST _t) throws RecognitionException {
  1035. PascalAST parameterGroup_AST_in = (PascalAST)_t;
  1036. PascalAST r = null;
  1037. Vector ids=null;
  1038. TypeSpecifier t=null;
  1039. try { // for error handling
  1040. AST __t36 = _t;
  1041. r = _t==ASTNULL ? null :(PascalAST)_t;
  1042. match(_t,ARGDECL);
  1043. _t = _t.getFirstChild();
  1044. ids=identifierList(_t);
  1045. _t = _retTree;
  1046. t=typeIdentifier(_t);
  1047. _t = _retTree;
  1048. _t = __t36;
  1049. _t = _t.getNextSibling();
  1050. // walk list of identifiers, creating variable syms and setting types
  1051. if ( t!=null ) {
  1052. Scope sc = (Scope)scopes.peek();
  1053. for (int i=0; ids!=null && i<ids.size(); i++) {
  1054. String id = (String)ids.elementAt(i);
  1055. Variable v = new Variable(id,t);
  1056. sc.addSymbol(v);
  1057. r.symbol = t; // AST def root points to symbol table entry now
  1058. }
  1059. }
  1060. }
  1061. catch (RecognitionException ex) {
  1062. reportError(ex);
  1063. if (_t!=null) {_t = _t.getNextSibling();}
  1064. }
  1065. _retTree = _t;
  1066. }
  1067. public final void functionDeclaration(AST _t) throws RecognitionException {
  1068. PascalAST functionDeclaration_AST_in = (PascalAST)_t;
  1069. PascalAST r = null;
  1070. TypeSpecifier t=null;
  1071. try { // for error handling
  1072. AST __t42 = _t;
  1073. r = _t==ASTNULL ? null :(PascalAST)_t;
  1074. match(_t,FUNCTION);
  1075. _t = _t.getFirstChild();
  1076. PascalAST tmp46_AST_in = (PascalAST)_t;
  1077. match(_t,IDENT);
  1078. _t = _t.getNextSibling();
  1079. {
  1080. if (_t==null) _t=ASTNULL;
  1081. switch ( _t.getType()) {
  1082. case ARGDECLS:
  1083. {
  1084. formalParameterList(_t);
  1085. _t = _retTree;
  1086. break;
  1087. }
  1088. case IDENT:
  1089. case CHAR:
  1090. case BOOLEAN:
  1091. case INTEGER:
  1092. case REAL:
  1093. case STRING:
  1094. {
  1095. break;
  1096. }
  1097. default:
  1098. {
  1099. throw new NoViableAltException(_t);
  1100. }
  1101. }
  1102. }
  1103. t=resultType(_t);
  1104. _t = _retTree;
  1105. block(_t);
  1106. _t = _retTree;
  1107. _t = __t42;
  1108. _t = _t.getNextSibling();
  1109. if ( t!=null ) {r.symbol = t;}
  1110. }
  1111. catch (RecognitionException ex) {
  1112. reportError(ex);
  1113. if (_t!=null) {_t = _t.getNextSibling();}
  1114. }
  1115. _retTree = _t;
  1116. }
  1117. public final void identifier(AST _t) throws RecognitionException {
  1118. PascalAST identifier_AST_in = (PascalAST)_t;
  1119. try { // for error handling
  1120. PascalAST tmp47_AST_in = (PascalAST)_t;
  1121. match(_t,IDENT);
  1122. _t = _t.getNextSibling();
  1123. }
  1124. catch (RecognitionException ex) {
  1125. reportError(ex);
  1126. if (_t!=null) {_t = _t.getNextSibling();}
  1127. }
  1128. _retTree = _t;
  1129. }
  1130. public final void label(AST _t) throws RecognitionException {
  1131. PascalAST label_AST_in = (PascalAST)_t;
  1132. try { // for error handling
  1133. PascalAST tmp48_AST_in = (PascalAST)_t;
  1134. match(_t,NUM_INT);
  1135. _t = _t.getNextSibling();
  1136. }
  1137. catch (RecognitionException ex) {
  1138. reportError(ex);
  1139. if (_t!=null) {_t = _t.getNextSibling();}
  1140. }
  1141. _retTree = _t;
  1142. }
  1143. public final void string(AST _t) throws RecognitionException {
  1144. PascalAST string_AST_in = (PascalAST)_t;
  1145. try { // for error handling
  1146. PascalAST tmp49_AST_in = (PascalAST)_t;
  1147. match(_t,STRING_LITERAL);
  1148. _t = _t.getNextSibling();
  1149. }
  1150. catch (RecognitionException ex) {
  1151. reportError(ex);
  1152. if (_t!=null) {_t = _t.getNextSibling();}
  1153. }
  1154. _retTree = _t;
  1155. }
  1156. public final void unpackedStructuredType(AST _t) throws RecognitionException {
  1157. PascalAST unpackedStructuredType_AST_in = (PascalAST)_t;
  1158. try { // for error handling
  1159. if (_t==null) _t=ASTNULL;
  1160. switch ( _t.getType()) {
  1161. case ARRAY:
  1162. {
  1163. arrayType(_t);
  1164. _t = _retTree;
  1165. break;
  1166. }
  1167. case RECORD:
  1168. {
  1169. recordType(_t);
  1170. _t = _retTree;
  1171. break;
  1172. }
  1173. case SET:
  1174. {
  1175. setType(_t);
  1176. _t = _retTree;
  1177. break;
  1178. }
  1179. case FILE:
  1180. {
  1181. fileType(_t);
  1182. _t = _retTree;
  1183. break;
  1184. }
  1185. default:
  1186. {
  1187. throw new NoViableAltException(_t);
  1188. }
  1189. }
  1190. }
  1191. catch (RecognitionException ex) {
  1192. reportError(ex);
  1193. if (_t!=null) {_t = _t.getNextSibling();}
  1194. }
  1195. _retTree = _t;
  1196. }
  1197. public final void arrayType(AST _t) throws RecognitionException {
  1198. PascalAST arrayType_AST_in = (PascalAST)_t;
  1199. try { // for error handling
  1200. AST __t64 = _t;
  1201. PascalAST tmp50_AST_in = (PascalAST)_t;
  1202. match(_t,ARRAY);
  1203. _t = _t.getFirstChild();
  1204. typeList(_t);
  1205. _t = _retTree;
  1206. type(_t);
  1207. _t = _retTree;
  1208. _t = __t64;
  1209. _t = _t.getNextSibling();
  1210. }
  1211. catch (RecognitionException ex) {
  1212. reportError(ex);
  1213. if (_t!=null) {_t = _t.getNextSibling();}
  1214. }
  1215. _retTree = _t;
  1216. }
  1217. public final void recordType(AST _t) throws RecognitionException {
  1218. PascalAST recordType_AST_in = (PascalAST)_t;
  1219. try { // for error handling
  1220. AST __t70 = _t;
  1221. PascalAST tmp51_AST_in = (PascalAST)_t;
  1222. match(_t,RECORD);
  1223. _t = _t.getFirstChild();
  1224. fieldList(_t);
  1225. _t = _retTree;
  1226. _t = __t70;
  1227. _t = _t.getNextSibling();
  1228. }
  1229. catch (RecognitionException ex) {
  1230. reportError(ex);
  1231. if (_t!=null) {_t = _t.getNextSibling();}
  1232. }
  1233. _retTree = _t;
  1234. }
  1235. public final void setType(AST _t) throws RecognitionException {
  1236. PascalAST setType_AST_in = (PascalAST)_t;
  1237. try { // for error handling
  1238. AST __t90 = _t;
  1239. PascalAST tmp52_AST_in = (PascalAST)_t;
  1240. match(_t,SET);
  1241. _t = _t.getFirstChild();
  1242. type(_t);
  1243. _t = _retTree;
  1244. _t = __t90;
  1245. _t = _t.getNextSibling();
  1246. }
  1247. catch (RecognitionException ex) {
  1248. reportError(ex);
  1249. if (_t!=null) {_t = _t.getNextSibling();}
  1250. }
  1251. _retTree = _t;
  1252. }
  1253. public final void fileType(AST _t) throws RecognitionException {
  1254. PascalAST fileType_AST_in = (PascalAST)_t;
  1255. try { // for error handling
  1256. AST __t92 = _t;
  1257. PascalAST tmp53_AST_in = (PascalAST)_t;
  1258. match(_t,FILE);
  1259. _t = _t.getFirstChild();
  1260. {
  1261. if (_t==null) _t=ASTNULL;
  1262. switch ( _t.getType()) {
  1263. case SCALARTYPE:
  1264. case IDENT:
  1265. case DOTDOT:
  1266. case CHAR:
  1267. case BOOLEAN:
  1268. case INTEGER:
  1269. case REAL:
  1270. case STRING:
  1271. case PACKED:
  1272. case ARRAY:
  1273. case RECORD:
  1274. case SET:
  1275. case FILE:
  1276. case POINTER:
  1277. {
  1278. type(_t);
  1279. _t = _retTree;
  1280. break;
  1281. }
  1282. case 3:
  1283. {
  1284. break;
  1285. }
  1286. default:
  1287. {
  1288. throw new NoViableAltException(_t);
  1289. }
  1290. }
  1291. }
  1292. _t = __t92;
  1293. _t = _t.getNextSibling();
  1294. }
  1295. catch (RecognitionException ex) {
  1296. reportError(ex);
  1297. if (_t!=null) {_t = _t.getNextSibling();}
  1298. }
  1299. _retTree = _t;
  1300. }
  1301. public final void typeList(AST _t) throws RecognitionException {
  1302. PascalAST typeList_AST_in = (PascalAST)_t;
  1303. try { // for error handling
  1304. AST __t66 = _t;
  1305. PascalAST tmp54_AST_in = (PascalAST)_t;
  1306. match(_t,TYPELIST);
  1307. _t = _t.getFirstChild();
  1308. {
  1309. int _cnt68=0;
  1310. _loop68:
  1311. do {
  1312. if (_t==null) _t=ASTNULL;
  1313. if ((_tokenSet_1.member(_t.getType()))) {
  1314. type(_t);
  1315. _t = _retTree;
  1316. }
  1317. else {
  1318. if ( _cnt68>=1 ) { break _loop68; } else {throw new NoViableAltException(_t);}
  1319. }
  1320. _cnt68++;
  1321. } while (true);
  1322. }
  1323. _t = __t66;
  1324. _t = _t.getNextSibling();
  1325. }
  1326. catch (RecognitionException ex) {
  1327. reportError(ex);
  1328. if (_t!=null) {_t = _t.getNextSibling();}
  1329. }
  1330. _retTree = _t;
  1331. }
  1332. public final void fieldList(AST _t) throws RecognitionException {
  1333. PascalAST fieldList_AST_in = (PascalAST)_t;
  1334. try { // for error handling
  1335. AST __t72 = _t;
  1336. PascalAST tmp55_AST_in = (PascalAST)_t;
  1337. match(_t,FIELDLIST);
  1338. _t = _t.getFirstChild();
  1339. {
  1340. if (_t==null) _t=ASTNULL;
  1341. switch ( _t.getType()) {
  1342. case FIELD:
  1343. {
  1344. fixedPart(_t);
  1345. _t = _retTree;
  1346. {
  1347. if (_t==null) _t=ASTNULL;
  1348. switch ( _t.getType()) {
  1349. case CASE:
  1350. {
  1351. variantPart(_t);
  1352. _t = _retTree;
  1353. break;
  1354. }
  1355. case 3:
  1356. {
  1357. break;
  1358. }
  1359. default:
  1360. {
  1361. throw new NoViableAltException(_t);
  1362. }
  1363. }
  1364. }
  1365. break;
  1366. }
  1367. case CASE:
  1368. {
  1369. variantPart(_t);
  1370. _t = _retTree;
  1371. break;
  1372. }
  1373. default:
  1374. {
  1375. throw new NoViableAltException(_t);
  1376. }
  1377. }
  1378. }
  1379. _t = __t72;
  1380. _t = _t.getNextSibling();
  1381. }
  1382. catch (RecognitionException ex) {
  1383. reportError(ex);
  1384. if (_t!=null) {_t = _t.getNextSibling();}
  1385. }
  1386. _retTree = _t;
  1387. }
  1388. public final void fixedPart(AST _t) throws RecognitionException {
  1389. PascalAST fixedPart_AST_in = (PascalAST)_t;
  1390. try { // for error handling
  1391. {
  1392. int _cnt77=0;
  1393. _loop77:
  1394. do {
  1395. if (_t==null) _t=ASTNULL;
  1396. if ((_t.getType()==FIELD)) {
  1397. recordSection(_t);
  1398. _t = _retTree;
  1399. }
  1400. else {
  1401. if ( _cnt77>=1 ) { break _loop77; } else {throw new NoViableAltException(_t);}
  1402. }
  1403. _cnt77++;
  1404. } while (true);
  1405. }
  1406. }
  1407. catch (RecognitionException ex) {
  1408. reportError(ex);
  1409. if (_t!=null) {_t = _t.getNextSibling();}
  1410. }
  1411. _retTree = _t;
  1412. }
  1413. public final void variantPart(AST _t) throws RecognitionException {
  1414. PascalAST variantPart_AST_in = (PascalAST)_t;
  1415. try { // for error handling
  1416. AST __t81 = _t;
  1417. PascalAST tmp56_AST_in = (PascalAST)_t;
  1418. match(_t,CASE);
  1419. _t = _t.getFirstChild();
  1420. tag(_t);
  1421. _t = _retTree;
  1422. {
  1423. int _cnt83=0;
  1424. _loop83:
  1425. do {
  1426. if (_t==null) _t=ASTNULL;
  1427. if ((_t.getType()==VARIANT_CASE)) {
  1428. variant(_t);
  1429. _t = _retTree;
  1430. }
  1431. else {
  1432. if ( _cnt83>=1 ) { break _loop83; } else {throw new NoViableAltException(_t);}
  1433. }
  1434. _cnt83++;
  1435. } while (true);
  1436. }
  1437. _t = __t81;
  1438. _t = _t.getNextSibling();
  1439. }
  1440. catch (RecognitionException ex) {
  1441. reportError(ex);
  1442. if (_t!=null) {_t = _t.getNextSibling();}
  1443. }
  1444. _retTree = _t;
  1445. }
  1446. public final void recordSection(AST _t) throws RecognitionException {
  1447. PascalAST recordSection_AST_in = (PascalAST)_t;
  1448. try { // for error handling
  1449. AST __t79 = _t;
  1450. PascalAST tmp57_AST_in = (PascalAST)_t;
  1451. match(_t,FIELD);
  1452. _t = _t.getFirstChild();
  1453. identifierList(_t);
  1454. _t = _retTree;
  1455. type(_t);
  1456. _t = _retTree;
  1457. _t = __t79;
  1458. _t = _t.getNextSibling();
  1459. }
  1460. catch (RecognitionException ex) {
  1461. reportError(ex);
  1462. if (_t!=null) {_t = _t.getNextSibling();}
  1463. }
  1464. _retTree = _t;
  1465. }
  1466. public final void tag(AST _t) throws RecognitionException {
  1467. PascalAST tag_AST_in = (PascalAST)_t;
  1468. try { // for error handling
  1469. if (_t==null) _t=ASTNULL;
  1470. switch ( _t.getType()) {
  1471. case VARIANT_TAG:
  1472. {
  1473. AST __t85 = _t;
  1474. PascalAST tmp58_AST_in = (PascalAST)_t;
  1475. match(_t,VARIANT_TAG);
  1476. _t = _t.getFirstChild();
  1477. identifier(_t);
  1478. _t = _retTree;
  1479. typeIdentifier(_t);
  1480. _t = _retTree;
  1481. _t = __t85;
  1482. _t = _t.getNextSibling();
  1483. break;
  1484. }
  1485. case VARIANT_TAG_NO_ID:
  1486. {
  1487. AST __t86 = _t;
  1488. PascalAST tmp59_AST_in = (PascalAST)_t;
  1489. match(_t,VARIANT_TAG_NO_ID);
  1490. _t = _t.getFirstChild();
  1491. typeIdentifier(_t);
  1492. _t = _retTree;
  1493. _t = __t86;
  1494. _t = _t.getNextSibling();
  1495. break;
  1496. }
  1497. default:
  1498. {
  1499. throw new NoViableAltException(_t);
  1500. }
  1501. }
  1502. }
  1503. catch (RecognitionException ex) {
  1504. reportError(ex);
  1505. if (_t!=null) {_t = _t.getNextSibling();}
  1506. }
  1507. _retTree = _t;
  1508. }
  1509. public final void variant(AST _t) throws RecognitionException {
  1510. PascalAST variant_AST_in = (PascalAST)_t;
  1511. try { // for error handling
  1512. AST __t88 = _t;
  1513. PascalAST tmp60_AST_in = (PascalAST)_t;
  1514. match(_t,VARIANT_CASE);
  1515. _t = _t.getFirstChild();
  1516. constList(_t);
  1517. _t = _retTree;
  1518. fieldList(_t);
  1519. _t = _retTree;
  1520. _t = __t88;
  1521. _t = _t.getNextSibling();
  1522. }
  1523. catch (RecognitionException ex) {
  1524. reportError(ex);
  1525. if (_t!=null) {_t = _t.getNextSibling();}
  1526. }
  1527. _retTree = _t;
  1528. }
  1529. public final void constList(AST _t) throws RecognitionException {
  1530. PascalAST constList_AST_in = (PascalAST)_t;
  1531. try { // for error handling
  1532. AST __t112 = _t;
  1533. PascalAST tmp61_AST_in = (PascalAST)_t;
  1534. match(_t,CONSTLIST);
  1535. _t = _t.getFirstChild();
  1536. {
  1537. int _cnt114=0;
  1538. _loop114:
  1539. do {
  1540. if (_t==null) _t=ASTNULL;
  1541. if ((_tokenSet_2.member(_t.getType()))) {
  1542. constant(_t);
  1543. _t = _retTree;
  1544. }
  1545. else {
  1546. if ( _cnt114>=1 ) { break _loop114; } else {throw new NoViableAltException(_t);}
  1547. }
  1548. _cnt114++;
  1549. } while (true);
  1550. }
  1551. _t = __t112;
  1552. _t = _t.getNextSibling();
  1553. }
  1554. catch (RecognitionException ex) {
  1555. reportError(ex);
  1556. if (_t!=null) {_t = _t.getNextSibling();}
  1557. }
  1558. _retTree = _t;
  1559. }
  1560. public final void procedureOrFunctionDeclaration(AST _t) throws RecognitionException {
  1561. PascalAST procedureOrFunctionDeclaration_AST_in = (PascalAST)_t;
  1562. try { // for error handling
  1563. if (_t==null) _t=ASTNULL;
  1564. switch ( _t.getType()) {
  1565. case PROCEDURE:
  1566. {
  1567. procedureDeclaration(_t);
  1568. _t = _retTree;
  1569. break;
  1570. }
  1571. case FUNCTION:
  1572. {
  1573. functionDeclaration(_t);
  1574. _t = _retTree;
  1575. break;
  1576. }
  1577. default:
  1578. {
  1579. throw new NoViableAltException(_t);
  1580. }
  1581. }
  1582. }
  1583. catch (RecognitionException ex) {
  1584. reportError(ex);
  1585. if (_t!=null) {_t = _t.getNextSibling();}
  1586. }
  1587. _retTree = _t;
  1588. }
  1589. public final void procedureDeclaration(AST _t) throws RecognitionException {
  1590. PascalAST procedureDeclaration_AST_in = (PascalAST)_t;
  1591. try { // for error handling
  1592. AST __t101 = _t;
  1593. PascalAST tmp62_AST_in = (PascalAST)_t;
  1594. match(_t,PROCEDURE);
  1595. _t = _t.getFirstChild();
  1596. PascalAST tmp63_AST_in = (PascalAST)_t;
  1597. match(_t,IDENT);
  1598. _t = _t.getNextSibling();
  1599. {
  1600. if (_t==null) _t=ASTNULL;
  1601. switch ( _t.getType()) {
  1602. case ARGDECLS:
  1603. {
  1604. formalParameterList(_t);
  1605. _t = _retTree;
  1606. break;
  1607. }
  1608. case BLOCK:
  1609. case IMPLEMENTATION:
  1610. case USES:
  1611. case LABEL:
  1612. case CONST:
  1613. case TYPE:
  1614. case FUNCTION:
  1615. case PROCEDURE:
  1616. case VAR:
  1617. {
  1618. break;
  1619. }
  1620. default:
  1621. {
  1622. throw new NoViableAltException(_t);
  1623. }
  1624. }
  1625. }
  1626. block(_t);
  1627. _t = _retTree;
  1628. _t = __t101;
  1629. _t = _t.getNextSibling();
  1630. }
  1631. catch (RecognitionException ex) {
  1632. reportError(ex);
  1633. if (_t!=null) {_t = _t.getNextSibling();}
  1634. }
  1635. _retTree = _t;
  1636. }
  1637. public final void formalParameterSection(AST _t) throws RecognitionException {
  1638. PascalAST formalParameterSection_AST_in = (PascalAST)_t;
  1639. try { // for error handling
  1640. if (_t==null) _t=ASTNULL;
  1641. switch ( _t.getType()) {
  1642. case ARGDECL:
  1643. {
  1644. parameterGroup(_t);
  1645. _t = _retTree;
  1646. break;
  1647. }
  1648. case VAR:
  1649. {
  1650. AST __t108 = _t;
  1651. PascalAST tmp64_AST_in = (PascalAST)_t;
  1652. match(_t,VAR);
  1653. _t = _t.getFirstChild();
  1654. parameterGroup(_t);
  1655. _t = _retTree;
  1656. _t = __t108;
  1657. _t = _t.getNextSibling();
  1658. break;
  1659. }
  1660. case FUNCTION:
  1661. {
  1662. AST __t109 = _t;
  1663. PascalAST tmp65_AST_in = (PascalAST)_t;
  1664. match(_t,FUNCTION);
  1665. _t = _t.getFirstChild();
  1666. parameterGroup(_t);
  1667. _t = _retTree;
  1668. _t = __t109;
  1669. _t = _t.getNextSibling();
  1670. break;
  1671. }
  1672. case PROCEDURE:
  1673. {
  1674. AST __t110 = _t;
  1675. PascalAST tmp66_AST_in = (PascalAST)_t;
  1676. match(_t,PROCEDURE);
  1677. _t = _t.getFirstChild();
  1678. parameterGroup(_t);
  1679. _t = _retTree;
  1680. _t = __t110;
  1681. _t = _t.getNextSibling();
  1682. break;
  1683. }
  1684. default:
  1685. {
  1686. throw new NoViableAltException(_t);
  1687. }
  1688. }
  1689. }
  1690. catch (RecognitionException ex) {
  1691. reportError(ex);
  1692. if (_t!=null) {_t = _t.getNextSibling();}
  1693. }
  1694. _retTree = _t;
  1695. }
  1696. public final void statement(AST _t) throws RecognitionException {
  1697. PascalAST statement_AST_in = (PascalAST)_t;
  1698. try { // for error handling
  1699. if (_t==null) _t=ASTNULL;
  1700. switch ( _t.getType()) {
  1701. case COLON:
  1702. {
  1703. AST __t116 = _t;
  1704. PascalAST tmp67_AST_in = (PascalAST)_t;
  1705. match(_t,COLON);
  1706. _t = _t.getFirstChild();
  1707. label(_t);
  1708. _t = _retTree;
  1709. unlabelledStatement(_t);
  1710. _t = _retTree;
  1711. _t = __t116;
  1712. _t = _t.getNextSibling();
  1713. break;
  1714. }
  1715. case BLOCK:
  1716. case PROC_CALL:
  1717. case CASE:
  1718. case ASSIGN:
  1719. case GOTO:
  1720. case IF:
  1721. case WHILE:
  1722. case REPEAT:
  1723. case FOR:
  1724. case WITH:
  1725. {
  1726. unlabelledStatement(_t);
  1727. _t = _retTree;
  1728. break;
  1729. }
  1730. default:
  1731. {
  1732. throw new NoViableAltException(_t);
  1733. }
  1734. }
  1735. }
  1736. catch (RecognitionException ex) {
  1737. reportError(ex);
  1738. if (_t!=null) {_t = _t.getNextSibling();}
  1739. }
  1740. _retTree = _t;
  1741. }
  1742. public final void unlabelledStatement(AST _t) throws RecognitionException {
  1743. PascalAST unlabelledStatement_AST_in = (PascalAST)_t;
  1744. try { // for error handling
  1745. if (_t==null) _t=ASTNULL;
  1746. switch ( _t.getType()) {
  1747. case PROC_CALL:
  1748. case ASSIGN:
  1749. case GOTO:
  1750. {
  1751. simpleStatement(_t);
  1752. _t = _retTree;
  1753. break;
  1754. }
  1755. case BLOCK:
  1756. case CASE:
  1757. case IF:
  1758. case WHILE:
  1759. case REPEAT:
  1760. case FOR:
  1761. case WITH:
  1762. {
  1763. structuredStatement(_t);
  1764. _t = _retTree;
  1765. break;
  1766. }
  1767. default:
  1768. {
  1769. throw new NoViableAltException(_t);
  1770. }
  1771. }
  1772. }
  1773. catch (RecognitionException ex) {
  1774. reportError(ex);
  1775. if (_t!=null) {_t = _t.getNextSibling();}
  1776. }
  1777. _retTree = _t;
  1778. }
  1779. public final void simpleStatement(AST _t) throws RecognitionException {
  1780. PascalAST simpleStatement_AST_in = (PascalAST)_t;
  1781. try { // for error handling
  1782. if (_t==null) _t=ASTNULL;
  1783. switch ( _t.getType()) {
  1784. case ASSIGN:
  1785. {
  1786. assignmentStatement(_t);
  1787. _t = _retTree;
  1788. break;
  1789. }
  1790. case PROC_CALL:
  1791. {
  1792. procedureStatement(_t);
  1793. _t = _retTree;
  1794. break;
  1795. }
  1796. case GOTO:
  1797. {
  1798. gotoStatement(_t);
  1799. _t = _retTree;
  1800. break;
  1801. }
  1802. default:
  1803. {
  1804. throw new NoViableAltException(_t);
  1805. }
  1806. }
  1807. }
  1808. catch (RecognitionException ex) {
  1809. reportError(ex);
  1810. if (_t!=null) {_t = _t.getNextSibling();}
  1811. }
  1812. _retTree = _t;
  1813. }
  1814. public final void structuredStatement(AST _t) throws RecognitionException {
  1815. PascalAST structuredStatement_AST_in = (PascalAST)_t;
  1816. try { // for error handling
  1817. if (_t==null) _t=ASTNULL;
  1818. switch ( _t.getType()) {
  1819. case BLOCK:
  1820. {
  1821. compoundStatement(_t);
  1822. _t = _retTree;
  1823. break;
  1824. }
  1825. case CASE:
  1826. case IF:
  1827. {
  1828. conditionalStatement(_t);
  1829. _t = _retTree;
  1830. break;
  1831. }
  1832. case WHILE:
  1833. case REPEAT:
  1834. case FOR:
  1835. {
  1836. repetetiveStatement(_t);
  1837. _t = _retTree;
  1838. break;
  1839. }
  1840. case WITH:
  1841. {
  1842. withStatement(_t);
  1843. _t = _retTree;
  1844. break;
  1845. }
  1846. default:
  1847. {
  1848. throw new NoViableAltException(_t);
  1849. }
  1850. }
  1851. }
  1852. catch (RecognitionException ex) {
  1853. reportError(ex);
  1854. if (_t!=null) {_t = _t.getNextSibling();}
  1855. }
  1856. _retTree = _t;
  1857. }
  1858. public final void assignmentStatement(AST _t) throws RecognitionException {
  1859. PascalAST assignmentStatement_AST_in = (PascalAST)_t;
  1860. try { // for error handling
  1861. AST __t120 = _t;
  1862. PascalAST tmp68_AST_in = (PascalAST)_t;
  1863. match(_t,ASSIGN);
  1864. _t = _t.getFirstChild();
  1865. variable(_t);
  1866. _t = _retTree;
  1867. expression(_t);
  1868. _t = _retTree;
  1869. _t = __t120;
  1870. _t = _t.getNextSibling();
  1871. }
  1872. catch (RecognitionException ex) {
  1873. reportError(ex);
  1874. if (_t!=null) {_t = _t.getNextSibling();}
  1875. }
  1876. _retTree = _t;
  1877. }
  1878. public final void procedureStatement(AST _t) throws RecognitionException {
  1879. PascalAST procedureStatement_AST_in = (PascalAST)_t;
  1880. try { // for error handling
  1881. AST __t166 = _t;
  1882. PascalAST tmp69_AST_in = (PascalAST)_t;
  1883. match(_t,PROC_CALL);
  1884. _t = _t.getFirstChild();
  1885. PascalAST tmp70_AST_in = (PascalAST)_t;
  1886. match(_t,IDENT);
  1887. _t = _t.getNextSibling();
  1888. {
  1889. if (_t==null) _t=ASTNULL;
  1890. switch ( _t.getType()) {
  1891. case ARGLIST:
  1892. {
  1893. parameterList(_t);
  1894. _t = _retTree;
  1895. break;
  1896. }
  1897. case 3:
  1898. {
  1899. break;
  1900. }
  1901. default:
  1902. {
  1903. throw new NoViableAltException(_t);
  1904. }
  1905. }
  1906. }
  1907. _t = __t166;
  1908. _t = _t.getNextSibling();
  1909. }
  1910. catch (RecognitionException ex) {
  1911. reportError(ex);
  1912. if (_t!=null) {_t = _t.getNextSibling();}
  1913. }
  1914. _retTree = _t;
  1915. }
  1916. public final void gotoStatement(AST _t) throws RecognitionException {
  1917. PascalAST gotoStatement_AST_in = (PascalAST)_t;
  1918. try { // for error handling
  1919. AST __t170 = _t;
  1920. PascalAST tmp71_AST_in = (PascalAST)_t;
  1921. match(_t,GOTO);
  1922. _t = _t.getFirstChild();
  1923. label(_t);
  1924. _t = _retTree;
  1925. _t = __t170;
  1926. _t = _t.getNextSibling();
  1927. }
  1928. catch (RecognitionException ex) {
  1929. reportError(ex);
  1930. if (_t!=null) {_t = _t.getNextSibling();}
  1931. }
  1932. _retTree = _t;
  1933. }
  1934. public final void variable(AST _t) throws RecognitionException {
  1935. PascalAST variable_AST_in = (PascalAST)_t;
  1936. try { // for error handling
  1937. if (_t==null) _t=ASTNULL;
  1938. switch ( _t.getType()) {
  1939. case LBRACK:
  1940. {
  1941. AST __t122 = _t;
  1942. PascalAST tmp72_AST_in = (PascalAST)_t;
  1943. match(_t,LBRACK);
  1944. _t = _t.getFirstChild();
  1945. variable(_t);
  1946. _t = _retTree;
  1947. {
  1948. int _cnt124=0;
  1949. _loop124:
  1950. do {
  1951. if (_t==null) _t=ASTNULL;
  1952. if ((_tokenSet_3.member(_t.getType()))) {
  1953. expression(_t);
  1954. _t = _retTree;
  1955. }
  1956. else {
  1957. if ( _cnt124>=1 ) { break _loop124; } else {throw new NoViableAltException(_t);}
  1958. }
  1959. _cnt124++;
  1960. } while (true);
  1961. }
  1962. _t = __t122;
  1963. _t = _t.getNextSibling();
  1964. break;
  1965. }
  1966. case LBRACK2:
  1967. {
  1968. AST __t125 = _t;
  1969. PascalAST tmp73_AST_in = (PascalAST)_t;
  1970. match(_t,LBRACK2);
  1971. _t = _t.getFirstChild();
  1972. variable(_t);
  1973. _t = _retTree;
  1974. {
  1975. int _cnt127=0;
  1976. _loop127:
  1977. do {
  1978. if (_t==null) _t=ASTNULL;
  1979. if ((_tokenSet_3.member(_t.getType()))) {
  1980. expression(_t);
  1981. _t = _retTree;
  1982. }
  1983. else {
  1984. if ( _cnt127>=1 ) { break _loop127; } else {throw new NoViableAltException(_t);}
  1985. }
  1986. _cnt127++;
  1987. } while (true);
  1988. }
  1989. _t = __t125;
  1990. _t = _t.getNextSibling();
  1991. break;
  1992. }
  1993. case DOT:
  1994. {
  1995. AST __t128 = _t;
  1996. PascalAST tmp74_AST_in = (PascalAST)_t;
  1997. match(_t,DOT);
  1998. _t = _t.getFirstChild();
  1999. variable(_t);
  2000. _t = _retTree;
  2001. PascalAST tmp75_AST_in = (PascalAST)_t;
  2002. match(_t,IDENT);
  2003. _t = _t.getNextSibling();
  2004. _t = __t128;
  2005. _t = _t.getNextSibling();
  2006. break;
  2007. }
  2008. case POINTER:
  2009. {
  2010. AST __t129 = _t;
  2011. PascalAST tmp76_AST_in = (PascalAST)_t;
  2012. match(_t,POINTER);
  2013. _t = _t.getFirstChild();
  2014. variable(_t);
  2015. _t = _retTree;
  2016. _t = __t129;
  2017. _t = _t.getNextSibling();
  2018. break;
  2019. }
  2020. case AT:
  2021. {
  2022. AST __t130 = _t;
  2023. PascalAST tmp77_AST_in = (PascalAST)_t;
  2024. match(_t,AT);
  2025. _t = _t.getFirstChild();
  2026. PascalAST tmp78_AST_in = (PascalAST)_t;
  2027. match(_t,IDENT);
  2028. _t = _t.getNextSibling();
  2029. _t = __t130;
  2030. _t = _t.getNextSibling();
  2031. break;
  2032. }
  2033. case IDENT:
  2034. {
  2035. PascalAST tmp79_AST_in = (PascalAST)_t;
  2036. match(_t,IDENT);
  2037. _t = _t.getNextSibling();
  2038. break;
  2039. }
  2040. default:
  2041. {
  2042. throw new NoViableAltException(_t);
  2043. }
  2044. }
  2045. }
  2046. catch (RecognitionException ex) {
  2047. reportError(ex);
  2048. if (_t!=null) {_t = _t.getNextSibling();}
  2049. }
  2050. _retTree = _t;
  2051. }
  2052. public final void expression(AST _t) throws RecognitionException {
  2053. PascalAST expression_AST_in = (PascalAST)_t;
  2054. try { // for error handling
  2055. if (_t==null) _t=ASTNULL;
  2056. switch ( _t.getType()) {
  2057. case EQUAL:
  2058. {
  2059. AST __t132 = _t;
  2060. PascalAST tmp80_AST_in = (PascalAST)_t;
  2061. match(_t,EQUAL);
  2062. _t = _t.getFirstChild();
  2063. expression(_t);
  2064. _t = _retTree;
  2065. expression(_t);
  2066. _t = _retTree;
  2067. _t = __t132;
  2068. _t = _t.getNextSibling();
  2069. break;
  2070. }
  2071. case NOT_EQUAL:
  2072. {
  2073. AST __t133 = _t;
  2074. PascalAST tmp81_AST_in = (PascalAST)_t;
  2075. match(_t,NOT_EQUAL);
  2076. _t = _t.getFirstChild();
  2077. expression(_t);
  2078. _t = _retTree;
  2079. expression(_t);
  2080. _t = _retTree;
  2081. _t = __t133;
  2082. _t = _t.getNextSibling();
  2083. break;
  2084. }
  2085. case LT:
  2086. {
  2087. AST __t134 = _t;
  2088. PascalAST tmp82_AST_in = (PascalAST)_t;
  2089. match(_t,LT);
  2090. _t = _t.getFirstChild();
  2091. expression(_t);
  2092. _t = _retTree;
  2093. expression(_t);
  2094. _t = _retTree;
  2095. _t = __t134;
  2096. _t = _t.getNextSibling();
  2097. break;
  2098. }
  2099. case LE:
  2100. {
  2101. AST __t135 = _t;
  2102. PascalAST tmp83_AST_in = (PascalAST)_t;
  2103. match(_t,LE);
  2104. _t = _t.getFirstChild();
  2105. expression(_t);
  2106. _t = _retTree;
  2107. expression(_t);
  2108. _t = _retTree;
  2109. _t = __t135;
  2110. _t = _t.getNextSibling();
  2111. break;
  2112. }
  2113. case GE:
  2114. {
  2115. AST __t136 = _t;
  2116. PascalAST tmp84_AST_in = (PascalAST)_t;
  2117. match(_t,GE);
  2118. _t = _t.getFirstChild();
  2119. expression(_t);
  2120. _t = _retTree;
  2121. expression(_t);
  2122. _t = _retTree;
  2123. _t = __t136;
  2124. _t = _t.getNextSibling();
  2125. break;
  2126. }
  2127. case GT:
  2128. {
  2129. AST __t137 = _t;
  2130. PascalAST tmp85_AST_in = (PascalAST)_t;
  2131. match(_t,GT);
  2132. _t = _t.getFirstChild();
  2133. expression(_t);
  2134. _t = _retTree;
  2135. expression(_t);
  2136. _t = _retTree;
  2137. _t = __t137;
  2138. _t = _t.getNextSibling();
  2139. break;
  2140. }
  2141. case IN:
  2142. {
  2143. AST __t138 = _t;
  2144. PascalAST tmp86_AST_in = (PascalAST)_t;
  2145. match(_t,IN);
  2146. _t = _t.getFirstChild();
  2147. expression(_t);
  2148. _t = _retTree;
  2149. expression(_t);
  2150. _t = _retTree;
  2151. _t = __t138;
  2152. _t = _t.getNextSibling();
  2153. break;
  2154. }
  2155. case PLUS:
  2156. {
  2157. AST __t139 = _t;
  2158. PascalAST tmp87_AST_in = (PascalAST)_t;
  2159. match(_t,PLUS);
  2160. _t = _t.getFirstChild();
  2161. expression(_t);
  2162. _t = _retTree;
  2163. {
  2164. if (_t==null) _t=ASTNULL;
  2165. switch ( _t.getType()) {
  2166. case FUNC_CALL:
  2167. case DOT:
  2168. case IDENT:
  2169. case EQUAL:
  2170. case CHR:
  2171. case NUM_INT:
  2172. case NUM_REAL:
  2173. case PLUS:
  2174. case MINUS:
  2175. case STRING_LITERAL:
  2176. case LBRACK:
  2177. case LBRACK2:
  2178. case SET:
  2179. case POINTER:
  2180. case AT:
  2181. case NOT_EQUAL:
  2182. case LT:
  2183. case LE:
  2184. case GE:
  2185. case GT:
  2186. case IN:
  2187. case OR:
  2188. case STAR:
  2189. case SLASH:
  2190. case DIV:
  2191. case MOD:
  2192. case AND:
  2193. case NOT:
  2194. case NIL:
  2195. {
  2196. expression(_t);
  2197. _t = _retTree;
  2198. break;
  2199. }
  2200. case 3:
  2201. {
  2202. break;
  2203. }
  2204. default:
  2205. {
  2206. throw new NoViableAltException(_t);
  2207. }
  2208. }
  2209. }
  2210. _t = __t139;
  2211. _t = _t.getNextSibling();
  2212. break;
  2213. }
  2214. case MINUS:
  2215. {
  2216. AST __t141 = _t;
  2217. PascalAST tmp88_AST_in = (PascalAST)_t;
  2218. match(_t,MINUS);
  2219. _t = _

Large files files are truncated, but you can click here to view the full file