package diffast-langs-java-parsing

  1. Overview
  2. Docs

Module Make.MenhirInterpreterSource

include MenhirLib.IncrementalEngine.INCREMENTAL_ENGINE with type token = token
Sourcetype token = token
Sourcetype production

A value of type production is (an index for) a production. The start productions (which do not exist in an .mly file, but are constructed by Menhir internally) are not part of this type.

Sourcetype 'a env

A value of type 'a env represents a configuration of the automaton: current state, stack, lookahead token, etc. The parameter 'a is the type of the semantic value that will eventually be produced if the parser succeeds.

In normal operation, the parser works with checkpoints: see the functions offer and resume. However, it is also possible to work directly with environments (see the functions pop, force_reduction, and feed) and to reconstruct a checkpoint out of an environment (see input_needed). This is considered advanced functionality; its purpose is to allow error recovery strategies to be programmed by the user.

Sourcetype 'a checkpoint = private
  1. | InputNeeded of 'a env
  2. | Shifting of 'a env * 'a env * bool
  3. | AboutToReduce of 'a env * production
  4. | HandlingError of 'a env
  5. | Accepted of 'a
  6. | Rejected

The type 'a checkpoint represents an intermediate or final state of the parser. An intermediate checkpoint is a suspension: it records the parser's current state, and allows parsing to be resumed. The parameter 'a is the type of the semantic value that will eventually be produced if the parser succeeds.

Accepted and Rejected are final checkpoints. Accepted carries a semantic value.

InputNeeded is an intermediate checkpoint. It means that the parser wishes to read one token before continuing.

Shifting is an intermediate checkpoint. It means that the parser is taking a shift transition. It exposes the state of the parser before and after the transition. The Boolean parameter tells whether the parser intends to request a new token after this transition. (It always does, except when it is about to accept.)

AboutToReduce is an intermediate checkpoint. It means that the parser is about to perform a reduction step. It exposes the parser's current state as well as the production that is about to be reduced.

HandlingError is an intermediate checkpoint. It means that the parser has detected an error and is currently handling it, in several steps.

offer allows the user to resume the parser after it has suspended itself with a checkpoint of the form InputNeeded env. offer expects the old checkpoint as well as a new token and produces a new checkpoint. It does not raise any exception.

Sourcetype strategy = [
  1. | `Legacy
  2. | `Simplified
]

