Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.43 KB | None | 0 0
  1. /* Copyright (c) 2006, Sun Microsystems, Inc.
  2. * All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the Sun Microsystems, Inc. nor the names of its
  13. * contributors may be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  20. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  26. * THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28.  
  29. options {
  30. JAVA_UNICODE_ESCAPE = true;
  31. ERROR_REPORTING = false;
  32. STATIC = false;
  33. COMMON_TOKEN_ACTION = false;
  34. //TOKEN_FACTORY = "MyToken";
  35. JDK_VERSION = "1.5";
  36. }
  37.  
  38. PARSER_BEGIN(JavaParser)
  39.  
  40. package lab2 ;
  41. import java.io.*;
  42.  
  43. /**
  44. * Grammar to parse Java version 1.5
  45. * @author Sreenivasa Viswanadha - Simplified and enhanced for 1.5
  46. */
  47. public class JavaParser
  48. {
  49. public static int countMethodDec = 0 ;
  50. public static int countConstruct = 0 ;
  51. public static int countVarDec = 0 ;
  52.  
  53.  
  54. /**
  55. * Class to hold modifiers.
  56. */
  57. static public final class ModifierSet
  58. {
  59. /* Definitions of the bits in the modifiers field. */
  60. public static final int PUBLIC = 0x0001;
  61. public static final int PROTECTED = 0x0002;
  62. public static final int PRIVATE = 0x0004;
  63. public static final int ABSTRACT = 0x0008;
  64. public static final int STATIC = 0x0010;
  65. public static final int FINAL = 0x0020;
  66. public static final int SYNCHRONIZED = 0x0040;
  67. public static final int NATIVE = 0x0080;
  68. public static final int TRANSIENT = 0x0100;
  69. public static final int VOLATILE = 0x0200;
  70. public static final int STRICTFP = 0x1000;
  71.  
  72. /** A set of accessors that indicate whether the specified modifier
  73. is in the set. */
  74.  
  75. public boolean isPublic(int modifiers)
  76. {
  77. return (modifiers & PUBLIC) != 0;
  78. }
  79.  
  80. public boolean isProtected(int modifiers)
  81. {
  82. return (modifiers & PROTECTED) != 0;
  83. }
  84.  
  85. public boolean isPrivate(int modifiers)
  86. {
  87. return (modifiers & PRIVATE) != 0;
  88. }
  89.  
  90. public boolean isStatic(int modifiers)
  91. {
  92. return (modifiers & STATIC) != 0;
  93. }
  94.  
  95. public boolean isAbstract(int modifiers)
  96. {
  97. return (modifiers & ABSTRACT) != 0;
  98. }
  99.  
  100. public boolean isFinal(int modifiers)
  101. {
  102. return (modifiers & FINAL) != 0;
  103. }
  104.  
  105. public boolean isNative(int modifiers)
  106. {
  107. return (modifiers & NATIVE) != 0;
  108. }
  109.  
  110. public boolean isStrictfp(int modifiers)
  111. {
  112. return (modifiers & STRICTFP) != 0;
  113. }
  114.  
  115. public boolean isSynchronized(int modifiers)
  116. {
  117. return (modifiers & SYNCHRONIZED) != 0;
  118. }
  119.  
  120. public boolean isTransient(int modifiers)
  121. {
  122. return (modifiers & TRANSIENT) != 0;
  123. }
  124.  
  125. public boolean isVolatile(int modifiers)
  126. {
  127. return (modifiers & VOLATILE) != 0;
  128. }
  129.  
  130. /**
  131. * Removes the given modifier.
  132. */
  133. static int removeModifier(int modifiers, int mod)
  134. {
  135. return modifiers & ~mod;
  136. }
  137. }
  138.  
  139. public JavaParser(String fileName)
  140. {
  141. this(System.in);
  142. try { ReInit(new FileInputStream(new File(fileName))); }
  143. catch(Exception e) { e.printStackTrace(); }
  144. }
  145.  
  146. public static void main(String args[]) {
  147. JavaParser parser;
  148. if (args.length == 0) {
  149. System.out.println("Java Parser Version 1.1: Reading from standard input . . .");
  150. parser = new JavaParser(System.in);
  151. } else if (args.length == 1) {
  152. System.out.println("Java Parser Version 1.1: Reading from file " + args[0] + " . . .");
  153. try {
  154. parser = new JavaParser(new java.io.FileInputStream(args[0]));
  155. } catch (java.io.FileNotFoundException e) {
  156. System.out.println("Java Parser Version 1.1: File " + args[0] + " not found.");
  157. return;
  158. }
  159. } else {
  160. System.out.println("Java Parser Version 1.1: Usage is one of:");
  161. System.out.println(" java JavaParser < inputfile");
  162. System.out.println("OR");
  163. System.out.println(" java JavaParser inputfile");
  164. return;
  165. }
  166. try {
  167. parser.CompilationUnit();
  168. System.out.println("Java Parser Version 1.1: Java program parsed successfully.");
  169. System.out.println("I parsed a count MethodDeclarator: " + countMethodDec) ;
  170. System.out.println("I parsed a count for Constructor: " + countConstruct) ;
  171. System.out.println("I parsed a count for Variable: " + countVarDec) ;
  172.  
  173. } catch (ParseException e) {
  174. System.out.println(e.getMessage());
  175. System.out.println("Java Parser Version 1.1: Encountered errors during parse.");
  176. }
  177. }
  178.  
  179. }
  180.  
  181. PARSER_END(JavaParser)
  182.  
  183. /* WHITE SPACE */
  184.  
  185. SKIP :
  186. {
  187. " "
  188. | "\t"
  189. | "\n"
  190. | "\r"
  191. | "\f"
  192. }
  193.  
  194. /* COMMENTS */
  195.  
  196. MORE :
  197. {
  198. <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
  199. |
  200. "/*" : IN_MULTI_LINE_COMMENT
  201. }
  202.  
  203. SPECIAL_TOKEN :
  204. {
  205. <SINGLE_LINE_COMMENT: "//" (~["\n", "\r"])* ("\n" | "\r" | "\r\n")?>
  206. }
  207.  
  208. <IN_FORMAL_COMMENT>
  209. SPECIAL_TOKEN :
  210. {
  211. <FORMAL_COMMENT: "*/" > : DEFAULT
  212. }
  213.  
  214. <IN_MULTI_LINE_COMMENT>
  215. SPECIAL_TOKEN :
  216. {
  217. <MULTI_LINE_COMMENT: "*/" > : DEFAULT
  218. }
  219.  
  220. <IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
  221. MORE :
  222. {
  223. < ~[] >
  224. }
  225.  
  226. /* RESERVED WORDS AND LITERALS */
  227.  
  228. TOKEN :
  229. {
  230. < ABSTRACT: "abstract" >
  231. | < ASSERT: "assert" >
  232. | < BOOLEAN: "boolean" >
  233. | < BREAK: "break" >
  234. | < BYTE: "byte" >
  235. | < CASE: "case" >
  236. | < CATCH: "catch" >
  237. | < CHAR: "char" >
  238. | < CLASS: "class" >
  239. | < CONST: "const" >
  240. | < CONTINUE: "continue" >
  241. | < _DEFAULT: "default" >
  242. | < DO: "do" >
  243. | < DOUBLE: "double" >
  244. | < ELSE: "else" >
  245. | < ENUM: "enum" >
  246. | < EXTENDS: "extends" >
  247. | < FALSE: "false" >
  248. | < FINAL: "final" >
  249. | < FINALLY: "finally" >
  250. | < FLOAT: "float" >
  251. | < FOR: "for" >
  252. | < GOTO: "goto" >
  253. | < IF: "if" >
  254. | < IMPLEMENTS: "implements" >
  255. | < IMPORT: "import" >
  256. | < INSTANCEOF: "instanceof" >
  257. | < INT: "int" >
  258. | < INTERFACE: "interface" >
  259. | < LONG: "long" >
  260. | < NATIVE: "native" >
  261. | < NEW: "new" >
  262. | < NULL: "null" >
  263. | < PACKAGE: "package">
  264. | < PRIVATE: "private" >
  265. | < PROTECTED: "protected" >
  266. | < PUBLIC: "public" >
  267. | < RETURN: "return" >
  268. | < SHORT: "short" >
  269. | < STATIC: "static" >
  270. | < STRICTFP: "strictfp" >
  271. | < SUPER: "super" >
  272. | < SWITCH: "switch" >
  273. | < SYNCHRONIZED: "synchronized" >
  274. | < THIS: "this" >
  275. | < THROW: "throw" >
  276. | < THROWS: "throws" >
  277. | < TRANSIENT: "transient" >
  278. | < TRUE: "true" >
  279. | < TRY: "try" >
  280. | < VOID: "void" >
  281. | < VOLATILE: "volatile" >
  282. | < WHILE: "while" >
  283. }
  284.  
  285. /* LITERALS */
  286.  
  287. TOKEN :
  288. {
  289. < INTEGER_LITERAL:
  290. <DECIMAL_LITERAL> (["l","L"])?
  291. | <HEX_LITERAL> (["l","L"])?
  292. | <OCTAL_LITERAL> (["l","L"])?
  293. >
  294. |
  295. < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
  296. |
  297. < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
  298. |
  299. < #OCTAL_LITERAL: "0" (["0"-"7"])* >
  300. |
  301. < FLOATING_POINT_LITERAL:
  302. <DECIMAL_FLOATING_POINT_LITERAL>
  303. | <HEXADECIMAL_FLOATING_POINT_LITERAL>
  304. >
  305. |
  306. < #DECIMAL_FLOATING_POINT_LITERAL:
  307. (["0"-"9"])+ "." (["0"-"9"])* (<DECIMAL_EXPONENT>)? (["f","F","d","D"])?
  308. | "." (["0"-"9"])+ (<DECIMAL_EXPONENT>)? (["f","F","d","D"])?
  309. | (["0"-"9"])+ <DECIMAL_EXPONENT> (["f","F","d","D"])?
  310. | (["0"-"9"])+ (<DECIMAL_EXPONENT>)? ["f","F","d","D"]
  311. >
  312. |
  313. < #DECIMAL_EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
  314. |
  315. < #HEXADECIMAL_FLOATING_POINT_LITERAL:
  316. "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])+ (".")? <HEXADECIMAL_EXPONENT> (["f","F","d","D"])?
  317. | "0" ["x", "X"] (["0"-"9","a"-"f","A"-"F"])* "." (["0"-"9","a"-"f","A"-"F"])+ <HEXADECIMAL_EXPONENT> (["f","F","d","D"])?
  318. >
  319. |
  320. < #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? (["0"-"9"])+ >
  321. |
  322. < CHARACTER_LITERAL:
  323. "'"
  324. ( (~["'","\\","\n","\r"])
  325. | ("\\"
  326. ( ["n","t","b","r","f","\\","'","\""]
  327. | ["0"-"7"] ( ["0"-"7"] )?
  328. | ["0"-"3"] ["0"-"7"] ["0"-"7"]
  329. )
  330. )
  331. )
  332. "'"
  333. >
  334. |
  335. < STRING_LITERAL:
  336. "\""
  337. ( (~["\"","\\","\n","\r"])
  338. | ("\\"
  339. ( ["n","t","b","r","f","\\","'","\""]
  340. | ["0"-"7"] ( ["0"-"7"] )?
  341. | ["0"-"3"] ["0"-"7"] ["0"-"7"]
  342. )
  343. )
  344. )*
  345. "\""
  346. >
  347. }
  348.  
  349. /* IDENTIFIERS */
  350.  
  351. TOKEN :
  352. {
  353. < IDENTIFIER: <LETTER> (<PART_LETTER>)* >
  354. |
  355. < #LETTER:
  356. [ // all chars for which Character.isIdentifierStart is true
  357. "$",
  358. "A"-"Z",
  359. "_",
  360. "a"-"z",
  361. "\u00a2"-"\u00a5",
  362. "\u00aa",
  363. "\u00b5",
  364. "\u00ba",
  365. "\u00c0"-"\u00d6",
  366. "\u00d8"-"\u00f6",
  367. "\u00f8"-"\u021f",
  368. "\u0222"-"\u0233",
  369. "\u0250"-"\u02ad",
  370. "\u02b0"-"\u02b8",
  371. "\u02bb"-"\u02c1",
  372. "\u02d0"-"\u02d1",
  373. "\u02e0"-"\u02e4",
  374. "\u02ee",
  375. "\u037a",
  376. "\u0386",
  377. "\u0388"-"\u038a",
  378. "\u038c",
  379. "\u038e"-"\u03a1",
  380. "\u03a3"-"\u03ce",
  381. "\u03d0"-"\u03d7",
  382. "\u03da"-"\u03f3",
  383. "\u0400"-"\u0481",
  384. "\u048c"-"\u04c4",
  385. "\u04c7"-"\u04c8",
  386. "\u04cb"-"\u04cc",
  387. "\u04d0"-"\u04f5",
  388. "\u04f8"-"\u04f9",
  389. "\u0531"-"\u0556",
  390. "\u0559",
  391. "\u0561"-"\u0587",
  392. "\u05d0"-"\u05ea",
  393. "\u05f0"-"\u05f2",
  394. "\u0621"-"\u063a",
  395. "\u0640"-"\u064a",
  396. "\u0671"-"\u06d3",
  397. "\u06d5",
  398. "\u06e5"-"\u06e6",
  399. "\u06fa"-"\u06fc",
  400. "\u0710",
  401. "\u0712"-"\u072c",
  402. "\u0780"-"\u07a5",
  403. "\u0905"-"\u0939",
  404. "\u093d",
  405. "\u0950",
  406. "\u0958"-"\u0961",
  407. "\u0985"-"\u098c",
  408. "\u098f"-"\u0990",
  409. "\u0993"-"\u09a8",
  410. "\u09aa"-"\u09b0",
  411. "\u09b2",
  412. "\u09b6"-"\u09b9",
  413. "\u09dc"-"\u09dd",
  414. "\u09df"-"\u09e1",
  415. "\u09f0"-"\u09f3",
  416. "\u0a05"-"\u0a0a",
  417. "\u0a0f"-"\u0a10",
  418. "\u0a13"-"\u0a28",
  419. "\u0a2a"-"\u0a30",
  420. "\u0a32"-"\u0a33",
  421. "\u0a35"-"\u0a36",
  422. "\u0a38"-"\u0a39",
  423. "\u0a59"-"\u0a5c",
  424. "\u0a5e",
  425. "\u0a72"-"\u0a74",
  426. "\u0a85"-"\u0a8b",
  427. "\u0a8d",
  428. "\u0a8f"-"\u0a91",
  429. "\u0a93"-"\u0aa8",
  430. "\u0aaa"-"\u0ab0",
  431. "\u0ab2"-"\u0ab3",
  432. "\u0ab5"-"\u0ab9",
  433. "\u0abd",
  434. "\u0ad0",
  435. "\u0ae0",
  436. "\u0b05"-"\u0b0c",
  437. "\u0b0f"-"\u0b10",
  438. "\u0b13"-"\u0b28",
  439. "\u0b2a"-"\u0b30",
  440. "\u0b32"-"\u0b33",
  441. "\u0b36"-"\u0b39",
  442. "\u0b3d",
  443. "\u0b5c"-"\u0b5d",
  444. "\u0b5f"-"\u0b61",
  445. "\u0b85"-"\u0b8a",
  446. "\u0b8e"-"\u0b90",
  447. "\u0b92"-"\u0b95",
  448. "\u0b99"-"\u0b9a",
  449. "\u0b9c",
  450. "\u0b9e"-"\u0b9f",
  451. "\u0ba3"-"\u0ba4",
  452. "\u0ba8"-"\u0baa",
  453. "\u0bae"-"\u0bb5",
  454. "\u0bb7"-"\u0bb9",
  455. "\u0c05"-"\u0c0c",
  456. "\u0c0e"-"\u0c10",
  457. "\u0c12"-"\u0c28",
  458. "\u0c2a"-"\u0c33",
  459. "\u0c35"-"\u0c39",
  460. "\u0c60"-"\u0c61",
  461. "\u0c85"-"\u0c8c",
  462. "\u0c8e"-"\u0c90",
  463. "\u0c92"-"\u0ca8",
  464. "\u0caa"-"\u0cb3",
  465. "\u0cb5"-"\u0cb9",
  466. "\u0cde",
  467. "\u0ce0"-"\u0ce1",
  468. "\u0d05"-"\u0d0c",
  469. "\u0d0e"-"\u0d10",
  470. "\u0d12"-"\u0d28",
  471. "\u0d2a"-"\u0d39",
  472. "\u0d60"-"\u0d61",
  473. "\u0d85"-"\u0d96",
  474. "\u0d9a"-"\u0db1",
  475. "\u0db3"-"\u0dbb",
  476. "\u0dbd",
  477. "\u0dc0"-"\u0dc6",
  478. "\u0e01"-"\u0e30",
  479. "\u0e32"-"\u0e33",
  480. "\u0e3f"-"\u0e46",
  481. "\u0e81"-"\u0e82",
  482. "\u0e84",
  483. "\u0e87"-"\u0e88",
  484. "\u0e8a",
  485. "\u0e8d",
  486. "\u0e94"-"\u0e97",
  487. "\u0e99"-"\u0e9f",
  488. "\u0ea1"-"\u0ea3",
  489. "\u0ea5",
  490. "\u0ea7",
  491. "\u0eaa"-"\u0eab",
  492. "\u0ead"-"\u0eb0",
  493. "\u0eb2"-"\u0eb3",
  494. "\u0ebd",
  495. "\u0ec0"-"\u0ec4",
  496. "\u0ec6",
  497. "\u0edc"-"\u0edd",
  498. "\u0f00",
  499. "\u0f40"-"\u0f47",
  500. "\u0f49"-"\u0f6a",
  501. "\u0f88"-"\u0f8b",
  502. "\u1000"-"\u1021",
  503. "\u1023"-"\u1027",
  504. "\u1029"-"\u102a",
  505. "\u1050"-"\u1055",
  506. "\u10a0"-"\u10c5",
  507. "\u10d0"-"\u10f6",
  508. "\u1100"-"\u1159",
  509. "\u115f"-"\u11a2",
  510. "\u11a8"-"\u11f9",
  511. "\u1200"-"\u1206",
  512. "\u1208"-"\u1246",
  513. "\u1248",
  514. "\u124a"-"\u124d",
  515. "\u1250"-"\u1256",
  516. "\u1258",
  517. "\u125a"-"\u125d",
  518. "\u1260"-"\u1286",
  519. "\u1288",
  520. "\u128a"-"\u128d",
  521. "\u1290"-"\u12ae",
  522. "\u12b0",
  523. "\u12b2"-"\u12b5",
  524. "\u12b8"-"\u12be",
  525. "\u12c0",
  526. "\u12c2"-"\u12c5",
  527. "\u12c8"-"\u12ce",
  528. "\u12d0"-"\u12d6",
  529. "\u12d8"-"\u12ee",
  530. "\u12f0"-"\u130e",
  531. "\u1310",
  532. "\u1312"-"\u1315",
  533. "\u1318"-"\u131e",
  534. "\u1320"-"\u1346",
  535. "\u1348"-"\u135a",
  536. "\u13a0"-"\u13f4",
  537. "\u1401"-"\u166c",
  538. "\u166f"-"\u1676",
  539. "\u1681"-"\u169a",
  540. "\u16a0"-"\u16ea",
  541. "\u1780"-"\u17b3",
  542. "\u17db",
  543. "\u1820"-"\u1877",
  544. "\u1880"-"\u18a8",
  545. "\u1e00"-"\u1e9b",
  546. "\u1ea0"-"\u1ef9",
  547. "\u1f00"-"\u1f15",
  548. "\u1f18"-"\u1f1d",
  549. "\u1f20"-"\u1f45",
  550. "\u1f48"-"\u1f4d",
  551. "\u1f50"-"\u1f57",
  552. "\u1f59",
  553. "\u1f5b",
  554. "\u1f5d",
  555. "\u1f5f"-"\u1f7d",
  556. "\u1f80"-"\u1fb4",
  557. "\u1fb6"-"\u1fbc",
  558. "\u1fbe",
  559. "\u1fc2"-"\u1fc4",
  560. "\u1fc6"-"\u1fcc",
  561. "\u1fd0"-"\u1fd3",
  562. "\u1fd6"-"\u1fdb",
  563. "\u1fe0"-"\u1fec",
  564. "\u1ff2"-"\u1ff4",
  565. "\u1ff6"-"\u1ffc",
  566. "\u203f"-"\u2040",
  567. "\u207f",
  568. "\u20a0"-"\u20af",
  569. "\u2102",
  570. "\u2107",
  571. "\u210a"-"\u2113",
  572. "\u2115",
  573. "\u2119"-"\u211d",
  574. "\u2124",
  575. "\u2126",
  576. "\u2128",
  577. "\u212a"-"\u212d",
  578. "\u212f"-"\u2131",
  579. "\u2133"-"\u2139",
  580. "\u2160"-"\u2183",
  581. "\u3005"-"\u3007",
  582. "\u3021"-"\u3029",
  583. "\u3031"-"\u3035",
  584. "\u3038"-"\u303a",
  585. "\u3041"-"\u3094",
  586. "\u309d"-"\u309e",
  587. "\u30a1"-"\u30fe",
  588. "\u3105"-"\u312c",
  589. "\u3131"-"\u318e",
  590. "\u31a0"-"\u31b7",
  591. "\u3400"-"\u4db5",
  592. "\u4e00"-"\u9fa5",
  593. "\ua000"-"\ua48c",
  594. "\uac00"-"\ud7a3",
  595. "\uf900"-"\ufa2d",
  596. "\ufb00"-"\ufb06",
  597. "\ufb13"-"\ufb17",
  598. "\ufb1d",
  599. "\ufb1f"-"\ufb28",
  600. "\ufb2a"-"\ufb36",
  601. "\ufb38"-"\ufb3c",
  602. "\ufb3e",
  603. "\ufb40"-"\ufb41",
  604. "\ufb43"-"\ufb44",
  605. "\ufb46"-"\ufbb1",
  606. "\ufbd3"-"\ufd3d",
  607. "\ufd50"-"\ufd8f",
  608. "\ufd92"-"\ufdc7",
  609. "\ufdf0"-"\ufdfb",
  610. "\ufe33"-"\ufe34",
  611. "\ufe4d"-"\ufe4f",
  612. "\ufe69",
  613. "\ufe70"-"\ufe72",
  614. "\ufe74",
  615. "\ufe76"-"\ufefc",
  616. "\uff04",
  617. "\uff21"-"\uff3a",
  618. "\uff3f",
  619. "\uff41"-"\uff5a",
  620. "\uff65"-"\uffbe",
  621. "\uffc2"-"\uffc7",
  622. "\uffca"-"\uffcf",
  623. "\uffd2"-"\uffd7",
  624. "\uffda"-"\uffdc",
  625. "\uffe0"-"\uffe1",
  626. "\uffe5"-"\uffe6"
  627. ]
  628. >
  629. |
  630. < #PART_LETTER:
  631. [ // all chars for which Character.isIdentifierPart is true
  632. "\u0000"-"\u0008",
  633. "\u000e"-"\u001b",
  634. "$",
  635. "0"-"9",
  636. "A"-"Z",
  637. "_",
  638. "a"-"z",
  639. "\u007f"-"\u009f",
  640. "\u00a2"-"\u00a5",
  641. "\u00aa",
  642. "\u00b5",
  643. "\u00ba",
  644. "\u00c0"-"\u00d6",
  645. "\u00d8"-"\u00f6",
  646. "\u00f8"-"\u021f",
  647. "\u0222"-"\u0233",
  648. "\u0250"-"\u02ad",
  649. "\u02b0"-"\u02b8",
  650. "\u02bb"-"\u02c1",
  651. "\u02d0"-"\u02d1",
  652. "\u02e0"-"\u02e4",
  653. "\u02ee",
  654. "\u0300"-"\u034e",
  655. "\u0360"-"\u0362",
  656. "\u037a",
  657. "\u0386",
  658. "\u0388"-"\u038a",
  659. "\u038c",
  660. "\u038e"-"\u03a1",
  661. "\u03a3"-"\u03ce",
  662. "\u03d0"-"\u03d7",
  663. "\u03da"-"\u03f3",
  664. "\u0400"-"\u0481",
  665. "\u0483"-"\u0486",
  666. "\u048c"-"\u04c4",
  667. "\u04c7"-"\u04c8",
  668. "\u04cb"-"\u04cc",
  669. "\u04d0"-"\u04f5",
  670. "\u04f8"-"\u04f9",
  671. "\u0531"-"\u0556",
  672. "\u0559",
  673. "\u0561"-"\u0587",
  674. "\u0591"-"\u05a1",
  675. "\u05a3"-"\u05b9",
  676. "\u05bb"-"\u05bd",
  677. "\u05bf",
  678. "\u05c1"-"\u05c2",
  679. "\u05c4",
  680. "\u05d0"-"\u05ea",
  681. "\u05f0"-"\u05f2",
  682. "\u0621"-"\u063a",
  683. "\u0640"-"\u0655",
  684. "\u0660"-"\u0669",
  685. "\u0670"-"\u06d3",
  686. "\u06d5"-"\u06dc",
  687. "\u06df"-"\u06e8",
  688. "\u06ea"-"\u06ed",
  689. "\u06f0"-"\u06fc",
  690. "\u070f"-"\u072c",
  691. "\u0730"-"\u074a",
  692. "\u0780"-"\u07b0",
  693. "\u0901"-"\u0903",
  694. "\u0905"-"\u0939",
  695. "\u093c"-"\u094d",
  696. "\u0950"-"\u0954",
  697. "\u0958"-"\u0963",
  698. "\u0966"-"\u096f",
  699. "\u0981"-"\u0983",
  700. "\u0985"-"\u098c",
  701. "\u098f"-"\u0990",
  702. "\u0993"-"\u09a8",
  703. "\u09aa"-"\u09b0",
  704. "\u09b2",
  705. "\u09b6"-"\u09b9",
  706. "\u09bc",
  707. "\u09be"-"\u09c4",
  708. "\u09c7"-"\u09c8",
  709. "\u09cb"-"\u09cd",
  710. "\u09d7",
  711. "\u09dc"-"\u09dd",
  712. "\u09df"-"\u09e3",
  713. "\u09e6"-"\u09f3",
  714. "\u0a02",
  715. "\u0a05"-"\u0a0a",
  716. "\u0a0f"-"\u0a10",
  717. "\u0a13"-"\u0a28",
  718. "\u0a2a"-"\u0a30",
  719. "\u0a32"-"\u0a33",
  720. "\u0a35"-"\u0a36",
  721. "\u0a38"-"\u0a39",
  722. "\u0a3c",
  723. "\u0a3e"-"\u0a42",
  724. "\u0a47"-"\u0a48",
  725. "\u0a4b"-"\u0a4d",
  726. "\u0a59"-"\u0a5c",
  727. "\u0a5e",
  728. "\u0a66"-"\u0a74",
  729. "\u0a81"-"\u0a83",
  730. "\u0a85"-"\u0a8b",
  731. "\u0a8d",
  732. "\u0a8f"-"\u0a91",
  733. "\u0a93"-"\u0aa8",
  734. "\u0aaa"-"\u0ab0",
  735. "\u0ab2"-"\u0ab3",
  736. "\u0ab5"-"\u0ab9",
  737. "\u0abc"-"\u0ac5",
  738. "\u0ac7"-"\u0ac9",
  739. "\u0acb"-"\u0acd",
  740. "\u0ad0",
  741. "\u0ae0",
  742. "\u0ae6"-"\u0aef",
  743. "\u0b01"-"\u0b03",
  744. "\u0b05"-"\u0b0c",
  745. "\u0b0f"-"\u0b10",
  746. "\u0b13"-"\u0b28",
  747. "\u0b2a"-"\u0b30",
  748. "\u0b32"-"\u0b33",
  749. "\u0b36"-"\u0b39",
  750. "\u0b3c"-"\u0b43",
  751. "\u0b47"-"\u0b48",
  752. "\u0b4b"-"\u0b4d",
  753. "\u0b56"-"\u0b57",
  754. "\u0b5c"-"\u0b5d",
  755. "\u0b5f"-"\u0b61",
  756. "\u0b66"-"\u0b6f",
  757. "\u0b82"-"\u0b83",
  758. "\u0b85"-"\u0b8a",
  759. "\u0b8e"-"\u0b90",
  760. "\u0b92"-"\u0b95",
  761. "\u0b99"-"\u0b9a",
  762. "\u0b9c",
  763. "\u0b9e"-"\u0b9f",
  764. "\u0ba3"-"\u0ba4",
  765. "\u0ba8"-"\u0baa",
  766. "\u0bae"-"\u0bb5",
  767. "\u0bb7"-"\u0bb9",
  768. "\u0bbe"-"\u0bc2",
  769. "\u0bc6"-"\u0bc8",
  770. "\u0bca"-"\u0bcd",
  771. "\u0bd7",
  772. "\u0be7"-"\u0bef",
  773. "\u0c01"-"\u0c03",
  774. "\u0c05"-"\u0c0c",
  775. "\u0c0e"-"\u0c10",
  776. "\u0c12"-"\u0c28",
  777. "\u0c2a"-"\u0c33",
  778. "\u0c35"-"\u0c39",
  779. "\u0c3e"-"\u0c44",
  780. "\u0c46"-"\u0c48",
  781. "\u0c4a"-"\u0c4d",
  782. "\u0c55"-"\u0c56",
  783. "\u0c60"-"\u0c61",
  784. "\u0c66"-"\u0c6f",
  785. "\u0c82"-"\u0c83",
  786. "\u0c85"-"\u0c8c",
  787. "\u0c8e"-"\u0c90",
  788. "\u0c92"-"\u0ca8",
  789. "\u0caa"-"\u0cb3",
  790. "\u0cb5"-"\u0cb9",
  791. "\u0cbe"-"\u0cc4",
  792. "\u0cc6"-"\u0cc8",
  793. "\u0cca"-"\u0ccd",
  794. "\u0cd5"-"\u0cd6",
  795. "\u0cde",
  796. "\u0ce0"-"\u0ce1",
  797. "\u0ce6"-"\u0cef",
  798. "\u0d02"-"\u0d03",
  799. "\u0d05"-"\u0d0c",
  800. "\u0d0e"-"\u0d10",
  801. "\u0d12"-"\u0d28",
  802. "\u0d2a"-"\u0d39",
  803. "\u0d3e"-"\u0d43",
  804. "\u0d46"-"\u0d48",
  805. "\u0d4a"-"\u0d4d",
  806. "\u0d57",
  807. "\u0d60"-"\u0d61",
  808. "\u0d66"-"\u0d6f",
  809. "\u0d82"-"\u0d83",
  810. "\u0d85"-"\u0d96",
  811. "\u0d9a"-"\u0db1",
  812. "\u0db3"-"\u0dbb",
  813. "\u0dbd",
  814. "\u0dc0"-"\u0dc6",
  815. "\u0dca",
  816. "\u0dcf"-"\u0dd4",
  817. "\u0dd6",
  818. "\u0dd8"-"\u0ddf",
  819. "\u0df2"-"\u0df3",
  820. "\u0e01"-"\u0e3a",
  821. "\u0e3f"-"\u0e4e",
  822. "\u0e50"-"\u0e59",
  823. "\u0e81"-"\u0e82",
  824. "\u0e84",
  825. "\u0e87"-"\u0e88",
  826. "\u0e8a",
  827. "\u0e8d",
  828. "\u0e94"-"\u0e97",
  829. "\u0e99"-"\u0e9f",
  830. "\u0ea1"-"\u0ea3",
  831. "\u0ea5",
  832. "\u0ea7",
  833. "\u0eaa"-"\u0eab",
  834. "\u0ead"-"\u0eb9",
  835. "\u0ebb"-"\u0ebd",
  836. "\u0ec0"-"\u0ec4",
  837. "\u0ec6",
  838. "\u0ec8"-"\u0ecd",
  839. "\u0ed0"-"\u0ed9",
  840. "\u0edc"-"\u0edd",
  841. "\u0f00",
  842. "\u0f18"-"\u0f19",
  843. "\u0f20"-"\u0f29",
  844. "\u0f35",
  845. "\u0f37",
  846. "\u0f39",
  847. "\u0f3e"-"\u0f47",
  848. "\u0f49"-"\u0f6a",
  849. "\u0f71"-"\u0f84",
  850. "\u0f86"-"\u0f8b",
  851. "\u0f90"-"\u0f97",
  852. "\u0f99"-"\u0fbc",
  853. "\u0fc6",
  854. "\u1000"-"\u1021",
  855. "\u1023"-"\u1027",
  856. "\u1029"-"\u102a",
  857. "\u102c"-"\u1032",
  858. "\u1036"-"\u1039",
  859. "\u1040"-"\u1049",
  860. "\u1050"-"\u1059",
  861. "\u10a0"-"\u10c5",
  862. "\u10d0"-"\u10f6",
  863. "\u1100"-"\u1159",
  864. "\u115f"-"\u11a2",
  865. "\u11a8"-"\u11f9",
  866. "\u1200"-"\u1206",
  867. "\u1208"-"\u1246",
  868. "\u1248",
  869. "\u124a"-"\u124d",
  870. "\u1250"-"\u1256",
  871. "\u1258",
  872. "\u125a"-"\u125d",
  873. "\u1260"-"\u1286",
  874. "\u1288",
  875. "\u128a"-"\u128d",
  876. "\u1290"-"\u12ae",
  877. "\u12b0",
  878. "\u12b2"-"\u12b5",
  879. "\u12b8"-"\u12be",
  880. "\u12c0",
  881. "\u12c2"-"\u12c5",
  882. "\u12c8"-"\u12ce",
  883. "\u12d0"-"\u12d6",
  884. "\u12d8"-"\u12ee",
  885. "\u12f0"-"\u130e",
  886. "\u1310",
  887. "\u1312"-"\u1315",
  888. "\u1318"-"\u131e",
  889. "\u1320"-"\u1346",
  890. "\u1348"-"\u135a",
  891. "\u1369"-"\u1371",
  892. "\u13a0"-"\u13f4",
  893. "\u1401"-"\u166c",
  894. "\u166f"-"\u1676",
  895. "\u1681"-"\u169a",
  896. "\u16a0"-"\u16ea",
  897. "\u1780"-"\u17d3",
  898. "\u17db",
  899. "\u17e0"-"\u17e9",
  900. "\u180b"-"\u180e",
  901. "\u1810"-"\u1819",
  902. "\u1820"-"\u1877",
  903. "\u1880"-"\u18a9",
  904. "\u1e00"-"\u1e9b",
  905. "\u1ea0"-"\u1ef9",
  906. "\u1f00"-"\u1f15",
  907. "\u1f18"-"\u1f1d",
  908. "\u1f20"-"\u1f45",
  909. "\u1f48"-"\u1f4d",
  910. "\u1f50"-"\u1f57",
  911. "\u1f59",
  912. "\u1f5b",
  913. "\u1f5d",
  914. "\u1f5f"-"\u1f7d",
  915. "\u1f80"-"\u1fb4",
  916. "\u1fb6"-"\u1fbc",
  917. "\u1fbe",
  918. "\u1fc2"-"\u1fc4",
  919. "\u1fc6"-"\u1fcc",
  920. "\u1fd0"-"\u1fd3",
  921. "\u1fd6"-"\u1fdb",
  922. "\u1fe0"-"\u1fec",
  923. "\u1ff2"-"\u1ff4",
  924. "\u1ff6"-"\u1ffc",
  925. "\u200c"-"\u200f",
  926. "\u202a"-"\u202e",
  927. "\u203f"-"\u2040",
  928. "\u206a"-"\u206f",
  929. "\u207f",
  930. "\u20a0"-"\u20af",
  931. "\u20d0"-"\u20dc",
  932. "\u20e1",
  933. "\u2102",
  934. "\u2107",
  935. "\u210a"-"\u2113",
  936. "\u2115",
  937. "\u2119"-"\u211d",
  938. "\u2124",
  939. "\u2126",
  940. "\u2128",
  941. "\u212a"-"\u212d",
  942. "\u212f"-"\u2131",
  943. "\u2133"-"\u2139",
  944. "\u2160"-"\u2183",
  945. "\u3005"-"\u3007",
  946. "\u3021"-"\u302f",
  947. "\u3031"-"\u3035",
  948. "\u3038"-"\u303a",
  949. "\u3041"-"\u3094",
  950. "\u3099"-"\u309a",
  951. "\u309d"-"\u309e",
  952. "\u30a1"-"\u30fe",
  953. "\u3105"-"\u312c",
  954. "\u3131"-"\u318e",
  955. "\u31a0"-"\u31b7",
  956. "\u3400"-"\u4db5",
  957. "\u4e00"-"\u9fa5",
  958. "\ua000"-"\ua48c",
  959. "\uac00"-"\ud7a3",
  960. "\uf900"-"\ufa2d",
  961. "\ufb00"-"\ufb06",
  962. "\ufb13"-"\ufb17",
  963. "\ufb1d"-"\ufb28",
  964. "\ufb2a"-"\ufb36",
  965. "\ufb38"-"\ufb3c",
  966. "\ufb3e",
  967. "\ufb40"-"\ufb41",
  968. "\ufb43"-"\ufb44",
  969. "\ufb46"-"\ufbb1",
  970. "\ufbd3"-"\ufd3d",
  971. "\ufd50"-"\ufd8f",
  972. "\ufd92"-"\ufdc7",
  973. "\ufdf0"-"\ufdfb",
  974. "\ufe20"-"\ufe23",
  975. "\ufe33"-"\ufe34",
  976. "\ufe4d"-"\ufe4f",
  977. "\ufe69",
  978. "\ufe70"-"\ufe72",
  979. "\ufe74",
  980. "\ufe76"-"\ufefc",
  981. "\ufeff",
  982. "\uff04",
  983. "\uff10"-"\uff19",
  984. "\uff21"-"\uff3a",
  985. "\uff3f",
  986. "\uff41"-"\uff5a",
  987. "\uff65"-"\uffbe",
  988. "\uffc2"-"\uffc7",
  989. "\uffca"-"\uffcf",
  990. "\uffd2"-"\uffd7",
  991. "\uffda"-"\uffdc",
  992. "\uffe0"-"\uffe1",
  993. "\uffe5"-"\uffe6",
  994. "\ufff9"-"\ufffb"
  995. ]
  996. >
  997. }
  998.  
  999. /* SEPARATORS */
  1000.  
  1001. TOKEN :
  1002. {
  1003. < LPAREN: "(" >
  1004. | < RPAREN: ")" >
  1005. | < LBRACE: "{" >
  1006. | < RBRACE: "}" >
  1007. | < LBRACKET: "[" >
  1008. | < RBRACKET: "]" >
  1009. | < SEMICOLON: ";" >
  1010. | < COMMA: "," >
  1011. | < DOT: "." >
  1012. | < AT: "@" >
  1013. }
  1014.  
  1015. /* OPERATORS */
  1016.  
  1017. TOKEN :
  1018. {
  1019. < ASSIGN: "=" >
  1020. | < LT: "<" >
  1021. | < BANG: "!" >
  1022. | < TILDE: "~" >
  1023. | < HOOK: "?" >
  1024. | < COLON: ":" >
  1025. | < EQ: "==" >
  1026. | < LE: "<=" >
  1027. | < GE: ">=" >
  1028. | < NE: "!=" >
  1029. | < SC_OR: "||" >
  1030. | < SC_AND: "&&" >
  1031. | < INCR: "++" >
  1032. | < DECR: "--" >
  1033. | < PLUS: "+" >
  1034. | < MINUS: "-" >
  1035. | < STAR: "*" >
  1036. | < SLASH: "/" >
  1037. | < BIT_AND: "&" >
  1038. | < BIT_OR: "|" >
  1039. | < XOR: "^" >
  1040. | < REM: "%" >
  1041. | < LSHIFT: "<<" >
  1042. | < PLUSASSIGN: "+=" >
  1043. | < MINUSASSIGN: "-=" >
  1044. | < STARASSIGN: "*=" >
  1045. | < SLASHASSIGN: "/=" >
  1046. | < ANDASSIGN: "&=" >
  1047. | < ORASSIGN: "|=" >
  1048. | < XORASSIGN: "^=" >
  1049. | < REMASSIGN: "%=" >
  1050. | < LSHIFTASSIGN: "<<=" >
  1051. //| < RSIGNEDSHIFTASSIGN: ">>=" >
  1052. //| < RUNSIGNEDSHIFTASSIGN: ">>>=" >
  1053. | < ELLIPSIS: "..." >
  1054. }
  1055.  
  1056. /* >'s need special attention due to generics syntax. */
  1057. //TOKEN :
  1058. //{
  1059. // < RUNSIGNEDSHIFT: ">>>" >
  1060. // {
  1061. // matchedToken.kind = GT;
  1062. // ((MyToken)matchedToken).realKind = RUNSIGNEDSHIFT;
  1063. // input_stream.backup(2);
  1064. // matchedToken.image = ">";
  1065. // }
  1066. //| < RSIGNEDSHIFT: ">>" >
  1067. // {
  1068. // matchedToken.kind = GT;
  1069. // ((MyToken)matchedToken).realKind = RSIGNEDSHIFT;
  1070. // input_stream.backup(1);
  1071. // matchedToken.image = ">";
  1072. // }
  1073. //| < GT: ">" >
  1074. //}
  1075.  
  1076.  
  1077. /*****************************************
  1078. * THE JAVA LANGUAGE GRAMMAR STARTS HERE *
  1079. *****************************************/
  1080.  
  1081. /*
  1082. * Program structuring syntax follows.
  1083. */
  1084.  
  1085. void CompilationUnit():
  1086. {}
  1087. {
  1088. [ LOOKAHEAD( ( Annotation() )* "package" ) PackageDeclaration() ]
  1089. ( ImportDeclaration() )*
  1090. ( TypeDeclaration() )+
  1091. ( < "\u001a" > )?
  1092. ( <STUFF_TO_IGNORE: ~[]> )?
  1093. <EOF>
  1094. }
  1095.  
  1096. void PackageDeclaration():
  1097. {}
  1098. {
  1099. Modifiers() "package" Name() ";"
  1100. }
  1101.  
  1102. void ImportDeclaration():
  1103. {}
  1104. {
  1105. "import" [ "static" ] Name() [ "." "*" ] ";"
  1106. }
  1107.  
  1108. /*
  1109. * Modifiers. We match all modifiers in a single rule to reduce the chances of
  1110. * syntax errors for simple modifier mistakes. It will also enable us to give
  1111. * better error messages.
  1112. */
  1113.  
  1114. int Modifiers():
  1115. {
  1116. int modifiers = 0;
  1117. }
  1118. {
  1119. (
  1120. LOOKAHEAD(2)
  1121. (
  1122. "public" { modifiers |= ModifierSet.PUBLIC; }
  1123. |
  1124. "static" { modifiers |= ModifierSet.STATIC; }
  1125. |
  1126. "protected" { modifiers |= ModifierSet.PROTECTED; }
  1127. |
  1128. "private" { modifiers |= ModifierSet.PRIVATE; }
  1129. |
  1130. "final" { modifiers |= ModifierSet.FINAL; }
  1131. |
  1132. "abstract" { modifiers |= ModifierSet.ABSTRACT; }
  1133. |
  1134. "synchronized" { modifiers |= ModifierSet.SYNCHRONIZED; }
  1135. |
  1136. "native" { modifiers |= ModifierSet.NATIVE; }
  1137. |
  1138. "transient" { modifiers |= ModifierSet.TRANSIENT; }
  1139. |
  1140. "volatile" { modifiers |= ModifierSet.VOLATILE; }
  1141. |
  1142. "strictfp" { modifiers |= ModifierSet.STRICTFP; }
  1143. |
  1144. Annotation()
  1145. )
  1146. )*
  1147.  
  1148. {
  1149. return modifiers;
  1150. }
  1151. }
  1152.  
  1153. /*
  1154. * Declaration syntax follows.
  1155. */
  1156. void TypeDeclaration():
  1157. {
  1158. int modifiers;
  1159. }
  1160. {
  1161. ";"
  1162. |
  1163. modifiers = Modifiers()
  1164. (
  1165. ClassOrInterfaceDeclaration(modifiers)
  1166. |
  1167. EnumDeclaration(modifiers)
  1168. |
  1169. AnnotationTypeDeclaration(modifiers)
  1170. )
  1171. }
  1172.  
  1173.  
  1174. void ClassOrInterfaceDeclaration(int modifiers):
  1175. {
  1176. boolean isInterface = false;
  1177. }
  1178. {
  1179. ( "class" | "interface" { isInterface = true; } )
  1180. <IDENTIFIER>
  1181. [ TypeParameters() ]
  1182. [ ExtendsList(isInterface) ]
  1183. [ ImplementsList(isInterface) ]
  1184. ClassOrInterfaceBody(isInterface)
  1185. }
  1186.  
  1187. void ExtendsList(boolean isInterface):
  1188. {
  1189. boolean extendsMoreThanOne = false;
  1190. }
  1191. {
  1192. "extends" ClassOrInterfaceType()
  1193. ( "," ClassOrInterfaceType() { extendsMoreThanOne = true; } )*
  1194. {
  1195. if (extendsMoreThanOne && !isInterface)
  1196. throw new ParseException("A class cannot extend more than one other class");
  1197. }
  1198. }
  1199.  
  1200. void ImplementsList(boolean isInterface):
  1201. {}
  1202. {
  1203. "implements" ClassOrInterfaceType()
  1204. ( "," ClassOrInterfaceType() )*
  1205. {
  1206. if (isInterface)
  1207. throw new ParseException("An interface cannot implement other interfaces");
  1208. }
  1209. }
  1210.  
  1211. void EnumDeclaration(int modifiers):
  1212. {}
  1213. {
  1214. "enum" <IDENTIFIER>
  1215. [ ImplementsList(false) ]
  1216. EnumBody()
  1217. }
  1218.  
  1219. void EnumBody():
  1220. {}
  1221. {
  1222. "{"
  1223. [ EnumConstant() ( LOOKAHEAD(2) "," EnumConstant() )* ]
  1224. [ "," ]
  1225. [ ";" ( ClassOrInterfaceBodyDeclaration(false) )* ]
  1226. "}"
  1227. }
  1228.  
  1229. void EnumConstant():
  1230. {}
  1231. {
  1232. Modifiers() <IDENTIFIER> [ Arguments() ] [ ClassOrInterfaceBody(false) ]
  1233. }
  1234.  
  1235. void TypeParameters():
  1236. {}
  1237. {
  1238. "<" TypeParameter() ( "," TypeParameter() )* ">"
  1239. }
  1240.  
  1241. void TypeParameter():
  1242. {}
  1243. {
  1244. <IDENTIFIER> [ TypeBound() ]
  1245. }
  1246.  
  1247. void TypeBound():
  1248. {}
  1249. {
  1250. "extends" ClassOrInterfaceType() ( "&" ClassOrInterfaceType() )*
  1251. }
  1252.  
  1253. void ClassOrInterfaceBody(boolean isInterface):
  1254. {}
  1255. {
  1256. "{" ( ClassOrInterfaceBodyDeclaration(isInterface) )* "}"
  1257. }
  1258.  
  1259. void ClassOrInterfaceBodyDeclaration(boolean isInterface):
  1260. {
  1261. boolean isNestedInterface = false;
  1262. int modifiers;
  1263. }
  1264. {
  1265. LOOKAHEAD(2)
  1266. Initializer()
  1267. {
  1268. if (isInterface)
  1269. throw new ParseException("An interface cannot have initializers");
  1270. }
  1271. |
  1272. modifiers = Modifiers() // Just get all the modifiers out of the way. If you want to do
  1273. // more checks, pass the modifiers down to the member
  1274. (
  1275. ClassOrInterfaceDeclaration(modifiers)
  1276. |
  1277. EnumDeclaration(modifiers)
  1278. |
  1279. LOOKAHEAD( [ TypeParameters() ] <IDENTIFIER> "(" )
  1280. ConstructorDeclaration()
  1281. |
  1282. LOOKAHEAD( Type() <IDENTIFIER> ( "[" "]" )* ( "," | "=" | ";" ) )
  1283. FieldDeclaration(modifiers)
  1284. |
  1285. MethodDeclaration(modifiers)
  1286. |
  1287. AnnotationTypeDeclaration(modifiers)
  1288. )
  1289. |
  1290. ";"
  1291. }
  1292.  
  1293. void FieldDeclaration(int modifiers):
  1294. {}
  1295. {
  1296. // Modifiers are already matched in the caller
  1297. Type() VariableDeclarator() ( "," VariableDeclarator() )* ";"
  1298. }
  1299.  
  1300. void VariableDeclarator():
  1301. {}
  1302. {
  1303. VariableDeclaratorId() [ "=" VariableInitializer() ]
  1304. }
  1305.  
  1306. void VariableDeclaratorId():
  1307. {Token t; }
  1308. {
  1309. t = <IDENTIFIER> ( "[" "]" )*
  1310. {
  1311. System.out.println("Here I am parsing count Variable Declarator" + t);
  1312. countVarDec++ ;
  1313. }
  1314. }
  1315.  
  1316. void VariableInitializer():
  1317. {}
  1318. {
  1319. ArrayInitializer()
  1320. |
  1321. Expression()
  1322. }
  1323.  
  1324. void ArrayInitializer():
  1325. {}
  1326. {
  1327. "{" [ VariableInitializer() ( LOOKAHEAD(2) "," VariableInitializer() )* ] [ "," ] "}"
  1328. }
  1329.  
  1330. void MethodDeclaration(int modifiers):
  1331. {}
  1332. {
  1333. // Modifiers already matched in the caller!
  1334. [ TypeParameters() ]
  1335. ResultType()
  1336. MethodDeclarator() [ "throws" NameList() ]
  1337. ( Block() | ";" )
  1338. }
  1339.  
  1340. void MethodDeclarator():
  1341. {Token t ;}
  1342. {
  1343. t= <IDENTIFIER> FormalParameters() ( "[" "]" )*
  1344. {
  1345. System.out.println ("I have parse countMethodDeclarator "+ t );
  1346. countMethodDec++ ;
  1347. }
  1348. }
  1349.  
  1350. void FormalParameters():
  1351. {}
  1352. {
  1353. "(" [ FormalParameter() ( "," FormalParameter() )* ] ")"
  1354. }
  1355.  
  1356. void FormalParameter():
  1357. {}
  1358. {
  1359. // danson, added
  1360. // [ "final" | Annotation() ]
  1361. // See Java Language Specification, 3rd Edition, section 8.4.1
  1362. Modifiers() [ "final" | Annotation() ] Type() [ "..." ] VariableDeclaratorId()
  1363. }
  1364.  
  1365. void ConstructorDeclaration():
  1366. {Token t ;}
  1367. { [ TypeParameters() ]
  1368. // Modifiers matched in the caller
  1369. t = <IDENTIFIER> FormalParameters() [ "throws" NameList() ]
  1370. "{"
  1371. [ LOOKAHEAD(ExplicitConstructorInvocation())
  1372. ExplicitConstructorInvocation()
  1373. ]
  1374. ( BlockStatement() )*
  1375. {
  1376. System.out.println("Here I parse ConstructorDeclaration" + t);
  1377. countConstruct++ ;
  1378. }
  1379. "}"
  1380. }
  1381.  
  1382. void ExplicitConstructorInvocation():
  1383. {}
  1384. {
  1385. ( <IDENTIFIER> "." )* [ LOOKAHEAD(2) "this" "." ]
  1386. [ TypeArguments() ] ("this"|"super") Arguments() ";"
  1387. }
  1388.  
  1389. void Initializer():
  1390. {}
  1391. {
  1392. [ "static" ] Block()
  1393. }
  1394.  
  1395.  
  1396. /*
  1397. * Type, name and expression syntax follows.
  1398. */
  1399.  
  1400. void Type():
  1401. {}
  1402. {
  1403. LOOKAHEAD(2) ReferenceType()
  1404. |
  1405. PrimitiveType()
  1406. }
  1407.  
  1408. void ReferenceType():
  1409. {}
  1410. {
  1411. PrimitiveType() ( LOOKAHEAD(2) "[" "]" )+
  1412. |
  1413. ( ClassOrInterfaceType() ) ( LOOKAHEAD(2) "[" "]" )*
  1414. }
  1415.  
  1416. void ClassOrInterfaceType():
  1417. {}
  1418. {
  1419. <IDENTIFIER> [ LOOKAHEAD(2) TypeArguments() ]
  1420. ( LOOKAHEAD(2) "." <IDENTIFIER> [ LOOKAHEAD(2) TypeArguments() ] )*
  1421. }
  1422.  
  1423. void TypeArguments():
  1424. {}
  1425. {
  1426. "<" TypeArgument() ( "," TypeArgument() )* ">"
  1427. }
  1428.  
  1429. void TypeArgument():
  1430. {}
  1431. {
  1432. ReferenceType()
  1433. |
  1434. "?" [ WildcardBounds() ]
  1435. }
  1436.  
  1437. void WildcardBounds():
  1438. {}
  1439. {
  1440. "extends" ReferenceType()
  1441. |
  1442. "super" ReferenceType()
  1443. }
  1444.  
  1445.  
  1446. void PrimitiveType():
  1447. {}
  1448. {
  1449. "boolean"
  1450. |
  1451. "char"
  1452. |
  1453. "byte"
  1454. |
  1455. "short"
  1456. |
  1457. "int"
  1458. |
  1459. "long"
  1460. |
  1461. "float"
  1462. |
  1463. "double"
  1464. }
  1465.  
  1466. void ResultType():
  1467. {}
  1468. {
  1469. "void"
  1470. |
  1471. Type()
  1472. }
  1473.  
  1474. void Name():
  1475. /*
  1476. * A lookahead of 2 is required below since "Name" can be followed
  1477. * by a ".*" when used in the context of an "ImportDeclaration".
  1478. */
  1479. {}
  1480. {
  1481. <IDENTIFIER>
  1482. ( LOOKAHEAD(2) "." <IDENTIFIER>
  1483. )*
  1484. }
  1485.  
  1486. void NameList():
  1487. {}
  1488. {
  1489. Name() ( "," Name() )*
  1490. }
  1491.  
  1492.  
  1493. /*
  1494. * Expression syntax follows.
  1495. */
  1496.  
  1497. void Expression():
  1498. /*
  1499. * This expansion has been written this way instead of:
  1500. * Assignment() | ConditionalExpression()
  1501. * for performance reasons.
  1502. * However, it is a weakening of the grammar for it allows the LHS of
  1503. * assignments to be any conditional expression whereas it can only be
  1504. * a primary expression. Consider adding a semantic predicate to work
  1505. * around this.
  1506. */
  1507. {}
  1508. {
  1509. ConditionalExpression()
  1510. [
  1511. LOOKAHEAD(2)
  1512. AssignmentOperator() Expression()
  1513. ]
  1514. }
  1515.  
  1516. void AssignmentOperator():
  1517. {}
  1518. {
  1519. "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | ">>>=" | "&=" | "^=" | "|="
  1520. }
  1521.  
  1522. void ConditionalExpression():
  1523. {}
  1524. {
  1525. ConditionalOrExpression() [ "?" Expression() ":" Expression() ]
  1526. }
  1527.  
  1528. void ConditionalOrExpression():
  1529. {}
  1530. {
  1531. ConditionalAndExpression() ( "||" ConditionalAndExpression() )*
  1532. }
  1533.  
  1534. void ConditionalAndExpression():
  1535. {}
  1536. {
  1537. InclusiveOrExpression() ( "&&" InclusiveOrExpression() )*
  1538. }
  1539.  
  1540. void InclusiveOrExpression():
  1541. {}
  1542. {
  1543. ExclusiveOrExpression() ( "|" ExclusiveOrExpression() )*
  1544. }
  1545.  
  1546. void ExclusiveOrExpression():
  1547. {}
  1548. {
  1549. AndExpression() ( "^" AndExpression() )*
  1550. }
  1551.  
  1552. void AndExpression():
  1553. {}
  1554. {
  1555. EqualityExpression() ( "&" EqualityExpression() )*
  1556. }
  1557.  
  1558. void EqualityExpression():
  1559. {}
  1560. {
  1561. InstanceOfExpression() ( ( "==" | "!=" ) InstanceOfExpression() )*
  1562. }
  1563.  
  1564. void InstanceOfExpression():
  1565. {}
  1566. {
  1567. RelationalExpression() [ "instanceof" Type() ]
  1568. }
  1569.  
  1570. void RelationalExpression():
  1571. {}
  1572. {
  1573. ShiftExpression() ( ( "<" | ">" | "<=" | ">=" ) ShiftExpression() )*
  1574. }
  1575.  
  1576. void ShiftExpression():
  1577. {}
  1578. {
  1579. AdditiveExpression() ( ( "<<" /*| RSIGNEDSHIFT() | RUNSIGNEDSHIFT() */ ) AdditiveExpression() )*
  1580. }
  1581.  
  1582. void AdditiveExpression():
  1583. {}
  1584. {
  1585. MultiplicativeExpression() ( ( "+" | "-" ) MultiplicativeExpression() )*
  1586. }
  1587.  
  1588. void MultiplicativeExpression():
  1589. {}
  1590. {
  1591. UnaryExpression() ( ( "*" | "/" | "%" ) UnaryExpression() )*
  1592. }
  1593.  
  1594. void UnaryExpression():
  1595. {}
  1596. {
  1597. ( "+" | "-" ) UnaryExpression()
  1598. |
  1599. PreIncrementExpression()
  1600. |
  1601. PreDecrementExpression()
  1602. |
  1603. UnaryExpressionNotPlusMinus()
  1604. }
  1605.  
  1606. void PreIncrementExpression():
  1607. {}
  1608. {
  1609. "++" PrimaryExpression()
  1610. }
  1611.  
  1612. void PreDecrementExpression():
  1613. {}
  1614. {
  1615. "--" PrimaryExpression()
  1616. }
  1617.  
  1618. void UnaryExpressionNotPlusMinus():
  1619. {}
  1620. {
  1621. ( "~" | "!" ) UnaryExpression()
  1622. |
  1623. LOOKAHEAD( CastLookahead() )
  1624. CastExpression()
  1625. |
  1626. PostfixExpression()
  1627. }
  1628.  
  1629. // This production is to determine lookahead only. The LOOKAHEAD specifications
  1630. // below are not used, but they are there just to indicate that we know about
  1631. // this.
  1632. void CastLookahead():
  1633. {}
  1634. {
  1635. LOOKAHEAD(2)
  1636. "(" PrimitiveType()
  1637. |
  1638. LOOKAHEAD("(" Type() "[")
  1639. "(" Type() "[" "]"
  1640. |
  1641. "(" Type() ")" ( "~" | "!" | "(" | <IDENTIFIER> | "this" | "super" | "new" | Literal() )
  1642. }
  1643.  
  1644. void PostfixExpression():
  1645. {}
  1646. {
  1647. PrimaryExpression() [ "++" | "--" ]
  1648. }
  1649.  
  1650. void CastExpression():
  1651. {}
  1652. {
  1653. LOOKAHEAD("(" PrimitiveType())
  1654. "(" Type() ")" UnaryExpression()
  1655. |
  1656. "(" Type() ")" UnaryExpressionNotPlusMinus()
  1657. }
  1658.  
  1659. void PrimaryExpression():
  1660. {}
  1661. {
  1662. PrimaryPrefix() ( LOOKAHEAD(2) PrimarySuffix() )*
  1663. }
  1664.  
  1665. void MemberSelector():
  1666. {}
  1667. {
  1668. "." TypeArguments() <IDENTIFIER>
  1669. }
  1670.  
  1671. void PrimaryPrefix():
  1672. {}
  1673. {
  1674. Literal()
  1675. |
  1676. LOOKAHEAD( ( <IDENTIFIER> "." )* "this" )
  1677. ( <IDENTIFIER> "." )*
  1678. "this"
  1679. |
  1680. "super" "." <IDENTIFIER>
  1681. |
  1682. // danson, added this part to support a construct like:
  1683. // Buffer.super.setDirty(true);
  1684. // See Java Language Specification, 3rd edition, section 15.11.2.
  1685. LOOKAHEAD( ClassOrInterfaceType() "." "super" "." <IDENTIFIER> )
  1686. ClassOrInterfaceType() "." "super" "." <IDENTIFIER>
  1687. |
  1688. "(" Expression() ")"
  1689. |
  1690. AllocationExpression()
  1691. |
  1692. LOOKAHEAD( ResultType() "." "class" )
  1693. ResultType() "." "class"
  1694. |
  1695. Name()
  1696. }
  1697.  
  1698. void PrimarySuffix():
  1699. {}
  1700. {
  1701. LOOKAHEAD("." "super" ".")
  1702. "." "super"
  1703. |
  1704. LOOKAHEAD("." "this")
  1705. "." "this"
  1706. |
  1707. LOOKAHEAD(2)
  1708. "." AllocationExpression()
  1709. |
  1710. LOOKAHEAD(3)
  1711. MemberSelector()
  1712. |
  1713. "[" Expression() "]"
  1714. |
  1715. "." <IDENTIFIER>
  1716. |
  1717. Arguments()
  1718. }
  1719.  
  1720. void Literal():
  1721. {}
  1722. {
  1723. <INTEGER_LITERAL>
  1724. |
  1725. <FLOATING_POINT_LITERAL>
  1726. |
  1727. <CHARACTER_LITERAL>
  1728. |
  1729. <STRING_LITERAL>
  1730. |
  1731. BooleanLiteral()
  1732. |
  1733. NullLiteral()
  1734. }
  1735.  
  1736. void BooleanLiteral():
  1737. {}
  1738. {
  1739. "true"
  1740. |
  1741. "false"
  1742. }
  1743.  
  1744. void NullLiteral():
  1745. {}
  1746. {
  1747. "null"
  1748. }
  1749.  
  1750. void Arguments():
  1751. {}
  1752. {
  1753. "(" [ ArgumentList() ] ")"
  1754. }
  1755.  
  1756. void ArgumentList():
  1757. {}
  1758. {
  1759. Expression() ( "," Expression() )*
  1760. }
  1761.  
  1762. void AllocationExpression():
  1763. {}
  1764. {
  1765. LOOKAHEAD(2)
  1766. "new" PrimitiveType() ArrayDimsAndInits()
  1767. |
  1768. "new" ClassOrInterfaceType() [ TypeArguments() ]
  1769. (
  1770. ArrayDimsAndInits()
  1771. |
  1772. Arguments() [ ClassOrInterfaceBody(false) ]
  1773. )
  1774. }
  1775.  
  1776. /*
  1777. * The third LOOKAHEAD specification below is to parse to PrimarySuffix
  1778. * if there is an expression between the "[...]".
  1779. */
  1780. void ArrayDimsAndInits():
  1781. {}
  1782. {
  1783. LOOKAHEAD(2)
  1784. ( LOOKAHEAD(2) "[" Expression() "]" )+ ( LOOKAHEAD(2) "[" "]" )*
  1785. |
  1786. ( "[" "]" )+ ArrayInitializer()
  1787. }
  1788.  
  1789.  
  1790. /*
  1791. * Statement syntax follows.
  1792. */
  1793.  
  1794. void Statement():
  1795. {}
  1796. {
  1797. LOOKAHEAD(2)
  1798. LabeledStatement()
  1799. |
  1800. AssertStatement()
  1801. |
  1802. Block()
  1803. |
  1804. EmptyStatement()
  1805. |
  1806. StatementExpression() ";"
  1807. |
  1808. SwitchStatement()
  1809. |
  1810. IfStatement()
  1811. |
  1812. WhileStatement()
  1813. |
  1814. DoStatement()
  1815. |
  1816. ForStatement()
  1817. |
  1818. BreakStatement()
  1819. |
  1820. ContinueStatement()
  1821. |
  1822. ReturnStatement()
  1823. |
  1824. ThrowStatement()
  1825. |
  1826. SynchronizedStatement()
  1827. |
  1828. TryStatement()
  1829. }
  1830.  
  1831. void AssertStatement():
  1832. {}
  1833. {
  1834. "assert" Expression() [ ":" Expression() ] ";"
  1835. }
  1836.  
  1837. void LabeledStatement():
  1838. {}
  1839. {
  1840. <IDENTIFIER> ":" Statement()
  1841. }
  1842.  
  1843. void Block():
  1844. {}
  1845. {
  1846. "{" ( BlockStatement() )* "}"
  1847. }
  1848.  
  1849. void BlockStatement():
  1850. {}
  1851. {
  1852. LOOKAHEAD( Modifiers() Type() <IDENTIFIER> )
  1853. LocalVariableDeclaration() ";"
  1854. |
  1855. Statement()
  1856. |
  1857. ClassOrInterfaceDeclaration(0)
  1858. }
  1859.  
  1860. void LocalVariableDeclaration():
  1861. {}
  1862. {
  1863. Modifiers() Type() VariableDeclarator() ( "," VariableDeclarator() )*
  1864. }
  1865.  
  1866. void EmptyStatement():
  1867. {}
  1868. {
  1869. ";"
  1870. }
  1871.  
  1872. void StatementExpression():
  1873. /*
  1874. * The last expansion of this production accepts more than the legal
  1875. * Java expansions for StatementExpression. This expansion does not
  1876. * use PostfixExpression for performance reasons.
  1877. */
  1878. {}
  1879. {
  1880. PreIncrementExpression()
  1881. |
  1882. PreDecrementExpression()
  1883. |
  1884. PrimaryExpression()
  1885. [
  1886. "++"
  1887. |
  1888. "--"
  1889. |
  1890. AssignmentOperator() Expression()
  1891. ]
  1892. }
  1893.  
  1894. void SwitchStatement():
  1895. {}
  1896. {
  1897. "switch" "(" Expression() ")" "{"
  1898. ( SwitchLabel() ( BlockStatement() )* )*
  1899. "}"
  1900. }
  1901.  
  1902. void SwitchLabel():
  1903. {}
  1904. {
  1905. "case" Expression() ":"
  1906. |
  1907. "default" ":"
  1908. }
  1909.  
  1910. void IfStatement():
  1911. /*
  1912. * The disambiguating algorithm of JavaCC automatically binds dangling
  1913. * else's to the innermost if statement. The LOOKAHEAD specification
  1914. * is to tell JavaCC that we know what we are doing.
  1915. */
  1916. {}
  1917. {
  1918. "if" "(" Expression() ")" Statement() [ LOOKAHEAD(1) "else" Statement() ]
  1919. }
  1920.  
  1921. void WhileStatement():
  1922. {}
  1923. {
  1924. "while" "(" Expression() ")" Statement()
  1925. }
  1926.  
  1927. void DoStatement():
  1928. {}
  1929. {
  1930. "do" Statement() "while" "(" Expression() ")" ";"
  1931. }
  1932.  
  1933. void ForStatement():
  1934. {}
  1935. {
  1936. "for" "("
  1937.  
  1938. (
  1939. LOOKAHEAD(Modifiers() Type() <IDENTIFIER> ":")
  1940. Modifiers() Type() <IDENTIFIER> ":" Expression()
  1941. |
  1942. [ ForInit() ] ";" [ Expression() ] ";" [ ForUpdate() ]
  1943. )
  1944.  
  1945. ")" Statement()
  1946. }
  1947.  
  1948. void ForInit():
  1949. {}
  1950. {
  1951. LOOKAHEAD( Modifiers() Type() <IDENTIFIER> )
  1952. LocalVariableDeclaration()
  1953. |
  1954. StatementExpressionList()
  1955. }
  1956.  
  1957. void StatementExpressionList():
  1958. {}
  1959. {
  1960. StatementExpression() ( "," StatementExpression() )*
  1961. }
  1962.  
  1963. void ForUpdate():
  1964. {}
  1965. {
  1966. StatementExpressionList()
  1967. }
  1968.  
  1969. void BreakStatement():
  1970. {}
  1971. {
  1972. "break" [ <IDENTIFIER> ] ";"
  1973. }
  1974.  
  1975. void ContinueStatement():
  1976. {}
  1977. {
  1978. "continue" [ <IDENTIFIER> ] ";"
  1979. }
  1980.  
  1981. void ReturnStatement():
  1982. {}
  1983. {
  1984. "return" [ Expression() ] ";"
  1985. }
  1986.  
  1987. void ThrowStatement():
  1988. {}
  1989. {
  1990. "throw" Expression() ";"
  1991. }
  1992.  
  1993. void SynchronizedStatement():
  1994. {}
  1995. {
  1996. "synchronized" "(" Expression() ")" Block()
  1997. }
  1998.  
  1999. void TryStatement():
  2000. /*
  2001. * Semantic check required here to make sure that at least one
  2002. * finally/catch is present.
  2003. */
  2004. {}
  2005. {
  2006. "try" Block()
  2007. ( "catch" "(" FormalParameter() ")" Block() )*
  2008. [ "finally" Block() ]
  2009. }
  2010.  
  2011. /* We use productions to match >>>, >> and > so that we can keep the
  2012. * type declaration syntax with generics clean
  2013. */
  2014. //
  2015. //void RUNSIGNEDSHIFT():
  2016. //{}
  2017. //{
  2018. // ( LOOKAHEAD({ getToken(1).kind == GT &&
  2019. // ((MyToken)getToken(1)).realKind == RUNSIGNEDSHIFT} )
  2020. // ">" ">" ">"
  2021. // )
  2022. //}
  2023. //
  2024. //void RSIGNEDSHIFT():
  2025. //{}
  2026. //{
  2027. // ( LOOKAHEAD({ getToken(1).kind == GT &&
  2028. // ((MyToken)getToken(1)).realKind == RSIGNEDSHIFT} )
  2029. // ">" ">"
  2030. // )
  2031. //}
  2032.  
  2033. /* Annotation syntax follows. */
  2034.  
  2035. void Annotation():
  2036. {}
  2037. {
  2038. LOOKAHEAD( "@" Name() "(" ( <IDENTIFIER> "=" | ")" ))
  2039. NormalAnnotation()
  2040. |
  2041. LOOKAHEAD( "@" Name() "(" )
  2042. SingleMemberAnnotation()
  2043. |
  2044. MarkerAnnotation()
  2045. }
  2046.  
  2047. void NormalAnnotation():
  2048. {}
  2049. {
  2050. "@" Name() "(" [ MemberValuePairs() ] ")"
  2051. }
  2052.  
  2053. void MarkerAnnotation():
  2054. {}
  2055. {
  2056. "@" Name()
  2057. }
  2058.  
  2059. void SingleMemberAnnotation():
  2060. {}
  2061. {
  2062. "@" Name() "(" MemberValue() ")"
  2063. }
  2064.  
  2065. void MemberValuePairs():
  2066. {}
  2067. {
  2068. MemberValuePair() ( "," MemberValuePair() )*
  2069. }
  2070.  
  2071. void MemberValuePair():
  2072. {}
  2073. {
  2074. <IDENTIFIER> "=" MemberValue()
  2075. }
  2076.  
  2077. void MemberValue():
  2078. {}
  2079. {
  2080. Annotation()
  2081. |
  2082. MemberValueArrayInitializer()
  2083. |
  2084. ConditionalExpression()
  2085. }
  2086.  
  2087. void MemberValueArrayInitializer():
  2088. {}
  2089. {
  2090. "{" (MemberValue() ( LOOKAHEAD(2) "," MemberValue() )* [ "," ])? "}"
  2091. }
  2092.  
  2093.  
  2094. /* Annotation Types. */
  2095.  
  2096. void AnnotationTypeDeclaration(int modifiers):
  2097. {}
  2098. {
  2099. "@" "interface" <IDENTIFIER> AnnotationTypeBody()
  2100. }
  2101.  
  2102. void AnnotationTypeBody():
  2103. {}
  2104. {
  2105. "{" ( AnnotationTypeMemberDeclaration() )* "}"
  2106. }
  2107.  
  2108. void AnnotationTypeMemberDeclaration():
  2109. {
  2110. int modifiers;
  2111. }
  2112. {
  2113. modifiers = Modifiers()
  2114. (
  2115. LOOKAHEAD(Type() <IDENTIFIER> "(")
  2116. Type() <IDENTIFIER> "(" ")" [ DefaultValue() ] ";"
  2117. |
  2118. ClassOrInterfaceDeclaration(modifiers)
  2119. |
  2120. EnumDeclaration(modifiers)
  2121. |
  2122. AnnotationTypeDeclaration(modifiers)
  2123. |
  2124. FieldDeclaration(modifiers)
  2125. )
  2126. |
  2127. ( ";" )
  2128. }
  2129.  
  2130. void DefaultValue():
  2131. {}
  2132. {
  2133. "default" MemberValue()
  2134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement