home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / ae / AEC / parser.y < prev    next >
Encoding:
Text File  |  1990-02-28  |  4.6 KB  |  173 lines

  1. /* yacc file for AEC, the AE Compiler.
  2.    Copyright (C) 1989, 1990 by James R. Larus (larus@cs.wisc.edu)
  3.  
  4.    AE and AEC are free software; you can redistribute it and/or modify it
  5.    under the terms of the GNU General Public License as published by the
  6.    Free Software Foundation; either version 1, or (at your option) any
  7.    later version.
  8.  
  9.    AE and AEC are distributed in the hope that it will be useful, but
  10.    WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with GNU CC; see the file COPYING.  If not, write to James R.
  16.    Larus, Computer Sciences Department, University of Wisconsin--Madison,
  17.    1210 West Dayton Street, Madison, WI 53706, USA or to the Free
  18.    Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  19.  
  20.  
  21. /* $Header: /var/home/larus/AE/AEC/RCS/parser.y,v 2.0 90/02/09 17:23:46 larus Exp Locker: larus $ */
  22.  
  23.  
  24. %start SCHEMA
  25.  
  26. %token Y_EOF 0
  27.  
  28. %token Y_FUNCTION_START
  29. %token Y_FUNCTION_END
  30. %token Y_BLOCK_START
  31. %token Y_BLOCK_START_TARGET
  32. %token Y_BLOCK_END
  33. %token Y_BLOCK_END_NEXT_TARGET
  34. %token Y_BLOCK_END_JUMP
  35. %token Y_BLOCK_END_JUMP_NEXT_TARGET
  36. %token Y_BLOCK_END_CJUMP
  37. %token Y_UNEVENTFUL_INST
  38. %token Y_STORE_INST
  39. %token Y_STORE_D_INST
  40. %token Y_STORE_UNKNOWN_INST
  41. %token Y_LOAD_INST
  42. %token Y_LOAD_D_INST
  43. %token Y_LOAD_UNKNOWN_INST
  44. %token Y_COMPUTE_DEFN_0
  45. %token Y_COMPUTE_DEFN_1
  46. %token Y_COMPUTE_DEFN_2
  47. %token Y_UNKNOWN_DEFN
  48. %token Y_CALL_INST
  49. %token Y_CALL_INDIRECT_INST
  50. %token Y_ID
  51. %token Y_LIT
  52. %token Y_INT
  53. %token Y_LPAREN
  54. %token Y_RPAREN
  55. %token Y_REG
  56. %token Y_NL
  57. %token Y_OP
  58. %token Y_LOOP_ENTRY
  59. %token Y_LOOP_BACK
  60. %token Y_LOOP_EXIT
  61.  
  62. %{
  63. #include <stdio.h>
  64. #include "aec.h"
  65.  
  66. extern int line_no;
  67. void print_erroneous_line ();
  68. void scanner_nl ();
  69. %}
  70.  
  71. %%
  72.  
  73. SCHEMA    :    LINE
  74.             {return(1);};
  75.  
  76. LINE    :    Y_FUNCTION_START Y_ID Y_INT Y_NL
  77.             {function_start ($2, $3); scanner_nl ();}
  78.     |    Y_FUNCTION_END Y_ID Y_NL
  79.             {function_end ($2); scanner_nl ();}
  80.  
  81.     |    Y_BLOCK_START Y_INT Y_NL
  82.             {block_start ($2); scanner_nl ();}
  83.     |    Y_BLOCK_START_TARGET Y_INT Y_NL
  84.             {block_start_target ($2); scanner_nl ();}
  85.  
  86.     |    Y_BLOCK_END Y_INT LOOP_ANNO Y_NL
  87.             {block_end ($2, 0, $3); scanner_nl ();}
  88.     |    Y_BLOCK_END_NEXT_TARGET Y_INT LOOP_ANNO Y_NL
  89.             {block_end ($2, 1, $3); scanner_nl ();}
  90.  
  91.     |    Y_BLOCK_END_JUMP Y_INT Y_INT LOOP_ANNO Y_NL
  92.             {block_end_jump ($2, $3, 0, $4); scanner_nl ();}
  93.     |    Y_BLOCK_END_JUMP_NEXT_TARGET Y_INT Y_INT LOOP_ANNO Y_NL
  94.             {block_end_jump ($2, $3, 1, $4); scanner_nl ();}
  95.  
  96.     |    Y_BLOCK_END_CJUMP Y_INT INT_LIST LOOP_ANNO Y_NL
  97.             {block_end_cjump ($2, $3, $4); scanner_nl ();}
  98.  
  99.     |    Y_UNEVENTFUL_INST Y_INT Y_INT Y_NL
  100.             {uneventful_inst ($2, $3); scanner_nl ();}
  101.  
  102.     |    Y_STORE_INST Y_LIT Y_OP Y_LIT Y_NL
  103.             {if (*(char *) $3 != '+') yyerror ("syntax");
  104.              store_inst ($2, $4); scanner_nl ();}
  105.     |    Y_STORE_D_INST Y_LIT Y_OP Y_LIT Y_NL
  106.             {if (*(char *) $3 != '+') yyerror ("syntax");
  107.              store_d_inst ($2, $4); scanner_nl ();}
  108.     |    Y_STORE_UNKNOWN_INST Y_NL
  109.             {store_unknown_inst (); scanner_nl ();}
  110.  
  111.     |    Y_LOAD_INST Y_LIT Y_OP Y_LIT Y_NL
  112.             {if (*(char *) $3 != '+') yyerror ("syntax");
  113.              load_inst ($2, $4); scanner_nl ();}
  114.     |    Y_LOAD_D_INST Y_LIT Y_OP Y_LIT Y_NL
  115.             {if (*(char *) $3 != '+') yyerror ("syntax");
  116.              load_d_inst ($2, $4); scanner_nl ();}
  117.     |    Y_LOAD_UNKNOWN_INST Y_NL
  118.             {load_unknown_inst (); scanner_nl ();}
  119.  
  120.     |    Y_COMPUTE_DEFN_0 Y_REG Y_LIT Y_NL
  121.             {compute_defn (0, $2, NULL, $3, NULL); scanner_nl ();}
  122.     |    Y_COMPUTE_DEFN_1 Y_REG Y_OP Y_LIT Y_NL
  123.             {compute_defn (1, $2, $3, $4, NULL); scanner_nl ();}
  124.     |    Y_COMPUTE_DEFN_2 Y_REG Y_LIT Y_OP Y_LIT Y_NL
  125.             {compute_defn (2, $2, $4, $3, $5); scanner_nl ();}
  126.     |    Y_UNKNOWN_DEFN Y_REG Y_NL
  127.             {unknown_defn ($2); scanner_nl ();}
  128.  
  129.     |    Y_CALL_INST Y_ID Y_NL
  130.             {call_inst ($2); scanner_nl ();}
  131.     |    Y_CALL_INDIRECT_INST Y_REG Y_NL
  132.             {call_indirect_inst ($2); scanner_nl ();}
  133.  
  134.     |    Y_NL
  135.             {scanner_nl ();}
  136.  
  137.     |    Y_EOF
  138.             {return (0);}
  139.  
  140.     |    error ;
  141.  
  142.  
  143. INT_LIST:    INT_LIST Y_INT
  144.             {$$ = (int) cons ($2, $1);}
  145.     |     Y_INT
  146.             {$$ = (int) cons ($1, NULL);};
  147.  
  148.  
  149. LOOP_ANNO:    LOOP_ANNO Y_LOOP_ENTRY Y_LPAREN Y_INT Y_INT Y_RPAREN
  150.             {$$ = (int) cons (cons (START_LOOP, cons ($4, $5)),
  151.                       $1);}
  152.     |    LOOP_ANNO Y_LOOP_BACK Y_LPAREN Y_INT Y_INT Y_RPAREN
  153.             {$$ = (int) cons (cons (CONT_LOOP, cons ($4, $5)),
  154.                       $1);}
  155.     |    LOOP_ANNO Y_LOOP_EXIT Y_LPAREN Y_INT Y_INT Y_RPAREN
  156.             {$$ = (int) cons (cons (END_LOOP, cons ($4, $5)),
  157.                       $1);}
  158.     |
  159.             {$$ = (int) NULL;};
  160.  
  161.  
  162. %%
  163.  
  164. yyerror (s)
  165.      char *s;
  166. {
  167.   extern char *input_file_name;
  168.  
  169.   fprintf (stderr, "aec: (parser) %s on line %d of file %s\n", s, line_no,
  170.        input_file_name);
  171.   print_erroneous_line (stderr);
  172. }
  173.