{"id":24707451,"url":"https://github.com/blacktechwarrior/cpparser","last_synced_at":"2025-03-22T05:26:59.394Z","repository":{"id":270680226,"uuid":"911117053","full_name":"BlackTechWarrior/cpparser","owner":"BlackTechWarrior","description":"C++ mathematical expression parser","archived":false,"fork":false,"pushed_at":"2025-03-07T07:29:32.000Z","size":42,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-07T07:32:02.627Z","etag":null,"topics":["cpp","shunting-yard","shunting-yard-algorithm","shunting-yard-evaluator"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BlackTechWarrior.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":"2025-01-02T09:30:42.000Z","updated_at":"2025-03-07T07:30:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"0d3da5e6-1206-4a9a-aaed-0936cbc7d800","html_url":"https://github.com/BlackTechWarrior/cpparser","commit_stats":null,"previous_names":["blacktechwarrior/cpparser"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackTechWarrior%2Fcpparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackTechWarrior%2Fcpparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackTechWarrior%2Fcpparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackTechWarrior%2Fcpparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlackTechWarrior","download_url":"https://codeload.github.com/BlackTechWarrior/cpparser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244912278,"owners_count":20530757,"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":["cpp","shunting-yard","shunting-yard-algorithm","shunting-yard-evaluator"],"created_at":"2025-01-27T06:17:01.246Z","updated_at":"2025-03-22T05:26:59.389Z","avatar_url":"https://github.com/BlackTechWarrior.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CalScript Calculator\n\nA C++ command-line calculator capable of evaluating complex mathematical expressions, managing variables, and defining custom functions. This tool leverages an efficient token-based parsing system based upon the shunting-yard algorithm for accurate numerical calculations. \n\n## Building the Project\n\nThis project requires C++17 or above for features like `std::optional` and `std::string_view`.\n\n```bash\ng++ -std=c++17 -I include src/*.cpp -o calscript\n```\n\nRun the executable to start the calculator.\n\n## Core Features\n\n### Constants\nBuilt-in mathematical constants:\n* `pi` - Pi (3.14159...)\n* `e` - Euler's number (2.71828...)\n* `phi` - Golden ratio (1.61803...)\n* `sqrt2` - Square root of 2 (1.41421...)\n* `ans` - Result of the last calculation\n\n### Mathematical Functions\n* `sin(x)` - Sine (in degrees)\n* `cos(x)` - Cosine (in degrees)\n* `tan(x)` - Tangent (in degrees)\n* `log(x)` - Base-10 logarithm\n* `ln(x)` - Natural logarithm\n* `sqrt(x)` - Square root\n\n### Operators\nIn order of precedence:\n1. `!` - Factorial\n2. `^` - Exponentiation\n3. `*`, `/`, `%` - Multiplication, Division, Modulo\n4. `+`, `-` - Addition, Subtraction\n\n### Implicit Multiplication\nThe parser intelligently recognizes:\n* `2(3)` evaluates to `6`\n* `4pi` evaluates to `4 * pi`\n* `2sin(30)` evaluates to `2 * sin(30)`\n* `(2+3)(4+5)` evaluates to `(2+3) * (4+5)`\n\n## Variable Management\n\n### Defining Variables\n```\ndef [variable_name] [expression]\n```\n\nExample:\n```\ndef radius 5\ndef area pi*radius^2\n```\n\n### Updating Variables\n```\nupd [variable_name] [expression]\n```\n\nExample:\n```\nupd radius 10\nupd area pi*radius^2\n```\n\n## Custom Functions\n\n### Defining Functions\n```\ncreate func [name]([param1], [param2], ...): [expression]\n```\n\nExample:\n```\ncreate func area(r): pi*r^2\ncreate func hypotenuse(a, b): sqrt(a^2 + b^2)\n```\n\n### Using Functions\nFunctions can be called directly:\n```\narea(5)\nhypotenuse(3, 4)\n```\n\n## Utility Commands\n\n### Listing Information\n* `ls vars` - Display all defined variables\n* `ls hist` - Show calculation history\n* `ls funcs` - List all defined functions\n\n### Deletion Commands\n* `del [variable_name]` - Delete a specific variable\n* `del func [function_name]` - Delete a function\n* `del vars` - Delete all variables\n* `del hist` - Clear calculation history\n\n### System Commands\n* `exit` - Close the calculator\n* `clear` - Clear the screen\n\n## Examples\n\n### Basic Arithmetic\n```\n2 + 3 * 4     # Returns 14\n(2 + 3) * 4   # Returns 20\n```\n\n### Using Built-in Functions\n```\nsin(30)       # Returns 0.5\nlog(100)      # Returns 2\n```\n\n### Variable Operations\n```\ndef radius 5\npi * radius^2  # Calculate circle area = 78.54\ndef area ans   # Save result to variable\n```\n\n### Custom Functions\n```\ncreate func circle_area(r): pi*r^2\ncircle_area(5)  # Returns 78.54\n\ncreate func quad(a, b, c, x): a*x^2 + b*x + c\nquad(1, -3, 2, 2)  # Returns 0\n```\n\n### Complex Calculations\n```\ncreate func normal_pdf(x, mean, std): (1/(std*sqrt(2*pi)))*e^(-0.5*((x-mean)/std)^2)\nnormal_pdf(0, 0, 1)  # Returns 0.3989 (standard normal at peak)\n```\n\n## Current Limitations\n* No control structures (if/else, loops)\n* No array/list support\n* Limited symbolic manipulation capabilities\n* Simple text-based interface\n\n## Best Practices\n1. Use parentheses to clarify operator precedence in complex expressions\n2. Always use parentheses with function calls for clarity\n3. Use descriptive variable and function names\n4. Break complex calculations into smaller parts using intermediate variables\n\n## Error Handling\nThe calculator provides error messages for:\n* Syntax errors\n* Undefined variables/functions\n* Division by zero\n* Invalid function arguments\n* Mismatched parentheses","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblacktechwarrior%2Fcpparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblacktechwarrior%2Fcpparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblacktechwarrior%2Fcpparser/lists"}