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

I Slice

a programming language that fucks up ©

Wat — A lightning talk by Gary Bernhardt from CodeMash 2012

Vitalii Chernopyskyi @v_uk_europe — https://unsplash.com/photos/Oxb84ENcFfU
var h1679 = "1"
val g2788 = 2
h1679 + g2788 == "12"
g2788 + h1679 == 3

II Slice — Programming languages

fun sum(var a1573: string, b7232): int {
a1573 + b7232
}
sum(1, 2) // 12

Well, it’s not really fun 🤔

I mean, I can hardly imagine that someone has written even two identical programs in PizzaScript 🤷‍♂️

<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'

A popular tool parser generator antlr provides an extended version of the calculator's grammar.

So, how do programming language compilers work?

interface Node {
type: string;
loc: SourceLocation | null;
}
interface NumericLiteral <: Literal {
type: "NumericLiteral";
value: number;
}

The AST Explorer allows us to see how different languages can be represented in different ast formats

III Slice — Reactive Patterns

One very important thing I haven’t said yet. This project is deeply inspired by the Writing An Interpreter In Go by Thorsten Ball, but not only. There are plenty of interesting resources that I’d like to share during the next articles and events. Some of the examples are taken from the book and rewritten with the flavor of our interest.

$ 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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store