{"id":19763743,"url":"https://github.com/devtony101/infix-expression-parser","last_synced_at":"2026-05-03T17:31:40.628Z","repository":{"id":56832979,"uuid":"448701543","full_name":"DevTony101/infix-expression-parser","owner":"DevTony101","description":"A dart package to help you parse and evaluate infix mathematical expressions into their prefix and postfix notations.","archived":false,"fork":false,"pushed_at":"2022-01-17T01:47:18.000Z","size":26,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-10T23:45:27.978Z","etag":null,"topics":["dart","dart-library","dart-package","flutter","parser","parser-library","side-project"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DevTony101.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-16T23:46:38.000Z","updated_at":"2022-01-28T18:08:02.000Z","dependencies_parsed_at":"2022-09-08T01:41:24.023Z","dependency_job_id":null,"html_url":"https://github.com/DevTony101/infix-expression-parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevTony101%2Finfix-expression-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevTony101%2Finfix-expression-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevTony101%2Finfix-expression-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevTony101%2Finfix-expression-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevTony101","download_url":"https://codeload.github.com/DevTony101/infix-expression-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241095991,"owners_count":19908900,"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":["dart","dart-library","dart-package","flutter","parser","parser-library","side-project"],"created_at":"2024-11-12T04:10:53.875Z","updated_at":"2026-05-03T17:31:40.594Z","avatar_url":"https://github.com/DevTony101.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License: MIT](https://img.shields.io/github/license/DevTony101/infix-expression-parser?style=flat-square)](https://github.com/DevTony101/gasteroids/blob/main/LICENSE)\n\nA dart package to help you parse and evaluate infix mathematical expressions into their prefix and postfix notations.\n\n## Features\n- Convert an infix expression into its prefix and postfix notations\n- Evaluate a mathematical expression\n- Support for basic mathematical operations\n\n## Usage\nYou can use `infix-expression-parser` as a library or as a CLI tool. Below are some examples explaining how to use the package in each case.\n\n### As a library\nThe package exposes two main classes:\n\n- **InfixExpressionConverter**: Use this class when you have an infix expression and want to convert it either to its postfix or infix notation.\n- **ExpressionEvaluator**: Use this class when you already have a postfix or prefix expression and want to evaluate it to a result. Use in combination with `InfixExpressionConverter` to also evaluate infix expressions easily. Note that in order to return a value, you need to provide a **context** in which you give each symbol in the expression a numeric value.\n\n#### Example #1: Converting an infix expression\n```dart\nimport 'package:infix_expression_parser/infix_expression_converter.dart';\n\nvoid main() {\n  // Provide an infix expression\n  const infixExpression = '(a-b+c)*(d+e*f)';\n\n  // Create an instance of InfixExpressionConverter\n  final converter = InfixExpressionConverter(expression: infixExpression);\n\n  final postfixExpression = converter.toPostfixNotation();\n  final prefixExpression = converter.toPrefixNotation();\n\n  print(postfixExpression); // ab-c+def*+*\n  print(prefixExpression); // *+-abc+d*ef\n}\n```\n\n#### Example #2: Evaluating a postfix expression\n```dart\nimport 'package:infix_expression_parser/expression_evaluator.dart';\n\nvoid main() {\n  // Define a context map\n  const context = {'a': 2, 'b': 3, 'c': 4, 'd': 5};\n\n  // Provide a postfix expression\n  const postfixExpression = 'abc+*d/';\n\n  // Use the static method provided by the ExpressionEvaluator class and pass both the expression and the context\n  final value = ExpressionEvaluator.evaluatePostfix(expression: postfixExpression, context: context);\n\n  print(value); // 2.8\n}\n```\n\n#### Example #3: Evaluating a prefix expression\n```dart\nimport 'package:infix_expression_parser/expression_evaluator.dart';\n\nvoid main() {\n  // Define a context map\n  const context = {'a': 2, 'b': 3, 'c': 4, 'd': 5, 'e': 6};\n\n  // Provide a postfix expression\n  const prefixExpression = '*-a/bc-/ade';\n\n  // Use the static method provided by the ExpressionEvaluator class and pass both the expression and the context\n  final value = ExpressionEvaluator.evaluatePrefix(expression: prefixExpression, context: context);\n\n  print(value); // -7.0\n}\n```\n\n#### Example #4: Evaluating an infix expression\n```dart\nimport 'package:infix_expression_parser/infix_expression_converter.dart';\nimport 'package:infix_expression_parser/expression_evaluator.dart';\n\nvoid main() {\n  // Provide an infix expression\n  const infixExpression = 'a-b+c-d*e';\n\n  // Convert it to either its postfix or prefix notation\n  final converter = InfixExpressionConverter(expression: infixExpression);\n  final postfixExpression = converter.toPostfixNotation();\n\n  // Define a context map\n  const context = {'a': 2, 'b': 3, 'c': 4, 'd': 5, 'e': 6};\n\n  // Use the static method provided by the ExpressionEvaluator class and pass both the expression and the context\n  final value = ExpressionEvaluator.evaluatePostfix(expression: postfixExpression, context: context);\n\n  print(value); // -27.0\n}\n```\n\n### As a CLI tool\nThe package expose a `infix-parser` command explained below:\n```bash\nA CLI tool for evaluating expressions in prefix or postfix notations or converting infix expressions.\n\nUsage: infix-parser \u003ccommand\u003e [arguments]\n\nGlobal options:\n-h, --help    Print this usage information.\n\nAvailable commands:\n  convert   Converts an expression to its prefix or postfix notation\n\nRun \"infix-parser help \u003ccommand\u003e\" for more information about a command.\n```\n\nYou can use the `convert` sub-command to parse infix expressions.\n\n#### Example #1: Converting an infix expression to a prefix expression\n```bash\npub run infix_expression_parser:main convert '(a-b/c)*(a/d-e)'  --prefix\n*-a/bc-/ade\n```\n\n#### Example #2: Converting an infix expression to a postfix expression\n```bash\npub run infix_expression_parser:main convert '(a-b/c)*(a/d-e)'  --postfix\nabc/-ad/e-*\n```\n\n## Future improvements\n- A sub-command for evaluating expressions in the command line may come in future iterations of this package\n- Support for other mathematical operations, functions and symbols may come come in future iterations of this package\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevtony101%2Finfix-expression-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevtony101%2Finfix-expression-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevtony101%2Finfix-expression-parser/lists"}