📄 grammar9.y
字号:
/******* A YACC grammar for Ada 9X *********************************/
/* Copyright (C) Intermetrics, Inc. 1994 Cambridge, MA USA */
/* Copying permitted if accompanied by this statement. */
/* Derivative works are permitted if accompanied by this statement.*/
/* This grammar is thought to be correct as of May 1, 1994 */
/* but as usual there is *no warranty* to that effect. */
/*******************************************************************/
%token TIC
%token DOT_DOT
%token LT_LT
%token BOX
%token LT_EQ
%token EXPON
%token NE
%token GT_GT
%token GE
%token IS_ASSIGNED
%token RIGHT_SHAFT
%token ABORT
%token ABS
%token ABSTRACT
%token ACCEPT
%token ACCESS
%token ALIASED
%token ALL
%token AND
%token ARRAY
%token AT
%token BEGiN
%token BODY
%token CASE
%token CONSTANT
%token DECLARE
%token DELAY
%token DELTA
%token DIGITS
%token DO
%token ELSE
%token ELSIF
%token END
%token ENTRY
%token EXCEPTION
%token EXIT
%token FOR
%token FUNCTION
%token GENERIC
%token GOTO
%token IF
%token IN
%token IS
%token LIMITED
%token LOOP
%token MOD
%token NEW
%token NOT
%token NuLL
%token OF
%token OR
%token OTHERS
%token OUT
%token PACKAGE
%token PRAGMA
%token PRIVATE
%token PROCEDURE
%token PROTECTED
%token RAISE
%token RANGE
%token RECORD
%token REM
%token RENAMES
%token REQUEUE
%token RETURN
%token REVERSE
%token SELECT
%token SEPARATE
%token SUBTYPE
%token TAGGED
%token TASK
%token TERMINATE
%token THEN
%token TYPE
%token UNTIL
%token USE
%token WHEN
%token WHILE
%token WITH
%token XOR
%token char_lit
%token identifier
%token char_string
%token numeric_lit
%{
%}
%%
goal_symbol : compilation
;
pragma : PRAGMA identifier ';'
| PRAGMA simple_name '(' pragma_arg_s ')' ';'
;
pragma_arg_s : pragma_arg
| pragma_arg_s ',' pragma_arg
;
pragma_arg : expression
| simple_name RIGHT_SHAFT expression
;
pragma_s :
| pragma_s pragma
;
decl : object_decl
| number_decl
| type_decl
| subtype_decl
| subprog_decl
| pkg_decl
| task_decl
| prot_decl
| exception_decl
| rename_decl
| generic_decl
| body_stub
| error ';'
;
object_decl : def_id_s ':' object_qualifier_opt object_subtype_def init_opt ';'
;
def_id_s : def_id
| def_id_s ',' def_id
;
def_id : identifier
;
object_qualifier_opt :
| ALIASED
| CONSTANT
| ALIASED CONSTANT
;
object_subtype_def : subtype_ind
| array_type
;
init_opt :
| IS_ASSIGNED expression
;
number_decl : def_id_s ':' CONSTANT IS_ASSIGNED expression ';'
;
type_decl : TYPE identifier discrim_part_opt type_completion ';'
;
discrim_part_opt :
| discrim_part
| '(' BOX ')'
;
type_completion :
| IS type_def
;
type_def : enumeration_type
| integer_type
| real_type
| array_type
| record_type
| access_type
| derived_type
| private_type
;
subtype_decl : SUBTYPE identifier IS subtype_ind ';'
;
subtype_ind : name constraint
| name
;
constraint : range_constraint
| decimal_digits_constraint
;
decimal_digits_constraint : DIGITS expression range_constr_opt
;
derived_type : NEW subtype_ind
| NEW subtype_ind WITH PRIVATE
| NEW subtype_ind WITH record_def
| ABSTRACT NEW subtype_ind WITH PRIVATE
| ABSTRACT NEW subtype_ind WITH record_def
;
range_constraint : RANGE range
;
range : simple_expression DOT_DOT simple_expression
| name TIC RANGE
| name TIC RANGE '(' expression ')'
;
enumeration_type : '(' enum_id_s ')'
enum_id_s : enum_id
| enum_id_s ',' enum_id
;
enum_id : identifier
| char_lit
;
integer_type : range_spec
| MOD expression
;
range_spec : range_constraint
;
range_spec_opt :
| range_spec
;
real_type : float_type
| fixed_type
;
float_type : DIGITS expression range_spec_opt
;
fixed_type : DELTA expression range_spec
| DELTA expression DIGITS expression range_spec_opt
;
array_type : unconstr_array_type
| constr_array_type
;
unconstr_array_type : ARRAY '(' index_s ')' OF component_subtype_def
;
constr_array_type : ARRAY iter_index_constraint OF component_subtype_def
;
component_subtype_def : aliased_opt subtype_ind
;
aliased_opt :
| ALIASED
;
index_s : index
| index_s ',' index
;
index : name RANGE BOX
;
iter_index_constraint : '(' iter_discrete_range_s ')'
;
iter_discrete_range_s : discrete_range
| iter_discrete_range_s ',' discrete_range
;
discrete_range : name range_constr_opt
| range
;
range_constr_opt :
| range_constraint
;
record_type : tagged_opt limited_opt record_def
;
record_def : RECORD pragma_s comp_list END RECORD
| NuLL RECORD
;
tagged_opt :
| TAGGED
| ABSTRACT TAGGED
;
comp_list : comp_decl_s variant_part_opt
| variant_part pragma_s
| NuLL ';' pragma_s
;
comp_decl_s : comp_decl
| comp_decl_s pragma_s comp_decl
;
variant_part_opt : pragma_s
| pragma_s variant_part pragma_s
;
comp_decl : def_id_s ':' component_subtype_def init_opt ';'
| error ';'
;
discrim_part : '(' discrim_spec_s ')'
;
discrim_spec_s : discrim_spec
| discrim_spec_s ';' discrim_spec
;
discrim_spec : def_id_s ':' access_opt mark init_opt
| error
;
access_opt :
| ACCESS
;
variant_part : CASE simple_name IS pragma_s variant_s END CASE ';'
;
variant_s : variant
| variant_s variant
;
variant : WHEN choice_s RIGHT_SHAFT pragma_s comp_list
;
choice_s : choice
| choice_s '|' choice
;
choice : expression
| discrete_with_range
| OTHERS
;
discrete_with_range : name range_constraint
| range
;
access_type : ACCESS subtype_ind
| ACCESS CONSTANT subtype_ind
| ACCESS ALL subtype_ind
| ACCESS prot_opt PROCEDURE formal_part_opt
| ACCESS prot_opt FUNCTION formal_part_opt RETURN mark
;
prot_opt :
| PROTECTED
;
decl_part :
| decl_item_or_body_s1
;
decl_item_s :
| decl_item_s1
;
decl_item_s1 : decl_item
| decl_item_s1 decl_item
;
decl_item : decl
| use_clause
| rep_spec
| pragma
;
decl_item_or_body_s1 : decl_item_or_body
| decl_item_or_body_s1 decl_item_or_body
;
decl_item_or_body : body
| decl_item
;
body : subprog_body
| pkg_body
| task_body
| prot_body
;
name : simple_name
| indexed_comp
| selected_comp
| attribute
| operator_symbol
;
mark : simple_name
| mark TIC attribute_id
| mark '.' simple_name
;
simple_name : identifier
;
compound_name : simple_name
| compound_name '.' simple_name
;
c_name_list : compound_name
| c_name_list ',' compound_name
;
used_char : char_lit
;
operator_symbol : char_string
;
indexed_comp : name '(' value_s ')'
;
value_s : value
| value_s ',' value
;
value : expression
| comp_assoc
| discrete_with_range
| error
;
selected_comp : name '.' simple_name
| name '.' used_char
| name '.' operator_symbol
| name '.' ALL
;
attribute : name TIC attribute_id
;
attribute_id : identifier
| DIGITS
| DELTA
| ACCESS
;
literal : numeric_lit
| used_char
| NuLL
;
aggregate : '(' comp_assoc ')'
| '(' value_s_2 ')'
| '(' expression WITH value_s ')'
| '(' expression WITH NuLL RECORD ')'
| '(' NuLL RECORD ')'
;
value_s_2 : value ',' value
| value_s_2 ',' value
;
comp_assoc : choice_s RIGHT_SHAFT expression
;
expression : relation
| expression logical relation
| expression short_circuit relation
;
logical : AND
| OR
| XOR
;
short_circuit : AND THEN
| OR ELSE
;
relation : simple_expression
| simple_expression relational simple_expression
| simple_expression membership range
| simple_expression membership name
;
relational : '='
| NE
| '<'
| LT_EQ
| '>'
| GE
;
membership : IN
| NOT IN
;
simple_expression : unary term
| term
| simple_expression adding term
;
unary : '+'
| '-'
;
adding : '+'
| '-'
| '&'
;
term : factor
| term multiplying factor
;
multiplying : '*'
| '/'
| MOD
| REM
;
factor : primary
| NOT primary
| ABS primary
| primary EXPON primary
;
primary : literal
| name
| allocator
| qualified
| parenthesized_primary
;
parenthesized_primary : aggregate
| '(' expression ')'
;
qualified : name TIC parenthesized_primary
;
allocator : NEW name
| NEW qualified
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -