{"id":18274076,"url":"https://github.com/iamriteshkoushik/hermes","last_synced_at":"2025-04-09T03:42:05.999Z","repository":{"id":210352006,"uuid":"725974402","full_name":"IAmRiteshKoushik/hermes","owner":"IAmRiteshKoushik","description":"An interpreter for a toy language written in Go.","archived":false,"fork":false,"pushed_at":"2024-10-23T11:04:33.000Z","size":149,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-05T12:08:29.031Z","etag":null,"topics":["ast","lexer","parser","repl","token"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IAmRiteshKoushik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-01T09:09:27.000Z","updated_at":"2024-10-23T11:04:36.000Z","dependencies_parsed_at":"2023-12-02T07:28:46.980Z","dependency_job_id":"2f1978ae-2372-4603-94e6-245d80e64de4","html_url":"https://github.com/IAmRiteshKoushik/hermes","commit_stats":null,"previous_names":["iamriteshkoushik/learn-vue","iamriteshkoushik/hermes"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IAmRiteshKoushik%2Fhermes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IAmRiteshKoushik%2Fhermes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IAmRiteshKoushik%2Fhermes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IAmRiteshKoushik%2Fhermes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IAmRiteshKoushik","download_url":"https://codeload.github.com/IAmRiteshKoushik/hermes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230866122,"owners_count":18292207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","lexer","parser","repl","token"],"created_at":"2024-11-05T12:08:35.706Z","updated_at":"2024-12-22T17:45:37.568Z","avatar_url":"https://github.com/IAmRiteshKoushik.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Feature List:\n- C-like syntax\n- variable bindings\n- integers and booleans\n- arithmetic exp\n- built-in functions\n- first-class and higher-order functions \n- closures\n- a string data structure\n- an array data structure\n- a hash data structure\n\n### Parts of the project:\n1. **The lexer (tokenizer)**  \n  It will take source code as input and output the tokens that represent the \n  source code. It will go through its input and output the next token that it \n  recognizes. It doesn't need to buffer or save tokens, since there will be only \n  one method called `NextToken()`, which will output the next token.\n\n- Ideally, it makes sense to think of adding something like `io.Reader` to get\nfilename and line-numbers as that would allow the interpreter to easily identify\nand throw it during errors.\n\n- When introducing identifiers and keywords, we need to recognize whether the \ncurrent character is a letter or not and if so, continue reading the rest till \na non-letter-character is encountered. After reading the entire identifier or \nkeyword, we can then check the appropriate token type.\n\n- You also need to account for whitespaces in your document so a function called \n`skipWhitespace()` or `eatWhitespace()` or `consumeWhitespace()` is found in a \nlot of parsers/lexers\n\n- Next, we need to support different symbols and tokens\n`==, !, !=, -, /, *, \u003c, \u003e, true, false, if, else, return`\n\n2. **The parser (consumes tokens)**  \n\u003e A parser is a software component that takes input data (frequently text) and \n\u003e builds a data structure - often some kind of parse tree, abstract syntax tree or \n\u003e other hierarchial structure - giving a structural representation of the input, \n\u003e checking for correct syntax in the process. The parser is often preceeded by a \n\u003e separate lexical analyzer, which creates tokens from the sequence of input \n\u003e characters.\n\nThe parser outputs an abstract syntax tree. It can look similar to this\n```js\n\u003e var input = `if (3 * 5 \u003e 10) { return \"Hello\"; } else { return \"goodbye\" }`;\n\u003e var tokens = MagixLexer.parse(input);\n\u003e MagicParser.parse(tokens);\n```\n```js\n{\n  type: \"if-statement\",\n  condition: {\n    type: \"operator-expression\",\n    operator: \"\u003e\",\n    left: {\n      type: \"opeartor-expression\",\n      operator: \"*\",\n      left: { type: \"integer-literal\", value: 3 },\n      right: { type: \"integer-literal\", value: 5 }\n    },\n    right: { type: \"integer-literal\", value: 10 }\n  },\n  consequence: {\n    type: \"return-statement\",\n    returnValue: { type: \"string-literal\", value: \"hello\" }\n  },\n  alternative: {\n    type: \"return-statement\",\n    returnValue: { type: \"string-literal\", value: \"goodbye\" }\n  }\n}\n```\n\nLook into parser generators like yacc or bison. There are different ways to parse\nthings :\n  1. top-down parsing (builds the root note first and then descends)\n  2. bottom-up parsing\n  3. recursive descent parsing (variant of top-down) ~ Pratt parser\n  4. early parsing\n  5. predictive parsing\n\n- Starting to build our abstract syntax tree by parsing \"let\" statements only.\n```js\n// Expressions produce value, statements do not produce value\nlet \u003cidentifier\u003e = \u003cexpression\u003e\n```\nThis is the usual structure of a \"let\" statement. We need to handle the \nstatements and the expressions separately. Some nodes in our tree are going to \nbe statements and others are going to be expressions\n\n3. **The Abstract Syntax Tree (AST)**\n4. **The internal object system**\n5. **The evaluator**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamriteshkoushik%2Fhermes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiamriteshkoushik%2Fhermes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamriteshkoushik%2Fhermes/lists"}