mathparser

package module
v0.0.0-...-28eb8af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2025 License: MIT Imports: 3 Imported by: 0

README

MathParser

This is a golang package for parsing math expressions. With MathParser you can easily working with prefix, infix and postfix notation of math expressions.

Install

go get -u "github.com/arhefr/MathParser"

Instruction

Import the package in your project.

import . "github.com/arhefr/MathParser"
  • Parser(string)[]string
    Breaks a math expression into its individual components.
    Example:
    fmt.Println(Parser("(1488.0+1488.0)*1488"))
    
    -> ["(", "1488.0", "+", "1488.0", ")", "*", "1488"]
  • InfixPostfix(string) []string
    Converts an infix to a postfix notation math expression.
    Example:
    fmt.Println(InfixPostfix("(1488.0+1488.0)*1488"))
    
    -> ["1488.0", "1488.0", "+", "1488", "*"]
  • InfixPrefix(string) []string
    Converts an infix to a prefix notation math expression.
    Example:
    fmt.Println(InfixPrefix("(1488.0+1488.0)*1488"))
    
    -> ["*", "+", "1488.0", "1488.0", "1488"]
  • PostfixInfix([]string) (string, error)
    Converts an postfix to a infix notation math expression. If math expression incorrect return an error.
    Example:
    fmt.Println(PostfixInfix([]string{"1488.0", "1488.0", "+", "1488", "*"}))
    
    -> ((1488.0+1488.0)*1488) <nil>
  • PrefixInfix([]string) (string, error)
    Converts an prefix to a infix notation math expression. If math expression incorrect return an error.
    Example:
    fmt.Println(PrefixInfix([]string{"*", "+", "1488.0", "1488.0", "1488"}))
    
    -> ((1488.0+1488.0)*1488) <nil>

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Token = map[any]int{"^": 4, "*": 3, "/": 3, "+": 2, "-": 2, "(": 1, ")": 0}

Functions

func InfixPostfix

func InfixPostfix(exprStr string) []string

func InfixPrefix

func InfixPrefix(exprStr string) []string

func IsNum

func IsNum(ent string) bool

func IsOp

func IsOp(ent string) bool

func Parser

func Parser(expr string) []string

func PostfixInfix

func PostfixInfix(expr []string) (string, error)

func PrefixInfix

func PrefixInfix(expr []string) (string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL