frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Trying to Become a Better Programmer by Writing a PHP Interpreter in C++

https://github.com/GiuseppePuleri/jimphp/blob/main/README.md
2•pulerigiuseppe•1h ago

Comments

pulerigiuseppe•1h ago
I want to build an interpreter to better understand how a programming language really works.

I’ve been working with PHP for years, and I studied C++ mainly for educational purposes. So I decided to combine both worlds and start writing my own interpreter, documenting the journey from day.

For example, today I learned how bytecode is generated. Because of that, I finally understand tools like OPcache. If there are any inaccuracies I'm happy if you point them out to me. Happy reading...

        Architecture  
The Jim PHP architecture is divided into three levels. Each level behaves like an object, and these three objects communicate with each other.

LEXER - Splits the source code into tokens PARSER - Builds the AST (Abstract Syntax Tree) from the tokens INTERPRETER - Analyzes the AST and executes its nodes

        Other Details  
This project is inspired by Jim Tcl by Salvatore Sanfilippo. Jim PHP follows a different approach in its architecture. The Lexer (Tokenizer) follows a similar philosophy, but the Parser and Interpreter are based on different ideas.

Note: Jim PHP uses an AST-based interpreter, not a run-time oriented like Jim Tcl.

        Daily Goal  
[DONE] DAY ZERO Set up Git and GitHub. Studied the general architecture. Wrote the README file and the CMakeLists.txt. Understood the basic structure and goals.

[DONE] DAY ONE Started studying how PHP code could be executed. Jim PHP can run code in three ways, similar to Jim Tcl: - Inline string: std::string php_code = "1+1;"; (for testing only) - Command line: jimphp -r 'echo 1+1;' - File execution: jimphp sum.php

Worked on inline string execution and Lexer implementation with a token structure. We need tokens because the Parser will operate on individual tokens. Lexer.cpp can now tokenize expressions — "1+1" becomes "1", "+", "1".

[DONE] DAY TWO Started fixing issues in Lexer.cpp. Issue #1: If you hardcode a PHP expression like: std::string php_code = "(10.2+0.5(2-0.4))2+(2.14)"; the Lexer would return "Unknown character" because it didn’t yet recognize symbols like ), {, and so on.

Yesterday (day one), Jim PHP was tested only with simple expressions like "1+1". Obviously, that’s not acceptable. We needed a better Lexer that can tokenize code more accurately and recognize symbols properly.

Jim PHP now implements these category for token structures: -Char Tokens: a-z A-Z and _ -Num Tokens: 0-9 -Punct (Punctuation) Tokens: . , : ; -Oper (Operator) Tokens: + - * / = % ^ -Parent (Parenthesis) Tokens: ()[]{} -SChar (Special char) Tokens: ! @ # $ & ? < > \ | ' " and == != >= <= && ||

In this way we can write more complex PHP expressions like: std::string php_code = "$hello = 5.5 + 10 * (3 - 1); // test! @#|_\";

Result: SCHAR: $ | CHAR: hello_user | OPER: = | NUM: 5 | PUNCT: . | NUM: 5... At this point the Lexer can reconize complex PHP expression.

[DONE] DAY THREE Today we need to understand how these tokens will be handled in order to build the AST (Abstract Syntax Tree). We are now inside the parser stage. After the lexer, the next step is to build the AST from the generated tokens.

My first question was: what is an Abstract Syntax Tree? In very simple terms, conceptually, it is like a contract between the human writing the code and the way that code must be organized and cleaned before being translated into machine language.

Let's take this expression: 3 + 5 * 2 The tree must first clean the expression by removing unnecessary spaces, and then represent the operation like this:

First, perform the addition: + / \ You need 3 and the the multiplication: 3 * / \ The multiplication is between: 5 2

Limit text here... Continue reading the readme on github if you like.

Gibraltar dumping all of its raw sewage into Mediterranean

https://www.theguardian.com/world/2026/may/06/uk-territory-gibraltar-dumps-raw-sewage-mediterranean
1•akyuu•23s ago•0 comments

Show HN: Is he OK? Senior safety monitoring app

https://howareu.app/
1•sminchev•31s ago•0 comments

The first lie about entrepreneurship

1•danish00111•3m ago•0 comments

InMusic will acquire Native Instruments, as NI joins brands from Akai to Moog

https://cdm.link/inmusic-will-acquire-native-instruments/
1•mrzool•3m ago•0 comments

