PageRenderTime 45ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/bsh/bsh.jj

#
Unknown | 2424 lines | 2326 code | 98 blank | 0 comment | 0 complexity | 14b9f04c54708cbbdde889850c34c04e MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*@bgen(jjtree) Generated By:JJTree: Do not edit this line. src/bsh/bsh.jj */
  2. /*@egen*//*****************************************************************************
  3. * *
  4. * This file is part of the BeanShell Java Scripting distribution. *
  5. * Documentation and updates may be found at http://www.beanshell.org/ *
  6. * *
  7. * Sun Public License Notice: *
  8. * *
  9. * The contents of this file are subject to the Sun Public License Version *
  10. * 1.0 (the "License"); you may not use this file except in compliance with *
  11. * the License. A copy of the License is available at http://www.sun.com *
  12. * *
  13. * The Original Code is BeanShell. The Initial Developer of the Original *
  14. * Code is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright *
  15. * (C) 2000. All Rights Reserved. *
  16. * *
  17. * GNU Public License Notice: *
  18. * *
  19. * Alternatively, the contents of this file may be used under the terms of *
  20. * the GNU Lesser General Public License (the "LGPL"), in which case the *
  21. * provisions of LGPL are applicable instead of those above. If you wish to *
  22. * allow use of your version of this file only under the terms of the LGPL *
  23. * and not to allow others to use your version of this file under the SPL, *
  24. * indicate your decision by deleting the provisions above and replace *
  25. * them with the notice and other provisions required by the LGPL. If you *
  26. * do not delete the provisions above, a recipient may use your version of *
  27. * this file under either the SPL or the LGPL. *
  28. * *
  29. * Patrick Niemeyer (pat@pat.net) *
  30. * Author of Learning Java, O'Reilly & Associates *
  31. * http://www.pat.net/~pat/ *
  32. * *
  33. *****************************************************************************/
  34. /*
  35. Notes:
  36. There is probably a lot of room for improvement in here.
  37. All of the syntactic lookaheads have been commented with:
  38. SYNTACTIC_LOOKAHEAD
  39. These are probably expensive and we may want to start weeding them out
  40. where possible.
  41. */
  42. options {
  43. JAVA_UNICODE_ESCAPE=true;
  44. STATIC=false;
  45. /* Print grammar debugging info as we parse
  46. DEBUG_PARSER=true; */
  47. /* Print detailed lookahead debugging info
  48. DEBUG_LOOKAHEAD=true; */
  49. }
  50. PARSER_BEGIN(Parser)
  51. package bsh;
  52. import java.io.Reader;
  53. class Parser/*@bgen(jjtree)*/implements ParserTreeConstants/*@egen*/ {/*@bgen(jjtree)*/
  54. protected JJTParserState jjtree = new JJTParserState();
  55. /*@egen*/
  56. void jjtreeOpenNodeScope(Node n) {
  57. ((SimpleNode)n).firstToken = getToken(1);
  58. }
  59. void jjtreeCloseNodeScope(Node n) {
  60. ((SimpleNode)n).lastToken = getToken(0);
  61. }
  62. /**
  63. Re-initialize the input stream and token source.
  64. */
  65. void reInitInput( Reader in ) {
  66. ReInit(in);
  67. }
  68. /**
  69. Explicitly re-initialize just the token reader.
  70. This seems to be necessary to avoid certain looping errors when
  71. reading bogus input. See Interpreter.
  72. */
  73. void reInitTokenInput( Reader in ) {
  74. jj_input_stream.ReInit( in,
  75. jj_input_stream.getEndLine(),
  76. jj_input_stream.getEndColumn() );
  77. }
  78. }
  79. PARSER_END(Parser)
  80. SKIP : /* WHITE SPACE */
  81. {
  82. " " | "\t" | "\r" | "\f"
  83. | "\n"
  84. | < NONPRINTABLE: (["\u0000"-" ", "\u0080"-"\u00ff"])+ >
  85. }
  86. SPECIAL_TOKEN : /* COMMENTS */
  87. {
  88. /*
  89. Single line comments fail on the last line of a file with no terminating
  90. linefeed. I thought the <EOF> would fix that, but no...
  91. <SINGLE_LINE_COMMENT: "//" (~["\n","\r"])* "<EOF>"|("\n"|"\r"|"\r\n")>
  92. */
  93. <SINGLE_LINE_COMMENT: "//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")>
  94. | <HASH_BANG_COMMENT: "#!" (~["\n","\r"])* ("\n"|"\r"|"\r\n")>
  95. | <FORMAL_COMMENT: "/**" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/">
  96. | <MULTI_LINE_COMMENT: "/*" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/">
  97. }
  98. TOKEN : /* RESERVED WORDS AND LITERALS */
  99. {
  100. < BOOLEAN: "boolean" >
  101. | < BREAK: "break" >
  102. | < CLASS: "class" >
  103. | < BYTE: "byte" >
  104. | < CASE: "case" >
  105. | < CATCH: "catch" >
  106. | < CHAR: "char" >
  107. | < CONST: "const" >
  108. | < CONTINUE: "continue" >
  109. | < _DEFAULT: "default" >
  110. | < DO: "do" >
  111. | < DOUBLE: "double" >
  112. | < ELSE: "else" >
  113. | < FALSE: "false" >
  114. | < FINAL: "final" >
  115. | < FINALLY: "finally" >
  116. | < FLOAT: "float" >
  117. | < FOR: "for" >
  118. | < GOTO: "goto" >
  119. | < IF: "if" >
  120. | < IMPORT: "import" >
  121. | < INSTANCEOF: "instanceof" >
  122. | < INT: "int" >
  123. | < INTERFACE: "interface" >
  124. | < LONG: "long" >
  125. | < NEW: "new" >
  126. | < NULL: "null" >
  127. | < PRIVATE: "private" >
  128. | < PROTECTED: "protected" >
  129. | < PUBLIC: "public" >
  130. | < RETURN: "return" >
  131. | < SHORT: "short" >
  132. | < STATIC: "static" >
  133. | < SWITCH: "switch" >
  134. | < THROW: "throw" >
  135. | < TRUE: "true" >
  136. | < TRY: "try" >
  137. | < VOID: "void" >
  138. | < WHILE: "while" >
  139. }
  140. TOKEN : /* LITERALS */
  141. {
  142. < INTEGER_LITERAL:
  143. <DECIMAL_LITERAL> (["l","L"])?
  144. | <HEX_LITERAL> (["l","L"])?
  145. | <OCTAL_LITERAL> (["l","L"])?
  146. >
  147. |
  148. < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
  149. |
  150. < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
  151. |
  152. < #OCTAL_LITERAL: "0" (["0"-"7"])* >
  153. |
  154. < FLOATING_POINT_LITERAL:
  155. (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
  156. | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
  157. | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
  158. | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
  159. >
  160. |
  161. < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
  162. |
  163. < CHARACTER_LITERAL:
  164. "'"
  165. ( (~["'","\\","\n","\r"])
  166. | ("\\"
  167. ( ["n","t","b","r","f","\\","'","\""]
  168. | ["0"-"7"] ( ["0"-"7"] )?
  169. | ["0"-"3"] ["0"-"7"] ["0"-"7"]
  170. )
  171. )
  172. )
  173. "'"
  174. >
  175. |
  176. < STRING_LITERAL:
  177. "\""
  178. ( (~["\"","\\","\n","\r"])
  179. | ("\\"
  180. ( ["n","t","b","r","f","\\","'","\""]
  181. | ["0"-"7"] ( ["0"-"7"] )?
  182. | ["0"-"3"] ["0"-"7"] ["0"-"7"]
  183. )
  184. )
  185. )*
  186. "\""
  187. >
  188. }
  189. TOKEN : /* IDENTIFIERS */
  190. {
  191. < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* >
  192. |
  193. < #LETTER:
  194. [
  195. "$",
  196. "A"-"Z",
  197. "_",
  198. "a"-"z",
  199. "\u00c0"-"\u00d6",
  200. "\u00d8"-"\u00f6",
  201. "\u00f8"-"\u00ff",
  202. "\u0100"-"\u1fff",
  203. "\u3040"-"\u318f",
  204. "\u3300"-"\u337f",
  205. "\u3400"-"\u3d2d",
  206. "\u4e00"-"\u9fff",
  207. "\uf900"-"\ufaff"
  208. ]
  209. >
  210. |
  211. < #DIGIT:
  212. [
  213. "0"-"9",
  214. "\u0660"-"\u0669",
  215. "\u06f0"-"\u06f9",
  216. "\u0966"-"\u096f",
  217. "\u09e6"-"\u09ef",
  218. "\u0a66"-"\u0a6f",
  219. "\u0ae6"-"\u0aef",
  220. "\u0b66"-"\u0b6f",
  221. "\u0be7"-"\u0bef",
  222. "\u0c66"-"\u0c6f",
  223. "\u0ce6"-"\u0cef",
  224. "\u0d66"-"\u0d6f",
  225. "\u0e50"-"\u0e59",
  226. "\u0ed0"-"\u0ed9",
  227. "\u1040"-"\u1049"
  228. ]
  229. >
  230. }
  231. TOKEN : /* SEPARATORS */
  232. {
  233. < LPAREN: "(" >
  234. | < RPAREN: ")" >
  235. | < LBRACE: "{" >
  236. | < RBRACE: "}" >
  237. | < LBRACKET: "[" >
  238. | < RBRACKET: "]" >
  239. | < SEMICOLON: ";" >
  240. | < COMMA: "," >
  241. | < DOT: "." >
  242. }
  243. TOKEN : /* OPERATORS */
  244. {
  245. < ASSIGN: "=" >
  246. | < GT: ">" >
  247. | < GTX: "@gt" >
  248. | < LT: "<" >
  249. | < LTX: "@lt" >
  250. | < BANG: "!" >
  251. | < TILDE: "~" >
  252. | < HOOK: "?" >
  253. | < COLON: ":" >
  254. | < EQ: "==" >
  255. | < LE: "<=" >
  256. | < LEX: "@lteq" >
  257. | < GE: ">=" >
  258. | < GEX: "@gteq" >
  259. | < NE: "!=" >
  260. | < BOOL_OR: "||" >
  261. | < BOOL_ORX: "@or" >
  262. | < BOOL_AND: "&&" >
  263. | < BOOL_ANDX: "@and" >
  264. | < INCR: "++" >
  265. | < DECR: "--" >
  266. | < PLUS: "+" >
  267. | < MINUS: "-" >
  268. | < STAR: "*" >
  269. | < SLASH: "/" >
  270. | < BIT_AND: "&" >
  271. | < BIT_ANDX: "@bitwise_and" >
  272. | < BIT_OR: "|" >
  273. | < BIT_ORX: "@bitwise_or" >
  274. | < XOR: "^" >
  275. | < MOD: "%" >
  276. | < LSHIFT: "<<" >
  277. | < LSHIFTX: "@left_shift" >
  278. | < RSIGNEDSHIFT: ">>" >
  279. | < RSIGNEDSHIFTX: "@right_shift" >
  280. | < RUNSIGNEDSHIFT: ">>>" >
  281. | < RUNSIGNEDSHIFTX: "@right_unsigned_shift" >
  282. | < PLUSASSIGN: "+=" >
  283. | < MINUSASSIGN: "-=" >
  284. | < STARASSIGN: "*=" >
  285. | < SLASHASSIGN: "/=" >
  286. | < ANDASSIGN: "&=" >
  287. | < ANDASSIGNX: "@and_assign" >
  288. | < ORASSIGN: "|=" >
  289. | < ORASSIGNX: "@or_assign" >
  290. | < XORASSIGN: "^=" >
  291. | < MODASSIGN: "%=" >
  292. | < LSHIFTASSIGN: "<<=" >
  293. | < LSHIFTASSIGNX: "@left_shift_assign" >
  294. | < RSIGNEDSHIFTASSIGN: ">>=" >
  295. | < RSIGNEDSHIFTASSIGNX: "@right_shift_assign" >
  296. | < RUNSIGNEDSHIFTASSIGN: ">>>=" >
  297. | < RUNSIGNEDSHIFTASSIGNX: "@right_unsigned_shift_assign" >
  298. }
  299. boolean Line() :
  300. {}
  301. {
  302. <EOF> {
  303. Interpreter.debug("End of File!");
  304. return true;
  305. }
  306. |
  307. (
  308. /*
  309. SYNTACTIC_LOOKAHEAD
  310. I'm guessing this is expensive, but I don't know how to work around
  311. it... Is there another syntactic indication that we are working
  312. through an expression as opposed to a statement?
  313. What is the difference? Well, some statements don't require a
  314. semicolon and they don't return vlues... We could probably broaden
  315. bsh to allow everything to return a value, but the semi-colon thing
  316. is tougher. You don't want to have to say if ( foo ) { } ;
  317. Maybe we can invert ths and enumerate all of those types of
  318. statements in a special lookahead that's cheaper??
  319. */
  320. LOOKAHEAD( Expression() ";" )
  321. Expression() ";"
  322. |
  323. BlockStatement()
  324. )
  325. {
  326. return false;
  327. }
  328. }
  329. /*****************************************
  330. * THE JAVA LANGUAGE GRAMMAR STARTS HERE *
  331. *****************************************/
  332. void MethodDeclaration() :
  333. {/*@bgen(jjtree) MethodDeclaration */
  334. BSHMethodDeclaration jjtn000 = new BSHMethodDeclaration(JJTMETHODDECLARATION);
  335. boolean jjtc000 = true;
  336. jjtree.openNodeScope(jjtn000);
  337. jjtreeOpenNodeScope(jjtn000);
  338. /*@egen*/ Token t = null; }
  339. {/*@bgen(jjtree) MethodDeclaration */
  340. try {
  341. /*@egen*/
  342. // SYNTACTIC_LOOKAHEAD
  343. // this one seems cheap enough
  344. LOOKAHEAD( MethodDeclarationTypeLookahead() )
  345. ReturnType() t = <IDENTIFIER> { jjtn000.name = t.image; }
  346. FormalParameters() Block()
  347. |
  348. t = <IDENTIFIER> { jjtn000.name = t.image; }
  349. FormalParameters() Block()/*@bgen(jjtree)*/
  350. } catch (Throwable jjte000) {
  351. if (jjtc000) {
  352. jjtree.clearNodeScope(jjtn000);
  353. jjtc000 = false;
  354. } else {
  355. jjtree.popNode();
  356. }
  357. if (jjte000 instanceof RuntimeException) {
  358. throw (RuntimeException)jjte000;
  359. }
  360. if (jjte000 instanceof ParseException) {
  361. throw (ParseException)jjte000;
  362. }
  363. throw (Error)jjte000;
  364. } finally {
  365. if (jjtc000) {
  366. jjtree.closeNodeScope(jjtn000, true);
  367. jjtreeCloseNodeScope(jjtn000);
  368. }
  369. }
  370. /*@egen*/
  371. }
  372. void MethodDeclarationLookahead() : { }
  373. {
  374. // SYNTACTIC_LOOKAHEAD
  375. // this one seems cheap enough
  376. LOOKAHEAD( MethodDeclarationTypeLookahead() )
  377. ReturnType() <IDENTIFIER> FormalParameters() "{"
  378. |
  379. <IDENTIFIER> FormalParameters() "{"
  380. }
  381. void MethodDeclarationTypeLookahead() : { }
  382. {
  383. ReturnType() <IDENTIFIER> "("
  384. }
  385. void ImportDeclaration() :
  386. {/*@bgen(jjtree) ImportDeclaration */
  387. BSHImportDeclaration jjtn000 = new BSHImportDeclaration(JJTIMPORTDECLARATION);
  388. boolean jjtc000 = true;
  389. jjtree.openNodeScope(jjtn000);
  390. jjtreeOpenNodeScope(jjtn000);
  391. /*@egen*/
  392. Token t = null;
  393. }
  394. {/*@bgen(jjtree) ImportDeclaration */
  395. try {
  396. /*@egen*/
  397. LOOKAHEAD( 2 )
  398. "import" AmbiguousName() [ t = "." "*" ] ";"/*@bgen(jjtree)*/
  399. {
  400. jjtree.closeNodeScope(jjtn000, true);
  401. jjtc000 = false;
  402. jjtreeCloseNodeScope(jjtn000);
  403. }
  404. /*@egen*/ {
  405. if ( t != null )
  406. jjtn000.importPackage = true;
  407. }
  408. |
  409. // bsh super import statement
  410. "import" "*" ";"/*@bgen(jjtree)*/
  411. {
  412. jjtree.closeNodeScope(jjtn000, true);
  413. jjtc000 = false;
  414. jjtreeCloseNodeScope(jjtn000);
  415. }
  416. /*@egen*/ {
  417. jjtn000.superImport = true;
  418. }/*@bgen(jjtree)*/
  419. } catch (Throwable jjte000) {
  420. if (jjtc000) {
  421. jjtree.clearNodeScope(jjtn000);
  422. jjtc000 = false;
  423. } else {
  424. jjtree.popNode();
  425. }
  426. if (jjte000 instanceof RuntimeException) {
  427. throw (RuntimeException)jjte000;
  428. }
  429. if (jjte000 instanceof ParseException) {
  430. throw (ParseException)jjte000;
  431. }
  432. throw (Error)jjte000;
  433. } finally {
  434. if (jjtc000) {
  435. jjtree.closeNodeScope(jjtn000, true);
  436. jjtreeCloseNodeScope(jjtn000);
  437. }
  438. }
  439. /*@egen*/
  440. }
  441. void VariableDeclarator() :
  442. {/*@bgen(jjtree) VariableDeclarator */
  443. BSHVariableDeclarator jjtn000 = new BSHVariableDeclarator(JJTVARIABLEDECLARATOR);
  444. boolean jjtc000 = true;
  445. jjtree.openNodeScope(jjtn000);
  446. jjtreeOpenNodeScope(jjtn000);
  447. /*@egen*/ Token t; }
  448. {/*@bgen(jjtree) VariableDeclarator */
  449. try {
  450. /*@egen*/
  451. t=<IDENTIFIER> [ "=" VariableInitializer() ]/*@bgen(jjtree)*/
  452. {
  453. jjtree.closeNodeScope(jjtn000, true);
  454. jjtc000 = false;
  455. jjtreeCloseNodeScope(jjtn000);
  456. }
  457. /*@egen*/ { jjtn000.name = t.image; }/*@bgen(jjtree)*/
  458. } catch (Throwable jjte000) {
  459. if (jjtc000) {
  460. jjtree.clearNodeScope(jjtn000);
  461. jjtc000 = false;
  462. } else {
  463. jjtree.popNode();
  464. }
  465. if (jjte000 instanceof RuntimeException) {
  466. throw (RuntimeException)jjte000;
  467. }
  468. if (jjte000 instanceof ParseException) {
  469. throw (ParseException)jjte000;
  470. }
  471. throw (Error)jjte000;
  472. } finally {
  473. if (jjtc000) {
  474. jjtree.closeNodeScope(jjtn000, true);
  475. jjtreeCloseNodeScope(jjtn000);
  476. }
  477. }
  478. /*@egen*/
  479. }
  480. /*
  481. Can get rid of this if we ignore postfix array dimensions in declarations.
  482. I don't like them and I don't want to deal with them right now.
  483. void VariableDeclaratorId() #VariableDeclaratorId :
  484. { Token t; }
  485. {
  486. t=<IDENTIFIER> { jjtThis.name = t.image; }
  487. ( "[" "]" { jjtThis.addArrayDimension(); } )*
  488. }
  489. */
  490. void VariableInitializer() :
  491. {}
  492. {
  493. ArrayInitializer()
  494. |
  495. Expression()
  496. }
  497. void ArrayInitializer() :
  498. {/*@bgen(jjtree) ArrayInitializer */
  499. BSHArrayInitializer jjtn000 = new BSHArrayInitializer(JJTARRAYINITIALIZER);
  500. boolean jjtc000 = true;
  501. jjtree.openNodeScope(jjtn000);
  502. jjtreeOpenNodeScope(jjtn000);
  503. /*@egen*/}
  504. {/*@bgen(jjtree) ArrayInitializer */
  505. try {
  506. /*@egen*/
  507. "{" [ VariableInitializer()
  508. ( LOOKAHEAD(2) "," VariableInitializer() )* ] [ "," ] "}"/*@bgen(jjtree)*/
  509. } catch (Throwable jjte000) {
  510. if (jjtc000) {
  511. jjtree.clearNodeScope(jjtn000);
  512. jjtc000 = false;
  513. } else {
  514. jjtree.popNode();
  515. }
  516. if (jjte000 instanceof RuntimeException) {
  517. throw (RuntimeException)jjte000;
  518. }
  519. if (jjte000 instanceof ParseException) {
  520. throw (ParseException)jjte000;
  521. }
  522. throw (Error)jjte000;
  523. } finally {
  524. if (jjtc000) {
  525. jjtree.closeNodeScope(jjtn000, true);
  526. jjtreeCloseNodeScope(jjtn000);
  527. }
  528. }
  529. /*@egen*/
  530. }
  531. void FormalParameters() :
  532. {/*@bgen(jjtree) FormalParameters */
  533. BSHFormalParameters jjtn000 = new BSHFormalParameters(JJTFORMALPARAMETERS);
  534. boolean jjtc000 = true;
  535. jjtree.openNodeScope(jjtn000);
  536. jjtreeOpenNodeScope(jjtn000);
  537. /*@egen*/}
  538. {/*@bgen(jjtree) FormalParameters */
  539. try {
  540. /*@egen*/
  541. "(" [ FormalParameter() ( "," FormalParameter() )* ] ")"/*@bgen(jjtree)*/
  542. } catch (Throwable jjte000) {
  543. if (jjtc000) {
  544. jjtree.clearNodeScope(jjtn000);
  545. jjtc000 = false;
  546. } else {
  547. jjtree.popNode();
  548. }
  549. if (jjte000 instanceof RuntimeException) {
  550. throw (RuntimeException)jjte000;
  551. }
  552. if (jjte000 instanceof ParseException) {
  553. throw (ParseException)jjte000;
  554. }
  555. throw (Error)jjte000;
  556. } finally {
  557. if (jjtc000) {
  558. jjtree.closeNodeScope(jjtn000, true);
  559. jjtreeCloseNodeScope(jjtn000);
  560. }
  561. }
  562. /*@egen*/
  563. }
  564. /*
  565. void FormalParameter() #FormalParameter :
  566. { Token t; }
  567. {
  568. // added [] to Type for bsh. Removed [ final ] - is that legal?
  569. [ LOOKAHEAD(2) Type() ] t=<IDENTIFIER> { jjtThis.name = t.image; }
  570. }
  571. */
  572. void FormalParameter() :
  573. {/*@bgen(jjtree) FormalParameter */
  574. BSHFormalParameter jjtn000 = new BSHFormalParameter(JJTFORMALPARAMETER);
  575. boolean jjtc000 = true;
  576. jjtree.openNodeScope(jjtn000);
  577. jjtreeOpenNodeScope(jjtn000);
  578. /*@egen*/ Token t; }
  579. {/*@bgen(jjtree) FormalParameter */
  580. try {
  581. /*@egen*/
  582. // added [] to Type for bsh. Removed [ final ] - is that legal?
  583. LOOKAHEAD(2) Type() t=<IDENTIFIER>/*@bgen(jjtree)*/
  584. {
  585. jjtree.closeNodeScope(jjtn000, true);
  586. jjtc000 = false;
  587. jjtreeCloseNodeScope(jjtn000);
  588. }
  589. /*@egen*/ { jjtn000.name = t.image; }
  590. |
  591. t=<IDENTIFIER>/*@bgen(jjtree)*/
  592. {
  593. jjtree.closeNodeScope(jjtn000, true);
  594. jjtc000 = false;
  595. jjtreeCloseNodeScope(jjtn000);
  596. }
  597. /*@egen*/ { jjtn000.name = t.image; }/*@bgen(jjtree)*/
  598. } catch (Throwable jjte000) {
  599. if (jjtc000) {
  600. jjtree.clearNodeScope(jjtn000);
  601. jjtc000 = false;
  602. } else {
  603. jjtree.popNode();
  604. }
  605. if (jjte000 instanceof RuntimeException) {
  606. throw (RuntimeException)jjte000;
  607. }
  608. if (jjte000 instanceof ParseException) {
  609. throw (ParseException)jjte000;
  610. }
  611. throw (Error)jjte000;
  612. } finally {
  613. if (jjtc000) {
  614. jjtree.closeNodeScope(jjtn000, true);
  615. jjtreeCloseNodeScope(jjtn000);
  616. }
  617. }
  618. /*@egen*/
  619. }
  620. /*
  621. Type, name and expression syntax follows.
  622. */
  623. void Type() :
  624. {/*@bgen(jjtree) Type */
  625. BSHType jjtn000 = new BSHType(JJTTYPE);
  626. boolean jjtc000 = true;
  627. jjtree.openNodeScope(jjtn000);
  628. jjtreeOpenNodeScope(jjtn000);
  629. /*@egen*/ }
  630. {/*@bgen(jjtree) Type */
  631. try {
  632. /*@egen*/
  633. /*
  634. The embedded lookahead is (was?) necessary to disambiguate for
  635. PrimaryPrefix. ( )* is a choice point. It took me a while to
  636. figure out where to put that. This stuff is annoying.
  637. */
  638. ( PrimitiveType() | AmbiguousName() )
  639. ( LOOKAHEAD(2) "[" "]" { jjtn000.addArrayDimension(); } )*/*@bgen(jjtree)*/
  640. } catch (Throwable jjte000) {
  641. if (jjtc000) {
  642. jjtree.clearNodeScope(jjtn000);
  643. jjtc000 = false;
  644. } else {
  645. jjtree.popNode();
  646. }
  647. if (jjte000 instanceof RuntimeException) {
  648. throw (RuntimeException)jjte000;
  649. }
  650. if (jjte000 instanceof ParseException) {
  651. throw (ParseException)jjte000;
  652. }
  653. throw (Error)jjte000;
  654. } finally {
  655. if (jjtc000) {
  656. jjtree.closeNodeScope(jjtn000, true);
  657. jjtreeCloseNodeScope(jjtn000);
  658. }
  659. }
  660. /*@egen*/
  661. }
  662. /*
  663. Originally called ResultType in the grammar
  664. */
  665. void ReturnType() :
  666. {/*@bgen(jjtree) ReturnType */
  667. BSHReturnType jjtn000 = new BSHReturnType(JJTRETURNTYPE);
  668. boolean jjtc000 = true;
  669. jjtree.openNodeScope(jjtn000);
  670. jjtreeOpenNodeScope(jjtn000);
  671. /*@egen*/ }
  672. {/*@bgen(jjtree) ReturnType */
  673. try {
  674. /*@egen*/
  675. "void"/*@bgen(jjtree)*/
  676. {
  677. jjtree.closeNodeScope(jjtn000, true);
  678. jjtc000 = false;
  679. jjtreeCloseNodeScope(jjtn000);
  680. }
  681. /*@egen*/ { jjtn000.isVoid = true; }
  682. |
  683. Type()/*@bgen(jjtree)*/
  684. } catch (Throwable jjte000) {
  685. if (jjtc000) {
  686. jjtree.clearNodeScope(jjtn000);
  687. jjtc000 = false;
  688. } else {
  689. jjtree.popNode();
  690. }
  691. if (jjte000 instanceof RuntimeException) {
  692. throw (RuntimeException)jjte000;
  693. }
  694. if (jjte000 instanceof ParseException) {
  695. throw (ParseException)jjte000;
  696. }
  697. throw (Error)jjte000;
  698. } finally {
  699. if (jjtc000) {
  700. jjtree.closeNodeScope(jjtn000, true);
  701. jjtreeCloseNodeScope(jjtn000);
  702. }
  703. }
  704. /*@egen*/
  705. }
  706. void PrimitiveType() :
  707. {/*@bgen(jjtree) PrimitiveType */
  708. BSHPrimitiveType jjtn000 = new BSHPrimitiveType(JJTPRIMITIVETYPE);
  709. boolean jjtc000 = true;
  710. jjtree.openNodeScope(jjtn000);
  711. jjtreeOpenNodeScope(jjtn000);
  712. /*@egen*/ } {/*@bgen(jjtree) PrimitiveType */
  713. try {
  714. /*@egen*/
  715. "boolean"/*@bgen(jjtree)*/
  716. {
  717. jjtree.closeNodeScope(jjtn000, true);
  718. jjtc000 = false;
  719. jjtreeCloseNodeScope(jjtn000);
  720. }
  721. /*@egen*/ { jjtn000.type = Boolean.TYPE; }
  722. | "char"/*@bgen(jjtree)*/
  723. {
  724. jjtree.closeNodeScope(jjtn000, true);
  725. jjtc000 = false;
  726. jjtreeCloseNodeScope(jjtn000);
  727. }
  728. /*@egen*/ { jjtn000.type = Character.TYPE; }
  729. | "byte"/*@bgen(jjtree)*/
  730. {
  731. jjtree.closeNodeScope(jjtn000, true);
  732. jjtc000 = false;
  733. jjtreeCloseNodeScope(jjtn000);
  734. }
  735. /*@egen*/ { jjtn000.type = Byte.TYPE; }
  736. | "short"/*@bgen(jjtree)*/
  737. {
  738. jjtree.closeNodeScope(jjtn000, true);
  739. jjtc000 = false;
  740. jjtreeCloseNodeScope(jjtn000);
  741. }
  742. /*@egen*/ { jjtn000.type = Short.TYPE; }
  743. | "int"/*@bgen(jjtree)*/
  744. {
  745. jjtree.closeNodeScope(jjtn000, true);
  746. jjtc000 = false;
  747. jjtreeCloseNodeScope(jjtn000);
  748. }
  749. /*@egen*/ { jjtn000.type = Integer.TYPE; }
  750. | "long"/*@bgen(jjtree)*/
  751. {
  752. jjtree.closeNodeScope(jjtn000, true);
  753. jjtc000 = false;
  754. jjtreeCloseNodeScope(jjtn000);
  755. }
  756. /*@egen*/ { jjtn000.type = Long.TYPE; }
  757. | "float"/*@bgen(jjtree)*/
  758. {
  759. jjtree.closeNodeScope(jjtn000, true);
  760. jjtc000 = false;
  761. jjtreeCloseNodeScope(jjtn000);
  762. }
  763. /*@egen*/ { jjtn000.type = Float.TYPE; }
  764. | "double"/*@bgen(jjtree)*/
  765. {
  766. jjtree.closeNodeScope(jjtn000, true);
  767. jjtc000 = false;
  768. jjtreeCloseNodeScope(jjtn000);
  769. }
  770. /*@egen*/ { jjtn000.type = Double.TYPE; }/*@bgen(jjtree)*/
  771. } finally {
  772. if (jjtc000) {
  773. jjtree.closeNodeScope(jjtn000, true);
  774. jjtreeCloseNodeScope(jjtn000);
  775. }
  776. }
  777. /*@egen*/
  778. }
  779. void AmbiguousName() :
  780. /*
  781. * A lookahead of 2 is required below since "Name" can be followed
  782. * by a ".*" when used in the context of an "ImportDeclaration".
  783. */
  784. {/*@bgen(jjtree) AmbiguousName */
  785. BSHAmbiguousName jjtn000 = new BSHAmbiguousName(JJTAMBIGUOUSNAME);
  786. boolean jjtc000 = true;
  787. jjtree.openNodeScope(jjtn000);
  788. jjtreeOpenNodeScope(jjtn000);
  789. /*@egen*/
  790. Token t;
  791. StringBuffer s;
  792. }
  793. {/*@bgen(jjtree) AmbiguousName */
  794. try {
  795. /*@egen*/
  796. t = <IDENTIFIER> {
  797. s = new StringBuffer(t.image);
  798. }
  799. ( LOOKAHEAD(2) "." t = <IDENTIFIER> {
  800. s.append("."+t.image);
  801. }
  802. )*/*@bgen(jjtree)*/
  803. {
  804. jjtree.closeNodeScope(jjtn000, true);
  805. jjtc000 = false;
  806. jjtreeCloseNodeScope(jjtn000);
  807. }
  808. /*@egen*/ {
  809. jjtn000.text = s.toString();
  810. }/*@bgen(jjtree)*/
  811. } finally {
  812. if (jjtc000) {
  813. jjtree.closeNodeScope(jjtn000, true);
  814. jjtreeCloseNodeScope(jjtn000);
  815. }
  816. }
  817. /*@egen*/
  818. }
  819. /*
  820. * Expression syntax follows.
  821. */
  822. void Expression() :
  823. { }
  824. {
  825. /**
  826. SYNTACTIC_LOOKAHEAD
  827. This is probably expensive. Can we simplify it somehow?
  828. */
  829. LOOKAHEAD( LHSPrimaryExpression() AssignmentOperator() )
  830. Assignment()
  831. |
  832. ConditionalExpression()
  833. }
  834. void Assignment() :
  835. {/*@bgen(jjtree) Assignment */
  836. BSHAssignment jjtn000 = new BSHAssignment(JJTASSIGNMENT);
  837. boolean jjtc000 = true;
  838. jjtree.openNodeScope(jjtn000);
  839. jjtreeOpenNodeScope(jjtn000);
  840. /*@egen*/ int op ; }
  841. {/*@bgen(jjtree) Assignment */
  842. try {
  843. /*@egen*/
  844. LHSPrimaryExpression()
  845. op = AssignmentOperator() {
  846. jjtn000.operator = op;
  847. }
  848. Expression()/*@bgen(jjtree)*/
  849. } catch (Throwable jjte000) {
  850. if (jjtc000) {
  851. jjtree.clearNodeScope(jjtn000);
  852. jjtc000 = false;
  853. } else {
  854. jjtree.popNode();
  855. }
  856. if (jjte000 instanceof RuntimeException) {
  857. throw (RuntimeException)jjte000;
  858. }
  859. if (jjte000 instanceof ParseException) {
  860. throw (ParseException)jjte000;
  861. }
  862. throw (Error)jjte000;
  863. } finally {
  864. if (jjtc000) {
  865. jjtree.closeNodeScope(jjtn000, true);
  866. jjtreeCloseNodeScope(jjtn000);
  867. }
  868. }
  869. /*@egen*/
  870. }
  871. int AssignmentOperator() :
  872. { Token t; }
  873. {
  874. ( "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "&=" | "^=" | "|=" |
  875. "<<=" | "@left_shift_assign" | ">>=" | "@right_shift_assign" |
  876. ">>>=" | "@right_unsigned_shift_assign" )
  877. {
  878. t = getToken(0);
  879. return t.kind;
  880. }
  881. }
  882. void ConditionalExpression() :
  883. { }
  884. {
  885. ConditionalOrExpression() [ "?" Expression() ":"/*@bgen(jjtree) #TernaryExpression( 3) */
  886. {
  887. BSHTernaryExpression jjtn001 = new BSHTernaryExpression(JJTTERNARYEXPRESSION);
  888. boolean jjtc001 = true;
  889. jjtree.openNodeScope(jjtn001);
  890. jjtreeOpenNodeScope(jjtn001);
  891. }
  892. try {
  893. /*@egen*/ ConditionalExpression()/*@bgen(jjtree)*/
  894. } catch (Throwable jjte001) {
  895. if (jjtc001) {
  896. jjtree.clearNodeScope(jjtn001);
  897. jjtc001 = false;
  898. } else {
  899. jjtree.popNode();
  900. }
  901. if (jjte001 instanceof RuntimeException) {
  902. throw (RuntimeException)jjte001;
  903. }
  904. if (jjte001 instanceof ParseException) {
  905. throw (ParseException)jjte001;
  906. }
  907. throw (Error)jjte001;
  908. } finally {
  909. if (jjtc001) {
  910. jjtree.closeNodeScope(jjtn001, 3);
  911. jjtreeCloseNodeScope(jjtn001);
  912. }
  913. }
  914. /*@egen*/ ]
  915. }
  916. void ConditionalOrExpression() :
  917. { Token t=null; }
  918. {
  919. ConditionalAndExpression()
  920. ( ( t = "||" | t = "@or" )
  921. ConditionalAndExpression()/*@bgen(jjtree) #BinaryExpression( 2) */
  922. {
  923. BSHBinaryExpression jjtn001 = new BSHBinaryExpression(JJTBINARYEXPRESSION);
  924. boolean jjtc001 = true;
  925. jjtree.openNodeScope(jjtn001);
  926. jjtreeOpenNodeScope(jjtn001);
  927. }
  928. try {
  929. /*@egen*//*@bgen(jjtree)*/
  930. {
  931. jjtree.closeNodeScope(jjtn001, 2);
  932. jjtc001 = false;
  933. jjtreeCloseNodeScope(jjtn001);
  934. }
  935. /*@egen*/
  936. { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  937. } finally {
  938. if (jjtc001) {
  939. jjtree.closeNodeScope(jjtn001, 2);
  940. jjtreeCloseNodeScope(jjtn001);
  941. }
  942. }
  943. /*@egen*/ )*
  944. }
  945. void ConditionalAndExpression() :
  946. { Token t=null; }
  947. {
  948. InclusiveOrExpression()
  949. ( ( t = "&&" | t = "@and" )
  950. InclusiveOrExpression()/*@bgen(jjtree) #BinaryExpression( 2) */
  951. {
  952. BSHBinaryExpression jjtn001 = new BSHBinaryExpression(JJTBINARYEXPRESSION);
  953. boolean jjtc001 = true;
  954. jjtree.openNodeScope(jjtn001);
  955. jjtreeOpenNodeScope(jjtn001);
  956. }
  957. try {
  958. /*@egen*//*@bgen(jjtree)*/
  959. {
  960. jjtree.closeNodeScope(jjtn001, 2);
  961. jjtc001 = false;
  962. jjtreeCloseNodeScope(jjtn001);
  963. }
  964. /*@egen*/
  965. { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  966. } finally {
  967. if (jjtc001) {
  968. jjtree.closeNodeScope(jjtn001, 2);
  969. jjtreeCloseNodeScope(jjtn001);
  970. }
  971. }
  972. /*@egen*/ )*
  973. }
  974. void InclusiveOrExpression() :
  975. { Token t=null; }
  976. {
  977. ExclusiveOrExpression()
  978. ( ( t = "|" | t = "@bitwise_or" )
  979. ExclusiveOrExpression()/*@bgen(jjtree) #BinaryExpression( 2) */
  980. {
  981. BSHBinaryExpression jjtn001 = new BSHBinaryExpression(JJTBINARYEXPRESSION);
  982. boolean jjtc001 = true;
  983. jjtree.openNodeScope(jjtn001);
  984. jjtreeOpenNodeScope(jjtn001);
  985. }
  986. try {
  987. /*@egen*//*@bgen(jjtree)*/
  988. {
  989. jjtree.closeNodeScope(jjtn001, 2);
  990. jjtc001 = false;
  991. jjtreeCloseNodeScope(jjtn001);
  992. }
  993. /*@egen*/
  994. { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  995. } finally {
  996. if (jjtc001) {
  997. jjtree.closeNodeScope(jjtn001, 2);
  998. jjtreeCloseNodeScope(jjtn001);
  999. }
  1000. }
  1001. /*@egen*/ )*
  1002. }
  1003. void ExclusiveOrExpression() :
  1004. { Token t=null; }
  1005. {
  1006. AndExpression() ( t="^" AndExpression()/*@bgen(jjtree) #BinaryExpression( 2) */
  1007. {
  1008. BSHBinaryExpression jjtn001 = new BSHBinaryExpression(JJTBINARYEXPRESSION);
  1009. boolean jjtc001 = true;
  1010. jjtree.openNodeScope(jjtn001);
  1011. jjtreeOpenNodeScope(jjtn001);
  1012. }
  1013. try {
  1014. /*@egen*//*@bgen(jjtree)*/
  1015. {
  1016. jjtree.closeNodeScope(jjtn001, 2);
  1017. jjtc001 = false;
  1018. jjtreeCloseNodeScope(jjtn001);
  1019. }
  1020. /*@egen*/
  1021. { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  1022. } finally {
  1023. if (jjtc001) {
  1024. jjtree.closeNodeScope(jjtn001, 2);
  1025. jjtreeCloseNodeScope(jjtn001);
  1026. }
  1027. }
  1028. /*@egen*/ )*
  1029. }
  1030. void AndExpression() :
  1031. { Token t=null; }
  1032. {
  1033. EqualityExpression()
  1034. ( ( t = "&" | t = "@bitwise_and" )
  1035. EqualityExpression()/*@bgen(jjtree) #BinaryExpression( 2) */
  1036. {
  1037. BSHBinaryExpression jjtn001 = new BSHBinaryExpression(JJTBINARYEXPRESSION);
  1038. boolean jjtc001 = true;
  1039. jjtree.openNodeScope(jjtn001);
  1040. jjtreeOpenNodeScope(jjtn001);
  1041. }
  1042. try {
  1043. /*@egen*//*@bgen(jjtree)*/
  1044. {
  1045. jjtree.closeNodeScope(jjtn001, 2);
  1046. jjtc001 = false;
  1047. jjtreeCloseNodeScope(jjtn001);
  1048. }
  1049. /*@egen*/
  1050. { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  1051. } finally {
  1052. if (jjtc001) {
  1053. jjtree.closeNodeScope(jjtn001, 2);
  1054. jjtreeCloseNodeScope(jjtn001);
  1055. }
  1056. }
  1057. /*@egen*/ )*
  1058. }
  1059. void EqualityExpression() :
  1060. { Token t = null; }
  1061. {
  1062. InstanceOfExpression() ( ( t= "==" | t= "!=" ) InstanceOfExpression()/*@bgen(jjtree) #BinaryExpression( 2) */
  1063. {
  1064. BSHBinaryExpression jjtn001 = new BSHBinaryExpression(JJTBINARYEXPRESSION);
  1065. boolean jjtc001 = true;
  1066. jjtree.openNodeScope(jjtn001);
  1067. jjtreeOpenNodeScope(jjtn001);
  1068. }
  1069. try {
  1070. /*@egen*//*@bgen(jjtree)*/
  1071. {
  1072. jjtree.closeNodeScope(jjtn001, 2);
  1073. jjtc001 = false;
  1074. jjtreeCloseNodeScope(jjtn001);
  1075. }
  1076. /*@egen*/
  1077. { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  1078. } finally {
  1079. if (jjtc001) {
  1080. jjtree.closeNodeScope(jjtn001, 2);
  1081. jjtreeCloseNodeScope(jjtn001);
  1082. }
  1083. }
  1084. /*@egen*/
  1085. )*
  1086. }
  1087. void InstanceOfExpression() :
  1088. { Token t = null; }
  1089. {
  1090. RelationalExpression()
  1091. [ t = "instanceof" Type()/*@bgen(jjtree) #BinaryExpression( 2) */
  1092. {
  1093. BSHBinaryExpression jjtn001 = new BSHBinaryExpression(JJTBINARYEXPRESSION);
  1094. boolean jjtc001 = true;
  1095. jjtree.openNodeScope(jjtn001);
  1096. jjtreeOpenNodeScope(jjtn001);
  1097. }
  1098. try {
  1099. /*@egen*//*@bgen(jjtree)*/
  1100. {
  1101. jjtree.closeNodeScope(jjtn001, 2);
  1102. jjtc001 = false;
  1103. jjtreeCloseNodeScope(jjtn001);
  1104. }
  1105. /*@egen*/ { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  1106. } finally {
  1107. if (jjtc001) {
  1108. jjtree.closeNodeScope(jjtn001, 2);
  1109. jjtreeCloseNodeScope(jjtn001);
  1110. }
  1111. }
  1112. /*@egen*/ ]
  1113. }
  1114. void RelationalExpression() :
  1115. { Token t = null; }
  1116. {
  1117. ShiftExpression()
  1118. ( ( t = "<" | t = "@lt" | t = ">" | t = "@gt" |
  1119. t = "<=" | t = "@lteq" | t = ">=" | t = "@gteq" )
  1120. ShiftExpression()/*@bgen(jjtree) #BinaryExpression( 2) */
  1121. {
  1122. BSHBinaryExpression jjtn001 = new BSHBinaryExpression(JJTBINARYEXPRESSION);
  1123. boolean jjtc001 = true;
  1124. jjtree.openNodeScope(jjtn001);
  1125. jjtreeOpenNodeScope(jjtn001);
  1126. }
  1127. try {
  1128. /*@egen*//*@bgen(jjtree)*/
  1129. {
  1130. jjtree.closeNodeScope(jjtn001, 2);
  1131. jjtc001 = false;
  1132. jjtreeCloseNodeScope(jjtn001);
  1133. }
  1134. /*@egen*/
  1135. { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  1136. } finally {
  1137. if (jjtc001) {
  1138. jjtree.closeNodeScope(jjtn001, 2);
  1139. jjtreeCloseNodeScope(jjtn001);
  1140. }
  1141. }
  1142. /*@egen*/ )*
  1143. }
  1144. void ShiftExpression() :
  1145. { Token t = null; }
  1146. {
  1147. AdditiveExpression()
  1148. ( ( t = "<<" | t = "@left_shift" | t = ">>" | t = "@right_shift" |
  1149. t = ">>>" | t = "@right_unsigned_shift" )
  1150. AdditiveExpression()/*@bgen(jjtree) #BinaryExpression( 2) */
  1151. {
  1152. BSHBinaryExpression jjtn001 = new BSHBinaryExpression(JJTBINARYEXPRESSION);
  1153. boolean jjtc001 = true;
  1154. jjtree.openNodeScope(jjtn001);
  1155. jjtreeOpenNodeScope(jjtn001);
  1156. }
  1157. try {
  1158. /*@egen*//*@bgen(jjtree)*/
  1159. {
  1160. jjtree.closeNodeScope(jjtn001, 2);
  1161. jjtc001 = false;
  1162. jjtreeCloseNodeScope(jjtn001);
  1163. }
  1164. /*@egen*/
  1165. { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  1166. } finally {
  1167. if (jjtc001) {
  1168. jjtree.closeNodeScope(jjtn001, 2);
  1169. jjtreeCloseNodeScope(jjtn001);
  1170. }
  1171. }
  1172. /*@egen*/ )*
  1173. }
  1174. void AdditiveExpression() :
  1175. { Token t = null; }
  1176. {
  1177. MultiplicativeExpression()
  1178. ( ( t= "+" | t= "-" ) MultiplicativeExpression()/*@bgen(jjtree) #BinaryExpression( 2) */
  1179. {
  1180. BSHBinaryExpression jjtn001 = new BSHBinaryExpression(JJTBINARYEXPRESSION);
  1181. boolean jjtc001 = true;
  1182. jjtree.openNodeScope(jjtn001);
  1183. jjtreeOpenNodeScope(jjtn001);
  1184. }
  1185. try {
  1186. /*@egen*//*@bgen(jjtree)*/
  1187. {
  1188. jjtree.closeNodeScope(jjtn001, 2);
  1189. jjtc001 = false;
  1190. jjtreeCloseNodeScope(jjtn001);
  1191. }
  1192. /*@egen*/ { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  1193. } finally {
  1194. if (jjtc001) {
  1195. jjtree.closeNodeScope(jjtn001, 2);
  1196. jjtreeCloseNodeScope(jjtn001);
  1197. }
  1198. }
  1199. /*@egen*/
  1200. )*
  1201. }
  1202. void MultiplicativeExpression() :
  1203. { Token t = null; }
  1204. {
  1205. UnaryExpression() ( ( t= "*" | t= "/" | t= "%" )
  1206. UnaryExpression()/*@bgen(jjtree) #BinaryExpression( 2) */
  1207. {
  1208. BSHBinaryExpression jjtn001 = new BSHBinaryExpression(JJTBINARYEXPRESSION);
  1209. boolean jjtc001 = true;
  1210. jjtree.openNodeScope(jjtn001);
  1211. jjtreeOpenNodeScope(jjtn001);
  1212. }
  1213. try {
  1214. /*@egen*//*@bgen(jjtree)*/
  1215. {
  1216. jjtree.closeNodeScope(jjtn001, 2);
  1217. jjtc001 = false;
  1218. jjtreeCloseNodeScope(jjtn001);
  1219. }
  1220. /*@egen*/ { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  1221. } finally {
  1222. if (jjtc001) {
  1223. jjtree.closeNodeScope(jjtn001, 2);
  1224. jjtreeCloseNodeScope(jjtn001);
  1225. }
  1226. }
  1227. /*@egen*/ )*
  1228. }
  1229. void UnaryExpression() :
  1230. { Token t = null; }
  1231. {
  1232. ( t="+" | t="-" ) UnaryExpression()/*@bgen(jjtree) #UnaryExpression( 1) */
  1233. {
  1234. BSHUnaryExpression jjtn001 = new BSHUnaryExpression(JJTUNARYEXPRESSION);
  1235. boolean jjtc001 = true;
  1236. jjtree.openNodeScope(jjtn001);
  1237. jjtreeOpenNodeScope(jjtn001);
  1238. }
  1239. try {
  1240. /*@egen*//*@bgen(jjtree)*/
  1241. {
  1242. jjtree.closeNodeScope(jjtn001, 1);
  1243. jjtc001 = false;
  1244. jjtreeCloseNodeScope(jjtn001);
  1245. }
  1246. /*@egen*/
  1247. { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  1248. } finally {
  1249. if (jjtc001) {
  1250. jjtree.closeNodeScope(jjtn001, 1);
  1251. jjtreeCloseNodeScope(jjtn001);
  1252. }
  1253. }
  1254. /*@egen*/
  1255. |
  1256. PreIncrementExpression()
  1257. |
  1258. PreDecrementExpression()
  1259. |
  1260. UnaryExpressionNotPlusMinus()
  1261. }
  1262. void PreIncrementExpression() :
  1263. { Token t = null; }
  1264. {
  1265. t="++" LHSPrimaryExpression()/*@bgen(jjtree) #UnaryExpression( 1) */
  1266. {
  1267. BSHUnaryExpression jjtn001 = new BSHUnaryExpression(JJTUNARYEXPRESSION);
  1268. boolean jjtc001 = true;
  1269. jjtree.openNodeScope(jjtn001);
  1270. jjtreeOpenNodeScope(jjtn001);
  1271. }
  1272. try {
  1273. /*@egen*//*@bgen(jjtree)*/
  1274. {
  1275. jjtree.closeNodeScope(jjtn001, 1);
  1276. jjtc001 = false;
  1277. jjtreeCloseNodeScope(jjtn001);
  1278. }
  1279. /*@egen*/
  1280. { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  1281. } finally {
  1282. if (jjtc001) {
  1283. jjtree.closeNodeScope(jjtn001, 1);
  1284. jjtreeCloseNodeScope(jjtn001);
  1285. }
  1286. }
  1287. /*@egen*/
  1288. }
  1289. void PreDecrementExpression() :
  1290. { Token t = null; }
  1291. {
  1292. t="--" LHSPrimaryExpression()/*@bgen(jjtree) #UnaryExpression( 1) */
  1293. {
  1294. BSHUnaryExpression jjtn001 = new BSHUnaryExpression(JJTUNARYEXPRESSION);
  1295. boolean jjtc001 = true;
  1296. jjtree.openNodeScope(jjtn001);
  1297. jjtreeOpenNodeScope(jjtn001);
  1298. }
  1299. try {
  1300. /*@egen*//*@bgen(jjtree)*/
  1301. {
  1302. jjtree.closeNodeScope(jjtn001, 1);
  1303. jjtc001 = false;
  1304. jjtreeCloseNodeScope(jjtn001);
  1305. }
  1306. /*@egen*/
  1307. { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  1308. } finally {
  1309. if (jjtc001) {
  1310. jjtree.closeNodeScope(jjtn001, 1);
  1311. jjtreeCloseNodeScope(jjtn001);
  1312. }
  1313. }
  1314. /*@egen*/
  1315. }
  1316. void UnaryExpressionNotPlusMinus() :
  1317. { Token t = null; }
  1318. {
  1319. ( t="~" | t="!" ) UnaryExpression()/*@bgen(jjtree) #UnaryExpression( 1) */
  1320. {
  1321. BSHUnaryExpression jjtn001 = new BSHUnaryExpression(JJTUNARYEXPRESSION);
  1322. boolean jjtc001 = true;
  1323. jjtree.openNodeScope(jjtn001);
  1324. jjtreeOpenNodeScope(jjtn001);
  1325. }
  1326. try {
  1327. /*@egen*//*@bgen(jjtree)*/
  1328. {
  1329. jjtree.closeNodeScope(jjtn001, 1);
  1330. jjtc001 = false;
  1331. jjtreeCloseNodeScope(jjtn001);
  1332. }
  1333. /*@egen*/
  1334. { jjtn001.kind = t.kind; }/*@bgen(jjtree)*/
  1335. } finally {
  1336. if (jjtc001) {
  1337. jjtree.closeNodeScope(jjtn001, 1);
  1338. jjtreeCloseNodeScope(jjtn001);
  1339. }
  1340. }
  1341. /*@egen*/
  1342. |
  1343. // SYNTACTIC_LOOKAHEAD
  1344. LOOKAHEAD( CastLookahead() ) CastExpression()
  1345. |
  1346. PostfixExpression()
  1347. }
  1348. // This production is to determine lookahead only.
  1349. void CastLookahead() : { }
  1350. {
  1351. LOOKAHEAD(2) "(" PrimitiveType()
  1352. |
  1353. // SYNTACTIC_LOOKAHEAD
  1354. LOOKAHEAD( "(" AmbiguousName() "[" ) "(" AmbiguousName() "[" "]"
  1355. |
  1356. "(" AmbiguousName() ")" ( "~" | "!" | "(" | <IDENTIFIER> | /* "this" | "super" | */ "new" | Literal() )
  1357. }
  1358. void PostfixExpression() :
  1359. { Token t = null; }
  1360. {
  1361. (
  1362. // SYNTACTIC_LOOKAHEAD
  1363. LOOKAHEAD( LHSPrimaryExpression() ("++"|"--") )
  1364. LHSPrimaryExpression()
  1365. [ ( t="++" | t="--" )/*@bgen(jjtree) #UnaryExpression( 1) */
  1366. {
  1367. BSHUnaryExpression jjtn001 = new BSHUnaryExpression(JJTUNARYEXPRESSION);
  1368. boolean jjtc001 = true;
  1369. jjtree.openNodeScope(jjtn001);
  1370. jjtreeOpenNodeScope(jjtn001);
  1371. }
  1372. try {
  1373. /*@egen*//*@bgen(jjtree)*/
  1374. {
  1375. jjtree.closeNodeScope(jjtn001, 1);
  1376. jjtc001 = false;
  1377. jjtreeCloseNodeScope(jjtn001);
  1378. }
  1379. /*@egen*/ {
  1380. jjtn001.kind = t.kind; jjtn001.postfix = true; }/*@bgen(jjtree)*/
  1381. } finally {
  1382. if (jjtc001) {
  1383. jjtree.closeNodeScope(jjtn001, 1);
  1384. jjtreeCloseNodeScope(jjtn001);
  1385. }
  1386. }
  1387. /*@egen*/ ]
  1388. |
  1389. PrimaryExpression()
  1390. )
  1391. }
  1392. void CastExpression() :
  1393. {/*@bgen(jjtree) CastExpression */
  1394. BSHCastExpression jjtn000 = new BSHCastExpression(JJTCASTEXPRESSION);
  1395. boolean jjtc000 = true;
  1396. jjtree.openNodeScope(jjtn000);
  1397. jjtreeOpenNodeScope(jjtn000);
  1398. /*@egen*/ }
  1399. {/*@bgen(jjtree) CastExpression */
  1400. try {
  1401. /*@egen*/
  1402. // SYNTACTIC_LOOKAHEAD
  1403. LOOKAHEAD( "(" PrimitiveType() ) "(" Type() ")" UnaryExpression()
  1404. |
  1405. "(" Type() ")" UnaryExpressionNotPlusMinus()/*@bgen(jjtree)*/
  1406. } catch (Throwable jjte000) {
  1407. if (jjtc000) {
  1408. jjtree.clearNodeScope(jjtn000);
  1409. jjtc000 = false;
  1410. } else {
  1411. jjtree.popNode();
  1412. }
  1413. if (jjte000 instanceof RuntimeException) {
  1414. throw (RuntimeException)jjte000;
  1415. }
  1416. if (jjte000 instanceof ParseException) {
  1417. throw (ParseException)jjte000;
  1418. }
  1419. throw (Error)jjte000;
  1420. } finally {
  1421. if (jjtc000) {
  1422. jjtree.closeNodeScope(jjtn000, true);
  1423. jjtreeCloseNodeScope(jjtn000);
  1424. }
  1425. }
  1426. /*@egen*/
  1427. }
  1428. void PrimaryExpression() : {/*@bgen(jjtree) PrimaryExpression */
  1429. BSHPrimaryExpression jjtn000 = new BSHPrimaryExpression(JJTPRIMARYEXPRESSION);
  1430. boolean jjtc000 = true;
  1431. jjtree.openNodeScope(jjtn000);
  1432. jjtreeOpenNodeScope(jjtn000);
  1433. /*@egen*/ }
  1434. {/*@bgen(jjtree) PrimaryExpression */
  1435. try {
  1436. /*@egen*/
  1437. PrimaryPrefix() ( PrimarySuffix() )*/*@bgen(jjtree)*/
  1438. } catch (Throwable jjte000) {
  1439. if (jjtc000) {
  1440. jjtree.clearNodeScope(jjtn000);
  1441. jjtc000 = false;
  1442. } else {
  1443. jjtree.popNode();
  1444. }
  1445. if (jjte000 instanceof RuntimeException) {
  1446. throw (RuntimeException)jjte000;
  1447. }
  1448. if (jjte000 instanceof ParseException) {
  1449. throw (ParseException)jjte000;
  1450. }
  1451. throw (Error)jjte000;
  1452. } finally {
  1453. if (jjtc000) {
  1454. jjtree.closeNodeScope(jjtn000, true);
  1455. jjtreeCloseNodeScope(jjtn000);
  1456. }
  1457. }
  1458. /*@egen*/
  1459. }
  1460. // The MethodInvocation node here simplifies the prefix/suffix parsing a bit
  1461. // by forcing the prefix to an object.
  1462. void PrimaryPrefix() : { }
  1463. {
  1464. Literal()
  1465. |
  1466. "(" Expression() ")"
  1467. |
  1468. AllocationExpression()
  1469. |
  1470. // SYNTACTIC_LOOKAHEAD
  1471. LOOKAHEAD( Type() "." "class" )
  1472. Type()
  1473. |/*@bgen(jjtree) #MethodInvocation(> 1) */
  1474. {
  1475. BSHMethodInvocation jjtn001 = new BSHMethodInvocation(JJTMETHODINVOCATION);
  1476. boolean jjtc001 = true;
  1477. jjtree.openNodeScope(jjtn001);
  1478. jjtreeOpenNodeScope(jjtn001);
  1479. }
  1480. try {
  1481. /*@egen*/
  1482. /*
  1483. Handle method invocation OR straight ambigous name...
  1484. (probably should just write this as two rules more clearly)
  1485. */
  1486. ( AmbiguousName() [ Arguments() ] )/*@bgen(jjtree)*/
  1487. } catch (Throwable jjte001) {
  1488. if (jjtc001) {
  1489. jjtree.clearNodeScope(jjtn001);
  1490. jjtc001 = false;
  1491. } else {
  1492. jjtree.popNode();
  1493. }
  1494. if (jjte001 instanceof RuntimeException) {
  1495. throw (RuntimeException)jjte001;
  1496. }
  1497. if (jjte001 instanceof ParseException) {
  1498. throw (ParseException)jjte001;
  1499. }
  1500. throw (Error)jjte001;
  1501. } finally {
  1502. if (jjtc001) {
  1503. jjtree.closeNodeScope(jjtn001, jjtree.nodeArity() > 1);
  1504. jjtreeCloseNodeScope(jjtn001);
  1505. }
  1506. }
  1507. /*@egen*/
  1508. /*
  1509. |
  1510. LOOKAHEAD( "void" "." "class" )
  1511. */
  1512. }
  1513. void PrimarySuffix() :
  1514. {/*@bgen(jjtree) PrimarySuffix */
  1515. BSHPrimarySuffix jjtn000 = new BSHPrimarySuffix(JJTPRIMARYSUFFIX);
  1516. boolean jjtc000 = true;
  1517. jjtree.openNodeScope(jjtn000);
  1518. jjtreeOpenNodeScope(jjtn000);
  1519. /*@egen*/
  1520. Token t = null;
  1521. }
  1522. {/*@bgen(jjtree) PrimarySuffix */
  1523. try {
  1524. /*@egen*/
  1525. LOOKAHEAD(2)
  1526. "." "class"/*@bgen(jjtree)*/
  1527. {
  1528. jjtree.closeNodeScope(jjtn000, true);
  1529. jjtc000 = false;
  1530. jjtreeCloseNodeScope(jjtn000);
  1531. }
  1532. /*@egen*/ {
  1533. jjtn000.operation = BSHPrimarySuffix.CLASS;
  1534. }
  1535. |
  1536. "[" Expression() "]"/*@bgen(jjtree)*/
  1537. {
  1538. jjtree.closeNodeScope(jjtn000, true);
  1539. jjtc000 = false;
  1540. jjtreeCloseNodeScope(jjtn000);
  1541. }
  1542. /*@egen*/ {
  1543. jjtn000.operation = BSHPrimarySuffix.INDEX;
  1544. }
  1545. |
  1546. // Field access or method invocation
  1547. "." t = <IDENTIFIER> [ Arguments() ]/*@bgen(jjtree)*/
  1548. {
  1549. jjtree.closeNodeScope(jjtn000, true);
  1550. jjtc000 = false;
  1551. jjtreeCloseNodeScope(jjtn000);
  1552. }
  1553. /*@egen*/ {
  1554. jjtn000.operation = BSHPrimarySuffix.NAME;
  1555. jjtn000.field = t.image;
  1556. }
  1557. |
  1558. "{" Expression() "}"/*@bgen(jjtree)*/
  1559. {
  1560. jjtree.closeNodeScope(jjtn000, true);
  1561. jjtc000 = false;
  1562. jjtreeCloseNodeScope(jjtn000);
  1563. }
  1564. /*@egen*/ {
  1565. jjtn000.operation = BSHPrimarySuffix.PROPERTY;
  1566. }/*@bgen(jjtree)*/
  1567. } catch (Throwable jjte000) {
  1568. if (jjtc000) {
  1569. jjtree.clearNodeScope(jjtn000);
  1570. jjtc000 = false;
  1571. } else {
  1572. jjtree.popNode();
  1573. }
  1574. if (jjte000 instanceof RuntimeException) {
  1575. throw (RuntimeException)jjte000;
  1576. }
  1577. if (jjte000 instanceof ParseException) {
  1578. throw (ParseException)jjte000;
  1579. }
  1580. throw (Error)jjte000;
  1581. } finally {
  1582. if (jjtc000) {
  1583. jjtree.closeNodeScope(jjtn000, true);
  1584. jjtreeCloseNodeScope(jjtn000);
  1585. }
  1586. }
  1587. /*@egen*/
  1588. /*
  1589. For inner classes
  1590. |
  1591. LOOKAHEAD(2)
  1592. "." AllocationExpression()
  1593. */
  1594. }
  1595. /*
  1596. Begin LHS part of the grammar --
  1597. The reason this stuff is duplicated (e.g. LHSPrimaryPrefix and
  1598. PrimaryPrefix) is that the whole grammar splits based on whether we
  1599. are preparig to do an assignment or not. This is an important issue
  1600. to revisit in the future.
  1601. */
  1602. /**
  1603. The method invocation is here to force this to an object type in order
  1604. to simplify the suffix processing.
  1605. */
  1606. void LHSPrimaryPrefix() : { }
  1607. {/*@bgen(jjtree) #MethodInvocation(> 1) */
  1608. {
  1609. BSHMethodInvocation jjtn001 = new BSHMethodInvocation(JJTMETHODINVOCATION);
  1610. boolean jjtc001 = true;
  1611. jjtree.openNodeScope(jjtn001);
  1612. jjtreeOpenNodeScope(jjtn001);
  1613. }
  1614. try {
  1615. /*@egen*/
  1616. /*
  1617. Method invocation or simple ambiguous name.
  1618. (probably should just write this as two rules more clearly)
  1619. */
  1620. ( AmbiguousName() [ Arguments() ] )/*@bgen(jjtree)*/
  1621. } catch (Throwable jjte001) {
  1622. if (jjtc001) {
  1623. jjtree.clearNodeScope(jjtn001);
  1624. jjtc001 = false;
  1625. } else {
  1626. jjtree.popNode();
  1627. }
  1628. if (jjte001 instanceof RuntimeException) {
  1629. throw (RuntimeException)jjte001;
  1630. }
  1631. if (jjte001 instanceof ParseException) {
  1632. throw (ParseException)jjte001;
  1633. }
  1634. throw (Error)jjte001;
  1635. } finally {
  1636. if (jjtc001) {
  1637. jjtree.closeNodeScope(jjtn001, jjtree.nodeArity() > 1);
  1638. jjtreeCloseNodeScope(jjtn001);
  1639. }
  1640. }
  1641. /*@egen*/
  1642. }
  1643. void LHSPrimaryExpression() : {/*@bgen(jjtree) LHSPrimaryExpression */
  1644. BSHLHSPrimaryExpression jjtn000 = new BSHLHSPrimaryExpression(JJTLHSPRIMARYEXPRESSION);
  1645. boolean jjtc000 = true;
  1646. jjtree.openNodeScope(jjtn000);
  1647. jjtreeOpenNodeScope(jjtn000);
  1648. /*@egen*/ }
  1649. {/*@bgen(jjtree) LHSPrimaryExpression */
  1650. try {
  1651. /*@egen*/
  1652. LHSPrimaryPrefix() ( LHSPrimarySuffix( ) )*/*@bgen(jjtree)*/
  1653. } catch (Throwable jjte000) {
  1654. if (jjtc000) {
  1655. jjtree.clearNodeScope(jjtn000);
  1656. jjtc000 = false;
  1657. } else {
  1658. jjtree.popNode();
  1659. }
  1660. if (jjte000 instanceof RuntimeException) {
  1661. throw (RuntimeException)jjte000;
  1662. }
  1663. if (jjte000 instanceof ParseException) {
  1664. throw (ParseException)jjte000;
  1665. }
  1666. throw (Error)jjte000;
  1667. } finally {
  1668. if (jjtc000) {
  1669. jjtree.closeNodeScope(jjtn000, true);
  1670. jjtreeCloseNodeScope(jjtn000);
  1671. }
  1672. }
  1673. /*@egen*/
  1674. }
  1675. void LHSPrimarySuffix() :
  1676. {/*@bgen(jjtree) LHSPrimarySuffix */
  1677. BSHLHSPrimarySuffix jjtn000 = new BSHLHSPrimarySuffix(JJTLHSPRIMARYSUFFIX);
  1678. boolean jjtc000 = true;
  1679. jjtree.openNodeScope(jjtn000);
  1680. jjtreeOpenNodeScope(jjtn000);
  1681. /*@egen*/
  1682. Token t=null, t1, t2 = null;
  1683. }
  1684. {/*@bgen(jjtree) LHSPrimarySuffix */
  1685. try {
  1686. /*@egen*/
  1687. // Indexed to a field
  1688. "[" Expression() "]"/*@bgen(jjtree)*/
  1689. {
  1690. jjtree.closeNodeScope(jjtn000, true);
  1691. jjtc000 = false;
  1692. jjtreeCloseNodeScope(jjtn000);
  1693. }
  1694. /*@egen*/ {
  1695. jjtn000.operation = BSHLHSPrimarySuffix.INDEX;
  1696. }
  1697. |
  1698. // Field access or method invocation followed by field access
  1699. "." t1 = <IDENTIFIER> [ Arguments() "." t2 = <IDENTIFIER> ]/*@bgen(jjtree)*/
  1700. {
  1701. jjtree.closeNodeScope(jjtn000, true);
  1702. jjtc000 = false;
  1703. jjtreeCloseNodeScope(jjtn000);
  1704. }
  1705. /*@egen*/ {
  1706. jjtn000.operation = BSHLHSPrimarySuffix.NAME;
  1707. if ( t2 == null )
  1708. jjtn000.field = t1.image;
  1709. else {
  1710. jjtn000.method = t1.image;
  1711. jjtn000.field = t2.image;
  1712. }
  1713. }
  1714. |
  1715. "{" Expression() "}"/*@bgen(jjtree)*/
  1716. {
  1717. jjtree.closeNodeScope(jjtn000, true);
  1718. jjtc000 = false;
  1719. jjtreeCloseNodeScope(jjtn000);
  1720. }
  1721. /*@egen*/ {
  1722. jjtn000.operation = BSHLHSPrimarySuffix.PROPERTY;
  1723. }/*@bgen(jjtree)*/
  1724. } catch (Throwable jjte000) {
  1725. if (jjtc000) {
  1726. jjtree.clearNodeScope(jjtn000);
  1727. jjtc000 = false;
  1728. } else {
  1729. jjtree.popNode();
  1730. }
  1731. if (jjte000 instanceof RuntimeException) {
  1732. throw (RuntimeException)jjte000;
  1733. }
  1734. if (jjte000 instanceof ParseException) {
  1735. throw (ParseException)jjte000;
  1736. }
  1737. throw (Error)jjte000;
  1738. } finally {
  1739. if (jjtc000) {
  1740. jjtree.closeNodeScope(jjtn000, true);
  1741. jjtreeCloseNodeScope(jjtn000);
  1742. }
  1743. }
  1744. /*@egen*/
  1745. }
  1746. /*
  1747. -- End LHS part of the grammar
  1748. */
  1749. void Literal() :
  1750. {/*@bgen(jjtree) Literal */
  1751. BSHLiteral jjtn000 = new BSHLiteral(JJTLITERAL);
  1752. boolean jjtc000 = true;
  1753. jjtree.openNodeScope(jjtn000);
  1754. jjtreeOpenNodeScope(jjtn000);
  1755. /*@egen*/
  1756. Token x;
  1757. boolean b;
  1758. String literal;
  1759. char ch;
  1760. }
  1761. {/*@bgen(jjtree) Literal */
  1762. try {
  1763. /*@egen*/
  1764. x = <INTEGER_LITERAL>/*@bgen(jjtree)*/
  1765. {
  1766. jjtree.closeNodeScope(jjtn000, true);
  1767. jjtc000 = false;
  1768. jjtreeCloseNodeScope(jjtn000);
  1769. }
  1770. /*@egen*/
  1771. {
  1772. literal = x.image;
  1773. ch = literal.charAt(literal.length()-1);
  1774. if(ch == 'l' || ch == 'L')
  1775. {
  1776. literal = literal.substring(0,literal.length()-1);
  1777. // This really should be Long.decode, but there isn't one. As a result,
  1778. // hex and octal literals ending in 'l' or 'L' don't work.
  1779. jjtn000.value = new Primitive( new Long( literal ) );
  1780. }
  1781. else
  1782. jjtn000.value = new Primitive( Integer.decode( literal ) );
  1783. }
  1784. |
  1785. x = <FLOATING_POINT_LITERAL>/*@bgen(jjtree)*/
  1786. {
  1787. jjtree.closeNodeScope(jjtn000, true);
  1788. jjtc000 = false;
  1789. jjtreeCloseNodeScope(jjtn000);
  1790. }
  1791. /*@egen*/
  1792. {
  1793. literal = x.image;
  1794. ch = literal.charAt(literal.length()-1);
  1795. if(ch == 'f' || ch == 'F')
  1796. {
  1797. literal = literal.substring(0,literal.length()-1);
  1798. jjtn000.value = new Primitive( new Float( literal ) );
  1799. }
  1800. else
  1801. {
  1802. if(ch == 'd' || ch == 'D')
  1803. literal = literal.substring(0,literal.length()-1);
  1804. jjtn000.value = new Primitive( new Double( literal ) );
  1805. }
  1806. }
  1807. |
  1808. x = <CHARACTER_LITERAL>/*@bgen(jjtree)*/
  1809. {
  1810. jjtree.closeNodeScope(jjtn000, true);
  1811. jjtc000 = false;
  1812. jjtreeCloseNodeScope(jjtn000);
  1813. }
  1814. /*@egen*/ {
  1815. try {
  1816. jjtn000.charSetup( x.image.substring(1, x.image.length() - 1) );
  1817. } catch ( Exception e ) {
  1818. throw new ParseException("Error parsing character: "+x.image);
  1819. }
  1820. }
  1821. |
  1822. x = <STRING_LITERAL>/*@bgen(jjtree)*/
  1823. {
  1824. jjtree.closeNodeScope(jjtn000, true);
  1825. jjtc000 = false;
  1826. jjtreeCloseNodeScope(jjtn000);
  1827. }
  1828. /*@egen*/ {
  1829. try {
  1830. jjtn000.stringSetup( x.image.substring(1, x.image.length() - 1) );
  1831. } catch ( Exception e ) {
  1832. throw new ParseException("Error parsing string: "+x.image);
  1833. }
  1834. }
  1835. |
  1836. b = BooleanLiteral()/*@bgen(jjtree)*/
  1837. {
  1838. jjtree.closeNodeScope(jjtn000, true);
  1839. jjtc000 = false;
  1840. jjtreeCloseNodeScope(jjtn000);
  1841. }
  1842. /*@egen*/ {
  1843. jjtn000.value = new Primitive( new Boolean(b) ); }
  1844. |
  1845. NullLiteral()/*@bgen(jjtree)*/
  1846. {
  1847. jjtree.closeNodeScope(jjtn000, true);
  1848. jjtc000 = false;
  1849. jjtreeCloseNodeScope(jjtn000);
  1850. }
  1851. /*@egen*/ {
  1852. jjtn000.value = Primitive.NULL;
  1853. }
  1854. |
  1855. VoidLiteral()/*@bgen(jjtree)*/
  1856. {
  1857. jjtree.closeNodeScope(jjtn000, true);
  1858. jjtc000 = false;
  1859. jjtreeCloseNodeScope(jjtn000);
  1860. }
  1861. /*@egen*/ {
  1862. jjtn000.value = Primitive.VOID; }/*@bgen(jjtree)*/
  1863. } catch (Throwable jjte000) {
  1864. if (jjtc000) {
  1865. jjtree.clearNodeScope(jjtn000);
  1866. jjtc000 = false;
  1867. } else {
  1868. jjtree.popNode();
  1869. }
  1870. if (jjte000 instanceof RuntimeException) {
  1871. throw (RuntimeException)jjte000;
  1872. }
  1873. if (jjte000 instanceof ParseException) {
  1874. throw (ParseException)jjte000;
  1875. }
  1876. throw (Error)jjte000;
  1877. } finally {
  1878. if (jjtc000) {
  1879. jjtree.closeNodeScope(jjtn000, true);
  1880. jjtreeCloseNodeScope(jjtn000);
  1881. }
  1882. }
  1883. /*@egen*/
  1884. }
  1885. boolean BooleanLiteral() :
  1886. {}
  1887. {
  1888. "true" { return true; }
  1889. |
  1890. "false" { return false; }
  1891. }
  1892. void NullLiteral() :
  1893. {}
  1894. {
  1895. "null"
  1896. }
  1897. void VoidLiteral() :
  1898. {}
  1899. {
  1900. "void"
  1901. }
  1902. void Arguments() :
  1903. {/*@bgen(jjtree) Arguments */
  1904. BSHArguments jjtn000 = new BSHArguments(JJTARGUMENTS);
  1905. boolean jjtc000 = true;
  1906. jjtree.openNodeScope(jjtn000);
  1907. jjtreeOpenNodeScope(jjtn000);
  1908. /*@egen*/ }
  1909. {/*@bgen(jjtree) Arguments */
  1910. try {
  1911. /*@egen*/
  1912. "(" [ ArgumentList() ] ")"/*@bgen(jjtree)*/
  1913. } catch (Throwable jjte000) {
  1914. if (jjtc000) {
  1915. jjtree.clearNodeScope(jjtn000);
  1916. jjtc000 = false;
  1917. } else {
  1918. jjtree.popNode();
  1919. }
  1920. if (jjte000 instanceof RuntimeException) {
  1921. throw (RuntimeException)jjte000;
  1922. }
  1923. if (jjte000 instanceof ParseException) {
  1924. throw (ParseException)jjte000;
  1925. }
  1926. throw (Error)jjte000;
  1927. } finally {
  1928. if (jjtc000) {
  1929. jjtree.closeNodeScope(jjtn000, true);
  1930. jjtreeCloseNodeScope(jjtn000);
  1931. }
  1932. }
  1933. /*@egen*/
  1934. }
  1935. // leave these on the stack for Arguments() to handle
  1936. void ArgumentList() :
  1937. { }
  1938. {
  1939. Expression()
  1940. ( "," Expression() )*
  1941. }
  1942. void AllocationExpression() :
  1943. {/*@bgen(jjtree) AllocationExpression */
  1944. BSHAllocationExpression jjtn000 = new BSHAllocationExpression(JJTALLOCATIONEXPRESSION);
  1945. boolean jjtc000 = true;
  1946. jjtree.openNodeScope(jjtn000);
  1947. jjtreeOpenNodeScope(jjtn000);
  1948. /*@egen*/ }
  1949. {/*@bgen(jjtree) AllocationExpression */
  1950. try {
  1951. /*@egen*/
  1952. LOOKAHEAD(2)
  1953. "new" PrimitiveType() ArrayDimensions()
  1954. |
  1955. "new" AmbiguousName()
  1956. (
  1957. ArrayDimensions()
  1958. |
  1959. // SYNTACTIC_LOOKAHEAD
  1960. Arguments() [ LOOKAHEAD(2) Block() ]
  1961. )/*@bgen(jjtree)*/
  1962. } catch (Throwable jjte000) {
  1963. if (jjtc000) {
  1964. jjtree.clearNodeScope(jjtn000);
  1965. jjtc000 = false;
  1966. } else {
  1967. jjtree.popNode();
  1968. }
  1969. if (jjte000 instanceof RuntimeException) {
  1970. throw (RuntimeException)jjte000;
  1971. }
  1972. if (jjte000 instanceof ParseException) {
  1973. throw (ParseException)jjte000;
  1974. }
  1975. throw (Error)jjte000;
  1976. } finally {
  1977. if (jjtc000) {
  1978. jjtree.closeNodeScope(jjtn000, true);
  1979. jjtreeCloseNodeScope(jjtn000);
  1980. }
  1981. }
  1982. /*@egen*/
  1983. }
  1984. void ArrayDimensions() :
  1985. {/*@bgen(jjtree) ArrayDimensions */
  1986. BSHArrayDimensions jjtn000 = new BSHArrayDimensions(JJTARRAYDIMENSIONS);
  1987. boolean jjtc000 = true;
  1988. jjtree.openNodeScope(jjtn000);
  1989. jjtreeOpenNodeScope(jjtn000);
  1990. /*@egen*/}
  1991. {/*@bgen(jjtree) ArrayDimensions */
  1992. try {
  1993. /*@egen*/
  1994. LOOKAHEAD(2)
  1995. ( LOOKAHEAD(2) "[" Expression() "]" { jjtn000.addArrayDimension(); } )+
  1996. // Removed trailing "[]" identifiers. Specify array dims fully.
  1997. |
  1998. ( "[" "]" { jjtn000.addArrayDimension(); } )+ ArrayInitializer()/*@bgen(jjtree)*/
  1999. } catch (Throwable jjte000) {
  2000. if (jjtc000) {
  2001. jjtree.clearNodeScope(jjtn000);
  2002. jjtc000 = false;
  2003. } else {
  2004. jjtree.popNode();
  2005. }
  2006. if (jjte000 instanceof RuntimeException) {
  2007. throw (RuntimeException)jjte000;
  2008. }
  2009. if (jjte000 instanceof ParseException) {
  2010. throw (ParseException)jjte000;
  2011. }
  2012. throw (Error)jjte000;
  2013. } finally {
  2014. if (jjtc000) {
  2015. jjtree.closeNodeScope(jjtn000, true);
  2016. jjtreeCloseNodeScope(jjtn000);
  2017. }
  2018. }
  2019. /*@egen*/
  2020. }
  2021. /*
  2022. * Statement syntax follows.
  2023. */
  2024. void Statement() : { }
  2025. {
  2026. LOOKAHEAD(2)
  2027. LabeledStatement()
  2028. |
  2029. Block()
  2030. |
  2031. EmptyStatement()
  2032. |
  2033. StatementExpression() ";"
  2034. |
  2035. SwitchStatement()
  2036. |
  2037. IfStatement()
  2038. |
  2039. WhileStatement()
  2040. |
  2041. DoStatement()
  2042. |
  2043. ForStatement()
  2044. |
  2045. BreakStatement()
  2046. |
  2047. ContinueStatement()
  2048. |
  2049. ReturnStatement()
  2050. |
  2051. ThrowStatement()
  2052. |
  2053. TryStatement()
  2054. }
  2055. void LabeledStatement() :
  2056. {}
  2057. {
  2058. <IDENTIFIER> ":" Statement()
  2059. }
  2060. void Block() :
  2061. {/*@bgen(jjtree) Block */
  2062. BSHBlock jjtn000 = new BSHBlock(JJTBLOCK);
  2063. boolean jjtc000 = true;
  2064. jjtree.openNodeScope(jjtn000);
  2065. jjtreeOpenNodeScope(jjtn000);
  2066. /*@egen*/}
  2067. {/*@bgen(jjtree) Block */
  2068. try {
  2069. /*@egen*/
  2070. "{" ( BlockStatement() )* "}"/*@bgen(jjtree)*/
  2071. } catch (Throwable jjte000) {
  2072. if (jjtc000) {
  2073. jjtree.clearNodeScope(jjtn000);
  2074. jjtc000 = false;
  2075. } else {
  2076. jjtree.popNode();
  2077. }
  2078. if (jjte000 instanceof RuntimeException) {
  2079. throw (RuntimeException)jjte000;
  2080. }
  2081. if (jjte000 instanceof ParseException) {
  2082. throw (ParseException)jjte000;
  2083. }
  2084. throw (Error)jjte000;
  2085. } finally {
  2086. if (jjtc000) {
  2087. jjtree.closeNodeScope(jjtn000, true);
  2088. jjtreeCloseNodeScope(jjtn000);
  2089. }
  2090. }
  2091. /*@egen*/
  2092. }
  2093. void BlockStatement() :
  2094. {}
  2095. {
  2096. // SYNTACTIC_LOOKAHEAD
  2097. LOOKAHEAD( MethodDeclarationLookahead() ) MethodDeclaration()
  2098. |
  2099. // SYNTACTIC_LOOKAHEAD
  2100. LOOKAHEAD([ "final" ] Type() <IDENTIFIER>)
  2101. TypedVariableDeclaration() ";"
  2102. |
  2103. Statement()
  2104. /* end */
  2105. |
  2106. // Allow BeanShell imports in any block
  2107. ImportDeclaration()
  2108. }
  2109. void EmptyStatement() :
  2110. {}
  2111. {
  2112. ";"
  2113. }
  2114. void StatementExpression() :
  2115. /*
  2116. * The last expansion of this production accepts more than the legal
  2117. * Java expansions for StatementExpression.
  2118. */
  2119. { }
  2120. {
  2121. PreIncrementExpression()
  2122. |
  2123. PreDecrementExpression()
  2124. |
  2125. // SYNTACTIC_LOOKAHEAD
  2126. LOOKAHEAD( PrimaryExpression() AssignmentOperator() )
  2127. Assignment() { }
  2128. |
  2129. PostfixExpression()
  2130. }
  2131. void SwitchStatement() :
  2132. {/*@bgen(jjtree) SwitchStatement */
  2133. BSHSwitchStatement jjtn000 = new BSHSwitchStatement(JJTSWITCHSTATEMENT);
  2134. boolean jjtc000 = true;
  2135. jjtree.openNodeScope(jjtn000);
  2136. jjtreeOpenNodeScope(jjtn000);
  2137. /*@egen*/}
  2138. {/*@bgen(jjtree) SwitchStatement */
  2139. try {
  2140. /*@egen*/
  2141. "switch" "(" Expression() ")" "{"
  2142. ( SwitchLabel() ( BlockStatement() )* )*
  2143. "}"/*@bgen(jjtree)*/
  2144. } catch (Throwable jjte000) {
  2145. if (jjtc000) {
  2146. jjtree.clearNodeScope(jjtn000);
  2147. jjtc000 = false;
  2148. } else {
  2149. jjtree.popNode();
  2150. }
  2151. if (jjte000 instanceof RuntimeException) {
  2152. throw (RuntimeException)jjte000;
  2153. }
  2154. if (jjte000 instanceof ParseException) {
  2155. throw (ParseException)jjte000;
  2156. }
  2157. throw (Error)jjte000;
  2158. } finally {
  2159. if (jjtc000) {
  2160. jjtree.closeNodeScope(jjtn000, true);
  2161. jjtreeCloseNodeScope(jjtn000);
  2162. }
  2163. }
  2164. /*@egen*/
  2165. }
  2166. void SwitchLabel() :
  2167. {/*@bgen(jjtree) SwitchLabel */
  2168. BSHSwitchLabel jjtn000 = new BSHSwitchLabel(JJTSWITCHLABEL);
  2169. boolean jjtc000 = true;
  2170. jjtree.openNodeScope(jjtn000);
  2171. jjtreeOpenNodeScope(jjtn000);
  2172. /*@egen*/}
  2173. {/*@bgen(jjtree) SwitchLabel */
  2174. try {
  2175. /*@egen*/
  2176. "case" Expression() ":"
  2177. |
  2178. "default" ":"/*@bgen(jjtree)*/
  2179. {
  2180. jjtree.closeNodeScope(jjtn000, true);
  2181. jjtc000 = false;
  2182. jjtreeCloseNodeScope(jjtn000);
  2183. }
  2184. /*@egen*/ { jjtn000.isDefault = true; }/*@bgen(jjtree)*/
  2185. } catch (Throwable jjte000) {
  2186. if (jjtc000) {
  2187. jjtree.clearNodeScope(jjtn000);
  2188. jjtc000 = false;
  2189. } else {
  2190. jjtree.popNode();
  2191. }
  2192. if (jjte000 instanceof RuntimeException) {
  2193. throw (RuntimeException)jjte000;
  2194. }
  2195. if (jjte000 instanceof ParseException) {
  2196. throw (ParseException)jjte000;
  2197. }
  2198. throw (Error)jjte000;
  2199. } finally {
  2200. if (jjtc000) {
  2201. jjtree.closeNodeScope(jjtn000, true);
  2202. jjtreeCloseNodeScope(jjtn000);
  2203. }
  2204. }
  2205. /*@egen*/
  2206. }
  2207. void IfStatement() :
  2208. /*
  2209. * The disambiguating algorithm of JavaCC automatically binds dangling
  2210. * else's to the innermost if statement. The LOOKAHEAD specification
  2211. * is to tell JavaCC that we know what we are doing.
  2212. */
  2213. {/*@bgen(jjtree) IfStatement */
  2214. BSHIfStatement jjtn000 = new BSHIfStatement(JJTIFSTATEMENT);
  2215. boolean jjtc000 = true;
  2216. jjtree.openNodeScope(jjtn000);
  2217. jjtreeOpenNodeScope(jjtn000);
  2218. /*@egen*/}
  2219. {/*@bgen(jjtree) IfStatement */
  2220. try {
  2221. /*@egen*/
  2222. "if" "(" Expression() ")" Statement() [ LOOKAHEAD(1) "else" Statement() ]/*@bgen(jjtree)*/
  2223. } catch (Throwable jjte000) {
  2224. if (jjtc000) {
  2225. jjtree.clearNodeScope(jjtn000);
  2226. jjtc000 = false;
  2227. } else {
  2228. jjtree.popNode();
  2229. }
  2230. if (jjte000 instanceof RuntimeException) {
  2231. throw (RuntimeException)jjte000;
  2232. }
  2233. if (jjte000 instanceof ParseException) {
  2234. throw (ParseException)jjte000;
  2235. }
  2236. throw (Error)jjte000;
  2237. } finally {
  2238. if (jjtc000) {
  2239. jjtree.closeNodeScope(jjtn000, true);
  2240. jjtreeCloseNodeScope(jjtn000);
  2241. }
  2242. }
  2243. /*@egen*/
  2244. }
  2245. void WhileStatement() :
  2246. {/*@bgen(jjtree) WhileStatement */
  2247. BSHWhileStatement jjtn000 = new BSHWhileStatement(JJTWHILESTATEMENT);
  2248. boolean jjtc000 = true;
  2249. jjtree.openNodeScope(jjtn000);
  2250. jjtreeOpenNodeScope(jjtn000);
  2251. /*@egen*/}
  2252. {/*@bgen(jjtree) WhileStatement */
  2253. try {
  2254. /*@egen*/
  2255. "while" "(" Expression() ")" Statement()/*@bgen(jjtree)*/
  2256. } catch (Throwable jjte000) {
  2257. if (jjtc000) {
  2258. jjtree.clearNodeScope(jjtn000);
  2259. jjtc000 = false;
  2260. } else {
  2261. jjtree.popNode();
  2262. }
  2263. if (jjte000 instanceof RuntimeException) {
  2264. throw (RuntimeException)jjte000;
  2265. }
  2266. if (jjte000 instanceof ParseException) {
  2267. throw (ParseException)jjte000;
  2268. }
  2269. throw (Error)jjte000;
  2270. } finally {
  2271. if (jjtc000) {
  2272. jjtree.closeNodeScope(jjtn000, true);
  2273. jjtreeCloseNodeScope(jjtn000);
  2274. }
  2275. }
  2276. /*@egen*/
  2277. }
  2278. /*
  2279. Do statement is just a While statement with a special hook to execute
  2280. at least once.
  2281. */
  2282. void DoStatement() :
  2283. {/*@bgen(jjtree) WhileStatement */
  2284. BSHWhileStatement jjtn000 = new BSHWhileStatement(JJTWHILESTATEMENT);
  2285. boolean jjtc000 = true;
  2286. jjtree.openNodeScope(jjtn000);
  2287. jjtreeOpenNodeScope(jjtn000);
  2288. /*@egen*/}
  2289. {/*@bgen(jjtree) WhileStatement */
  2290. try {
  2291. /*@egen*/
  2292. "do" Statement() "while" "(" Expression() ")" ";"/*@bgen(jjtree)*/
  2293. {
  2294. jjtree.closeNodeScope(jjtn000, true);
  2295. jjtc000 = false;
  2296. jjtreeCloseNodeScope(jjtn000);
  2297. }
  2298. /*@egen*/
  2299. { jjtn000.isDoStatement=true; }/*@bgen(jjtree)*/
  2300. } catch (Throwable jjte000) {
  2301. if (jjtc000) {
  2302. jjtree.clearNodeScope(jjtn000);
  2303. jjtc000 = false;
  2304. } else {
  2305. jjtree.popNode();
  2306. }
  2307. if (jjte000 instanceof RuntimeException) {
  2308. throw (RuntimeException)jjte000;
  2309. }
  2310. if (jjte000 instanceof ParseException) {
  2311. throw (ParseException)jjte000;
  2312. }
  2313. throw (Error)jjte000;
  2314. } finally {
  2315. if (jjtc000) {
  2316. jjtree.closeNodeScope(jjtn000, true);
  2317. jjtreeCloseNodeScope(jjtn000);
  2318. }
  2319. }
  2320. /*@egen*/
  2321. }
  2322. void ForStatement() :
  2323. {/*@bgen(jjtree) ForStatement */
  2324. BSHForStatement jjtn000 = new BSHForStatement(JJTFORSTATEMENT);
  2325. boolean jjtc000 = true;
  2326. jjtree.openNo