Here's a copy of the entire grammar for the Ada/CS language described in our text. I got this from Dr. LeBlanc it's long and probably confusing since it does the whole thing, rather than the incremental approach i take with the "hints". but, i figured it would be of interest k ------------------------------------------------------------------ Date: Mon, 24 Sep 90 13:36:07 EDT From: rich%panther@gatech.edu (Richard LeBlanc) To: stewart%math@sdsu.edu Cc: rich%panther@gatech.edu Subject: crafting in c Status: R %{ /* This is the Yacc specification for the AdaCS language, used in CS701. This was developed from the BNF given in Fischer and Leblanc. There are many differences between this grammar and the BNF. We found some omissions in the BNF which we feel the language requires, and we have included those constructs in this grammar. Written by Manjeri R. Dharmarajan and Susan B. Horwitz */ %} %token PRAGMA %token ID %token PACKAGE %token IS %token END %token BODY %token TYPE %token PRIVATE %token SUBTYPE %token USE %token EXCEPTION %token IDENTIFIER %token CONSTANT %token ASSGNOP %token ACCESS %token RECORD %token NULL %token CASE %token WHEN %token IMPLY %token ARRAY %token OF %token RANGE %token LESSTHANGRTRTHAN %token DOTDOT %token DOT %token COLON %token COMMA %token L_PAREN %token R_PAREN %token QUOTE %token VERT_BAR %token PLUS %token MINUS %token STAR %token DIVIDE %token AMPERSAND %token BEGIN %token PROCEDURE %token FUNCTION %token RETURN %token STRLITERAL %token IN %token OUT %token OTHERS %token DECLARE %token RAISE %token IF %token THEN %token ELSIF %token ELSE %token LOOP %token WHILE %token FOR %token REVERSE %token EXIT %token AND %token OR %token NOT %token ABS %token POWEROP %token INTLITERAL %token FLOATLITERAL %token EQUAL %token NOTEQUAL %token LESSTHAN %token GRTRTHAN %token LESSEQ %token GREATEREQ %token MOD %token ALL %token SEMI %% compilation : pragma_list compilation_unit ; | compilation pragma_list compilation_unit ; pragma_list : ; | pragma_list pragma ; pragma : PRAGMA ID SEMI ; compilation_unit : package_declaration; package_declaration : PACKAGE package_spec_or_body SEMI ; package_spec_or_body : id IS spec_decl_list private_part_option body_option END id_option ; private_part_option : ; | private_part ; spec_decl_list : ; | spec_decl_list spec_declaration ; package_spec_or_body : BODY id IS body_decl_list stmnt_list_option exception_part_option END id_option ; exception_part_option : ; | exception_part ; body_decl_list : ; | body_decl_list body_declaration ; stmnt_list_option : ; | BEGIN stmnt_list ; stmnt_list : ; | stmnt_list statement ; body_option : ; | BODY body_decl_list stmnt_list_option exception_part_option ; id_option : ; | id ; spec_declaration : private_type_declaration ; | declaration; private_type_declaration : TYPE id IS PRIVATE SEMI ; private_part : PRIVATE private_item_list ; private_item_list : private_item ; | private_item_list private_item ; private_item : SUBTYPE id IS subtype_definition SEMI ; | SUBTYPE id IS type_name SEMI ; | TYPE id IS type_definition SEMI ; body_declaration : subprogram_body_decl ; | declaration; declaration : object_declaration; | type_declaration; | subtype_declaration; | pragma; | subprogram_declaration; | USE name_list SEMI ; | id_list COLON EXCEPTION SEMI ; object_declaration : id_list COLON constant_option type_or_subtype initialization_option SEMI ; id_list : id ; | id_list COMMA id ; id : IDENTIFIER; constant_option : ; | CONSTANT ; type_or_subtype : type; | subtype_definition; initialization_option : ; | ASSGNOP expression ; type_declaration : TYPE id IS type_definition SEMI ; | incomplete_type_decl; type : type_name; | type_definition; type_name : id_dot_list ; id_dot_list : id ; | id DOT id_dot_list ; type_definition : record_type_definition; | array_type_definition; | enumeration_type_def; | ACCESS subtype; incomplete_type_decl : TYPE id SEMI ; record_type_definition : RECORD component_list END RECORD; component_list : NULL SEMI ; | variant_part ; | component_declaration_list ; | component_declaration_list variant_part ; component_declaration_list : component_declaration ; | component_declaration_list component_declaration ; component_declaration : id_list COLON type_or_subtype initialization_option SEMI ; variant_part : CASE id COLON type_name IS variant_list END CASE SEMI ; variant_list : variant ; | variant_list variant ; variant : WHEN vchoice IMPLY component_list; vchoice : simple_expression; array_type_definition : unconstrained_array_def; | constrained_array_def; unconstrained_array_def : ARRAY unconstrained_index_list OF element_type; unconstrained_index_list : L_PAREN index_subtype_def_list R_PAREN ; index_subtype_def_list : index_subtype_def ; | index_subtype_def_list COMMA index_subtype_def ; index_subtype_def : name RANGE LESSTHANGRTRTHAN; constrained_array_def : ARRAY constrained_index_list OF element_type; constrained_index_list : L_PAREN discrete_range_list R_PAREN ; discrete_range_list : discrete_range ; | discrete_range_list COMMA discrete_range ; element_type : type_or_subtype; enumeration_type_def : L_PAREN enumeration_id_list R_PAREN ; enumeration_id_list : id ; | enumeration_id_list COMMA id ; subtype_declaration : SUBTYPE id IS subtype_definition SEMI ; | SUBTYPE id IS type_name SEMI ; subtype : subtype_definition; subtype_definition : range_constraint; | type_name range_constraint; | type_name index_constraint; range_constraint : RANGE range; range : simple_expression DOTDOT simple_expression; index_constraint : L_PAREN discrete_range_list R_PAREN ; discrete_range : id ; | range ; subprogram_declaration : subprogram_specification SEMI ; subprogram_body_decl : subprogram_specification IS body_decl_list BEGIN stmnt_list exception_part_option END id_option SEMI ; subprogram_specification : PROCEDURE id formal_part_opt; | FUNCTION designator formal_part_opt RETURN subtype ; designator : id; | operator_symbol; operator_symbol : STRLITERAL; formal_part_opt : ; | formal_part ; formal_part : L_PAREN parameter_declaration_list R_PAREN ; parameter_declaration_list : parameter_decl ; | parameter_declaration_list SEMI parameter_decl ; parameter_decl : id_list COLON mode_option type_or_subtype; mode_option : ; | mode ; mode : IN out_option; | OUT; out_option : ; | OUT ; exception_part : EXCEPTION exception_handler_list ; exception_handler_list : ; | exception_handler_list exception_handler ; exception_handler : WHEN exception_when_tail; exception_when_tail : OTHERS IMPLY stmnt_list ; | listofnames IMPLY stmnt_list ; listofnames : name ; | listofnames VERT_BAR name ; statement : pragma; | null_statement; | assignment_statement; | call_statement; | block; | loop_statement; | if_statement; | exit_statement; | return_statement; | case_statement; | raise_statement; null_statement : NULL SEMI ; assignment_statement : name ASSGNOP expression SEMI ; call_statement : name SEMI ; block : id_colon_option decl_part_option BEGIN stmnt_list exception_part_option END id_option SEMI ; id_colon_option : ; | id COLON ; decl_part_option : ; | decl_part ; decl_part : DECLARE body_decl_list ; return_statement : RETURN expression_option SEMI ; expression_option : ; | expression ; raise_statement : RAISE name_option SEMI ; if_statement : IF b_expr THEN stmnt_list elsif_list else_part_option END IF SEMI ; elsif_list : ; | elsif_list ELSIF b_expr THEN stmnt_list ; else_part_option : ; | else_part ; else_part : ELSE stmnt_list ; loop_statement : id_colon_option iteration_clause_option basic_loop id_option SEMI ; iteration_clause_option : ; | iteration_clause ; basic_loop : LOOP stmnt_list END LOOP; iteration_clause : WHILE b_expr; | FOR id IN reverse_option discrete_range ; reverse_option : ; | REVERSE ; exit_statement : EXIT name_option when_option SEMI ; when_option : ; | WHEN b_expr ; name_option : ; | name ; case_statement : CASE expression IS when_list others_option END CASE SEMI ; when_list : ; | when_list WHEN choice_list IMPLY stmnt_list ; others_option : ; | WHEN OTHERS IMPLY stmnt_list ; choice_list : choice ; | choice_list VERT_BAR choice ; choice : expression; | expression DOTDOT expression; b_expr : expression; expression : relation ; | expression logical_op relation ; relation : unary_simple_expression ; | unary_simple_expression relational_op unary_simple_expression ; unary_simple_expression : simple_expression ; | unary_adding_op simple_expression ; simple_expression : term ; | simple_expression adding_op term ; term : factor ; | term multiplying_op factor ; factor : primary ; | primary POWEROP primary ; | NOT primary ; | ABS primary ; primary : literal ; | name ; | L_PAREN expression R_PAREN ; literal : INTLITERAL; | FLOATLITERAL; | STRLITERAL; logical_op : AND then_option ; | OR then_option ; then_option : ; | THEN ; adding_op : PLUS ; | MINUS ; | AMPERSAND ; unary_adding_op : PLUS ; | MINUS ; multiplying_op : STAR ; | DIVIDE ; | MOD ; relational_op : EQUAL ; | NOTEQUAL ; | LESSTHAN; | LESSEQ; | GRTRTHAN ; | GREATEREQ ; name : id name_suffix_list all_option ; all_option : ; | DOT ALL ; name_suffix_list : ; | name_suffix_list name_suffix ; name_suffix : DOT selected_suffix ; selected_suffix : id ; | operator_symbol ; name_suffix : L_PAREN expression_list R_PAREN; expression_list : expression ; | expression_list COMMA expression ; name_suffix : QUOTE id ; name_list : name ; | name_list COMMA name ; %%