Skip to content
This repository was archived by the owner on Apr 10, 2026. It is now read-only.

hiepph/jsonparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON parser

A simple JSON parser using Pratt Parsing. This repository is mainly for educational purpose.

Code is based on Writing An Interpreter In Go by Thorsten Ball.

The original JSON string will be parsed and turned into a Go struct, defined in object/object.go:

type Hash struct {
	Pairs map[HashKey]HashPair
}

There are three stages:

  • Lexing: breaks down the original string into an array of tokens.

  • Parsing: forms an Abstract Syntax Tree (AST) based on the tokens. Pratt parsing—"top-down operator precedence" category—is used.

  • Evaluation: walks down the AST and checks for syntax error. The hash of the keys are also checked.

Run

To test the parser, fire up the REPL and type in a JSON string.

go run main.go

Test

go test ./lexer
go test ./parser
go test ./ast
go test ./object
go test ./evaluator

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages