⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ada语法.c

📁 语言的语法,格式严紧,对于处理yacc,lex有帮助!
💻 C
📖 第 1 页 / 共 3 页
字号:
X */ 

X 

X..basic_decl_item.. : 

X ..prag.. | 

X ..basic_decl_item.. basic_decl_item ..prag..; 

X 

X..later_decl_item.. : 

X ..prag.. | 

X ..later_decl_item.. later_decl_item ..prag..; 

X 

X 

X/* 4.1 */ 

X 

X/* slice is included under idxed_cmpon */ 

X 

X/* 

X * The def of name includes func_call. 

X * 

X * A prmless func call is recognized as a sim name or a selected cmpon. 

X * A func call with prms is recognized as an idxed cmpon. 

X * 

X * Reserved word attribute designators are included in the rules as a 

X * convenience. Alternativly, since an attribute designator is always prece 

ded 

X * by an apostrophe, as noted in the RR_ 4.1.4, such usage may be detected 

X * during lexical analysis thus obviating the need for special rules. 

X * 

X * The univ static expr of an attribute designator is reduced as an idxed_c 

mpon. 

X */ 

X 

X/* 

X * Component ascs are generalized to include dscr rngs. 

X * Thus, an aggr can be used for slices and idx and discr constrts. 

X */ 

X...cmpon_asc.. : 

X /* empty */ | 

X ...cmpon_asc.. ',' cmpon_asc; 

X 

Xrel..AND__rel.. : 

X rel AND_ rel | 

X rel..AND__rel.. AND_ rel; 

X 

Xrel..OR__rel.. : 

X rel OR_ rel | 

X rel..OR__rel.. OR_ rel; 

X 

Xrel..XOR__rel.. : 

X rel | 

X ..XOR__rel..; 

X 

X..XOR__rel.. : 

X rel XOR_ rel | 

X ..XOR__rel.. XOR_ rel; 

X 

Xrel..AND__THEN__rel.. : 

X rel AND_ THEN_ rel | 

X rel..AND__THEN__rel.. AND_ THEN_ rel; 

X 

Xrel..OR__ELSE__rel.. : 

X rel OR_ ELSE_ rel | 

X rel..OR__ELSE__rel.. OR_ ELSE_ rel; 

X 

X.relal_op__sim_expr. : 

X /* empty */ | 

X relal_op sim_expr; 

X 

X/* ty_mk is included under rng */ 

Xsim_expr.NOT.IN__rng_or_sim_expr.NOT.IN__ty_mk : sim_expr .NOT. IN_ rng; 

X 

X.NOT. : 

X /* empty */ | 

X NOT_; 

X 

X.unary_add_op.term..binary_add_op__term.. : 

X term | 

X unary_add_op term | 

X .unary_add_op.term..binary_add_op__term.. binary_add_op term; 

X 

Xfactor..mult_op__factor.. : 

X factor | 

X factor..mult_op__factor.. mult_op factor; 

X 

X/* stringsit is included under name as op_symbol */ 

X/* func_call is included under name */ 

X/* ty_cnvr is included under name */ 

X._EXP___pri. : 

X /* empty */ | 

X EXP_ pri; 

X 

X/* The "prefix must be a "ty_mk". The "PexprP_" is an "aggr". */ 

Xty_mkaggr_or_ty_mkPexprP_ : prefix '\'' aggr; 

X 

X/* 

X * Here the qualified_expr can be given exactly 

X * 

X * We use the fact that the constrt must be an idx or discr 

X * constrt. 

X */ 

X 

X 

X/* 5.1 */ 

X..stmt.. : 

X ..prag.. | 

X ..stmt.. stmt ..prag..; 

X 

X..label.. : 

X /* empty */ | 

X ..label.. label; 

X 

X..ELSIF__cond__THEN__seq_of_stmts.. : 

X /* empty */ | 

X ..ELSIF__cond__THEN__seq_of_stmts.. 

X ELSIF_ cond THEN_ 

X   seq_of_stmts; 

X 

X.ELSE__seq_of_stmts. : 

X /* empty */ | 

X ELSE_ 

X   seq_of_stmts; 

X 

Xcase_stmt_alt..case_stmt_alt.. : 

X ..prag.. 

X case_stmt_alt 

X ..case_stmt_alt..; 

X 

X..case_stmt_alt.. : 

X /* empty */ | 

X ..case_stmt_alt.. case_stmt_alt; 

X 

X.sim_nC. : 

X /* empty */ | 

X sim_n ':'; 

X 

X.sim_n. : 

X /* empty */ | 

X sim_n; 

X 

X.iteration_scheme. : 

X /* empty */ | 

X iteration_scheme; 

X 

X.REVERSE. : 

X /* empty */ | 

X REVERSE_; 

X 

