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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. int result = 0;
  11. if(argc > 1) {
  12. c = argv[1];
  13. while(*c) {
  14. switch(*c) {
  15. case 'd':
  16. yydebug = 1;
  17. break;
  18. case 't':
  19. printtree = 1;
  20. break;
  21. case 'r':
  22. if(argc < 2) {
  23. printf("r option requires file\n");
  24. return 2;
  25. }
  26. prgstream = fopen(argv[2], "r");
  27. }
  28. c++;
  29. }
  30. }
  31. if(!prgstream) {
  32. printf("No input program (check filenames)\n");
  33. return 2;
  34. }
  35. program = sol_compile_file(prgstream);
  36. if(!program) {
  37. printf("NULL program (probably a syntax error)\n");
  38. return 2;
  39. }
  40. if(prgstream != stdin) {
  41. fclose(prgstream);
  42. }
  43. sol_state_init(&state);
  44. if(printtree) {
  45. st_print(&state, program);
  46. }
  47. sol_exec(&state, program);
  48. if(sol_has_error(&state)) {
  49. printf("Error: ");
  50. ob_print(state.error);
  51. printf("\n");
  52. result = 1;
  53. }
  54. if(state.ret) {
  55. printf("Toplevel return: ");
  56. ob_print(state.ret);
  57. printf("\n");
  58. if(sol_is_int(state.ret)) {
  59. result = state.ret->ival;
  60. }
  61. }
  62. st_free(program);
  63. sol_state_cleanup(&state);
  64. return result;
  65. }