PageRenderTime 50ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/jEdit/tags/jedit-4-2-pre4/bsh/bsh.jj

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