Writing PizzaScript Lexer with RxGo — A Saga in III Slices 🍕

  • I Slice — PizzaScript Introduction
  • II Slice — Programming languages
  • III Slice — Reactive Patterns

I Slice

- which introduces the PizzaScript programming language, aka

a programming language that fucks up ©

  • Understand how programming languages & interpreters work
  • Learn Go language and key libraries like RxGo
  • Experiment with WebAssembly

PizzaScript 🍕 Key Features

  • Cool name (and logo, todo)!
Vitalii Chernopyskyi @v_uk_europe — https://unsplash.com/photos/Oxb84ENcFfU
  • JavaScript -like syntax, kind of
  • Variables, integers, floats, and strings
  • Arithmetic expressions, built-in functions
  • First-class functions, closures
  • Dynamic types and coercions
  • Modules & Standard library
  • Awesome ideas and interpreter flows
var h1679 = "1"
val g2788 = 2
h1679 + g2788 == "12"
g2788 + h1679 == 3
  • PizzaScript compiles to WebAssembly, which makes it a portable and suitable target for execution both on client and server sides.
  • I’m interested in learning the Go language myself.
  • I wanted to decompose a project in areactive way too. Also, learning a library can help with the new programming language. RxGo will help to organize data flow - split input text into tokens, then parse and organize them into an abstract-syntax tree data structure
  • WebAssembly is a big thing, and we are going to produce modules in wasm or wat formats.

II Slice — Programming languages

fun sum(var a1573: string, b7232): int {
a1573 + b7232
}
sum(1, 2) // 12
  • We have an alphabet of all available symbols. A text written in it is essentially a string or a chain of characters.
  • And then, we have a specific set of chains from the alphabet. Those form a language.
  • a program that validates if the given text is of a particular language,
  • or a program that generates possible chains from the language
  • Grammar is a set of rules defining a language, written in a special form.
<personal-part> ::= <initial> "." | <first-name>
expr ::= operand {('+' | '-' | '*' | '/') operand} ; any number of infix operations
; with no precedence
operand ::= num [+/-] | '(' expr ')' ; a number followed optionally by
; +/- or a parenthsized expression
num ::= digit {digit} ['.' {digit}]] ; numbers can be integer or real
digit ::= '0 | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
interface Node {
type: string;
loc: SourceLocation | null;
}
interface NumericLiteral <: Literal {
type: "NumericLiteral";
value: number;
}

III Slice — Reactive Patterns

  • to split the text into tokens or to perform lexical analysis,
  • to parse lexemes or syntactic analysis,
  • to build an abstract syntax tree,
  • to compile or evaluate the parsed tree.
  • main - the main package to run,
  • repl - reads user's input, initializes all needed actors and produces output,
  • token - declares PizzaScript's allowed symbols and operators,
  • lexer - splits input text into tokens,
  • parser - generates a program's abstract-syntax tree,
  • ast - describes ast types,
  • eval - evaluates the program tree and produces the result.
$ git clone https://github.com/x-technology/PizzaScript.git
$ cd pizzascript
$ go get
$ go run main.go
Hello alex! This is the PizzaScript programming language!
Feel free to type in commands
>> 123
123
>> 1+2
3
>> 2+3
5
>> 123+2
125
>> 12*3
36
RxGo
RxGo — Scan Operator

Next Steps

  • More about PizzaScript 🍕
  • Deep into parsers, programming languages 🎓
  • Let’s compile it to WebAssembly already 💻

--

--

--

Software engineer, instructor, mentor, and author of technical materials #JavaScript

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

ShoeFy announces Strategic Partnership with Bird

Benchmarking Static Analysis Tools for C

LeetCode topics — Binary Indexed Tree

Visually Grounded Compound PCFG: New Advancement in Multimodal Natural Language Processing

Bringing business and IT together with low-code platforms

Version Control: Developer’s Best Friend

What is version control?

When ACID went Sour

Tools for Agile Teams — by Agile Teams

Agile project management tools — Clarkson’s choice of tractor to work the farm.

Get the Medium app

Alex Korzhikov

Alex Korzhikov

Software engineer, instructor, mentor, and author of technical materials #JavaScript

More from Medium

gRPC rocks build your first gRPC service(part 1)

Rain Water Trapping Problem using-Golang/Java

Adding/Replacing Cassandra Nodes, You might wanna cleanup

Scalable, Shard-able, Containerized & Distributed Computing