{"id":20429035,"url":"https://github.com/yossef-khaled/arithmetic-expressions-evaluator","last_synced_at":"2025-10-13T08:35:33.274Z","repository":{"id":109524372,"uuid":"273008445","full_name":"yossef-khaled/Arithmetic-expressions-evaluator","owner":"yossef-khaled","description":"A parser for the arithmetic expressions using C# language. ","archived":false,"fork":false,"pushed_at":"2021-09-01T06:28:15.000Z","size":1010,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T19:46:46.883Z","etag":null,"topics":["automation","csharp","parser","regex"],"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/yossef-khaled.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":"2020-06-17T15:18:56.000Z","updated_at":"2021-09-01T06:28:18.000Z","dependencies_parsed_at":"2023-04-13T22:50:16.285Z","dependency_job_id":null,"html_url":"https://github.com/yossef-khaled/Arithmetic-expressions-evaluator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yossef-khaled/Arithmetic-expressions-evaluator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yossef-khaled%2FArithmetic-expressions-evaluator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yossef-khaled%2FArithmetic-expressions-evaluator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yossef-khaled%2FArithmetic-expressions-evaluator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yossef-khaled%2FArithmetic-expressions-evaluator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yossef-khaled","download_url":"https://codeload.github.com/yossef-khaled/Arithmetic-expressions-evaluator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yossef-khaled%2FArithmetic-expressions-evaluator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279014316,"owners_count":26085492,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"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":["automation","csharp","parser","regex"],"created_at":"2024-11-15T07:32:40.834Z","updated_at":"2025-10-13T08:35:33.259Z","avatar_url":"https://github.com/yossef-khaled.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Arithmetic-expressions-evaluator\n\nA parser for the arithmetic expressions using C# language. It consists of (as the main components): \n- Lexer.\n- Parser.\n- Evaluator.\n\n\n\n## Lexer\nThe lexer is implemented in the Lexer.cs file. It's all about dividing the input stream into tokens, each is one type of the following tokens : \n- Numbers                        {0-9}*\n- Plus                           { + }\n- Minus                          { - }\n- Multiply                       { * }\n- Divide                         { / }\n- Open Parenthesis               { ( }\n- Close Parenthesis              { ) }\n- End Of File                    { \\0 }\n- White Space                    {   }*\n- Bad Token                      { $ / @ / ! / % / ^ …. etc}*  \n\nThese tokens are later implemented as an enum in the SyntaxKind file.\n\nThe following DFA represents the lexer, which accepts only these tokens :\n\n![DFA](https://raw.githubusercontent.com/yossef-khaled/Arithmetic-expressions-evaluator/master/Images/DFA.PNG)\n\n\n\n## Parser\nThe parser is all about receiving an array of tokens from the lexer and then construct these tokens as \na tree of nodes. The parser is implemented in the Parser.cs file. \nWe used the following CFG (Context Free Grammer) to derive our expressions:\n- E → E + T | T\n- T → T * F | F\n- F → (E) | Number\n\nAfter converting the CFG to be LL(1) the following is our new grammer:\n- E → T E’\n- E’→ + T E’ | ε\n- T → F T’\n- T’→ *F T’ | ε\n- F → (E) | num\n\n#### Computing the first and follow :\n\n![First and follow implementation](https://raw.githubusercontent.com/yossef-khaled/Arithmetic-expressions-evaluator/master/Images/FirstAndFollow.PNG)\n\n\n#### Calculating parsing table :\n\n![The parsing table](https://raw.githubusercontent.com/yossef-khaled/Arithmetic-expressions-evaluator/master/Images/ParsingTable.PNG)\n\nThis “SyntaxTree” class represents the tree that the parser will return. It has a root, a list of diagnostics for errors, and an end of file.\nIt will be something like this :\n\n![The tree](https://raw.githubusercontent.com/yossef-khaled/Arithmetic-expressions-evaluator/master/Images/HierarchyTree.PNG)\n\n\u003e **Note:** the parser is using **recursive descent** to parse the stream input.\n\n\n\n## Evaluator\nThe evaluator is where we calculate the result starting from the tree. It takes the root of the tree that the parser passes. It walks over all the nodes and when it reaches the leaves of the tree, it goes up the tree calculating the result till it goes through the whole stream.\nThe evaluator is implemented in the Evaluator.cs file.\n\nFinally, at the end, \"Pretty Print\" function (which is not that pretty) will output the result and the tree into the console as follow:\n\n![The output](https://raw.githubusercontent.com/yossef-khaled/Arithmetic-expressions-evaluator/master/Images/Output.PNG)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyossef-khaled%2Farithmetic-expressions-evaluator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyossef-khaled%2Farithmetic-expressions-evaluator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyossef-khaled%2Farithmetic-expressions-evaluator/lists"}