{"id":21261859,"url":"https://github.com/kassick/compiladores-codes","last_synced_at":"2026-05-07T03:36:57.600Z","repository":{"id":78557412,"uuid":"144179550","full_name":"kassick/Compiladores-Codes","owner":"kassick","description":"Code samples for a Compilers course","archived":false,"fork":false,"pushed_at":"2018-08-09T16:53:33.000Z","size":8326,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T07:44:54.633Z","etag":null,"topics":["antlr","c","cmake","compiler","compilers","cpp","cpp11","csharp","virtual-machine"],"latest_commit_sha":null,"homepage":"https://bitbucket.org/kassick/compilerscodes/","language":"JavaScript","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/kassick.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":"2018-08-09T16:45:07.000Z","updated_at":"2021-12-09T18:46:27.000Z","dependencies_parsed_at":"2023-02-28T03:00:58.380Z","dependency_job_id":null,"html_url":"https://github.com/kassick/Compiladores-Codes","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/kassick/Compiladores-Codes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kassick%2FCompiladores-Codes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kassick%2FCompiladores-Codes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kassick%2FCompiladores-Codes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kassick%2FCompiladores-Codes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kassick","download_url":"https://codeload.github.com/kassick/Compiladores-Codes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kassick%2FCompiladores-Codes/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261249428,"owners_count":23130494,"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":["antlr","c","cmake","compiler","compilers","cpp","cpp11","csharp","virtual-machine"],"created_at":"2024-11-21T04:56:08.214Z","updated_at":"2026-05-07T03:36:52.544Z","avatar_url":"https://github.com/kassick.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Compilers Course Code Collection\n\nThis is a collections of codes used in a Compilers course taught by me at Uniritter (2016-1 and 2017-1). The codes showcase some parsing techniques and the usage of antlr as a parser. It also shows how to associate semantic actions with rules of the grammar and how to generate code.\n\nThis repo hosts the code for StackVM (a virtual machine used as code generation target) and the reference code MMMLc (the compiler for the MMML language, used in the courses).\n\n- [S-Expression Parsers](./SExpr) : A collection of parsers for S-Expressions.\n\n- [StackVM](./StackVM) : A stack virtual machine, inspired in JVM but with way less features.\n\n- [Math Expression Parser](./MathExprParser) : A parser for mathematical expressions. It uses antlr with the *Listener* pattern to generate code for StackVM\n\n- [MMML Compiler](./MMML) : A compiler for the MMML language. It used antlr and the Visitor pattern to generate code for StackVM.\n\n# JavaScript files for the Playgrounds\n\nThe javascript files present in the git tree are generated from C++ sources with [EMScripten](https://github.com/juj/emsdk). The git-managed versions aren't used in the zip-file generated by CMake (rules `mmml.zip`, `stackvm.zip`), but they make it easier to test the generated HTMLs (from org-mode).\n\nThis code was tested with\n- sdk-tag-1.37.18-64bit (compiled from source)\n- emscripten-tag-1.37.18-64bit (compiled from source)\n- node-4.1.1-64bit (downloaded)\n\nIn order to build the javascript:\n\n1. **Prepare the Build Environment**\n    1. Download and install emscripten in some path (e.g. `./emscripten`)\n    2. Install and/or Activate a SDK environment (may take a while)\n\n        `emsdk install node-4.1.1-64bit clang-tag-e1.37.18-64bit emscripten-tag-1.37.18-64bit sdk-tag-1.37.18-64bit`\n\n        `emsdk activate sdk-tag-1.37.18-64bit`\n\n    2. Create a build directory\n\n        `mkdir JS`\n\n        `cd JS`\n\n    3. Load the emsdk environment:\n\n        `source ../emsdk-portable/emsdk_env.sh`\n\n    4. Execute cmake to prepare the build environment\n\n        `emconfigure cmake ..`\n\n2. **Compile**: Just call `make` in the previously configures build directory. Since CMake has already cached the commands it should use, there's no need to wrap `make` with `emmake` or to `source` the sdk environment.\n\n    `cd JS`\n\n    `make`\n\nThe generated javascript files are not executable, but they export a `parse_script_c` symbol -- the function implemented in C++.\n```sh\nif(${CMAKE_CXX_COMPILER} MATCHES \"em\\\\+\\\\+\")\n  set(CMAKE_EXE_LINKER_FLAGS \"-s EXPORTED_FUNCTIONS=\\\"['_parse_string_c']\\\"\")\nendif()\n```\n\nThese files can be used by a browser, such as in the following example:\n```html\n\u003cscript type=\"text/javascript\" src=\"./sparser.js\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n  doParse = function(text) {\n      r = ccall('parse_string_c', 'string', ['string'], [text]);\n      return r;\n  };\n\n  parseSource = function() {\n      d_ta = document.getElementById('esource');\n      d_res = document.getElementById('result');\n\n      res = doParse(d_ta.value);\n\n      d_res.value = res;\n  };\n\u003c/script\u003e\n```\n\n## DO NOT USE -- Manually Compiling a C++ code to JavaScript:\n```sh\nsource emsdk_env.sh\nemsdk activate sdk-tag-1.37.18-64bit\nemcc -o sparser2.js sparser_2.cpp -s EXPORTED_FUNCTIONS=\"['_parse_string_c']\"\n```\n\nIf one wants to generate the console web app:\n```sh\nemcc -o sparser_console.html sparser_2.cpp\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkassick%2Fcompiladores-codes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkassick%2Fcompiladores-codes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkassick%2Fcompiladores-codes/lists"}