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.

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