Skip to content
VS
All work
06 /

Piwo

A language front end, with Serbian beer for keywords.

Kind
personal project
Domain
SYSTEMS
Piwo
Screenshot pending

A Piwo source file beside its JSON AST output. Real output from the parser, not a mock.

/projects/piwo/ast.png

Overview

Piwo is the front half of a language implementation, written by hand in Java. Source text goes through a lexer into tokens, and a recursive-descent parser turns those tokens into an abstract syntax tree that can be serialized to JSON.

The grammar covers variables, functions, arrays, control flow, expressions and comments. The keywords are Serbian beer brands, which is the joke, but the error reporting is not: lexical and syntax errors are reported with line and column tracking.

This is a front end. It produces an AST, not a running program.

Front end

  1. Source
  2. Lexer
  3. Tokens
  4. Parser
  5. AST
  6. JSON

Technical challenge

Recursive-descent parsing is straightforward until the error cases. Reporting a syntax error usefully means keeping accurate line and column information through the lexer and into every AST node, so a message can point at the character that broke rather than at the statement that contained it.

What it does

  • 01Hand-written lexer
  • 02Recursive-descent parser
  • 03Abstract syntax tree generation
  • 04Variables, functions and arrays
  • 05Control flow and expressions
  • 06Comments
  • 07Serbian beer-themed keyword set
  • 08Lexical error handling
  • 09Syntax error handling
  • 10Line and column tracking
  • 11JSON serialization of the generated AST

Technologies

Language

Java

Front end

Lexer

Recursive-descent parser

AST

Error reporting

Line/column tracking

JSON serialization