{"id":21171471,"url":"https://github.com/tebogoyungmercykay/recspl-compiler-construction-in-python","last_synced_at":"2025-07-09T19:32:57.479Z","repository":{"id":259540787,"uuid":"871788309","full_name":"TebogoYungMercykay/RecSPL-Compiler-Construction-In-Python","owner":"TebogoYungMercykay","description":"This repository contains the core components of our Recursive Student Programming Language Compiler Construction and Design project. The project aims to implement a complete compiler, including lexical analysis, parsing, semantic analysis, and code generation.","archived":false,"fork":false,"pushed_at":"2024-11-07T17:20:59.000Z","size":1549,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"development","last_synced_at":"2025-04-05T06:11:46.489Z","etag":null,"topics":["intermediate-code-generation","lexer","parser","pytest","semantics","syntax-tree","testing","tokens","type-checker"],"latest_commit_sha":null,"homepage":"https://tebogoyungmercykay.vercel.app","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TebogoYungMercykay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-10-12T23:57:46.000Z","updated_at":"2025-02-10T20:49:49.000Z","dependencies_parsed_at":"2024-10-26T10:46:04.803Z","dependency_job_id":"b72ed17e-32c5-4ee8-9859-a4bc573c4899","html_url":"https://github.com/TebogoYungMercykay/RecSPL-Compiler-Construction-In-Python","commit_stats":null,"previous_names":["tebogoyungmercykay/recspl-compiler-construction-in-python"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/TebogoYungMercykay/RecSPL-Compiler-Construction-In-Python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TebogoYungMercykay%2FRecSPL-Compiler-Construction-In-Python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TebogoYungMercykay%2FRecSPL-Compiler-Construction-In-Python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TebogoYungMercykay%2FRecSPL-Compiler-Construction-In-Python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TebogoYungMercykay%2FRecSPL-Compiler-Construction-In-Python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TebogoYungMercykay","download_url":"https://codeload.github.com/TebogoYungMercykay/RecSPL-Compiler-Construction-In-Python/tar.gz/refs/heads/development","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TebogoYungMercykay%2FRecSPL-Compiler-Construction-In-Python/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264502490,"owners_count":23618617,"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":["intermediate-code-generation","lexer","parser","pytest","semantics","syntax-tree","testing","tokens","type-checker"],"created_at":"2024-11-20T16:06:26.753Z","updated_at":"2025-07-09T19:32:57.195Z","avatar_url":"https://github.com/TebogoYungMercykay.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RecSPL Compiler Construction and Design Project\n\n\u003cimg src=\"images/readme.jpg\" style=\"width: 100%; height: 40%;\" /\u003e\n\nThis `src/` directory contains the core components of our `Recursive Student Programming Language` Compiler Construction and Design project. The project aims to implement a complete compiler, including lexical analysis, parsing, semantic analysis, and code generation.\n\n## Current Structure\n\n- `lexer.py`: Implementation of the lexical analyzer.\n- `parser.py`: Implementation of the syntactic parser.\n- `test.py`: Test suite for various compiler components.\n- `helpers/`: Directory containing helper functions and utilities.\n- `utilities/`: Additional utility scripts and modules.\n- `out/`: Directory for storing output files generated during compilation.\n- `...`\n\n## Planned Components (100% completed tasks marked with `*`)\n\nThe project will include the following main components:\n\n1. **Lexer**: Tokenizes the input source code. (`*`)\n2. **Parser**: Performs syntactic analysis and builds an abstract syntax tree. (`*`)\n3. **Scope-Analyser**: Handles scope resolution and symbol table management. (`*`)\n4. **Type-Checker**: Performs semantic analysis and type-checking. (`*`)\n5. **Code-Generator**: Generates target code or intermediate representation.\n\n## How to Run Compiler:\n\n- ### Initial Compiler Setup and Usage Guide\n\n  The set up is already configured that one can just add the filenames and run the code. The code is in the `src` directory.\n\n  - #### Single File Compilation\n\n    - ##### 1. Configure File Paths\n\n      In `src/main.py`, set the following file paths:\n\n      ```python\n      code_filename = \"RecSPL.txt\"          # Input source code file\n      lexer_filepath = \"out/lexer.xml\"      # Lexer output\n      parser_filepath = \"out/syntax_tree.xml\"  # Parser output\n      crawling_filepath = \"out/semantics_crawling_output.txt\"  # Semantic crawling results\n      semantics_filepath = \"out/semantics_symbols_output.txt\"  # Symbol table output\n      ```\n\n    - ##### 2. Run the Compiler\n    \n      To compile a single file, use the `single()` function:\n\n      ```python\n      single(\n          code_filename,\n          lexer_filepath,\n          parser_filepath,\n          crawling_filepath,\n          semantics_filepath\n      )\n      ```\n\n  - #### Batch Compilation\n\n      To compile multiple files at once, use the `bulk()` function. Here's how to set it up:\n\n      ```python\n      # Create a list of file configurations\n      batch_files = []\n\n      # Generate file paths for each test case (1 through 20)\n      for k in range(1, 21):\n          file_paths = {\n              \"code_filename\": f\"out/testing/typechecker/recspl/code-{k}.txt\",\n              \"lexer_filepath\": f\"out/testing/typechecker/tokens/lexer-{k}.xml\",\n              \"parser_filepath\": f\"out/testing/typechecker/tree/tree-{k}.xml\",\n              \"crawling_filepath\": f\"out/testing/typechecker/crawling/crawl-{k}.txt\",\n              \"semantics_filepath\": f\"out/testing/typechecker/symbols/symbols-{k}.txt\"\n          }\n          batch_files.append(file_paths)\n\n      # Run the compiler on all files\n      bulk(batch_files)\n      ```\n\n- ### Installing Python Virtual Environment:\n\n  ```bash\n  # Installing dependencies\n  sudo apt-get update\n  sudo apt-get install python3-venv\n  python3 -m venv venv\n  ```\n- ### Activating the Python Virtual Environment:\n\n  ```bash\n  source venv/bin/activate\n  ```\n- ### Deactivating the Python Virtual Environment:\n\n  ```bash\n  deactivate\n  ```\n- ### Run/Test The Compiler:\n\n  ```bash\n  # Change Directories\n  cd src\n  # Instling Dependencies\n  pip install -r requirements.txt\n\n  # Runnung the Compiler\n  python main.py\n  # Running the Tests\n  pytest .\n  # Running Tests and Showing Output\n  pytest -s\n  ```\n\n- ### Project Structure\n\n  ```txt\n  .\n  ├── conftest.py\n  ├── helpers\n  │   ├── analyser.py\n  │   ├── convert_to_dfa.py\n  │   ├── dfa_lexer.py\n  │   ├── __init__.py\n  │   ├── lexing.py\n  │   ├── node_class.py\n  │   ├── parsing.py\n  │   ├── README.md\n  │   ├── symbols_class.py\n  │   ├── syntax_tree.py\n  │   └── type_checker.py\n  ├── __init__.py\n  ├── lexer.py\n  ├── main.py\n  ├── out\n  │   ├── dfa_output.txt\n  │   ├── lexer.xml\n  │   ├── README.md\n  │   ├── semantics_crawling_output.txt\n  │   ├── semantics_sybols_output.txt\n  │   ├── semantics_symbols_output.txt\n  │   ├── syntax_tree.xml\n  │   └── testing\n  │       ├── recspl\n  │       │   ├── code-1.txt\n  │       │   └── ...\n  │       ├── semantics\n  │       │   ├── crawling\n  │       │   │   ├── crawl-1.txt\n  │       │   │   └── ...\n  │       │   ├── recspl\n  │       │   │   ├── code-1.txt\n  │       │   │   └── ...\n  │       │   ├── symbols\n  │       │   │   ├── symbols-1.txt\n  │       │   │   └── ...\n  │       │   ├── tokens\n  │       │   │   ├── lexer-1.xml\n  │       │   │   └── ...\n  │       │   └── tree\n  │       │       ├── tree-1.xml\n  │       │       └── ...\n  │       ├── tokens\n  │       │   ├── lexer-1.xml\n  │       │   └── ...\n  │       ├── tree\n  │       │   ├── tree-1.xml\n  │       │   └── ...\n  │       └── typechecker\n  │           ├── crawling\n  │           │   ├── crawl-1.txt\n  │           │   └── ...\n  │           ├── recspl\n  │           │   ├── code-1.txt\n  │           │   └── ...\n  │           ├── symbols\n  │           │   ├── symbols-1.txt\n  │           │   └── ...\n  │           ├── tokens\n  │           │   ├── lexer-1.xml\n  │           │   └── ...\n  │           └── tree\n  │               ├── tree-1.xml\n  │               └── ...\n  ├── parser.py\n  ├── pytest.ini\n  ├── RecSPL.txt\n  ├── requirements.txt\n  ├── runner.py\n  ├── semantics.py\n  ├── test\n  │   ├── __init__.py\n  │   ├── test_default.py\n  │   ├── test_lexer.py\n  │   ├── test_parser.py\n  │   ├── test_semantics.py\n  │   └── test_type_check.py\n  ├── tree.txt\n  ├── type_checker.py\n  ├── utilities\n  │   ├── __init__.py\n  │   ├── nfa_to_dfa.py\n  │   ├── random_id.py\n  │   ├── README.md\n  │   ├── tree_crawling.py\n  │   └── xml_methods.py\n  └── venv\n      ├── bin\n      │   ├── ...\n      ├── include\n      ├── lib\n      │   └── ...\n      ├── lib64 -\u003e lib\n      └── pyvenv.cfg\n  ```\n\n## Development Guidelines\n\n1. **Modularity**: Keep each component (lexer, parser, etc.) in separate files or modules.\n2. **Testing**: Write unit tests for each component in `/tests/filename_test.py` or a dedicated `tests/` directory.\n3. **Documentation**: Document your code thoroughly, including function descriptions and complex logic explanations.\n4. **Error Handling**: Implement robust error handling and reporting throughout the compilation process.\n\n## Contributing\n\nWhen working on this project:\n\n1. Create a new branch for each feature or component you're working on.\n2. Write clean, well-commented code.\n3. Ensure all tests pass before merging your changes.\n4. Update this README when adding new components or making significant changes to the project structure.\n\n## Output\n\nCompilation outputs and intermediate files are stored in the `out/` directory. Refer to the README in that directory for more details on the output files.\n\n## Future Enhancements\n\n- Optimization passes\n- Support for additional language features\n- Integration with IDEs or text editors\n\n## Resources\n\n- [Compiler Design Lecture Tips](./docs/lecture%20tips/README.md)\n- [Language Specification](docs/specification/RecSPL_2024.md)\n- [Project Documentation](docs/README.md)\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftebogoyungmercykay%2Frecspl-compiler-construction-in-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftebogoyungmercykay%2Frecspl-compiler-construction-in-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftebogoyungmercykay%2Frecspl-compiler-construction-in-python/lists"}