In coal country, black lung surges as federal protections stall

https://e360.yale.edu/features/black-lung-pennsylvania
1•speckx•4m ago•0 comments

"ClaudeBleed" allows any Chrome extension to control Anthropic's AI assistant

https://cyberinsider.com/claudebleed-allows-any-chrome-extension-to-control-anthropics-ai-assistant/
1•flyaway123•6m ago•0 comments

Write programs you can still hack when you feel dumb

https://www.draketo.de/software/programs-you-can-still-hack-when-dumb.html
1•xhevahir•8m ago•0 comments

Open Source AI App Store Screenshot Designer

https://ai-app-store-screenshots.vercel.app/
1•jonnyjackson26•9m ago•0 comments

Gemma Chat: Offline Vibe Coding on Apple Silicon

https://github.com/ammaarreshi/gemma-chat
1•steveharing1•11m ago•0 comments

New Orleans needs to prepare to relocate residents

https://www.npr.org/2026/05/06/nx-s1-5810941/new-orleans-ocean-study
1•measurablefunc•13m ago•0 comments

Movies Are Too Long

https://www.slowboring.com/p/why-movies-are-getting-longer
2•paulpauper•21m ago•0 comments

Smoking, chromosomal aberrations, and cancer incidence in healthy subjects

https://www.sciencedirect.com/science/article/pii/S1383571821000644
1•paulpauper•22m ago•0 comments

Show HN: ChonkLM – Tiny language models running offline in the browser

https://chonklm.com
3•bilalba•22m ago•0 comments

Two kinds of work, and where AI belongs

https://twitter.com/talhof8/status/2051337721151455509
1•talhof8•22m ago•0 comments

Three Model Organisms for Taste

https://www.astralcodexten.com/p/three-model-organisms-for-taste
1•paulpauper•22m ago•0 comments

Off-Grid Boat Communications with Meshtastic

https://blog.noforeignland.com/off-grid-boat-communications-with-meshtastic/
1•tmalsburg2•22m ago•0 comments

I've Banned Query Strings

https://chrismorgan.info/no-query-strings
2•Brajeshwar•24m ago•0 comments

The XM30 program: The Army's Bradley replacement

https://taskandpurpose.com/tech-tactics/army-xm30-bradley-replacement/
1•lorenzohess•25m ago•0 comments

APRS Messaging 36 Miles with Two HTs

https://midnightcheese.com/2026/05/aprs-message-36-miles-two-ht-radios/
1•thcipriani•27m ago•0 comments

Simpson Chalkboard Generator: A Tool for Creating Bart Chalkboard Stills

https://enufstyle.com/generators/bart/
3•stefankuehnel•36m ago•0 comments

Extraterrestrial intelligent beings do not exist

https://articles.adsabs.harvard.edu/pdf/1980QJRAS..21..267T
2•Topfi•37m ago•1 comments

Show HN: Mlx-code – I built a "backyard shed" AI coding agent for Mac

https://github.com/JosefAlbers/mlx-code
1•JosefAlbers•37m ago•0 comments

Claude Code Sandboxing

https://code.claude.com/docs/en/sandboxing
3•Destiner•37m ago•0 comments

Merle Tuve and the development of the proximity fuze

https://www.youtube.com/watch?v=yjQtzk_4czg
1•bane•38m ago•1 comments

Drivers of success – the gap between actual drivers and what we read about

https://alearningaday.blog/2018/12/26/drivers-of-success-the-gap-between-actual-drivers-and-what-...
2•Olshansky•40m ago•0 comments

New financed PostmarketOS project: q6voice(d)

https://postmarketos.org/blog/2026/05/08/q6voice-project/
1•wicket•42m ago•0 comments

Musk, Altman Management Styles Under Fire at OpenAI Trial

https://www.bloomberg.com/news/articles/2026-05-08/musk-altman-management-styles-come-under-fire-...
1•1vuio0pswjnm7•45m ago•1 comments

Musk has never built a wafer fab, but he wants to burn $119B on one anyway

https://www.theregister.com/systems/2026/05/06/spacex-plots-119b-wafer-fab-to-make-elons-orbital-...
4•Bender•47m ago•1 comments

NYC Mesh

https://en.wikipedia.org/wiki/NYC_Mesh
2•thunderbong•47m ago•0 comments

Laptops all have built-in security tokens these days

https://ahelwer.ca/post/2026-05-08-builtin-u2f/
4•psxuaw•49m ago•0 comments