The optional argument strategy influences the manner in which resume deals with checkpoints of the form HandlingError _. Its default value is `Legacy. It can be briefly described as follows:

  • If the error token is used only to report errors (that is, if the error token appears only at the end of a production, whose semantic action raises an exception) then the simplified strategy should be preferred. (This includes the case where the error token does not appear at all in the grammar.)
  • If the error token is used to recover after an error, or if perfect backward compatibility is required, the legacy strategy should be selected.

More details on strategies appear in the file Engine.ml.

Sourceval resume : ?strategy:strategy -> 'a checkpoint -> 'a checkpoint

resume allows the user to resume the parser after it has suspended itself with a checkpoint of the form Shifting _, AboutToReduce _, or HandlingError _. resume expects the old checkpoint and produces a new checkpoint. It does not raise any exception.

A token supplier is a function of no arguments which delivers a new token (together with its start and end positions) every time it is called.

Sourceval lexer_lexbuf_to_supplier : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> supplier

A pair of a lexer and a lexing buffer can be turned into a supplier.

The functions offer and resume are sufficient to write a parser loop. One can imagine many variations (which is why we expose these functions in the first place!). Here, we expose a few variations of the main loop, ready for use.

Sourceval loop : ?strategy:strategy -> supplier -> 'a checkpoint -> 'a

loop supplier checkpoint begins parsing from checkpoint, reading tokens from supplier. It continues parsing until it reaches a checkpoint of the form Accepted v or Rejected. In the former case, it returns v. In the latter case, it raises the exception Error. The optional argument strategy, whose default value is Legacy, is passed to resume and influences the error-handling strategy.

Sourceval loop_handle : ('a -> 'answer) -> ('a checkpoint -> 'answer) -> supplier -> 'a checkpoint -> 'answer

loop_handle succeed fail supplier checkpoint begins parsing from checkpoint, reading tokens from supplier. It continues parsing until it reaches a checkpoint of the form Accepted v or HandlingError env (or Rejected, but that should not happen, as HandlingError _ will be observed first). In the former case, it calls succeed v. In the latter case, it calls fail with this checkpoint. It cannot raise Error.

This means that Menhir's error-handling procedure does not get a chance to run. For this reason, there is no strategy parameter. Instead, the user can implement her own error handling code, in the fail continuation.

Sourceval loop_handle_undo : ('a -> 'answer) -> ('a checkpoint -> 'a checkpoint -> 'answer) -> supplier -> 'a checkpoint -> 'answer

loop_handle_undo is analogous to loop_handle, except it passes a pair of checkpoints to the failure continuation.

The first (and oldest) checkpoint is the last InputNeeded checkpoint that was encountered before the error was detected. The second (and newest) checkpoint is where the error was detected, as in loop_handle. Going back to the first checkpoint can be thought of as undoing any reductions that were performed after seeing the problematic token. (These reductions must be default reductions or spurious reductions.)

loop_handle_undo must initially be applied to an InputNeeded checkpoint. The parser's initial checkpoints satisfy this constraint.

Sourceval shifts : 'a checkpoint -> 'a env option

shifts checkpoint assumes that checkpoint has been obtained by submitting a token to the parser. It runs the parser from checkpoint, through an arbitrary number of reductions, until the parser either accepts this token (i.e., shifts) or rejects it (i.e., signals an error). If the parser decides to shift, then Some env is returned, where env is the parser's state just before shifting. Otherwise, None is returned.

It is desirable that the semantic actions be side-effect free, or that their side-effects be harmless (replayable).

The function acceptable allows testing, after an error has been detected, which tokens would have been accepted at this point. It is implemented using shifts. Its argument should be an InputNeeded checkpoint.

For completeness, one must undo any spurious reductions before carrying out this test -- that is, one must apply acceptable to the FIRST checkpoint that is passed by loop_handle_undo to its failure continuation.

This test causes some semantic actions to be run! The semantic actions should be side-effect free, or their side-effects should be harmless.

The position pos is used as the start and end positions of the hypothetical token, and may be picked up by the semantic actions. We suggest using the position where the error was detected.

Sourcetype 'a lr1state

The abstract type 'a lr1state describes the non-initial states of the LR(1) automaton. The index 'a represents the type of the semantic value associated with this state's incoming symbol.

Sourceval number : _ lr1state -> int

The states of the LR(1) automaton are numbered (from 0 and up).

Sourceval production_index : production -> int

production_index maps a production to its integer index.

Sourceval find_production : int -> production

find_production maps a production index to a production. Its argument must be a valid index; use with care.

An element is a pair of a non-initial state s and a semantic value v associated with the incoming symbol of this state. The idea is, the value v was pushed onto the stack just before the state s was entered. Thus, for some type 'a, the state s has type 'a lr1state and the value v has type 'a. In other words, the type element is an existential type.

The parser's stack is (or, more precisely, can be viewed as) a stream of elements. The functions top and pop offer access to this stream.

Sourceval top : 'a env -> element option

top env returns the parser's top stack element. The state contained in this stack element is the current state of the automaton. If the stack is empty, None is returned. In that case, the current state of the automaton must be an initial state.

Sourceval pop_many : int -> 'a env -> 'a env option

pop_many i env pops i cells off the automaton's stack. This is done via i successive invocations of pop. Thus, pop_many 1 is pop. The index i must be nonnegative. The time complexity is O(i).

Sourceval get : int -> 'a env -> element option

get i env returns the parser's i-th stack element. The index i is 0-based: thus, get 0 is top. If i is greater than or equal to the number of elements in the stack, None is returned. The time complexity is O(i).

Sourceval current_state_number : 'a env -> int

current_state_number env is (the integer number of) the automaton's current state. This works even if the automaton's stack is empty, in which case the current state is an initial state. This number can be passed as an argument to a message function generated by menhir --compile-errors.

Sourceval equal : 'a env -> 'a env -> bool

equal env1 env2 tells whether the parser configurations env1 and env2 are equal in the sense that the automaton's current state is the same in env1 and env2 and the stack is *physically* the same in env1 and env2. If equal env1 env2 is true, then the sequence of the stack elements, as observed via pop and top, must be the same in env1 and env2. Also, if equal env1 env2 holds, then the checkpoints input_needed env1 and input_needed env2 must be equivalent. The function equal has time complexity O(1).

positions env returns the start and end positions of the current lookahead token. In an initial state, a pair of twice the initial position is returned.

Sourceval env_has_default_reduction : 'a env -> bool

When applied to an environment taken from a checkpoint of the form AboutToReduce (env, prod), the function env_has_default_reduction tells whether the reduction that is about to take place is a default reduction.

Sourceval state_has_default_reduction : _ lr1state -> bool

state_has_default_reduction s tells whether the state s has a default reduction. This includes the case where s is an accepting state.

Sourceval pop : 'a env -> 'a env option

pop env returns a new environment, where the parser's top stack cell has been popped off. (If the stack is empty, None is returned.) This amounts to pretending that the (terminal or nonterminal) symbol that corresponds to this stack cell has not been read.

Sourceval force_reduction : production -> 'a env -> 'a env

force_reduction prod env should be called only if in the state env the parser is capable of reducing the production prod. If this condition is satisfied, then this production is reduced, which means that its semantic action is executed (this can have side effects!) and the automaton makes a goto (nonterminal) transition. If this condition is not satisfied, Invalid_argument _ is raised.

Sourceval input_needed : 'a env -> 'a checkpoint

input_needed env returns InputNeeded env. That is, out of an env that might have been obtained via a series of calls to the functions pop, force_reduction, feed, etc., it produces a checkpoint, which can be used to resume normal parsing, by supplying this checkpoint as an argument to offer.

This function should be used with some care. It could "mess up the lookahead" in the sense that it allows parsing to resume in an arbitrary state s with an arbitrary lookahead symbol t, even though Menhir's reachability analysis (menhir --list-errors) might well think that it is impossible to reach this particular configuration. If one is using Menhir's new error reporting facility, this could cause the parser to reach an error state for which no error message has been prepared.

Sourcetype _ nonterminal =
  1. | N_yield_statement : Ast.statement nonterminal
  2. | N_wildcard_3 : (Ast.wildcard * Lexing.position) nonterminal
  3. | N_wildcard_2 : (Ast.wildcard * Lexing.position) nonterminal
  4. | N_wildcard_1 : (Ast.wildcard * Lexing.position) nonterminal
  5. | N_wildcard : Ast.wildcard nonterminal
  6. | N_while_statement_no_short_if : Ast.statement nonterminal
  7. | N_while_statement : Ast.statement nonterminal
  8. | N_void : Ast.javatype nonterminal
  9. | N_variable_modifier : Ast.modifier nonterminal
  10. | N_variable_initializers : Ast.variable_initializer list nonterminal
  11. | N_variable_initializer : Ast.variable_initializer nonterminal
  12. | N_variable_declarator_id : Ast.variable_declarator_id nonterminal
  13. | N_variable_declarator : Ast.variable_declarator nonterminal
  14. | N_unary_pointcut_expr : Ast.pointcut_expr nonterminal
  15. | N_unary_expression_not_plus_minus_or_lambda_expression : Ast.left_hand_side nonterminal
  16. | N_unary_expression_not_plus_minus_nn : Ast.left_hand_side nonterminal
  17. | N_unary_expression_not_plus_minus : Ast.left_hand_side nonterminal
  18. | N_unary_expression_nn : Ast.left_hand_side nonterminal
  19. | N_unary_expression : Ast.left_hand_side nonterminal
  20. | N_unary_classname_pattern_expr : Ast.classname_pattern_expr nonterminal
  21. | N_unann_type : Ast.javatype nonterminal
  22. | N_unann_reference_type : Ast.javatype nonterminal
  23. | N_unann_primitive_type : Ast.javatype nonterminal
  24. | N_unann_class_or_interface_type_spec : (Ast.type_spec list * Ast.annotations * Ast.name) nonterminal
  25. | N_unann_class_or_interface_type : Ast.javatype nonterminal
  26. | N_unann_array_type : Ast.javatype nonterminal
  27. | N_type_variable : (Ast.annotations * string) nonterminal
  28. | N_type_parameters : Ast.type_parameters nonterminal
  29. | N_type_parameter_list_1 : Ast.type_parameter list nonterminal
  30. | N_type_parameter_list : Ast.type_parameter list nonterminal
  31. | N_type_parameter_1 : Ast.type_parameter nonterminal
  32. | N_type_parameter : Ast.type_parameter nonterminal
  33. | N_type_import_on_demand_declaration : Ast.import_declaration nonterminal
  34. | N_type_declaration : Ast.type_declaration nonterminal
  35. | N_type_bound_1 : Ast.type_bound nonterminal
  36. | N_type_bound : Ast.type_bound nonterminal
  37. | N_type_arguments : Ast.type_arguments nonterminal
  38. | N_type_argument_list_3 : Ast.type_argument list nonterminal
  39. | N_type_argument_list_2 : Ast.type_argument list nonterminal
  40. | N_type_argument_list_1 : Ast.type_argument list nonterminal
  41. | N_type_argument_list : Ast.type_argument list nonterminal
  42. | N_type_argument_3 : Ast.type_argument nonterminal
  43. | N_type_argument_2 : Ast.type_argument nonterminal
  44. | N_type_argument_1 : Ast.type_argument nonterminal
  45. | N_type_argument : Ast.type_argument nonterminal
  46. | N_try_statement : Ast.statement nonterminal
  47. | N_try_head : unit nonterminal
  48. | N_try_block : (Ast.resource_spec option * Ast.block) nonterminal
  49. | N_throws : Ast.throws nonterminal
  50. | N_throw_statement : Ast.statement nonterminal
  51. | N_this : Ast.loc nonterminal
  52. | N_synchronized_statement : Ast.statement nonterminal
  53. | N_switch_statement : Ast.statement nonterminal
  54. | N_switch_rules : Ast.switch_rule list nonterminal
  55. | N_switch_rule_label : Ast.switch_rule_label nonterminal
  56. | N_switch_rule : Ast.switch_rule nonterminal
  57. | N_switch_label : Ast.switch_label nonterminal
  58. | N_switch_expression : Ast.left_hand_side nonterminal
  59. | N_switch_block_statement_groups : Ast.switch_block_stmt_grp list nonterminal
  60. | N_switch_block_statement_group : Ast.switch_block_stmt_grp nonterminal
  61. | N_switch_block : Ast.switch_block nonterminal
  62. | N_super_ext : Ast.extends_class nonterminal
  63. | N_super : Ast.loc nonterminal
  64. | N_static_type_import_on_demand_declaration : Ast.import_declaration nonterminal
  65. | N_static_single_type_import_declaration : Ast.import_declaration nonterminal
  66. | N_static_initializer : Ast.class_body_declaration nonterminal
  67. | N_statement_without_trailing_substatement : Ast.statement nonterminal
  68. | N_statement_no_short_if : Ast.statement nonterminal
  69. | N_statement_expression : Ast.statement_expression nonterminal
  70. | N_statement : Ast.statement nonterminal
  71. | N_single_type_import_declaration : Ast.import_declaration nonterminal
  72. | N_single_element_annotation_body : Ast.annotation_desc nonterminal
  73. | N_simple_name_pattern : string nonterminal
  74. | N_simple_name : string nonterminal
  75. | N_shift_expression_nn : Ast.left_hand_side nonterminal
  76. | N_shift_expression : Ast.left_hand_side nonterminal
  77. | N_separated_nonempty_list_COMMA_variable_declarator_ : Ast.variable_declarators nonterminal
  78. | N_separated_nonempty_list_COMMA_statement_expression_ : Ast.statement_expression list nonterminal
  79. | N_separated_nonempty_list_COMMA_name_ : Ast.name list nonterminal
  80. | N_separated_nonempty_list_COMMA_module_name_ : Ast.module_name list nonterminal
  81. | N_separated_nonempty_list_COMMA_interface_type_ : Ast.javatype list nonterminal
  82. | N_separated_nonempty_list_COMMA_identifier_ : (Ast.loc * string) list nonterminal
  83. | N_separated_nonempty_list_COMMA_formal_parameter_ : Ast.formal_parameter list nonterminal
  84. | N_separated_nonempty_list_COMMA_expr_or_err_ : Ast.left_hand_side list nonterminal
  85. | N_separated_nonempty_list_COMMA_element_value_pair_ : Ast.element_value_pair list nonterminal
  86. | N_separated_nonempty_list_COMMA_element_value_ : Ast.element_value list nonterminal
  87. | N_separated_nonempty_list_COMMA_constant_expression_ : Ast.left_hand_side list nonterminal
  88. | N_separated_nonempty_list_COMMA_class_type_ : Ast.javatype list nonterminal
  89. | N_return_statement : Ast.statement nonterminal
  90. | N_resource_spec : Ast.resource_spec nonterminal
  91. | N_resource_list : Ast.resource list nonterminal
  92. | N_resource : Ast.resource nonterminal
  93. | N_reserved : unit nonterminal
  94. | N_requires_modifier : Ast.modifier nonterminal
  95. | N_relational_expression_nn : Ast.left_hand_side nonterminal
  96. | N_relational_expression : Ast.left_hand_side nonterminal
  97. | N_reference_type_3 : Ast.javatype nonterminal
  98. | N_reference_type_2 : Ast.javatype nonterminal
  99. | N_reference_type_1 : Ast.javatype nonterminal
  100. | N_record_header : Ast.formal_parameter list nonterminal
  101. | N_record_declaration_head1 : ((Ast.modifiers option * (Ast.loc * string)) * Ast.type_parameters option) nonterminal
  102. | N_record_declaration_head0 : (Ast.modifiers option * (Ast.loc * string)) nonterminal
  103. | N_record_declaration_head : Ast.record_declaration_head nonterminal
  104. | N_record_declaration : Ast.class_declaration nonterminal
  105. | N_record_body_declaration : Ast.record_body_declaration nonterminal
  106. | N_record_body : Ast.record_body nonterminal
  107. | N_primary_no_new_array : Ast.primary nonterminal
  108. | N_primary : Ast.primary nonterminal
  109. | N_pre_increment_expression : Ast.left_hand_side nonterminal
  110. | N_pre_decrement_expression : Ast.left_hand_side nonterminal
  111. | N_postfix_expression_nn : Ast.left_hand_side nonterminal
  112. | N_postfix_expression : Ast.left_hand_side nonterminal
  113. | N_post_increment_expression : Ast.left_hand_side nonterminal
  114. | N_post_decrement_expression : Ast.left_hand_side nonterminal
  115. | N_pointcut_expr : Ast.pointcut_expr nonterminal
  116. | N_pointcut_declaration : Ast.pointcut_declaration nonterminal
  117. | N_permits : Ast.permits nonterminal
  118. | N_pattern : Ast.local_variable_declaration nonterminal
  119. | N_partial_block_statement : Ast.block_statement nonterminal
  120. | N_partial_assert_statement : Ast.statement nonterminal
  121. | N_package_declaration : Ast.package_declaration nonterminal
  122. | N_or_pointcut_expr : Ast.pointcut_expr nonterminal
  123. | N_numeric_type : Ast.javatype nonterminal
  124. | N_normal_interface_declaration_head1 : ((Ast.modifiers option * string) * Ast.type_parameters option) nonterminal
  125. | N_normal_interface_declaration_head0 : (Ast.modifiers option * string) nonterminal
  126. | N_normal_interface_declaration_head : Ast.interface_declaration_head nonterminal
  127. | N_normal_interface_declaration : Ast.interface_declaration nonterminal
  128. | N_normal_annotation_body : Ast.annotation_desc nonterminal
  129. | N_nonempty_list_variable_modifier_ : Ast.modifier list nonterminal
  130. | N_nonempty_list_switch_label_ : Ast.switch_label list nonterminal
  131. | N_nonempty_list_element_value_comma_ : Ast.element_value list nonterminal
  132. | N_nonempty_list_catch_clause_ : Ast.catches nonterminal
  133. | N_nonempty_list_block_statement_ : Ast.block_statement list nonterminal
  134. | N_nonempty_list_annotation_or_modifier_ : Ast.modifier list nonterminal
  135. | N_nonempty_list_annotation_ : Ast.annotations nonterminal
  136. | N_nonempty_list_ann_dim_ : Ast.annot_dim list nonterminal
  137. | N_nonempty_list_additional_bound_ : Ast.additional_bound list nonterminal
  138. | N_name_pattern : string nonterminal
  139. | N_name : Ast.name nonterminal
  140. | N_multiplicative_expression_nn : Ast.left_hand_side nonterminal
  141. | N_multiplicative_expression : Ast.left_hand_side nonterminal
  142. | N_module_name : Ast.module_name nonterminal
  143. | N_module_directive : Ast.module_directive nonterminal
  144. | N_module_declaration_head : Ast.module_declaration_head nonterminal
  145. | N_module_declaration : Ast.module_declaration nonterminal
  146. | N_module_body : Ast.module_body nonterminal
  147. | N_modifiers : Ast.modifiers nonterminal
  148. | N_method_reference : Ast.method_reference nonterminal
  149. | N_method_invocation : Ast.method_invocation nonterminal
  150. | N_method_header : Ast.method_header nonterminal
  151. | N_method_declarator_head : ((Ast.loc * string) * Ast.loc) nonterminal
  152. | N_method_declarator : (((Ast.loc * string) * Ast.loc * Ast.formal_parameter list) * Ast.annot_dim list) nonterminal
  153. | N_method_declaration : Ast.class_body_declaration nonterminal
  154. | N_method_body : Ast.block option nonterminal
  155. | N_marker_annotation_body : Ast.annotation_desc nonterminal
  156. | N_main : Ast.compilation_unit nonterminal
  157. | N_loption_block_statements_ : Ast.block_statement list nonterminal
  158. | N_local_variable_declaration_statement : Ast.block_statement nonterminal
  159. | N_local_variable_declaration : Ast.local_variable_declaration nonterminal
  160. | N_literal : Ast.literal nonterminal
  161. | N_list_requires_modifier_ : Ast.modifier list nonterminal
  162. | N_list_record_body_declaration_ : Ast.record_body_declaration list nonterminal
  163. | N_list_module_directive_ : Ast.module_directive list nonterminal
  164. | N_list_interface_member_declaration_ : Ast.interface_member_declaration list nonterminal
  165. | N_list_class_body_declaration_ : Ast.class_body_declaration list nonterminal
  166. | N_list_annotation_type_member_declaration_ : Ast.annotation_type_member_declaration list nonterminal
  167. | N_lambda_parameters : Ast.lambda_params nonterminal
  168. | N_lambda_expression : Ast.left_hand_side nonterminal
  169. | N_lambda_e : Ast.left_hand_side nonterminal
  170. | N_lambda_body : Ast.lambda_body nonterminal
  171. | N_lambda_b : Ast.lambda_body nonterminal
  172. | N_labeled_statement_no_short_if : Ast.statement nonterminal
  173. | N_labeled_statement_head : string nonterminal
  174. | N_labeled_statement : Ast.statement nonterminal
  175. | N_javatype_vdid : Ast.formal_parameter nonterminal
  176. | N_interfaces : Ast.implements nonterminal
  177. | N_interface_method_declaration : Ast.interface_method_declaration nonterminal
  178. | N_interface_member_declaration : Ast.interface_member_declaration nonterminal
  179. | N_interface_declaration : Ast.interface_declaration nonterminal
  180. | N_interface_body : Ast.interface_body nonterminal
  181. | N_integral_type : Ast.primitive_type nonterminal
  182. | N_instanceof_expression_nn : Ast.left_hand_side nonterminal
  183. | N_instanceof_expression : Ast.left_hand_side nonterminal
  184. | N_instance_initializer : Ast.class_body_declaration nonterminal
  185. | N_inclusive_or_expression_nn : Ast.left_hand_side nonterminal
  186. | N_inclusive_or_expression : Ast.left_hand_side nonterminal
  187. | N_import_declaration : Ast.import_declaration nonterminal
  188. | N_if_then_statement : Ast.statement nonterminal
  189. | N_if_then_else_statement_no_short_if : Ast.statement nonterminal
  190. | N_if_then_else_statement : Ast.statement nonterminal
  191. | N_identifier : (Ast.loc * string) nonterminal
  192. | N_formal_parameter : Ast.formal_parameter nonterminal
  193. | N_for_update0 : Ast.statement_expression list nonterminal
  194. | N_for_update : Ast.statement_expression list nonterminal
  195. | N_for_statement_no_short_if : Ast.statement nonterminal
  196. | N_for_statement_head : unit nonterminal
  197. | N_for_statement : Ast.statement nonterminal
  198. | N_for_init_opt : Ast.for_init option nonterminal
  199. | N_for_init : Ast.for_init nonterminal
  200. | N_floating_point_type : Ast.primitive_type nonterminal
  201. | N_finally : Ast.finally nonterminal
  202. | N_field_declaration : Ast.field_declaration nonterminal
  203. | N_field_access : Ast.field_access nonterminal
  204. | N_extends_interfaces_opt : Ast.extends_interfaces option nonterminal
  205. | N_expression_statement : Ast.statement nonterminal
  206. | N_expression_opt : Ast.left_hand_side option nonterminal
  207. | N_expression_nn : Ast.left_hand_side nonterminal
  208. | N_expression : Ast.left_hand_side nonterminal
  209. | N_explicit_constructor_invocation : Ast.explicit_constructor_invocation nonterminal
  210. | N_exclusive_or_expression_nn : Ast.left_hand_side nonterminal
  211. | N_exclusive_or_expression : Ast.left_hand_side nonterminal
  212. | N_equality_expression_nn : Ast.left_hand_side nonterminal
  213. | N_equality_expression : Ast.left_hand_side nonterminal
  214. | N_enum_declaration_head0 : (Ast.modifiers option * (Ast.loc * string)) nonterminal
  215. | N_enum_declaration_head : Ast.class_declaration_head nonterminal
  216. | N_enum_declaration : Ast.class_declaration nonterminal
  217. | N_enum_constants : Ast.enum_constant list nonterminal
  218. | N_enum_constant_head : (Ast.loc * Ast.annotations * string * Ast.arguments option) nonterminal
  219. | N_enum_constant : Ast.enum_constant nonterminal
  220. | N_enum_body_declarations0 : Ast.class_body_declaration list nonterminal
  221. | N_enum_body : Ast.enum_body nonterminal
  222. | N_enhanced_for_statement_no_short_if : Ast.statement nonterminal
  223. | N_enhanced_for_statement : Ast.statement nonterminal
  224. | N_empty_statement : Ast.statement nonterminal
  225. | N_element_value_pair : Ast.element_value_pair nonterminal
  226. | N_element_value_array_initializer : Ast.element_value list nonterminal
  227. | N_element_value : Ast.element_value nonterminal
  228. | N_do_statement : Ast.statement nonterminal
  229. | N_dim_exprs : Ast.dim_expr list nonterminal
  230. | N_dim_expr : Ast.dim_expr nonterminal
  231. | N_default_value_opt : Ast.element_value option nonterminal
  232. | N_default_value : Ast.element_value nonterminal
  233. | N_declare_declaration : Ast.declare_declaration nonterminal
  234. | N_declarations : Ast.declaration list nonterminal
  235. | N_declaration : Ast.declaration nonterminal
  236. | N_continue_statement : Ast.statement nonterminal
  237. | N_constructor_declarator_head : (string * Ast.loc) nonterminal
  238. | N_constructor_declarator : (Ast.loc * string * Ast.loc * Ast.formal_parameter list) nonterminal
  239. | N_constructor_declaration : Ast.constructor_declaration nonterminal
  240. | N_constructor_body : Ast.constructor_body nonterminal
  241. | N_conditional_or_expression_nn : Ast.left_hand_side nonterminal
  242. | N_conditional_or_expression : Ast.left_hand_side nonterminal
  243. | N_conditional_expression_nn : Ast.left_hand_side nonterminal
  244. | N_conditional_expression : Ast.left_hand_side nonterminal
  245. | N_conditional_and_expression_nn : Ast.left_hand_side nonterminal
  246. | N_conditional_and_expression : Ast.left_hand_side nonterminal
  247. | N_compilation_unit : Ast.compilation_unit nonterminal
  248. | N_compact_constructor_declaration : Ast.compact_constructor_declaration nonterminal
  249. | N_classname_pattern_expr_list : Ast.classname_pattern_expr list nonterminal
  250. | N_classname_pattern_expr : Ast.classname_pattern_expr nonterminal
  251. | N_class_member_declaration : Ast.class_body_declaration nonterminal
  252. | N_class_instance_creation_head_qualified : (Ast.primary option * Ast.name option * Ast.type_arguments option) nonterminal
  253. | N_class_instance_creation_head : (Ast.type_arguments option * Ast.javatype) nonterminal
  254. | N_class_instance_creation_expression : Ast.class_instance_creation nonterminal
  255. | N_class_declaration_head1 : ((Ast.modifiers option * (Ast.loc * string)) * Ast.type_parameters option) nonterminal
  256. | N_class_declaration_head0 : (Ast.modifiers option * (Ast.loc * string)) nonterminal
  257. | N_class_declaration_head : Ast.class_declaration_head nonterminal
  258. | N_class_declaration : Ast.class_declaration nonterminal
  259. | N_class_body_declaration : Ast.class_body_declaration nonterminal
  260. | N_class_body : Ast.class_body nonterminal
  261. | N_catch_type : Ast.javatype list nonterminal
  262. | N_catch_formal_parameter : Ast.catch_formal_parameter nonterminal
  263. | N_catch_clause_header : unit nonterminal
  264. | N_catch_clause : Ast.catch nonterminal
  265. | N_cast_expression : Ast.left_hand_side nonterminal
  266. | N_break_statement : Ast.statement nonterminal
  267. | N_block_statement : Ast.block_statement nonterminal
  268. | N_block : Ast.block nonterminal
  269. | N_basic_pointcut_expr : Ast.pointcut_expr nonterminal
  270. | N_basic_classname_pattern_expr : Ast.classname_pattern_expr nonterminal
  271. | N_assignment_expression_nn : Ast.left_hand_side nonterminal
  272. | N_assignment_expression : Ast.left_hand_side nonterminal
  273. | N_assignment : Ast.assignment nonterminal
  274. | N_assert_statement : Ast.statement nonterminal
  275. | N_aspect_declaration_head0 : (Ast.modifiers option * (Ast.loc * string)) nonterminal
  276. | N_aspect_declaration_head : Ast.class_declaration_head nonterminal
  277. | N_aspect_declaration : Ast.class_declaration nonterminal
  278. | N_aspect_body_declarations : Ast.class_body_declaration list nonterminal
  279. | N_aspect_body_declaration : Ast.class_body_declaration nonterminal
  280. | N_aspect_body : Ast.aspect_body nonterminal
  281. | N_array_initializer : Ast.variable_initializer nonterminal
  282. | N_array_creation_noinit : Ast.array_creation_expression nonterminal
  283. | N_array_creation_init : Ast.array_creation_expression nonterminal
  284. | N_array_access : Ast.array_access nonterminal
  285. | N_annotations : Ast.annotations nonterminal
  286. | N_annotation_type_member_declaration : Ast.annotation_type_member_declaration nonterminal
  287. | N_annotation_type_declaration_head : Ast.interface_declaration_head nonterminal
  288. | N_annotation_type_declaration : Ast.interface_declaration nonterminal
  289. | N_annotation_type_body : Ast.annotation_type_body nonterminal
  290. | N_annotation_body : Ast.annotation_desc nonterminal
  291. | N_annotation : Ast.annotation nonterminal
  292. | N_ann_dims : Ast.annot_dim list nonterminal
  293. | N_ann_dim : Ast.annot_dim nonterminal
  294. | N_and_expression_nn : Ast.left_hand_side nonterminal
  295. | N_and_expression : Ast.left_hand_side nonterminal
  296. | N_and_classname_pattern_expr : Ast.classname_pattern_expr nonterminal
  297. | N_adhoc_modifier : Ast.modifier_desc nonterminal
  298. | N_additive_expression_nn : Ast.left_hand_side nonterminal
  299. | N_additive_expression : Ast.left_hand_side nonterminal
  300. | N_additional_bound_list_1 : Ast.additional_bound list nonterminal
  301. | N_additional_bound_list : Ast.additional_bound list nonterminal
  302. | N_additional_bound_1 : Ast.additional_bound nonterminal
  303. | N_additional_bound : Ast.additional_bound nonterminal
include MenhirLib.IncrementalEngine.INSPECTION with type 'a lr1state := 'a lr1state with type production := production with type 'a terminal := 'a terminal with type 'a nonterminal := 'a nonterminal with type 'a env := 'a env
include MenhirLib.IncrementalEngine.SYMBOLS with type 'a terminal := 'a terminal with type 'a nonterminal := 'a nonterminal
Sourcetype 'a symbol =
  1. | T : 'a terminal -> 'a symbol
  2. | N : 'a nonterminal -> 'a symbol

The type 'a symbol represents a terminal or nonterminal symbol. It is the disjoint union of the types 'a terminal and 'a nonterminal.

Sourcetype xsymbol =
  1. | X : 'a symbol -> xsymbol

The type xsymbol is an existentially quantified version of the type 'a symbol. This type is useful in situations where 'a is not statically known.

Sourcetype item = production * int

An LR(0) item is a pair of a production prod and a valid index i into this production. That is, if the length of rhs prod is n, then i is comprised between 0 and n, inclusive.

The following are total ordering functions.

Sourceval compare_terminals : _ terminal -> _ terminal -> int
Sourceval compare_nonterminals : _ nonterminal -> _ nonterminal -> int
Sourceval compare_symbols : xsymbol -> xsymbol -> int
Sourceval compare_productions : production -> production -> int
Sourceval compare_items : item -> item -> int
Sourceval incoming_symbol : 'a lr1state -> 'a symbol

incoming_symbol s is the incoming symbol of the state s, that is, the symbol that the parser must recognize before (has recognized when) it enters the state s. This function gives access to the semantic value v stored in a stack element Element (s, v, _, _). Indeed, by case analysis on the symbol incoming_symbol s, one discovers the type 'a of the value v.

Sourceval items : _ lr1state -> item list

items s is the set of the LR(0) items in the LR(0) core of the LR(1) state s. This set is not epsilon-closed. This set is presented as a list, in an arbitrary order.

lhs prod is the left-hand side of the production prod. This is always a non-terminal symbol.

Sourceval rhs : production -> xsymbol list

rhs prod is the right-hand side of the production prod. This is a (possibly empty) sequence of (terminal or nonterminal) symbols.

Sourceval nullable : _ nonterminal -> bool

nullable nt tells whether the non-terminal symbol nt is nullable. That is, it is true if and only if this symbol produces the empty word epsilon.

Sourceval first : _ nonterminal -> _ terminal -> bool

first nt t tells whether the FIRST set of the nonterminal symbol nt contains the terminal symbol t. That is, it is true if and only if nt produces a word that begins with t.

Sourceval xfirst : xsymbol -> _ terminal -> bool

xfirst is analogous to first, but expects a first argument of type xsymbol instead of _ terminal.

Sourceval foreach_terminal : (xsymbol -> 'a -> 'a) -> 'a -> 'a

foreach_terminal enumerates the terminal symbols, including error.

Sourceval foreach_terminal_but_error : (xsymbol -> 'a -> 'a) -> 'a -> 'a

foreach_terminal_but_error enumerates the terminal symbols, excluding error.

feed symbol startp semv endp env causes the parser to consume the (terminal or nonterminal) symbol symbol, accompanied with the semantic value semv and with the start and end positions startp and endp. Thus, the automaton makes a transition, and reaches a new state. The stack grows by one cell. This operation is permitted only if the current state (as determined by env) has an outgoing transition labeled with symbol. Otherwise, Invalid_argument _ is raised.