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.

55 lines
1.7 KiB

1 year ago
1 year ago
1 year ago
1 year ago
  1. #include "molasses/lexer.h"
  2. #include "molasses/parser_primitives.h"
  3. #include <iostream>
  4. int main() {
  5. /*
  6. molasses::lexed_output initial;
  7. initial.dictionary[1] = "+";
  8. {
  9. auto v = molasses::lex("hello hello potato 128 hello 128 +");
  10. auto v2 = molasses::lex("salad hello potato 129 hello 128");
  11. for (auto symbol: v.symbols) {
  12. std::cout << "v: " << symbol << " - " << v.dictionary.at(symbol) << "\n";
  13. }
  14. std::cout << "\n";
  15. for (auto symbol: v2.symbols) {
  16. std::cout << "v2: " << symbol << " - " << v2.dictionary.at(symbol) << "\n";
  17. }
  18. auto v_merged = molasses::concatenate(initial, molasses::concatenate(v, v2));
  19. std::cout << "\n";
  20. for (auto symbol: v_merged.symbols) {
  21. std::cout << "v_merged: " << symbol << " - " << v_merged.dictionary.at(symbol) << "\n";
  22. }
  23. }
  24. auto v = molasses::lex("1 2 +");
  25. molasses::parser_context ctx;
  26. ctx = molasses::register_integers(ctx);
  27. ctx.operations.emplace_back(std::make_shared<molasses::primitive_operation>(std::string{"+"}, std::vector<std::string>({"i32", "i32"}), std::vector<std::string>({"i32"})));
  28. if(molasses::type_check(ctx, v, v.symbols, {}, {"i32"})) {
  29. std::cout << "Checks out\n";
  30. }*/
  31. /*
  32. auto lexed = molasses::lex("__PROC__ sum\n"
  33. "i32 i32\n"
  34. "__--__\n"
  35. "i32\n"
  36. "__DO__\n"
  37. "+\n"
  38. "__END__");*/
  39. auto lexed = molasses::lex("__PROC__ main\n"
  40. "__--__\n"
  41. "__DO__\n"
  42. "__END__");
  43. molasses::parser_context ctx;
  44. ctx = molasses::register_integers(ctx);
  45. ctx = molasses::register_i32_operations(ctx);
  46. molasses::parse(ctx, lexed);
  47. }