home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / coven / coven-utils-1.1.tgz / coven-utils-1.1.tar / utils / coven-language / main.c < prev    next >
C/C++ Source or Header  |  2003-01-28  |  3KB  |  133 lines

  1. /*
  2.  * (C) 2001 Clemson University
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7.  
  8. #include <stdio.h>
  9. #include <getopt.h>
  10. #include <Coven_lang.h>
  11. #include <symbol.h>
  12.  
  13. static void initialize();
  14. static void parse_args(int argc, char **argv);
  15. static void finalize();
  16.  
  17. /*
  18.  * Global Variables
  19.  */
  20.  
  21. extern FILE *yyin;
  22.  
  23. int input_file_flag = 0;
  24. int out_file_flag = 0;
  25. FILE *out_file;
  26. int line = 1;
  27.  
  28. main(int argc, char **argv)
  29. {
  30.     printf("NOTES / TODO:\n");
  31.     printf("\tParser does not allow for specifying user defined types.\n"); 
  32.     printf("\t  does not allow for arguments to modules to be arrays {,,}\n");
  33.     printf("\t  does not do any type checking\n");
  34.     printf("\t  does not always do symbol checking (symbol prev. defined.)\n");
  35.     printf("\t  does not handle 'if' statements or 'while' loops.\n");
  36.     printf("\t  does not handle ADA-style local_binding=global_binding\n");
  37.     printf("\t    module arguments.\n");
  38.     printf("\t  does not allow 'for' loops to have a single module\n");
  39.     printf("\t    inside of them.\n");
  40.     initialize();
  41.     parse_args(argc, argv);
  42.     yyparse();
  43.     finalize();
  44. }
  45.  
  46. static void initialize()
  47. {
  48.     sym_ent_p sym;
  49.     init_symbol_table();
  50.     sym = symenter("int", NULL, TYPE_TYPE);
  51.     sym->type = TYPE_TYPE;
  52.     sym = symenter("uint", NULL, TYPE_TYPE);
  53.     sym->type = TYPE_TYPE;
  54.     sym = symenter("string", NULL, TYPE_TYPE);
  55.     sym->type = TYPE_TYPE;
  56.     sym = symenter("float", NULL, TYPE_TYPE);
  57.     sym->type = TYPE_TYPE;
  58.     sym = symenter("double", NULL, TYPE_TYPE);
  59.     sym->type = TYPE_TYPE;
  60.     sym = symenter("char", NULL, TYPE_TYPE);
  61.     sym->type = TYPE_TYPE;
  62.     sym = symenter("uchar", NULL, TYPE_TYPE);
  63.     sym->type = TYPE_TYPE;
  64.     sym = symenter("short", NULL, TYPE_TYPE);
  65.     sym->type = TYPE_TYPE;
  66.     sym = symenter("ushort", NULL, TYPE_TYPE);
  67.     sym->type = TYPE_TYPE;
  68.     sym = symenter("MEDEA_BODY", NULL, TYPE_TYPE);
  69. }
  70.  
  71. static void parse_args(int argc, char **argv)
  72. {
  73.     int c;
  74.     int digit_optind = 0;
  75.     while(1)
  76.     {
  77.         int this_option_optind = optind ? optind : 1;
  78.         int option_index = 0;
  79.         static struct option long_options[] = {
  80.             /* {"option_name", has_arg, *flag, val}, */
  81.             {"option_name", 0, NULL, 0},
  82.             {0, 0, 0, 0}
  83.         };
  84.         c = getopt_long ( argc, argv, "i:o:", long_options, &option_index);
  85.         if (c == -1)
  86.             break;
  87.         switch (c) {
  88.             case 0 : /* a long option */
  89.                 break;
  90.  
  91.             case 'i' : /* setup input file */
  92.                 yyin = fopen(optarg,"r");
  93.                 input_file_flag = 1;
  94.                 break;
  95.  
  96.             case 'o' : /* set output file */
  97.                 out_file = fopen(optarg,"w");
  98.                 out_file_flag = 1;
  99.                 break;
  100.  
  101.             default:
  102.                 fprintf(stderr,"%s: undefined option %c given\n", argv[0], c);
  103.         }
  104.     }
  105.     if(!input_file_flag)
  106.     {
  107.            fprintf(stderr, "Must specify input file with '-i' option.\n");
  108.         exit(-1);
  109.     }
  110.     if(!out_file_flag)
  111.     {
  112.            fprintf(stderr, "Must specify output file with '-o' option.\n");
  113.         exit(-1);
  114.     }
  115. }
  116.  
  117. static void finalize()
  118. {
  119.     fclose(out_file);
  120. }
  121.  
  122. yyerror(s)
  123. {
  124.     fprintf(stderr,"syntax error line %d: %s\n", line, s);
  125.     exit(1);
  126. }
  127.  
  128. void produce_listing(int line, char *listing)
  129. {
  130.     /* fprintf(stderr, "produce_listing\n"); /* */
  131. }
  132.  
  133.