So I did a few things:
- I decided on the syntax of Zen++. Since I want to use it for like codeforces and stuff it should be very fast to type out while still being fast. So I decided on the syntax of the language. It will use curly braces to delineate blocks of code, no semicolons, for variables no let keyword and optional type so like x=1 for now. For loops and if statements no need for parentheses, just do while tc-- or if bool. See idea.md for more.
- I decided it'll be interpreted and I got started on basic math. So the way it works is you start with the statement in code, then a lexer tokenizes it (it identifies what is a parenthesis what is a plus sign, stuff like that), and then a parser takes the tokens and creates a hierarchy (so like pemdas) by making an Abstract Syntax Tree which we then evaluate by going to the bottom nodes, evaluating them and then propagating upwards. So very cool things. So far I just did basic binary arithmetic operations like + - * / % ** and also a unary operator !. The code is made so its decently easy to add more tokens.
I added variables and assignment. You can declare a variable like x=4 and reassign it like x=5
What changed:
- The lexer now recognizes identifiers and the = token
- The AST supports variable nodes and assignment nodes.
- The parser now uses a lookahead to treat identifier = expr as an assignment, and it also lets identifiers show up inside normal expressions.
- The evaluator keeps a small variable map so assignments store values and identifiers read them back.
This step adds booleans and comparisons so I can start building if/else statements later. Booleans are just like they are in C++, a true boolean is a 1 and a false boolean is a 0.
What changed:
- The lexer now recognizes
true/falseand multi-character operators like==,!=,<=,>=. - The AST got boolean literals, comparison operators, and logical NOT.
- The parser now handles comparison expressions and prefix
!, while keeping postfix!for factorial. - The evaluator now returns 0/1 for comparisons and supports logical NOT.
I added if else statments to the code! The way an if else-if else statment will be written is like tihs:
if bool1{
x=1
}else if bool2{
x=2
}else{
x=3
}
Note the lack of parantehsis, you don't rly need them beacuse you know your condition is just gonna be sandwiched between the if and the next curly brace. Also now that I added braces I made the parser handle the braces and the AST handle blocks of code.
What changed:
- The lexer recognizes
if,else,{and}. - The parser builds block nodes and full if/else chains, and parses the full program instead of a single statement.
- The evaluator now runs blocks and if/else nodes.
- The REPL buffers lines and runs the program when you submit a blank line.
Ok so in this devlog I spent a lot of time thinking about syntax and I would like some feedback about for loops. First though, while loops were simple (not simple to implement these loops cooked me in coding but syntaxically simple), its just.
while boolean {
do this code here yeah
}
So while loops are very simple. Now for loops were a pain. I wanted them to be simple as this is meant to be super fast to write for competitive programming and the likes. So for this I took inspiration from my C++ template file.
#define FOR(i, a) for(int i = 0; i < a; i++)
#define ROF(i, a) for(int i = a; i >= 0; i--)
#define FORA(i, a, b) for(int i = a; i <= b; i++)
#define ROFA(i, a, b) for(int i = a; i >= b; i--)
That's how I macro for loops during Codeforces contests. So instead of
for(int i=0;i<n;i++){...} I can just do FOR(i,n). Now I wanted something nice and simple for Zen++ to. So I landed on this:
A four loop has four components, the variable used, the start, the end, and the step. So why not instead of writing those as a declaration, a boolean, and an incrementation like in C++, just treat those almost as paramateres to a method. So thats what I did.
for i start end step {...}
Thats the syntax. If you want a reverse for loop you just make end bigger than start and step will be negative.
There is a 3-arg version which defaults step to 1 or -1 depending on direction and looks like: for i start end{...} and there is a 2-arg one which is: for i end{...} and defaults step to +1 and start to 0. So for codeforces you can just write for i n{...}. Very simple, but leave comments if you think its ugly. Its exclusive by default rn with no way to make it inclusive, I'll fix that later.
This was a pretty big update but I didn't add anything that is syntaxically weird. I added functions, vectors, and strings.
-
Functions + Returns
- Added parsing/eval support for
fn name(args){...}andreturn expr. - Function definitions are stored and callable later.
- Added function scope behavior so params/locals resolve correctly.
- This includes built-ins like
read()andprintln(...).
- Added parsing/eval support for
-
Strings
- Lexer now tokenizes string literals.
- Parser builds string AST nodes.
- Runtime can store/print/concatenate strings.
- You can index into strings (
s[i]) and uselen(s).
-
Vectors (Dynamic Arrays)
- Added vector syntax:
[1, 2, 3]. - Added vector indexing:
v[i]. - Added built-ins:
len(v)push(v, x)pop(v)
- Added vector concatenation through
+when both sides are vectors.
- Added vector syntax:
-
Multidimensonal vectors
- Because vectors can contain vectors, nested structures like
[[1,2],[3,4]]just work. - Nested indexing works (
m[1][0]).
- Because vectors can contain vectors, nested structures like
-
Comments + Illegal Character Throwing
- Added support for comments:
- line comments
// ... - block comments
/* ... */
- line comments
- Added stricter behavior for unknown/invalid characters so bad input doesn’t silently pass.
- Added support for comments:
-
Reorginization
src/now contains all.cpp+.hppsource files.test/now contains test scripts + expected output.build/now contains the compiled binariesdocs/contains docs/devlogs.
-
Makefile + Testing
- Added a
Makefilewith nice commands make runlaunches REPL.make run <file.zpp>runs a file directly.- Made
test.zppas a file with every command in the language and then wrote the expected output and mademake testrun the test script and compare output.
- Added a
This batch saw a lot of new, big features, and some minor ones. Big: data structures, structs, imports. Small: bitwise operators, numerical type fixes, IO expansion.
-
Numeric types
- Integers are now 64-bit.
- Added float
-
Operators
- Exponent operator is now
**. ^,&,|are bitwise operators.- Added compound assignments for bitwise ops.
- Exponent operator is now
-
IO
- Added
readInt(),readFloat(), andreadLine(). read()maps toreadInt().
- Added
-
Structs + methods + member access
- New
struct Name { fn ... }syntax. - Method calls with
obj.method(...)and field access withobj.field. - Assignment to fields supported (
obj.field = x).
- New
-
Imports + stdlib bundle
- New
import fileandimport std. - Stdlib is bundled via
stdlib/manifest.txtand loaded byimport std.
- New
-
Data structures
- Hash table in runtime (map/set) for O(1).
- Exposed as stdlib
MapandSetstructs. - Added DSU, PriorityQueue, Stack, Queue, Pair, Tuple in stdlib.
-
Tests
- Test runner has more complete coverage.
-
Math functions
- Added standard math functions like
min(a,b),gcd(a,b)andabs(a)to stdlib bundle
- Added standard math functions like
I compiled the C++ Interpreter over to Web Assembly so I could make a web interpreter for it.
- Made a web UI inspired by USACO IDE, with Input and outputed
- Added syntax highlighting to it
- Added runtime error messages
- Fixed bugs in the langauge
- Added tests for the website
Big batch of changes getting ready for v1. A mix of language features, website fixes, tooling, and docs cleanup.
-
Map/Set bracket indexing
- Maps now support
m[key]for reading andm[key] = valfor writing, like C++. - Works on member maps too (
obj.data[key] = val). - Sets support
s[key]to check membership (returns 1 or 0). .get(),.set(),.has(),.add()all still work alongside[].
- Maps now support
-
Struct field definitions
- Structs can now declare fields with default values directly in the body:
struct Point { x = 0 y = 0 fn init(a, b) { self.x = a self.y = b } } - Defaults are applied when the struct is constructed, before
init()runs.
- Structs can now declare fields with default values directly in the body:
-
Break, continue, for-each
- Added
breakandcontinuefor loops. - Added for-each syntax:
for x in collection { }to iterate over vectors, maps, and sets.
- Added
-
Website: fixed intellisense
- Added better intellisnse and removed filler words
-
Website: docs button
- Added a "Docs" link in the toolbar of website
-
Packaging / install script
- Added
install.sh
- Added
-
VSCode extension
- Built and packaged a VS Code extension (
zenpp-0.0.1.vsix) with TextMate grammar for syntax highlighting and language configuration. - Published it to VSCode Extnsion Marketplace
- Built and packaged a VS Code extension (
-
Docs polish
- Fixed some errors in the docs
- A screenshot of the extnension in the VSCode Marketplace (so cool!!!)
- A screenshot of intellsense in the web interpreter
- Here is the link to the documentation: https://github.com/zainmarshall/zen-plus-plus/blob/master/docs/language-reference.md
Prepping for v0.1.0. Implemented the last missing language features, synced up the website/extension/docs, added a version flag, and just fixed a lot of bugs.
-
Website updates
- Syntax highlighting and autocomplete now cover all builtins (
println,ord,chr,parseInt) and new keywords (break,continue,in). - Added line numbers to the code editor.
- Grouped toolbar buttons together, default program uses
println.
- Syntax highlighting and autocomplete now cover all builtins (
-
VS Code extension v0.1.0
- Updated TextMate grammar with all new builtins and keywords.
- Bumped version, updated CHANGELOG, repackaged VSIX.
-
CLI
--versionflagzenpp --versionnow printszenpp 0.1.0.
-
Docs, samples, tests
- Language reference now documents for-each, break, continue.
- New samples:
foreach_demo.zpp,bracket_indexing.zpp. - Added test coverage for new features. All tests passing.
- Rebuilt WASM so the web version has everything too.
Zen++ is a fast, lightweight interpreted language designed for competitive programming.
Zen++ features C-style syntax with curly braces, no semicolons, automatic type inference, and a standard library with common data structures out of the box.
The language has everything you need for competitive programming and then some:
- Implicit variable declarations, 64-bit integers, floats, strings, booleans
- Vectors, maps, sets with bracket indexing
- Structs with fields, methods, and defaults
- For loops (
for i n,for i a b,for i a b step), for-each, while, break, continue - Functions with recursion, closures over global scope
- Standard library: Stack, Queue, DSU, PriorityQueue, min/max/abs/gcd
- Built-in IO:
read(),readInt(),readFloat(),readLine(),print(),println()
It runs three ways:
- CLI interpreter -
zenpp file.zppor justzenppfor the REPL - Browser - full web IDE at zainmarshall.github.io/zen-plus-plus with syntax highlighting, autocomplete, and the interpreter compiled to WebAssembly
- VS Code - syntax highlighting extension on the Marketplace
I also solved a the full Codeforces Round 1084 (Div. 3) with Zen++ to prove it works.
I compared my C++ competitive programming macro/template with Zen++ and realized there were a bunch of things the macro could do that Zen++ couldn't. So I went through and added them.
-
Bulk I/O
read(n)readsnintegers from stdin and returns a vector. No more manual loops to read input.read(v)readslen(v)integers directly into an existing vector.- Same for
readFloat(n)andreadFloat(v). - Before:
a = []thenfor i n { push(a, read()) }. Now:a = read(n). One line.
-
Type casting
str(x)converts any value (int, float, vector) to a string.int(x)converts a string or float to an integer (truncates floats, parses strings).float(x)converts a string or int to a float.- These replace the old
parseInt()pattern with cleaner, more general casts.
-
New stdlib math functions (
import std)lcm(a, b)- least common multiple.mid(a, b)- midpoint, equivalent to(a + b) / 2.ckmin(a, b)- returns the smaller of two values.ckmax(a, b)- returns the larger of two values.prefix(v)- builds a prefix sum array. Returns array of lengthlen(v) + 1wherep[i]= sum of firstielements.
-
Binary search (
import std)binarySearch(v, target)- searches a sorted vector fortarget, returns index or -1.
-
Dijkstra's algorithm
dijkstra(adj, start)- runs Dijkstra's shortest path fromstart.adj[u]is a list of[v, w]pairs (neighbor, weight).- Returns a distance array.
Big batch of language features, new builtins, and stdlib additions. The main theme was closing the gap between Zen++ and a C++ competitive programming template.
-
Ternary operator
x = a > b ? a : b- inline conditionals, nestable.- Added
?and:tokens to lexer,TERNARYnode type, and right-associative parsing soa ? b : c ? d : eworks as expected.
-
Negative indexing
v[-1]for last element,v[-2]for second-to-last. Works for vectors and strings, both reading and assignment.
-
Multiple assignment
a, b = 1, 2assigns multiple variables at once.a, b = b, aswaps values - all RHS values are evaluated before any assignment happens._discards a value:_, b = 0, 42.
-
_in for loopsfor _ n { }when you don't need the loop variable. Works in for-each too.
-
String repeat
"ha" * 3gives"hahaha". Works both ways:3 * "ha".
-
New builtins
split(s, delim)- split string into vector of strings.join(v, delim)- join vector elements into a string.find(v, x)- first index ofxin vector or string, -1 if not found.count(v, x)- count occurrences in vector or string.swap(v, i, j)- swap two elements in a vector (supports negative indices).fill(n, val)- create a vector ofncopies ofval. Deep-copies vectors so each element is independent.
-
Graph builtins
graph(n)- create adjacency list withnempty vectors.graph(n, m)- readmundirected edges (u v) from stdin, build adjacency list.dgraph(n, m)- readmdirected edges.wgraph(n, m)- readmundirected weighted edges (u v w), stores[v, w]pairs.dwgraph(n, m)- readmdirected weighted edges.- Dijkstra sample went from 8 lines of graph setup to
adj = wgraph(n, m).
-
New stdlib functions (
import std)sum(v)- sum a vector.lowerBound(v, x)/upperBound(v, x)- binary search returning insertion index in a sorted vector.modpow(base, exp, mod)- modular exponentiation.bfs(adj, start)- BFS shortest paths on unweighted graph, returns distance array.
-
Internal fix
push(v[i], x)now works - you can push to indexed vectors directly (needed for manual adjacency list building).
This one was all about making Zen++ more expressive and closing gaps that were annoying when solving problems.
-
Lambda functions
- Anonymous functions as expressions:
fn(a, b) { a - b }. sort(v, fn(a, b) { a[1] - b[1] })- sort a vector of pairs by second element, inline.
- Anonymous functions as expressions:
-
Slicing
- Python-style slicing for vectors and strings:
v[1:4],s[0:5],v[::-1]. - Full syntax:
[start:end],[start:end:step]. All three parts are optional. v[::-1]- reversed copy.- Works for strings too:
s[::-1]reverses a string,s[0:5]takes a substring.
- Python-style slicing for vectors and strings:
-
Tuple unpacking in for-each
for u, v in edges { }- destructure each element when iterating vectors of vectors.for k, v in myMap { }- iterate key-value pairs of a map.- Supports
_for discarding:for _, v in pairs { }. - This is huge for graph problems where adjacency lists store
[neighbor, weight]pairs.
-
Default function arguments
fn solve(n, mod = 1000000007) { ... }- parameters with= valueget defaults.- Call with fewer args and the defaults fill in:
solve(5)uses the default mod. - Works in regular functions, struct methods, and lambdas.
- Required params must come before optional ones.
-
Bitwise shift operators
<<and>>with correct precedence (between addition and comparison, like C).- Compound assignments:
x <<= 3,x >>= 1. - Essential for bitmask DP and bit manipulation problems.
-
String manipulation builtins
replace(s, old, new)- replace all occurrences.upper(s)/lower(s)- case conversion.startswith(s, prefix)/endswith(s, suffix)- boolean checks.trim(s)- strip leading/trailing whitespace.substr(s, start)orsubstr(s, start, len)- substring with negative index support.contains(s, sub)- check if string contains substring.
-
Multi-dimensional
fill()fill(n, m, val)creates an n×m grid filled withval.fill(n, m, k, val)creates a 3D array. Works for any number of dimensions.- Each row is an independent deep copy, so
grid[0][0] = 5doesn't affectgrid[1][0]. - Before:
grid = fill(n, fill(m, 0)). Now:grid = fill(n, m, 0). Cleaner and fewer mistakes.
More language features. Bitwise NOT, f-strings, chained comparisons, destructuring, min/max on vectors, and all/any predicates.
-
Bitwise NOT (
~)~xgives bitwise complement.clearBitis now justn & ~(1 << i).
-
min(v)/max(v)on vectorsmin([3, 1, 4])returns1.max([3, 1, 4])returns4.- Still works with 2 args:
min(a, b). Noimport stdneeded anymore.
-
String interpolation
f"hello {name}, {1 + 2} = {3}"- expressions inside{}are evaluated and stringified.
-
all(v, fn)/any(v, fn)all(v, fn(x) { x > 0 })- true if every element passes.any(v, fn(x) { x > 0 })- true if at least one passes. Short-circuits.
-
Chained comparisons
1 < x < 10works like1 < x && x < 10. Any number of comparisons can be chained.
-
Destructuring assignment
[a, b, c] = vunpacks a vector into variables. Supports_to discard.[x, _, z] = getPoint()- grab first and third, skip second.
-
Newline-aware postfix parsing
- Fixed a parser ambiguity where
[on a new line was consumed as an index operator from the previous expression. Indexing with[now requires it to be on the same line as the expression.
- Fixed a parser ambiguity where
Four optimizations to the interpreter. Combined: 11x speedup on composite benchmark (33.7s → 3.05s).
- Flag-based control flow - replaced C++
throw/catchforreturn/break/continuewith aSignalenum. Function calls: 7.5s → 0.4s (17x). - Arena allocator - AST nodes allocated from contiguous 4096-node blocks instead of individual
new. Better cache locality. - Scope frame reuse - function calls reuse cleared
unordered_mapframes instead of alloc/free each call. Variable ops: 1.14s → 1.00s. - Constant folding -
1 + 2 + 3folds to6at parse time.
- Simple loop (1M): 1.08s → 0.95s (1.1x)
- Function calls (100K): 7.53s → 0.36s (21x)
- Variable read/write (500K): 1.14s → 1.00s (1.1x)
- Vector push (100K): 0.16s → 0.14s (1.1x)
- Composite (all + fib(25)): 33.67s → 3.05s (11x)
- Sample dropdown label - selecting a sample now updates the dropdown text to show what's loaded instead of always saying "Samples".
- Settings / theme switcher - added a settings cog in the toolbar that opens a theme picker. Ships with 6 themes: Tokyo Night (default), Dracula, Catppuccin Mocha, GitHub Dark, Gruvbox, and Nord. Selection persists via localStorage.
-
New builtins
rand(lo, hi),randvec(n, lo, hi)- random number generation.exit()- terminate program.reverse(v)- reverse vector or string in-place.unique(v)- remove consecutive duplicates.sorted(v)- return a sorted copy without modifying the original.flatten(v)- flatten one level of nesting.zip(a, b)- pair up two vectors into[[a[0],b[0]], ...].
-
String iteration -
for c in s { }iterates over each character in a string. -
FenwickTree and SegTree (
import std)FenwickTree- point update + prefix/range sum queries in O(log n).SegTree- range sum queries + point updates in O(log n). Build from an array withst.build(arr).
-
Scoping fix - fixed a bug where local variables in recursive functions would leak into parent calls. Functions now correctly see only their own scope + globals.
-
VS Code extension v0.2.0 + web IDE syntax highlighting
- F-string interpolation highlighting - expressions inside
{}are colored normally, string parts stay green. - All new builtins highlighted (
sorted,unique,flatten,zip,rand,replace,upper,lower,all,any, etc.). - Stdlib classes highlighted as types (
FenwickTree,SegTree,MinPriorityQueue, etc.). - Bitwise shift (
<<,>>) and NOT (~) operator highlighting. - User-defined function calls get their own highlight color in VS Code.
- VS Code extension and web IDE are now in sync.
- F-string interpolation highlighting - expressions inside
-
Web IDE intellisense overhaul
- Autocomplete now shows full function signatures with parameter names and short descriptions instead of just empty parens (e.g.
push(v, x)with "append x to vector v"). - Added code snippets for
fn,for,while,if,struct.
- Autocomplete now shows full function signatures with parameter names and short descriptions instead of just empty parens (e.g.
-
Samples cleanup
- Removed test files, added 5 new demos (fenwick tree, segment tree, lambdas, slicing, f-strings).
- Modernized all 8 Codeforces solutions with new syntax (
read(n), slicing,for c in s,any()). - Website samples synced 1:1 with file samples (22 total across 5 categories).
-
Auto-loaded stdlib - the standard library is now loaded automatically on startup. No more
import stdboilerplate - all math functions, data structures, and algorithms are available immediately.