DEV Community

Cover image for I Built My Own Programming Language From Scratch β€” Meet NexPro πŸš€
Probal Dhali
Probal Dhali

Posted on

I Built My Own Programming Language From Scratch β€” Meet NexPro πŸš€

What happens when you stop using programming languages and decide to build one?

That was the question that led me to start NexPro β€” an experimental programming language that I'm building from scratch to understand how programming languages actually work internally.

πŸ”— GitHub: https://github.com/probal2005/NexPro

NexPro is still in its early stages, but it already has the foundations of a real language implementation: lexical analysis, parsing, an AST, interpretation, runtime components, a CLI, and tests.

This article explains why I started NexPro, how the architecture works, what the syntax looks like, and where I want to take the project next.


🧠 Why Build Another Programming Language?

There are already hundreds of programming languages.

So why build another one?

For me, the goal wasn't to replace Python, JavaScript, Rust, or any existing language.

The goal was to understand what actually happens between this:

say "Hello NexPro!"
Enter fullscreen mode Exit fullscreen mode

and the computer executing it.

When we write code, we usually think:

Source Code β†’ Output
Enter fullscreen mode Exit fullscreen mode

But internally, there is a lot more happening.

A simplified language implementation looks more like:

Source Code
     β”‚
     β–Ό
    Lexer
     β”‚
     β–Ό
   Tokens
     β”‚
     β–Ό
   Parser
     β”‚
     β–Ό
    AST
     β”‚
     β–Ό
 Interpreter
     β”‚
     β–Ό
   Runtime
     β”‚
     β–Ό
   Output
Enter fullscreen mode Exit fullscreen mode

I wanted to build every major part myself.

That's how NexPro started.


πŸš€ What Is NexPro?

NexPro is an experimental programming language designed around simple and readable syntax.

The project currently lives on GitHub:

πŸ”— https://github.com/probal2005/NexPro

The language uses the .pa extension for source files.

For example:

name = "Probal"
city = "Kolkata"

say name
say city
Enter fullscreen mode Exit fullscreen mode

The idea is intentionally simple:

code β†’ easy to read β†’ easy to understand β†’ easy to execute
Enter fullscreen mode Exit fullscreen mode

NexPro isn't trying to compete with established languages yet.

Right now, it is a learning project, language-design experiment, and open-source project that I want to grow over time.


πŸ—οΈ NexPro Architecture

One of the most interesting parts of this project is understanding how the individual components communicate.

The current architecture can be represented like this:

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚    NexPro Source    β”‚
                    β”‚       (.pa)         β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚        Lexer        β”‚
                    β”‚  Source β†’ Tokens    β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚       Parser        β”‚
                    β”‚ Tokens β†’ Structure  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚         AST         β”‚
                    β”‚ Program Structure   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚     Interpreter     β”‚
                    β”‚   Execute the AST   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚       Runtime       β”‚
                    β”‚ Values & Execution  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚       Output        β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

Each component has a specific responsibility.


πŸ” 1. The Lexer

The first step is lexical analysis.

The lexer reads the raw source code and converts it into tokens.

For example:

say "Hello NexPro!"
Enter fullscreen mode Exit fullscreen mode

can conceptually become:

SAY
STRING("Hello NexPro!")
EOF
Enter fullscreen mode Exit fullscreen mode

For a variable assignment:

name = "Probal"
Enter fullscreen mode Exit fullscreen mode

the lexer needs to recognize things such as:

IDENTIFIER(name)
ASSIGN(=)
STRING("Probal")
Enter fullscreen mode Exit fullscreen mode

This is the first major transformation:

Characters
    ↓
Tokens
Enter fullscreen mode Exit fullscreen mode

The lexer doesn't need to understand the complete meaning of the program.

Its job is to identify the building blocks.


🌳 2. The Parser

Once the lexer produces tokens, the parser takes over.

The parser answers a different question:

"How are these tokens structured?"

For example:

name = "Probal"
Enter fullscreen mode Exit fullscreen mode

is not just three independent pieces.

It represents an assignment.

Conceptually, the parser can construct something similar to:

Assignment
β”œβ”€β”€ Variable: name
└── Value
    └── String: "Probal"
Enter fullscreen mode Exit fullscreen mode

This structured representation becomes part of the Abstract Syntax Tree, or AST.


🌲 3. The AST

The AST is one of the most important concepts in a programming language.

Instead of executing raw text directly, NexPro represents the program as structured nodes.

For example:

say 10 + 20
Enter fullscreen mode Exit fullscreen mode

could conceptually become:

        Say
         β”‚
       Binary
       /    \
     10      20
Enter fullscreen mode Exit fullscreen mode

The advantage is that the interpreter doesn't need to repeatedly analyze the original source text.

