Skip to content

Web API to parse expression to Abstract Syntax Tree

Notifications You must be signed in to change notification settings

kooixh/ast-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AST Parser API

Web API to parse an expression into an Abstract Syntax Tree.

Easy, lightweight parsing solution to turn any expression and operators into an AST.

No external parsing tool needed.

Prerequisite

  • Maven
  • Java 8+

Starting the app

make build to build the app

make run to run it

Sample API Input

POST /api/parser/parse

Request

{
	"expression": "(x+y)*z",
	"operators": [
		{
			"symbol": "+",
			"precedence": 1,
			"type": "binary"
		},
		{
			"symbol": "-",
			"precedence": 1,
			"type": "binary"
		},
		{
			"symbol": "*",
			"precedence": 2,
			"type": "binary"
		},
		{
			"symbol": "/",
			"precedence": 2,
			"type": "binary"
		}
	]
}

Response

{
    "status": "success",
    "root": {
        "value": "*",
        "left": {
            "value": "+",
            "left": {
                "value": "x",
                "left": null,
                "right": null
            },
            "right": {
                "value": "y",
                "left": null,
                "right": null
            }
        },
        "right": {
            "value": "z",
            "left": null,
            "right": null
        }
    }
}

References

Releases

No releases published

Packages

No packages published

Languages