X.DECLARE__decl_part. : 

X /* empty */ | 

X DECLARE_ 

X   decl_part; 

X 

X.EXCEPTION__excptn_handler..excptn_handler... : 

X /* empty */ | 

X EXCEPTION_ 

X   ..prag.. excptn_handlers; 

X 

Xexcptn_handlers : 

X excptn_handler | 

X excptn_handlers excptn_handler; 

X 

X.expanded_n. : 

X /* empty */ | 

X expanded_n; 

X 

X.WHEN__cond. : 

X /* empty */ | 

X WHEN_ cond; 

X 

X.expr. : 

X /* empty */ | 

X expr; 

X 

X 

X/* 6.1 */ 

X.fml_part. : 

X /* empty */ | 

X fml_part; 

X 

X.._.prm_spec.. : 

X /* empty */ | 

X .._.prm_spec.. ';' prm_spec; 

X 

X.IN. : 

X /* empty */ | 

X IN_; 

X 

X/* A "decl_part" may be empty. */ 

X.decl_part. : decl_part; 

X 

X.designator. : 

X /* empty */ | 

X designator; 

X 

X 

X/* 7.1 */ 

X.PRIVATE..basic_decl_item... : 

X /* empty */ | 

X PRIVATE_ 

X   ..basic_decl_item..; 

X 

X.BEGIN__seq_of_stmts.EXCEPTION__excptn_handler..excptn_handler... : 

X /* empty */ | 

X BEGIN_ 

X   seq_of_stmts 

X .EXCEPTION__excptn_handler..excptn_handler...; 

X 

X.LIMITED. : 

X /* empty */ | 

X LIMITED_; 

X 

X...expanded_n.. : 

X /* empty */ | 

X ...expanded_n.. ',' expanded_n; 

X 

X 

X/* 9.1 */ 

X.TYPE. : 

X /* empty */ | 

X TYPE_; 

X 

X.IS..ent_d_..rep_cl_END.sim_n. : 

X /* empty */ | 

X IS_ 

X   ..ent_d.. 

X   ..rep_cl.. 

X END_ .sim_n.; 

X 

X..ent_d.. : 

X ..prag.. | 

X ..ent_d.. ent_d ..prag..; 

X 

X..rep_cl.. : 

X /* empty */ | 

X ..rep_cl.. rep_cl ..prag..; 

X 

X.Pent_idx_P..fml_part. : 

X .fml_part. | 

X '(' ent_idx ')' .fml_part.; 

X 

X.DO__seq_of_stmts__END.sim_n.. : 

X /* empty */ | 

X DO_ 

X   seq_of_stmts 

X END_ .sim_n.; 

X 

X..OR__select_alt.. : 

X /* empty */ | 

X ..OR__select_alt.. OR_ select_alt; 

X 

X.WHEN__condARROW.selec_wait_alt : 

X selec_wait_alt | 

X WHEN_ cond ARROW_ selec_wait_alt; 

X 

Xaccept_stmt.seq_of_stmts. : ..prag.. accept_stmt .seq_of_stmts.; 

X 

Xdelay_stmt.seq_of_stmts. : ..prag.. delay_stmt .seq_of_stmts.; 

X 

XTERM_stmt : ..prag.. TERMINATE_ ';' ..prag..; 

X 

X.seq_of_stmts. : 

X ..prag.. | 

X seq_of_stmts; 

X 

X...name.. : 

X /* empty */ | 

X ...name.. ',' name; 

X 

X 

X/* 10.1 */ 

X..compilation_unit.. : 

X ..prag.. | 

X ..compilation_unit.. 

X compilation_unit ..prag..; 

X 

X/* "subprg_body" is already contained in the class "library_unit". */ 

Xpkg_body_or_subprg_body : pkg_body; 

X 

X..with_cl..use_cl.... : 

X /* empty */ | 

X ..with_cl..use_cl.... with_cl use_cls; 

X 

Xuse_cls : 

X ..prag.. | 

X use_cls use_cl ..prag..; 

X 

X...sim_n.. : 

X /* empty */ | 

X ...sim_n.. ',' sim_n; 

X 

X 

X/* 11.1 */ 

X..or_excptn_choice.. : 

X /* empty */ | 

X ..or_excptn_choice.. '|' excptn_choice; 

X 

X 

X/* 12.1 */ 

X..gen_prm_d.. : 

X /* empty */ | 

X ..gen_prm_d.. gen_prm_d; 

X 

X.IN.OUT.. : 

X .IN. | 

X IN_ OUT_; 

X 

X.IS_BOX_. : 

X /* empty */ | 

X IS_ name | 

X IS_ BOX_; 

X 

X/* To avoid conflicts, the more general "subprg_spec" is used. */ 

