https://github.com/darylnwk/mathtoken
Go library for parsing mathematical expression to tokens
https://github.com/darylnwk/mathtoken
golang infix-to-postfix math postfix-expression
Last synced: 5 months ago
JSON representation
Go library for parsing mathematical expression to tokens
- Host: GitHub
- URL: https://github.com/darylnwk/mathtoken
- Owner: darylnwk
- License: mit
- Created: 2020-03-11T09:36:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-12T02:21:14.000Z (about 6 years ago)
- Last Synced: 2023-08-07T11:44:48.019Z (almost 3 years ago)
- Topics: golang, infix-to-postfix, math, postfix-expression
- Language: Go
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mathtoken
--
import "github.com/darylnwk/mathtoken"
## Usage
#### type Associativity
```go
type Associativity uint
```
Associativity defines token associativity data type
```go
const (
// AssociativityNone defines a token has no associativity
AssociativityNone Associativity = iota
// AssociativityLeft defines a token is left associative
AssociativityLeft
// AssociativityRight defines a token is right associative
AssociativityRight
)
```
#### type Token
```go
type Token struct {
Type Type
Value string
Associativity Associativity
Precedence uint
}
```
Token defines a mathematical expression token
#### type Tokens
```go
type Tokens []Token
```
Tokens defines a list of `Token`
#### func Parse
```go
func Parse(s string) (tokens Tokens, err error)
```
Parse mathematical expression in infix format to `Tokens` and returns error if
unknown token found
#### type Type
```go
type Type uint
```
Type defines token type data type
```go
const (
TypeUnknown Type = iota
TypeSpace
TypeLParent
TypeRParent
TypeConstant
TypeVariable
TypeOperator
)
```
List of token types