javaparser.y 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. /* yacc grammar for JAVA language */
  2. /* print with psf -p 10 -L50 -l 50 -w -E j.y > xx */
  3. %{
  4. #define REDUCE /* will display the reduce rules */
  5. #undef REDUCE
  6. #define PRNT_SYM
  7. #undef PRNT_SYM
  8. #define YYDEBUG 1
  9. #include <stdio.h>
  10. extern FILE *yyin;
  11. extern int yylineno;
  12. extern int yydebug;
  13. extern char yytext[];
  14. #ifdef REDUCE
  15. # define reduce(a) printf("%s\n",a)
  16. #else
  17. # define reduce(a)
  18. #endif
  19. #define YYSTYPE PyObject *
  20. %}
  21. /* Things defined here have to match the order of what's in the
  22. binop_lookup table. */
  23. %token PLUS_TOKEN MINUS_TOKEN MUL_TOKEN DIV_TOKEN MOD_TOKEN
  24. %token SHL_TOKEN SHR_TOKEN SAR_TOKEN
  25. %token AND_TOKEN XOR_TOKEN OR_TOKEN
  26. %token LOGICAL_AND_TOKEN LOGICAL_OR_TOKEN
  27. %token EQ_TOKEN NE_OP_TOKEN GREATER_TOKEN GE_TOKEN LESS_TOKEN LE_TOKEN
  28. /* This maps to the same binop_lookup entry than the token above */
  29. %token ADD_ASSIGN_TOKEN SUB_ASSIGN_TOKEN MUL_ASSIGN_TOKEN DIV_ASSIGN_TOKEN
  30. %token MOD_ASSIGN_TOKEN
  31. %token SHL_ASSIGN_TOKEN SHR_ASSIGN_TOKEN SAR_ASSIGN_TOKEN
  32. %token AND_ASSIGN_TOKEN XOR_ASSIGN_TOKEN OR_ASSIGN_TOKEN
  33. /* Modifier TOKEN have to be kept in this order. Don't scramble it */
  34. %token PUBLIC_TOKEN PRIVATE_TOKEN PROTECTED_TOKEN
  35. %token STATIC_TOKEN FINAL_TOKEN SYNCHRONIZED_TOKEN
  36. %token VOLATILE_TOKEN TRANSIENT_TOKEN NATIVE_TOKEN
  37. %token PAD_TOKEN ABSTRACT_TOKEN MODIFIER_TOKEN
  38. %token STRICT_TOKEN STRICTFP_TOKEN
  39. /* Keep those two in order, too */
  40. %token DEC_TOKEN INC_TOKEN
  41. /* From now one, things can be in any order */
  42. %token DEFAULT_TOKEN IF_TOKEN THROW_TOKEN
  43. %token BOOLEAN_TOKEN DO_TOKEN IMPLEMENTS_TOKEN
  44. %token THROWS_TOKEN BREAK_TOKEN IMPORT_TOKEN
  45. %token ELSE_TOKEN INSTANCEOF_TOKEN RETURN_TOKEN
  46. %token VOID_TOKEN CATCH_TOKEN INTERFACE_TOKEN
  47. %token CASE_TOKEN EXTENDS_TOKEN FINALLY_TOKEN
  48. %token SUPER_TOKEN WHILE_TOKEN CLASS_TOKEN
  49. %token SWITCH_TOKEN CONST_TOKEN TRY_TOKEN
  50. %token FOR_TOKEN NEW_TOKEN CONTINUE_TOKEN
  51. %token GOTO_TOKEN PACKAGE_TOKEN THIS_TOKEN
  52. %token ASSERT_TOKEN
  53. %token BYTE_TOKEN SHORT_TOKEN INT_TOKEN LONG_TOKEN
  54. %token CHAR_TOKEN
  55. %token FLOAT_TOKEN DOUBLE_TOKEN
  56. %token ID_TOKEN
  57. %token CONDITIONAL_TOKEN COLON_TOKEN TILDE_TOKEN NOT_TOKEN
  58. %token ASSIGN_ANY_TOKEN ASSIGNS_TOKEN
  59. %token OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN OPEN_BRACE_TOKEN CLOSE_BRACE_TOKEN OPEN_BRACKET_TOKEN CLOSE_BRACKET_TOKEN SEMICOLON_TOKEN COMMA_TOKEN PERIOD_TOKEN
  60. %token INTEGER_LITERAL_TOKEN FLOATING_POINT_LITERAL_TOKEN BOOLEAN_LITERAL_TOKEN STRING_LITERAL_TOKEN
  61. %token CHARACTER_LITERAL_TOKEN NULL_TOKEN
  62. %right SHL_ASSIGN_TOKEN SAR_ASSIGN_TOKEN AND_ASSIGN_TOKEN OR_ASSIGN_TOKEN XOR_ASSIGN_TOKEN
  63. ASSIGNS_TOKEN ADD_ASSIGN_TOKEN SUB_ASSIGN_TOKEN MUL_ASSIGN_TOKEN DIV_ASSIGN_TOKEN MOD_ASSIGN_TOKEN
  64. %left LOGICAL_OR_TOKEN
  65. %left LOGICAL_AND_TOKEN
  66. %left OR_TOKEN
  67. %left XOR_TOKEN
  68. %left AND_TOKEN
  69. %left RELATIVEQEUAL_TOKEN NE_OP_TOKEN
  70. %left GREATER_TOKEN LESS_TOKEN GE_TOKEN LE_TOKEN
  71. %left SHL_TOKEN SAR_TOKEN SHR_TOKEN
  72. %left PLUS_TOKEN MINUS_TOKEN
  73. %left MUL_TOKEN DIV_TOKEN MOD_TOKEN
  74. %nonassoc NOT_TOKEN TILDE_TOKEN
  75. %start goal
  76. %%
  77. goal
  78. : compilation_unit
  79. ;
  80. literal
  81. : INTEGER_LITERAL_TOKEN
  82. | FLOATING_POINT_LITERAL_TOKEN
  83. | BOOLEAN_LITERAL_TOKEN
  84. | CHARACTER_LITERAL_TOKEN
  85. | STRING_LITERAL_TOKEN
  86. | NULL_TOKEN
  87. ;
  88. type
  89. : primitive_type
  90. | reference_type
  91. ;
  92. primitive_type
  93. : INT_TOKEN
  94. | LONG_TOKEN
  95. | FLOAT_TOKEN
  96. | DOUBLE_TOKEN
  97. | BOOLEAN_TOKEN
  98. | BYTE_TOKEN
  99. | CHAR_TOKEN
  100. | SHORT_TOKEN
  101. ;
  102. reference_type
  103. : class_or_interface_type
  104. | array_type
  105. ;
  106. class_or_interface_type
  107. : name
  108. ;
  109. class_type
  110. : class_or_interface_type
  111. ;
  112. interface_type
  113. : class_or_interface_type
  114. ;
  115. array_type
  116. : primitive_type dims
  117. | name dims
  118. ;
  119. name
  120. : simple_name
  121. | qualified_name
  122. ;
  123. simple_name
  124. : identifier
  125. ;
  126. qualified_name
  127. : name PERIOD_TOKEN identifier
  128. ;
  129. identifier
  130. : ID_TOKEN
  131. ;
  132. compilation_unit
  133. :
  134. | package_declaration
  135. | import_declarations
  136. | type_declarations
  137. | package_declaration import_declarations
  138. | package_declaration type_declarations
  139. | import_declarations type_declarations
  140. | package_declaration import_declarations type_declarations
  141. ;
  142. import_declarations
  143. : import_declaration
  144. | import_declarations import_declaration
  145. ;
  146. type_declarations
  147. : type_declaration
  148. | type_declarations type_declaration
  149. ;
  150. package_declaration
  151. : PACKAGE_TOKEN name SEMICOLON_TOKEN
  152. ;
  153. import_declaration
  154. : single_type_import_declaration
  155. | type_import_on_demand_declaration
  156. ;
  157. single_type_import_declaration
  158. : IMPORT_TOKEN name SEMICOLON_TOKEN
  159. ;
  160. type_import_on_demand_declaration
  161. : IMPORT_TOKEN name PERIOD_TOKEN MUL_TOKEN SEMICOLON_TOKEN
  162. ;
  163. type_declaration
  164. : class_declaration
  165. | interface_declaration
  166. | empty_statement
  167. ;
  168. modifiers
  169. : modifier
  170. | modifiers modifier
  171. ;
  172. modifier
  173. : STATIC_TOKEN
  174. | PUBLIC_TOKEN
  175. | PROTECTED_TOKEN
  176. | PRIVATE_TOKEN
  177. | ABSTRACT_TOKEN
  178. | FINAL_TOKEN
  179. | NATIVE_TOKEN
  180. | SYNCHRONIZED_TOKEN
  181. | TRANSIENT_TOKEN
  182. | VOLATILE_TOKEN
  183. ;
  184. class_declaration
  185. : modifiers CLASS_TOKEN identifier super interfaces class_body
  186. | CLASS_TOKEN identifier super interfaces class_body
  187. ;
  188. super
  189. :
  190. | EXTENDS_TOKEN class_type
  191. ;
  192. interfaces
  193. :
  194. | IMPLEMENTS_TOKEN interface_type_list
  195. ;
  196. interface_type_list
  197. : interface_type
  198. | interface_type_list COMMA_TOKEN interface_type
  199. ;
  200. class_body
  201. : OPEN_BRACE_TOKEN CLOSE_BRACE_TOKEN
  202. | OPEN_BRACE_TOKEN class_body_declarations CLOSE_BRACE_TOKEN
  203. ;
  204. class_body_declarations
  205. : class_body_declaration
  206. | class_body_declarations class_body_declaration
  207. ;
  208. class_body_declaration
  209. : class_member_declaration
  210. | static_initializer
  211. | constructor_declaration
  212. | block
  213. ;
  214. class_member_declaration
  215. : field_declaration
  216. | method_declaration
  217. | class_declaration
  218. | interface_declaration
  219. | empty_statement
  220. ;
  221. field_declaration
  222. : type variable_declarators SEMICOLON_TOKEN
  223. | modifiers type variable_declarators SEMICOLON_TOKEN
  224. ;
  225. variable_declarators
  226. : variable_declarator
  227. | variable_declarators COMMA_TOKEN variable_declarator
  228. ;
  229. variable_declarator
  230. : variable_declarator_id
  231. | variable_declarator_id ASSIGNS_TOKEN variable_initializer
  232. ;
  233. variable_declarator_id
  234. : identifier
  235. | variable_declarator_id OPEN_BRACKET_TOKEN CLOSE_BRACKET_TOKEN
  236. ;
  237. variable_initializer
  238. : expression
  239. | array_initializer
  240. ;
  241. method_declaration
  242. : method_header method_body
  243. ;
  244. method_header
  245. : type method_declarator throws
  246. | VOID_TOKEN method_declarator throws
  247. | modifiers type method_declarator throws
  248. | modifiers VOID_TOKEN method_declarator throws
  249. ;
  250. method_declarator
  251. : identifier OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN
  252. | identifier OPEN_PAREN_TOKEN formal_parameter_list CLOSE_PAREN_TOKEN
  253. | method_declarator OPEN_BRACKET_TOKEN CLOSE_BRACKET_TOKEN
  254. ;
  255. formal_parameter_list
  256. : formal_parameter
  257. | formal_parameter_list COMMA_TOKEN formal_parameter
  258. ;
  259. formal_parameter
  260. : type variable_declarator_id
  261. | modifiers type variable_declarator_id
  262. ;
  263. throws
  264. :
  265. | THROWS_TOKEN class_type_list
  266. ;
  267. class_type_list
  268. : class_type
  269. | class_type_list COMMA_TOKEN class_type
  270. ;
  271. method_body
  272. : block
  273. | SEMICOLON_TOKEN
  274. ;
  275. static_initializer
  276. : static block
  277. ;
  278. static
  279. : modifiers
  280. ;
  281. constructor_declaration
  282. : constructor_header constructor_body
  283. ;
  284. constructor_header
  285. : constructor_declarator throws
  286. | modifiers constructor_declarator throws
  287. ;
  288. constructor_declarator
  289. : simple_name OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN
  290. | simple_name OPEN_PAREN_TOKEN formal_parameter_list CLOSE_PAREN_TOKEN
  291. ;
  292. constructor_body
  293. : block_begin constructor_block_end
  294. | block_begin explicit_constructor_invocation constructor_block_end
  295. | block_begin block_statements constructor_block_end
  296. | block_begin explicit_constructor_invocation block_statements constructor_block_end
  297. ;
  298. constructor_block_end
  299. : block_end
  300. ;
  301. block_begin
  302. : OPEN_BRACE_TOKEN
  303. ;
  304. block_end
  305. : CLOSE_BRACE_TOKEN
  306. ;
  307. explicit_constructor_invocation
  308. : this_or_super OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN SEMICOLON_TOKEN
  309. | this_or_super OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN SEMICOLON_TOKEN
  310. | name PERIOD_TOKEN SUPER_TOKEN OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN SEMICOLON_TOKEN
  311. | name PERIOD_TOKEN SUPER_TOKEN OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN SEMICOLON_TOKEN
  312. ;
  313. this_or_super
  314. : THIS_TOKEN
  315. | SUPER_TOKEN
  316. ;
  317. interface_declaration
  318. : INTERFACE_TOKEN identifier interface_body
  319. | modifiers INTERFACE_TOKEN identifier interface_body
  320. | INTERFACE_TOKEN identifier extends_interfaces interface_body
  321. | modifiers INTERFACE_TOKEN identifier extends_interfaces interface_body
  322. ;
  323. extends_interfaces
  324. : EXTENDS_TOKEN interface_type
  325. | extends_interfaces COMMA_TOKEN interface_type
  326. ;
  327. interface_body
  328. : OPEN_BRACE_TOKEN CLOSE_BRACE_TOKEN
  329. | OPEN_BRACE_TOKEN interface_member_declarations CLOSE_BRACE_TOKEN
  330. ;
  331. interface_member_declarations
  332. : interface_member_declaration
  333. | interface_member_declarations interface_member_declaration
  334. ;
  335. interface_member_declaration
  336. : constant_declaration
  337. | abstract_method_declaration
  338. | class_declaration
  339. | interface_declaration
  340. ;
  341. constant_declaration
  342. : field_declaration
  343. ;
  344. abstract_method_declaration
  345. : method_header SEMICOLON_TOKEN
  346. ;
  347. array_initializer
  348. : OPEN_BRACE_TOKEN CLOSE_BRACE_TOKEN
  349. | OPEN_BRACE_TOKEN COMMA_TOKEN CLOSE_BRACE_TOKEN
  350. | OPEN_BRACE_TOKEN variable_initializers CLOSE_BRACE_TOKEN
  351. | OPEN_BRACE_TOKEN variable_initializers COMMA_TOKEN CLOSE_BRACE_TOKEN
  352. ;
  353. variable_initializers
  354. : variable_initializer
  355. | variable_initializers COMMA_TOKEN variable_initializer
  356. ;
  357. block
  358. : OPEN_BRACE_TOKEN CLOSE_BRACE_TOKEN
  359. | OPEN_BRACE_TOKEN block_statements CLOSE_BRACE_TOKEN
  360. ;
  361. block_statements
  362. : block_statement
  363. | block_statements block_statement
  364. ;
  365. block_statement
  366. : local_variable_declaration_statement
  367. | statement
  368. | class_declaration
  369. ;
  370. local_variable_declaration_statement
  371. : local_variable_declaration SEMICOLON_TOKEN
  372. ;
  373. local_variable_declaration
  374. : type variable_declarators
  375. | modifiers type variable_declarators
  376. ;
  377. statement
  378. : statement_without_trailing_substatement
  379. | labeled_statement
  380. | if_then_statement
  381. | if_then_else_statement
  382. | while_statement
  383. | for_statement
  384. ;
  385. statement_nsi
  386. : statement_without_trailing_substatement
  387. | labeled_statement_nsi
  388. | if_then_else_statement_nsi
  389. | while_statement_nsi
  390. | for_statement_nsi
  391. ;
  392. statement_without_trailing_substatement
  393. : block
  394. | empty_statement
  395. | expression_statement
  396. | switch_statement
  397. | do_statement
  398. | break_statement
  399. | continue_statement
  400. | return_statement
  401. | synchronized_statement
  402. | throw_statement
  403. | try_statement
  404. | assert_statement
  405. ;
  406. empty_statement
  407. : SEMICOLON_TOKEN
  408. ;
  409. label_decl
  410. : identifier COLON_TOKEN
  411. ;
  412. labeled_statement
  413. : label_decl statement
  414. ;
  415. labeled_statement_nsi
  416. : label_decl statement_nsi
  417. ;
  418. expression_statement
  419. : statement_expression SEMICOLON_TOKEN
  420. | SYNCHRONIZED_TOKEN OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN block
  421. ;
  422. statement_expression
  423. : assignment
  424. | primary
  425. | pre_increment_expression
  426. | pre_decrement_expression
  427. | post_increment_expression
  428. | post_decrement_expression
  429. | method_invocation
  430. | class_instance_creation_expression
  431. ;
  432. if_then_statement
  433. : IF_TOKEN OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN statement
  434. ;
  435. if_then_else_statement
  436. : IF_TOKEN OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN statement_nsi ELSE_TOKEN statement
  437. ;
  438. if_then_else_statement_nsi
  439. : IF_TOKEN OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN statement_nsi ELSE_TOKEN statement_nsi
  440. ;
  441. switch_statement
  442. : switch_expression switch_block
  443. ;
  444. switch_expression
  445. : SWITCH_TOKEN OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN
  446. ;
  447. switch_block
  448. : OPEN_BRACE_TOKEN CLOSE_BRACE_TOKEN
  449. | OPEN_BRACE_TOKEN switch_labels CLOSE_BRACE_TOKEN
  450. | OPEN_BRACE_TOKEN switch_block_statement_groups CLOSE_BRACE_TOKEN
  451. | OPEN_BRACE_TOKEN switch_block_statement_groups switch_labels CLOSE_BRACE_TOKEN
  452. ;
  453. switch_block_statement_groups
  454. : switch_block_statement_group
  455. | switch_block_statement_groups switch_block_statement_group
  456. ;
  457. switch_block_statement_group
  458. : switch_labels block_statements
  459. ;
  460. switch_labels
  461. : switch_label
  462. | switch_labels switch_label
  463. ;
  464. switch_label
  465. : CASE_TOKEN constant_expression COLON_TOKEN
  466. | DEFAULT_TOKEN COLON_TOKEN
  467. ;
  468. while_expression
  469. : WHILE_TOKEN OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN
  470. ;
  471. while_statement
  472. : while_expression statement
  473. ;
  474. while_statement_nsi
  475. : while_expression statement_nsi
  476. ;
  477. do_statement_begin
  478. : DO_TOKEN
  479. ;
  480. do_statement
  481. : do_statement_begin statement WHILE_TOKEN OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN SEMICOLON_TOKEN
  482. ;
  483. for_statement
  484. : for_begin SEMICOLON_TOKEN expression SEMICOLON_TOKEN for_update CLOSE_PAREN_TOKEN statement
  485. | for_begin SEMICOLON_TOKEN SEMICOLON_TOKEN for_update CLOSE_PAREN_TOKEN statement
  486. ;
  487. for_statement_nsi
  488. : for_begin SEMICOLON_TOKEN expression SEMICOLON_TOKEN for_update CLOSE_PAREN_TOKEN statement_nsi
  489. | for_begin SEMICOLON_TOKEN SEMICOLON_TOKEN for_update CLOSE_PAREN_TOKEN statement_nsi
  490. ;
  491. for_header
  492. : FOR_TOKEN OPEN_PAREN_TOKEN
  493. ;
  494. for_begin
  495. : for_header for_init
  496. ;
  497. for_init
  498. :
  499. | statement_expression_list
  500. | local_variable_declaration
  501. ;
  502. for_update
  503. :
  504. | statement_expression_list
  505. ;
  506. statement_expression_list
  507. : statement_expression
  508. | statement_expression_list COMMA_TOKEN statement_expression
  509. ;
  510. break_statement
  511. : BREAK_TOKEN SEMICOLON_TOKEN
  512. | BREAK_TOKEN identifier SEMICOLON_TOKEN
  513. ;
  514. continue_statement
  515. : CONTINUE_TOKEN SEMICOLON_TOKEN
  516. | CONTINUE_TOKEN identifier SEMICOLON_TOKEN
  517. ;
  518. return_statement
  519. : RETURN_TOKEN SEMICOLON_TOKEN
  520. | RETURN_TOKEN expression SEMICOLON_TOKEN
  521. ;
  522. throw_statement
  523. : THROW_TOKEN expression SEMICOLON_TOKEN
  524. ;
  525. assert_statement
  526. : ASSERT_TOKEN expression COLON_TOKEN expression SEMICOLON_TOKEN
  527. | ASSERT_TOKEN expression SEMICOLON_TOKEN
  528. | ASSERT_TOKEN error
  529. | ASSERT_TOKEN expression error
  530. ;
  531. synchronized_statement
  532. : synchronized OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN block
  533. | synchronized OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN error
  534. ;
  535. synchronized
  536. : MODIFIER_TOKEN
  537. ;
  538. try_statement
  539. : TRY_TOKEN block catches
  540. | TRY_TOKEN block finally
  541. | TRY_TOKEN block catches finally
  542. ;
  543. catches
  544. : catch_clause
  545. | catches catch_clause
  546. ;
  547. catch_clause
  548. : CATCH_TOKEN OPEN_PAREN_TOKEN formal_parameter CLOSE_PAREN_TOKEN block
  549. ;
  550. finally
  551. : FINALLY_TOKEN block
  552. ;
  553. primary
  554. : primary_no_new_array
  555. | array_creation_expression
  556. ;
  557. primary_no_new_array
  558. : literal
  559. | THIS_TOKEN
  560. | OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN
  561. | class_instance_creation_expression
  562. | field_access
  563. | method_invocation
  564. | array_access
  565. | type_literals
  566. | name PERIOD_TOKEN THIS_TOKEN
  567. ;
  568. type_literals
  569. : name PERIOD_TOKEN CLASS_TOKEN
  570. | array_type PERIOD_TOKEN CLASS_TOKEN
  571. | primitive_type PERIOD_TOKEN CLASS_TOKEN
  572. | VOID_TOKEN PERIOD_TOKEN CLASS_TOKEN
  573. ;
  574. class_instance_creation_expression
  575. : NEW_TOKEN class_type OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN
  576. | NEW_TOKEN class_type OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN
  577. | anonymous_class_creation
  578. | something_dot_new identifier OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN
  579. | something_dot_new identifier OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN class_body
  580. | something_dot_new identifier OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN
  581. | something_dot_new identifier OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN class_body
  582. ;
  583. anonymous_class_creation
  584. : NEW_TOKEN class_type OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN class_body
  585. | NEW_TOKEN class_type OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN class_body
  586. ;
  587. something_dot_new
  588. : name PERIOD_TOKEN NEW_TOKEN
  589. | primary PERIOD_TOKEN NEW_TOKEN
  590. ;
  591. argument_list
  592. : expression
  593. | argument_list COMMA_TOKEN expression
  594. | argument_list COMMA_TOKEN error
  595. ;
  596. array_creation_expression
  597. : NEW_TOKEN primitive_type dim_exprs
  598. | NEW_TOKEN class_or_interface_type dim_exprs
  599. | NEW_TOKEN primitive_type dim_exprs dims
  600. | NEW_TOKEN class_or_interface_type dim_exprs dims
  601. | NEW_TOKEN class_or_interface_type dims array_initializer
  602. | NEW_TOKEN primitive_type dims array_initializer
  603. ;
  604. dim_exprs
  605. : dim_expr
  606. | dim_exprs dim_expr
  607. ;
  608. dim_expr
  609. : OPEN_BRACKET_TOKEN expression CLOSE_BRACKET_TOKEN
  610. ;
  611. dims
  612. : OPEN_BRACKET_TOKEN CLOSE_BRACKET_TOKEN
  613. | dims OPEN_BRACKET_TOKEN CLOSE_BRACKET_TOKEN
  614. ;
  615. field_access
  616. : primary PERIOD_TOKEN identifier
  617. | SUPER_TOKEN PERIOD_TOKEN identifier
  618. ;
  619. method_invocation
  620. : name OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN
  621. | name OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN
  622. | primary PERIOD_TOKEN identifier OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN
  623. | primary PERIOD_TOKEN identifier OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN
  624. | SUPER_TOKEN PERIOD_TOKEN identifier OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN
  625. | SUPER_TOKEN PERIOD_TOKEN identifier OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN
  626. ;
  627. array_access
  628. : name OPEN_BRACKET_TOKEN expression CLOSE_BRACKET_TOKEN
  629. | primary_no_new_array OPEN_BRACKET_TOKEN expression CLOSE_BRACKET_TOKEN
  630. ;
  631. postfix_expression
  632. : primary
  633. | name
  634. | post_increment_expression
  635. | post_decrement_expression
  636. ;
  637. post_increment_expression
  638. : postfix_expression INC_TOKEN
  639. ;
  640. post_decrement_expression
  641. : postfix_expression DEC_TOKEN
  642. ;
  643. trap_overflow_corner_case
  644. : pre_increment_expression
  645. | pre_decrement_expression
  646. | PLUS_TOKEN unary_expression
  647. | unary_expression_not_plus_minus
  648. ;
  649. unary_expression
  650. : trap_overflow_corner_case
  651. | MINUS_TOKEN trap_overflow_corner_case
  652. | MINUS_TOKEN error
  653. ;
  654. pre_increment_expression
  655. : INC_TOKEN unary_expression
  656. ;
  657. pre_decrement_expression
  658. : DEC_TOKEN unary_expression
  659. ;
  660. unary_expression_not_plus_minus
  661. : postfix_expression
  662. | TILDE_TOKEN unary_expression
  663. | NOT_TOKEN unary_expression
  664. | cast_expression
  665. ;
  666. cast_expression
  667. : OPEN_PAREN_TOKEN primitive_type dims CLOSE_PAREN_TOKEN unary_expression
  668. | OPEN_PAREN_TOKEN primitive_type CLOSE_PAREN_TOKEN unary_expression
  669. | OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN unary_expression_not_plus_minus
  670. | OPEN_PAREN_TOKEN name dims CLOSE_PAREN_TOKEN unary_expression_not_plus_minus
  671. ;
  672. multiplicative_expression
  673. : unary_expression
  674. | multiplicative_expression MUL_TOKEN unary_expression
  675. | multiplicative_expression DIV_TOKEN unary_expression
  676. | multiplicative_expression MOD_TOKEN unary_expression
  677. ;
  678. additive_expression
  679. : multiplicative_expression
  680. | additive_expression PLUS_TOKEN multiplicative_expression
  681. | additive_expression MINUS_TOKEN multiplicative_expression
  682. ;
  683. shift_expression
  684. : additive_expression
  685. | shift_expression SHL_TOKEN additive_expression
  686. | shift_expression SHR_TOKEN additive_expression
  687. | shift_expression SAR_TOKEN additive_expression
  688. ;
  689. relational_expression
  690. : shift_expression
  691. | relational_expression LESS_TOKEN shift_expression
  692. | relational_expression GREATER_TOKEN shift_expression
  693. | relational_expression LE_TOKEN shift_expression
  694. | relational_expression GE_TOKEN shift_expression
  695. | relational_expression INSTANCEOF_TOKEN reference_type
  696. ;
  697. equality_expression
  698. : relational_expression
  699. | equality_expression EQ_TOKEN relational_expression
  700. | equality_expression NE_OP_TOKEN relational_expression
  701. ;
  702. and_expression
  703. : equality_expression
  704. | and_expression AND_TOKEN equality_expression
  705. ;
  706. exclusive_or_expression
  707. : and_expression
  708. | exclusive_or_expression XOR_TOKEN and_expression
  709. ;
  710. inclusive_or_expression
  711. : exclusive_or_expression
  712. | inclusive_or_expression OR_TOKEN exclusive_or_expression
  713. ;
  714. conditional_and_expression
  715. : inclusive_or_expression
  716. | conditional_and_expression LOGICAL_AND_TOKEN inclusive_or_expression
  717. ;
  718. conditional_or_expression
  719. : conditional_and_expression
  720. | conditional_or_expression LOGICAL_OR_TOKEN conditional_and_expression
  721. ;
  722. conditional_expression
  723. : conditional_or_expression
  724. | conditional_or_expression CONDITIONAL_TOKEN expression COLON_TOKEN conditional_expression
  725. ;
  726. assignment_expression
  727. : conditional_expression
  728. | assignment
  729. ;
  730. assignment
  731. : left_hand_side assignment_operator assignment_expression
  732. ;
  733. left_hand_side
  734. : name
  735. | field_access
  736. | array_access
  737. ;
  738. assignment_operator
  739. : ASSIGNS_TOKEN
  740. | ADD_ASSIGN_TOKEN
  741. | SUB_ASSIGN_TOKEN
  742. | MUL_ASSIGN_TOKEN
  743. | DIV_ASSIGN_TOKEN
  744. | MOD_ASSIGN_TOKEN
  745. | SHL_ASSIGN_TOKEN
  746. | SHR_ASSIGN_TOKEN
  747. | SAR_ASSIGN_TOKEN
  748. | AND_ASSIGN_TOKEN
  749. | XOR_ASSIGN_TOKEN
  750. | OR_ASSIGN_TOKEN
  751. ;
  752. expression
  753. : assignment_expression
  754. ;
  755. constant_expression
  756. : expression
  757. ;
  758. %%
  759. void print_prototype(void)
  760. {
  761. }
  762. void generate_default_constructor(char *name)
  763. {
  764. }
  765. int yyerror(char *mesg)
  766. {
  767. printf("line %d: %s before %s\n", yylineno, mesg, yytext);
  768. exit(0);
  769. }