Home / Companies / Courier / Blog / Post Details
Content Deep Dive

Build a WebAssembly Language for Fun and Profit: Lexing

Blog post from Courier

Post Details
Company
Date Published
Author
Andrew Youngwerth
Word Count
1,959
Language
English
Hacker News Points
9
Summary

WebAssembly (wasm) is a high-performance assembly-like format optimized for the web, enabling demanding desktop-class apps to run in browsers. The WebAssembly team developed binaryen, a powerful compiler toolchain library that facilitates wasm adoption by offering dead code removal, code size reduction, and performance optimizations. A guide on building languages using wasm has been created, focusing on intermediate to advanced software developers looking for a fun side project. The guide covers setup, lexing, parsing, and compiling, with the first part covering setup and lexing. The lex function takes a string input and outputs an array of tokens, which are then identified as specific types such as integers, floats, identifiers, and brackets. A simple example, wispy, is used to demonstrate the lexer's functionality, outputting tokens that represent the code's structure. With the lexer working, the next step will be parsing these tokens into a logical tree for compilation to wasm.