The dictionary definition of parse is:
- to divide (a sentence) into grammatical parts and identify the parts and their relations to each other
- to analyze (a string of characters) in order to associate groups of characters with the syntactic units of the underlying grammar.
Where the grammar is the rule of the parsed language/string.
'Yet another JSON parser' is a TypeScript program able to parser text against the JSON Grammar rule.
- It accepts a string of characters that might or might not contain a valid JSON syntax.
- It runs both lexical and syntactic analysis on the given string.
- It then outputs an abstract representation of the string in the form of an Abstract Syntax Tree (AST).
I think I managed to create a good mental model of how software and hardware interact with each other in order to produce for a given input a specific output. From afar, everything makes sense; each element has its role and an understandable way to interact with the rest of the system. However, as soon as you get closer, the picture became sharper, new details became visible, noise starts to form, and you start losing track of the contours of said element. And this goes on and on as you keep zooming in on your subject. The closer you look, the more you will find yourself surrounded by this arising complexity, the less the overall system will seem to be coherent.
But sometimes it is necessary to hone in on the detail to understand how said element works toward contributing to the system.
This curiosity led me to question how the code that I write day in day out is understood by the computer and then processed. There is no better way to understand something that trying to build it yourself.
So I set myself to build a language parser. I selected JSON for its simple syntax and grammar. TypeScript as the implementation language for its ability to express intent directly in the type system.
Realizing that "the evaluator, which determines the meaning of expressions in a programming language, is just another program" (Hal Abelson and Gerald Sussman, Structure and Interpretation of Computer Programs) had crazy repercussions on how now I think of a programming language.
There are plenty of open-source parsers out there that do the exact same thing that I'm trying to accomplish and more, but they are all written in Javascript. To name a few:
- acornjs
- estree
- @babel/parser
- eslint/espree
- jquery/esprima
This project is under active development: 🚧 WIP 🚧.
It hasn't reached a stable state yet, therefore it should not be used in any way or fashion.
Yes..., the name of this project is really "yet another json parser"! 🤦♂️
The name is a reference to YACC (Yet Another Compiler-Compiler). I was introduced to YACC by Professor Brailsford's video series on compilers and parsers on Computerphile. I found that name so catchy that I have decided to reference it when naming this project.
Is this project in any other way related to what YACC is about? The short answer is no. But both produce a look-ahead left to right (LALR) bottom-up language parser.
Yacc (Yet Another Compiler-Compiler) is a parser generator. It produces only a parser (phrase analyzer). It accepts the grammar rules written in C. It outputs a shift-reduce parser in C that executes the C snippets associated with each rule as soon as a rule is recognized. To get the full syntactic analysis, an external lexical analyzer is required to perform the first tokenization stage (word analysis), which is then followed by the parsing stage.
- TypeScript - Language
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Giovanni Ravalico - Initial work - @suddenlyGiovanni
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details
–