The Sol Programming Language!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

solrun.c 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <stdio.h>
  2. #include "ast.h"
  3. #include "parser.tab.h"
  4. int main(int argc, char **argv) {
  5. stmt_node *program;
  6. sol_state_t state;
  7. char *c;
  8. int printtree = 0;
  9. FILE *prgstream = stdin;
  10. if(argc>1) {
  11. c = argv[1];
  12. while(*c) {
  13. switch(*c) {
  14. case 'd':
  15. yydebug = 1;
  16. break;
  17. case 't':
  18. printtree = 1;
  19. break;
  20. case 'r':
  21. if(argc<2) {
  22. printf("r option requires file\n");
  23. return 1;
  24. }
  25. prgstream = fopen(argv[2], "r");
  26. }
  27. c++;
  28. }
  29. }
  30. if(!prgstream) {
  31. printf("No input program (check filenames)\n");
  32. return 1;
  33. }
  34. program = sol_compile_file(prgstream);
  35. if(prgstream!=stdin) fclose(prgstream);
  36. if(printtree) st_print(program);
  37. if(program) {
  38. sol_state_init(&state);
  39. sol_exec(&state, program);
  40. if(sol_has_error(&state)) {
  41. printf("Error: ");
  42. ob_print(state.error);
  43. printf("\n");
  44. }
  45. //st_free(program);
  46. sol_state_cleanup(&state);
  47. return 0;
  48. }
  49. printf("NULL program (probably a syntax error)\n");
  50. return 1;
  51. }