{"id":22513312,"url":"https://github.com/malk97sc/lexical","last_synced_at":"2025-03-28T01:23:12.014Z","repository":{"id":264720866,"uuid":"894203980","full_name":"Malk97sc/Lexical","owner":"Malk97sc","description":"Lexical Analyzer","archived":false,"fork":false,"pushed_at":"2024-12-14T22:55:28.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T03:18:43.180Z","etag":null,"topics":["c","compiler","lexical-analyzer"],"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/Malk97sc.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":"2024-11-26T00:01:43.000Z","updated_at":"2024-12-14T22:55:32.000Z","dependencies_parsed_at":"2024-12-14T23:32:12.901Z","dependency_job_id":null,"html_url":"https://github.com/Malk97sc/Lexical","commit_stats":null,"previous_names":["malk97sc/lexical"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Malk97sc%2FLexical","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Malk97sc%2FLexical/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Malk97sc%2FLexical/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Malk97sc%2FLexical/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Malk97sc","download_url":"https://codeload.github.com/Malk97sc/Lexical/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245950632,"owners_count":20699100,"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":["c","compiler","lexical-analyzer"],"created_at":"2024-12-07T03:11:09.995Z","updated_at":"2025-03-28T01:23:12.007Z","avatar_url":"https://github.com/Malk97sc.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Lexical Analyzer in C\n\n**Lexical analyzer simplified** written in C that processes an input file and identifies various types of tokens: keywords, identifiers, numeric constants, delimiters, operators, and string literals. It also handles basic errors related to invalid or incomplete tokens.\n\n## Features\nThis file contains the implementation of the lexical analyzer. The program uses specific functions to recognize and process different token types in an input file. Key features include:\n\n- **Input File Reading:** The `readFile` function reads the content of a file and stores it in memory for analysis.\n- **Token Detection:** The `analyzer` function processes the content and categorizes tokens into the following types:\n  - **Keywords:** `if`, `else`, `while`, `return`, etc.\n  - **Identifiers:** Valid variables following specific rules.\n  - **Numeric Constants:** Includes integers, floats, and scientific notation.\n  - **Delimiters:** `,`, `;`, `{`, `}`, `(`, `)`, etc.\n  - **Operators:** `+`, `-`, `*`, `/`, `\u0026\u0026`, `||`, etc.\n  - **String Literals:** Strings enclosed in double quotes (`\"example\"`).\n- **Validation Using Deterministic Finite Automata (DFA):**\n  - DFA for numbers (`statenumb`).\n  - DFA for identifiers and variables (`stateVar`).\n- **Error Detection:** The program identifies and displays error messages for invalid or improperly formatted tokens.\n\n## Getting Started\n\nFollow these simple steps to install, compile, and run the program.\n\n### 1. Prerequisites\n\n- A Linux-based operating system (tested on Linux Mint).\n- GCC (GNU Compiler Collection) installed on your system.\n\n\n### 2. Compiling the Code\n\nUse the following command to compile the code:\n\n```bash\ngcc analyzer.c  -o  analyzer\n```\n\n### 3. Running the Program\n\nExecute the program with an input file:\n\n```bash\n./analyzer prueba.c\n```\n\n## Examples\n\nHere are some examples of input and the corresponding output from the lexical analyzer:\n\n### Example 1: Simple Input\n#### Input File (`example1.c`):\n```c\nint main() {\n    int a = 5;\n    float b = 10.25;\n    if (a \u003c b) {\n        printf(\"a is less than b\\n\");\n    }\n    return 0;\n}\n```\n#### Output is:\n\n```bash\nThe file is: \n\nint main() {\n    int a = 5;\n    float b = 10.25;\n    if (a \u003c b) {\n        printf(\"a is less than b\\n\");\n    }\n    return 0;\n}\n\nThe tokens in the file: \n\nTOKEN (INT): int\nTOKEN (MAIN): main\nTOKEN (LPAR): (\nTOKEN (RPAR): )\nTOKEN (LBRACE): {\nTOKEN (INT): int\nTOKEN (ID): a\nTOKEN (ASSIGN): =\nTOKEN (NUMBER): 5\nTOKEN (SEMI): ;\nTOKEN (FLOAT): float\nTOKEN (ID): b\nTOKEN (ASSIGN): =\nTOKEN (NUMBER): 10.25\nTOKEN (SEMI): ;\nTOKEN (IF): if\nTOKEN (LPAR): (\nTOKEN (ID): a\nTOKEN (LT): \u003c\nTOKEN (ID): b\nTOKEN (RPAR): )\nTOKEN (LBRACE): {\nTOKEN (PRINTF): printf\nTOKEN (LPAR): (\nTOKEN (STRING): \"a is less than b\\n\" \nTOKEN (RPAR): )\nTOKEN (SEMI): ;\nTOKEN (RBRACE): }\nTOKEN (RETURN): return\nTOKEN (NUMBER): 0\nTOKEN (SEMI): ;\nTOKEN (RBRACE): }\n```\n## 🛠️ How It Works  \n\nThe lexical analyzer operates in the following steps:  \n\n1. **File Reading**  \n   The program reads the input file line by line using the `readFile` function, storing the content in memory. This enables sequential token processing.  \n\n2. **Tokenization**  \n   The `analyzer` function scans the file content character by character to identify token boundaries. It uses specific rules to classify tokens, such as checking for keywords, operators, delimiters, and numeric constants.  \n\n3. **Token Validation**  \n   Each identified token is validated using helper functions:\n   - **Keywords:** Compared against a predefined list (`if`, `else`, etc.).  \n   - **Identifiers:** Verified to start with a letter or underscore, followed by letters, digits, or underscores.\n   - **Operators:** Classified based on common C operators (`+`, `-`, `*`, `=`, etc.).\n   - **Delimiters:** Identified based on common syntax delimiters (`;`, `,`, `(`, `)`, etc.).\n   - **Constants:** Identified based on numeric formats for integers or floats.\n\n4. **Output**  \n   Once tokens are recognized, they are output with their corresponding types and values. Invalid tokens are flagged with error messages.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalk97sc%2Flexical","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmalk97sc%2Flexical","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalk97sc%2Flexical/lists"}