XPROCEDURE__ident__IS_ : subprg_spec IS_; 

X 

X.gen_act_part. : 

X /* empty */ | 

X gen_act_part; 

X 

X...gen_asc.. : 

X /* empty */ | 

X ...gen_asc.. ',' gen_asc; 

X 

X.gen_fml_prmARROW.gen_act_prm : 

X gen_act_prm | 

X gen_fml_prm ARROW_ gen_act_prm; 

X 

X/* The below alts are included under expr */ 

Xexpr_or_name_or_subprg_n_or_ent_n_or_ty_mk : expr; 

X 

X 

X/* 13.1 */ 

X/* The "sim_n" must be a "ty_sim_n". */ 

XFOR__ty_sim_n__USE_ : FOR_ sim_n USE_; 

X 

X.algt_cl. : 

X ..prag.. | 

X ..prag.. algt_cl ..prag..; 

X 

X..cmpon_cl.. : 

X /* empty */ | 

X ..cmpon_cl.. cmpon_cl ..prag..; 

X 

X/* The qualified expr must contain a rec aggr. */ 

Xty_mk_rec_aggr : qualified_expr; 

END_OF_FILE 

if test 19965 -ne `wc -c <'ada.y'`; then 

    echo shar: \"'ada.y'\" unpacked with wrong size! 

fi 

# end of 'ada.y' 

fi 

if test -f 'main.c' -a "${1}" != "-c" ; then 

  echo shar: Will not clobber existing file \"'main.c'\" 

else 

echo shar: Extracting \"'main.c'\" \(128 characters\) 

sed "s/^X//" >'main.c' <<'END_OF_FILE' 

X/* 

X *    This is the test program for the Ada lex/yacc grammars. 

X */ 

X 

Xmain() 

X{ 

X  extern int yyparse(); 

X 

X  ( void ) yyparse(); 

X} 

END_OF_FILE 

if test 128 -ne `wc -c <'main.c'`; then 

    echo shar: \"'main.c'\" unpacked with wrong size! 

fi 

# end of 'main.c' 

fi 

if test -f 'rw.c' -a "${1}" != "-c" ; then 

  echo shar: Will not clobber existing file \"'rw.c'\" 

else 

echo shar: Extracting \"'rw.c'\" \(3957 characters\) 

sed "s/^X//" >'rw.c' <<'END_OF_FILE' 

X/* 

X *    The detection that an identifer is actually an Ada reserved 

X *  word is done via a hash function.  See SIGAda Letters V4 N1 

X *  pages 40-44 for more information regarding the hash technique. 

X */ 

X 

X#include <ctype.h> 

X#include "y.tab.h" 

X 

X#define ERROR_TOKEN 0 

X 

Xtypedef struct reserved_word_entry { 

X  char *text_value; 

X  int token_value; 

X} reserved_word_entry; 

X 

Xstatic reserved_word_entry reserved_word_table[ 71 ] = 

X  { { "else"     , ELSE_ }, 

X    { "exit"     , EXIT_ }, 

X    { "end"      , END_ }, 

X    { "at"       , AT_ }, 

X    { "then"     , THEN_ }, 

X    { "range"    , RANGE_ }, 

X    { "abs"      , ABS_ }, 

X    { "do"       , DO_ }, 

X    { "exception", EXCEPTION_ }, 

X    { "delay"    , DELAY_ }, 

X    { "use"      , USE_ }, 

X    { "xor"      , XOR_ }, 

X    { "select"   , SELECT_ }, 

X    { ""         , ERROR_TOKEN }, 

X    { "declare"  , DECLARE_ }, 

X    { "type"     , TYPE_ }, 

X    { "array"    , ARRAY_ }, 

X    { "limited"  , LIMITED_ }, 

X    { "subtype"  , SUBTYPE_ }, 

X    { "elsif"    , ELSIF_ }, 

X    { "case"     , CASE_ }, 

X    { "generic"  , GENERIC_ }, 

X    { "and"      , AND_ }, 

X    { "not"      , NOT_ }, 

X    { "renames"  , RENAMES_ }, 

X    { "package"  , PACKAGE_ }, 

X    { "null"     , NULL_ }, 

X    { "separate" , SEPARATE_ }, 

X    { "terminate", TERMINATE_ }, 

X    { "raise"    , RAISE_ }, 

X    { "entry"    , ENTRY_ }, 

X    { "reverse"  , REVERSE_ }, 

X    { "task"     , TASK_ }, 

X    { ""         , ERROR_TOKEN }, 

X    { "all"      , ALL_ }, 

X    { "constant" , CONSTANT_ }, 

X    { "delta"    , DELTA_ }, 

X    { "accept"   , ACCEPT_ }, 

X    { "digits"   , DIGITS_ }, 

X    { "return"   , RETURN_ }, 

X    { "abort"    , ABORT_ }, 

X    { "record"   , RECORD_ }, 

X    { "in"       , IN_ }, 

X    { "access"   , ACCESS_ }, 

X    { "or"       , OR_ }, 

X    { "function" , FUNCTION_ }, 

X    { "goto"     , GOTO_ }, 

X    { "others"   , OTHERS_ }, 

X    { "rem"      , REM_ }, 

X    { "procedure", PROCEDURE_ }, 

X    { "out"      , OUT_ }, 

X    { "private"  , PRIVATE_ }, 

X    { "is"       , IS_ }, 

X    { "mod"      , MOD_ }, 

X    { "of"       , OF_ }, 

X    { ""         , ERROR_TOKEN }, 

X    { "pragma"   , PRAGMA_ }, 

X    { "for"      , FOR_ }, 

X    { "new"      , NEW_ }, 

X    { "when"     , WHEN_ }, 

X    { "with"     , WITH_ }, 

X    { "begin"    , BEGIN_ }, 

X    { ""         , ERROR_TOKEN }, 

X    { "while"    , WHILE_ }, 

X    { ""         , ERROR_TOKEN }, 

X    { ""         , ERROR_TOKEN }, 

X    { ""         , ERROR_TOKEN }, 

X    { "loop"     , LOOP_ }, 

X    { ""         , ERROR_TOKEN }, 

X    { "if"       , IF_ }, 

X    { "body"     , BODY_ } }; 

