The W Language is a domain-specific language (DSL) for workout/exercise journaling. The current compiler of the language is built using C++ with GNU Flex and Bison.
I wanted to have quantifiable and granular data on my workouts. I wanted to be able to record how much as I was lifting per rep, for each set and for each exercise.
To give you a visual picture, I wanted something like this (for each rep of each exercise of each workout):
| Set | Rep | Percentage Execution | Resistance Type | Weight |
|---|---|---|---|---|
| 1 | 1 | 1 | weight vest | 30.000 |
| 1 | 2 | 1 | weight vest | 30.000 |
| 1 | 3 | 1 | weight vest | 30.000 |
| 2 | 1 | 1 | weight vest | 30.000 |
| 2 | 2 | 1 | weight vest | 30.000 |
| 2 | 3 | 0.95 | weight vest | 30.000 |
| 3 | 1 | 1 | weight vest | 0.000 |
| 3 | 2 | 1 | weight vest | 0.000 |
| 3 | 3 | 1 | weight vest | 0.000 |
Doing that manually in an excel spreadsheet for each exercise, everytime I work out, would be very tedious and time consuming. And if I wanted to add more variables, it would only get worse.
So, I made the W language to help me. Let it be known that, I had already called dibs on the .w extension for the language back in 2022. That’s right, the first iteration/version of the language was made in 2022. It was made, from scratch (everything from the parser to the interpreter), in Python and the source code is here.
The language changed quite a bit since 2022. Back then it had a very Python-like syntax:
meta:
debug
save
workout:
74kg 74.6kg
18:00
45min
set:
"squat" 1-15 25kg type="warm up"
. 10 30kg
"REST" 3min
. 0-25 50kg type="hypertrophy"
. 5 45kg
"REST" 3min45s
set:
"Running" type="cardio" 25min15s
"REST" 5min
I thought I’d like it, since I really like programmig in Python. But the style didn’t really click for me here. I didn’t really know what would work best either. I am not exactly an expert on language ergonomics.
Performance-wise, it was alright. It would do its job in less than 2 seconds for big workouts.
After a bit, I decided to change it up. I went with a more C-like DNA this time and built the whole thing in C++. I used the OG GNU Flex and Bison.
The result was a waaaay faster run time. We are talking in the milliseconds!
Here’s a sneak peak of the syntax:
// Sample workout
field weight type float default 10 as w
field resistance_type type string default "dumbbel" as rt
field percentage_execution type float default 1 as pe
const date "15/01/2025"
workout {
exercise "squats" sets 5 reps 5 rt "barbel" w ++19{ // adds 19 to the previous value of w (which is 10)
set 1 {
reps 1-5 w +5 // using alias 'w' instead of full 'weight'
}
set 2 w 10{
rep 1 w 29
rest 1m
reps 2-5 w --5 // cumulatively subtracts 5 for each rep because of double -
}
set 3 w 10 {}
set 4 rt "bb" w ++59{
reps 3-5 w -5 // only subtracts 5 once and keeps that result because of single -
}
set 5 {
rep 1 rt "body"
}
}
exercise "pull ups" sets 3 reps 3 w +20 rt "weight vest" {
set 3 w 0
}
}
As per 2025, the W Language is at version 2. Currently, built using C++ and GNU Flex and Bison.
The compiler has a bug I haven’t gotten time to fix yet. Whenever it reports errors (like a syntax errors), in some cases, there might be a discrepancy in the column location of where the error started.
There are also some cool features, that came to me while using it, that I wanted to add. And I also wanted to improve the syntax a bit more.
Some part of the compiler also needed rewriting. So with all of that, I decided to move on to the third version.
Version 3 of the W Language will be very similar to its predecessor. It will however not be backwards compatible, sadly.
I am still using C++ but this time with PEGTL. Something more modern! I am working on improving its syntax (it’s looking very Go-like right now) and adding some new features.
I am not sure when it will be finished. I am focusing on a bunch of other stuff at the moment and school is taking a big chunk of my time. Idk, maybe next year.
Yes for wlang and wlang2. As mentionned above, wlang3 is in development and hence closed-source for now. I will make it public, like the other versions, once it’s done.
Ever since I started this project back in 2022, I became more and more interested in compiler design and also language ergonomics. I started paying more attention to how programming languages are designed, especially newer ones. It’s fascinating to see how older languages ,like C, had more of the hardware in mind than languages we use nowadays, like Python, which focus more on the programmer, convenience, abstraction and my favorite, ease of use.