It works with a structured representation of the program.


βš™οΈ 4. The Interpreter

After the AST has been created, the interpreter walks through it and executes the nodes.

For example:

name = "Probal"
say name
Enter fullscreen mode Exit fullscreen mode

The interpreter can conceptually perform:

1. Create variable "name"
2. Store "Probal"
3. Find variable "name"
4. Retrieve its value
5. Send the value to output
Enter fullscreen mode Exit fullscreen mode

So the overall process becomes:

Source
  ↓
Lexer
  ↓
Tokens
  ↓
Parser
  ↓
AST
  ↓
Interpreter
  ↓
Runtime
  ↓
Output
Enter fullscreen mode Exit fullscreen mode

This pipeline is the heart of NexPro.


πŸ§ͺ A Small NexPro Program

Here's a simple example:

name = "Probal"
city = "Kolkata"

say name
say city
Enter fullscreen mode Exit fullscreen mode

The expected output is:

Probal
Kolkata
Enter fullscreen mode Exit fullscreen mode

The important thing isn't the complexity of this program.

The important thing is everything happening underneath it.


βž• Expressions

NexPro is also moving toward expression evaluation.

For example:

a = 10
b = 20

say a + b
Enter fullscreen mode Exit fullscreen mode

Conceptually, the parser can represent the expression as:

       +
      / \
     a   b
Enter fullscreen mode Exit fullscreen mode

The interpreter then resolves:

a β†’ 10
b β†’ 20

10 + 20 β†’ 30
Enter fullscreen mode Exit fullscreen mode

and produces:

30
Enter fullscreen mode Exit fullscreen mode

This is where a programming language starts becoming more interesting.


πŸ’» Running NexPro

The project is designed around a CLI.

A NexPro program can be executed with:

nexpro run examples/hello.pa
Enter fullscreen mode Exit fullscreen mode

For example:

say "Hello NexPro!"
Enter fullscreen mode Exit fullscreen mode

produces:

Hello NexPro!
Enter fullscreen mode Exit fullscreen mode

The CLI acts as the interface between the developer and the language implementation.

Instead of manually calling the lexer, parser, and interpreter, the developer simply runs a NexPro program.


πŸ“ Project Structure

The repository is organized around the language implementation itself.

The current project structure includes:

NexPro/
β”‚
β”œβ”€β”€ nexpro/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ cli.py
β”‚   β”œβ”€β”€ lexer.py
β”‚   β”œβ”€β”€ parser.py
β”‚   β”œβ”€β”€ interpreter.py
β”‚   β”œβ”€β”€ runtime.py
β”‚   β”œβ”€β”€ tokens.py
β”‚   β”œβ”€β”€ ast.py
β”‚   β”œβ”€β”€ errors.py
β”‚   └── __version__.py
β”‚
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ hello.pa
β”‚   └── variables.pa
β”‚
β”œβ”€β”€ tests/
β”‚
β”œβ”€β”€ README.md
β”œβ”€β”€ LICENSE
└── pyproject.toml
Enter fullscreen mode Exit fullscreen mode

The GitHub repository currently exposes the main examples, nexpro, and tests directories alongside the project configuration and documentation.

The implementation itself is written in Python.

That choice was deliberate.

Python lets me focus on language implementation concepts without spending most of my time dealing with low-level memory management.


🧩 Why Python?

A natural question is:

"If you're creating a programming language, why implement it in Python?"

Because the current goal is learning and experimentation.

Python gives me useful building blocks:

  • Easy string manipulation
  • Dictionaries for environments
  • Classes for AST nodes
  • Exceptions for error handling
  • Simple testing
  • Fast iteration

For an early interpreter, this makes development much faster.

Later, I may explore implementing parts of NexPro in another language for performance.


πŸ›‘οΈ Error Handling

A programming language isn't complete if it only handles valid programs.

It also needs to explain invalid programs.

For example:

name =
Enter fullscreen mode Exit fullscreen mode

shouldn't simply crash with an obscure Python traceback.

Eventually, NexPro should provide language-level errors such as:

NexPro Syntax Error

Line 1:
name =

Expected a value after '='.
Enter fullscreen mode Exit fullscreen mode

Good error messages are a major part of good developer experience.

Improving NexPro's error system is therefore an important part of the roadmap.


πŸ§ͺ Testing the Language

Programming languages are particularly sensitive to regressions.

A small lexer change can break parsing.

A parser change can break the interpreter.

An AST change can affect multiple features.

That's why NexPro includes a test suite.

The goal is to test individual components such as:

Source Code
     β”‚
     β–Ό
   Lexer
     β”‚
     β”œβ”€β”€ Token tests
     β”‚
     β–Ό
   Parser
     β”‚
     β”œβ”€β”€ AST tests
     β”‚
     β–Ό
 Interpreter
     β”‚
     └── Execution tests