X 

Xstatic int magic_table[ 26 ] = 

X  { 0, 49,   0,  -7, -20,  18,  -2, -38,  33,   0,  -9,   9,  29, 

X   -9,  6,  26,   0,   8,   1,   1,  -9,   0,  56, -28,  11,   0 }; 

X 

Xint reserved_word( word ) 

X 

X  char *word; 

X 

X{ 

X  int index; 

X  int hash_value; 

X  int word_length = strlen( word ); 

X  char canonical_word[ 1024 ]; 

X 

X  /* 

X   * Check some simple things first: 

X   *   - it has the correct length, must be >= 2 and <= 9 

X   *   - it doesn't have any digits in important (for the hash) places 

X   */ 

X  if ( ( word_length < 2 ) || ( word_length > 9 ) || 

X       ( isdigit( word[ 0 ] ) ) || 

X       ( isdigit( word[ word_length - 1 ] ) ) || 

X       ( isdigit( word[ word_length - 2 ] ) ) ) { 

X    return identifier; 

X  } 

X 

X  /* convert the identifier to all lower case characters */ 

X  for ( index = 0; *word; word++, index++ ) { 

X    canonical_word[ index ] = isupper( *word ) ? tolower( *word ) : *word; 

X  } 

X 

X  /* compute the magic hash value */ 

X  hash_value = magic_table[ canonical_word[ 0 ] - 'a' ] + 

X               magic_table[ canonical_word[ word_length - 1 ] - 'a' ] + 

X               ( 2 * ( canonical_word[ word_length - 2 ] - 'a' ) ) + 

X               word_length; 

X 

X  if ( ( hash_value >= 0 ) && ( hash_value <= 70 ) && 

X       ( strncmp( canonical_word, 

X                  reserved_word_table[ hash_value ].text_value, 

X                  word_length ) == 0 ) ) { 

X    return reserved_word_table[ hash_value ].token_value; 

X  } else { 

X    return identifier; 

X  } 

X} 

END_OF_FILE 

if test 3957 -ne `wc -c <'rw.c'`; then 

    echo shar: \"'rw.c'\" unpacked with wrong size! 

fi 

# end of 'rw.c' 

fi 

if test -f 'yyerror.c' -a "${1}" != "-c" ; then 

  echo shar: Will not clobber existing file \"'yyerror.c'\" 

else 

echo shar: Extracting \"'yyerror.c'\" \(228 characters\) 

sed "s/^X//" >'yyerror.c' <<'END_OF_FILE' 

X#include <stdio.h> 

X 

Xyyerror( s ) 

X 

X  char *s; 

X 

X{ 

X  extern void exit(); 

X 

X  extern int yylineno; 

X  extern char yytext[]; 

X 

X  fprintf( stderr, "Syntax error on line %d, found \"%s\"\n", 

X           yylineno, yytext ); 

X 

X  exit( 1 ); 

X} 

END_OF_FILE 

if test 228 -ne `wc -c <'yyerror.c'`; then 



    echo shar: \"'yyerror.c'\" unpacked with wrong size! 

fi 

# end of 'yyerror.c' 

fi 

echo shar: End of shell archive. 

exit 0 

  

-- 

We work in the dark 

We do what we can 

We give what we have 

Our doubt is our passion, and our passion is our task 

The rest is the madness of art. 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -