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.

73 lines
1.1 KiB

  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(!program) {
  36. printf("NULL program (probably a syntax error)\n");
  37. return 1;
  38. }
  39. if(prgstream != stdin) {
  40. fclose(prgstream);
  41. }
  42. sol_state_init(&state);
  43. if(printtree) {
  44. st_print(&state, program);
  45. }
  46. sol_exec(&state, program);
  47. if(sol_has_error(&state)) {
  48. printf("Error: ");
  49. ob_print(state.error);
  50. printf("\n");
  51. }
  52. if(state.ret) {
  53. printf("Toplevel return: ");
  54. ob_print(state.ret);
  55. printf("\n");
  56. }
  57. st_free(program);
  58. sol_state_cleanup(&state);
  59. return 0;
  60. }