Standard library / go/parser
go/parser.ParseExpr()
Parses a standalone expression. Position information is undefined; syntax errors may return a partial AST. Expected stdout: '+\n'.
Formal Syntax & Structure
go syntaxgo
func ParseExpr(x string) (ast.Expr, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | string | Go expression source text. |
Return Value
(ast.Expr, error)
Parses a standalone expression.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/ast" "go/parser")
func check(e error) { if e != nil { panic(e) }}
func main() { x, e := parser.ParseExpr("1+2*3"); check(e); fmt.Println(x.(*ast.BinaryExpr).Op) }