{"id":28958732,"url":"https://github.com/shaina-gh/type-checking","last_synced_at":"2026-07-06T11:31:09.214Z","repository":{"id":296982673,"uuid":"995233013","full_name":"shaina-gh/type-checking","owner":"shaina-gh","description":"A C++ program to implement type checking of variable assignments and expressions, simulating a part of the semantic analysis phase of a compiler.","archived":false,"fork":false,"pushed_at":"2025-06-03T07:13:17.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-23T23:06:38.965Z","etag":null,"topics":["compiler-design","cpp","semantic-analysis","type-checking"],"latest_commit_sha":null,"homepage":"","language":"C++","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/shaina-gh.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,"zenodo":null}},"created_at":"2025-06-03T07:03:58.000Z","updated_at":"2025-06-03T07:13:18.000Z","dependencies_parsed_at":"2025-06-08T02:32:01.971Z","dependency_job_id":null,"html_url":"https://github.com/shaina-gh/type-checking","commit_stats":null,"previous_names":["shaina-gh/type-checking"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shaina-gh/type-checking","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaina-gh%2Ftype-checking","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaina-gh%2Ftype-checking/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaina-gh%2Ftype-checking/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaina-gh%2Ftype-checking/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shaina-gh","download_url":"https://codeload.github.com/shaina-gh/type-checking/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaina-gh%2Ftype-checking/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35189713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-06T02:00:07.184Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["compiler-design","cpp","semantic-analysis","type-checking"],"created_at":"2025-06-23T23:06:36.798Z","updated_at":"2026-07-06T11:31:09.192Z","avatar_url":"https://github.com/shaina-gh.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 🧠 AIM\n\nTo implement **type checking** for variable declarations and arithmetic expressions using C++, ensuring compatibility of data types in assignments.\n\n---\n\n## 📘 EXPLANATION\n\nIn the semantic analysis phase of a compiler, type checking ensures that operations are semantically valid — particularly that data types match across expressions. This project replicates a simplified version of that:\n\n- Users declare variables along with their types (`int`, `float`, `real`).\n- An expression is provided in the form of an assignment.\n- The program checks that the data type of the LHS variable is not of lower precision than any variables on the RHS.\n\nIt flags mismatches or confirms correctness accordingly.\n\n---\n\n## 🔍 LOGIC\n\n1. **Input Stage**:\n   - Prompt for the number of variables.\n   - For each, get a variable name and its type (validated against `int`, `float`, `real`).\n\n2. **Store Types**:\n   - Map variable names to an integer representing their type precedence (e.g., `int` = 0, `float` = 1, `real` = 2).\n\n3. **Parse Expression**:\n   - Extract LHS and RHS of the expression.\n   - Tokenize RHS and check that no variable on RHS has higher precedence than LHS.\n\n4. **Type Validation**:\n   - If an incompatibility is found, report the expected type.\n   - Otherwise, print \"Correct\".\n\n---\n\n## 💡 SAMPLE INPUT/OUTPUT\n\n### ✅ Valid Case\n\n**Input:**\n```cpp\nEnter the number of variables: 2\nEnter variable name and type (e.g., a int): x float\nEnter variable name and type (e.g., a int): y int\nEnter the expression: x = y\n```\n**Output:**\n```cpp\nCorrect\n```\n\n---\n\n### ❌ Invalid Case\n\n**Input:**\n```cpp\nEnter the number of variables: 3\nEnter variable name and type (e.g., a int): a int\nEnter variable name and type (e.g., a int): b float\nEnter variable name and type (e.g., a int): c int\nEnter the expression: a = b + c\n```\n**Output:**\n```cpp\na should be of type float\n```\n\n---\n\n## 🌍 REAL-WORLD APPLICATIONS\n\n- **Compiler Design**: Helps detect semantic type errors at compile-time.\n- **Integrated Development Environments (IDEs)**: Underpins type hints and warnings.\n- **Data Transformation Pipelines**: Prevents operations on mismatched types in ETL systems.\n- **Embedded Systems Development**: Ensures type safety to avoid low-level errors in constrained environments.\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaina-gh%2Ftype-checking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshaina-gh%2Ftype-checking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaina-gh%2Ftype-checking/lists"}