Enter fullscreen mode Exit fullscreen mode

As the language grows, I want the test suite to grow with it.


πŸ—ΊοΈ NexPro Roadmap

NexPro is still early.

There is a lot left to build.

My current roadmap looks roughly like this:

                    NexPro
                       β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚              β”‚              β”‚
        β–Ό              β–Ό              β–Ό
     Language        Tooling        Runtime
        β”‚              β”‚              β”‚
        β”œβ”€ if/else     β”œβ”€ REPL        β”œβ”€ Types
        β”œβ”€ loops       β”œβ”€ Formatter   β”œβ”€ Collections
        β”œβ”€ functions   β”œβ”€ VS Code     β”œβ”€ Modules
        β”œβ”€ arrays      └─ Debugger    └─ Standard Library
        └─ objects
Enter fullscreen mode Exit fullscreen mode

Near-term goals

  • if / else
  • Loops
  • Functions
  • More operators
  • Arrays / collections
  • Better error messages
  • More comprehensive tests
  • Improved runtime

Medium-term goals

  • REPL
  • Modules
  • Standard library
  • File operations
  • Better CLI tooling
  • Formatter
  • Documentation
  • VS Code syntax highlighting

Long-term goals

I'd like to explore:

  • A more powerful type system
  • Package management
  • Faster execution
  • Bytecode or compilation
  • Debugging tools
  • Language server support
  • Cross-platform distribution
  • A proper developer ecosystem

Some of these are deliberately ambitious.

The roadmap will evolve as the language evolves.


πŸ”¬ What I'm Learning From Building NexPro

Building a programming language has changed how I think about programming.

Before starting NexPro, concepts like:

Lexer
Parser
AST
Interpreter
Runtime
Enter fullscreen mode Exit fullscreen mode

could feel abstract.

Now they feel much more concrete.

When I write:

say "Hello"
Enter fullscreen mode Exit fullscreen mode

I can think about the entire journey:

"say"
   ↓
Token
   ↓
Parser
   ↓
SayNode
   ↓
Interpreter
   ↓
Runtime
   ↓
Hello
Enter fullscreen mode Exit fullscreen mode

That mental model is probably the most valuable thing I've gained from this project.


🚧 NexPro Is Not Finished

I want to be very clear about this.

NexPro is not a production-ready programming language.

It's an evolving project.

There will be:

  • Bugs
  • Design changes
  • Breaking changes
  • Missing features
  • Experiments that don't work
  • Architectural decisions that will probably need to be revisited

And that's okay.

That's part of building a language from scratch.


🀝 I Want Developer Feedback

This project is now at the point where feedback from other developers could be extremely valuable.

If you are interested in:

  • Programming languages
  • Compilers
  • Interpreters
  • Lexers
  • Parsers
  • ASTs
  • Language design
  • Python
  • Developer tooling
  • Open source

I'd love to hear your thoughts.

Especially:

What would you change about the language design?

Which feature should I build next?

Does the architecture make sense?

What am I overlooking?

Would you be interested in contributing?


⭐ Contribute to NexPro

If you'd like to experiment with it, check out the repository:

πŸ”— GitHub: https://github.com/probal2005/NexPro

You can:

⭐ Star the project
πŸ› Open an issue
πŸ’‘ Suggest a feature
πŸ”§ Submit a pull request
πŸ§ͺ Experiment with the language
πŸ“– Improve the documentation
Enter fullscreen mode Exit fullscreen mode

Even a small suggestion can influence the direction of the project.


πŸš€ Final Thoughts

NexPro started with a simple question:

"Can I build a programming language myself?"

The answer so far is:

Yes β€” but building one teaches you how much there is to learn.

A programming language isn't just syntax.

It's a pipeline:

                 SOURCE CODE
                      β”‚
                      β–Ό
                    LEXER
                      β”‚
                      β–Ό
                   TOKENS
                      β”‚
                      β–Ό
                   PARSER
                      β”‚
                      β–Ό
                     AST
                      β”‚
                      β–Ό
                INTERPRETER
                      β”‚
                      β–Ό
                   RUNTIME
                      β”‚
                      β–Ό
                    OUTPUT
Enter fullscreen mode Exit fullscreen mode

And NexPro is my attempt to understand and build that pipeline from the ground up.

It's still early.

But that's what makes it exciting.

If you're interested in programming languages, I'd love for you to take a look at NexPro and tell me what you think.

Repository: https://github.com/probal2005/NexPro

Let's see how far this little language can go. πŸš€


Tags

programming #opensource #python #programminglanguage #compiler #interpreter #parsing #softwaredevelopment #devtools #beginners

Top comments (0)