Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

59 rindas
1.4 KiB

  1. struct Environment {
  2. struct Environment* parent;
  3. int key_count;
  4. char** keys;
  5. Ast_Node* values;
  6. };
  7. typedef struct Environment Environment;
  8. Environment* create_empty_environment() {
  9. Environment* env = new(Environment);
  10. env->parent = NULL;
  11. env->key_count = 0;
  12. env->keys = NULL;
  13. env->values = NULL;
  14. return env;
  15. }
  16. Ast_Node* lookup_symbol(Symbol* sym, Environment* env) {
  17. for (int i = 0; i < env->key_count; ++i)
  18. if (string_equal(env->keys[i], sym->identifier))
  19. return env->values+i;
  20. if (env->parent)
  21. return lookup_symbol(sym, env->parent);
  22. char* built_in_names[] = {
  23. // Math stuff
  24. "+", "-", "*", "/",
  25. ">", "<", "=",
  26. // Conditional stuff
  27. "if", "and", "or", "not",
  28. // Cons stuff
  29. "first", "rest", "pair",
  30. // rest
  31. "load", "define",
  32. "lambda", "progn",
  33. "eval", "quote",
  34. "print", "read",
  35. "help"
  36. };
  37. int built_in_count = 23;
  38. for (int i = 0; i < built_in_count; ++i) {
  39. if (string_equal(built_in_names[i], sym->identifier)) {
  40. Ast_Node* ret = new(Ast_Node);
  41. ret->type = Ast_Node_Type_Built_In_Function;
  42. ret->value.built_in_function = new(Built_In_Function);
  43. ret->value.built_in_function->identifier = built_in_names[i];
  44. return ret;
  45. }
  46. }
  47. return NULL;
  48. }