Help Building Programming Language

Thread Starter

Ethan Technology

Joined Dec 18, 2024
5
A few days ago I decided I wanted to make a programming language, so I designed the syntax and I think I have it now but than I thought now what what do I do next after designing the syntax do I build it in C#, Python or what? Basically all I want to know is what I'm doing after I created the lexer

Here is an example code in case this helps

Code:
//My programming language
String data = "My programming language"; //This creates a string variable like in C

Func clicked() { //"Func" does not immediately execute the program inside unless called in a "Run"
Print, "Button Clicked", console; //Print prints the following string to the "console" (at the end of print)
}

Run Loop() { //Does immediately execute the program. How? (Or name if lowercase) It will "Loop()"
Button, "Click Me", clicked(), style: button; //Button creates a button, the next section displays on the text (or icon) on the button, the next section tells it what to do when the button is clicked, "style:" styles the button the following variable is the style
if(TIME(sec) < 10) {//if it runs for more than ten seconds close it
END; //end the code (for instance you want to close a window in the EthanOS (My OS) you use END; to close the window
Will not do anything in anything else
}
}

Style button {//use a CSS like code to style things
background-color: blue;
color: white;
border: none;
border-radius: 25px;
//Styles the button
}
 

WBahn

Joined Mar 31, 2012
32,702
Take a look at the Nand-to-Tetris project. In that you not only build the digital logic for the entire computer (in emulation), but you write the assembler and then a stack-oriented virtual machine translator and then a compiler for a simple object-oriented language and then the operating system libraries. It is designed so that you can do it in modules without doing the preceding modules, so I would recommend that you start with the assembler and work your way up. You will then see everything that is involved in implementing a programming language.

As for your question of what comes after the lexer, the answer is something that should have come before it. Construct a grammar for your language. To do that well, you need to have an understanding of what a parser is and how it works (there are a few basic types) and what it is and isn't capable of. The Nand-to-Tetris compiler project will get you a good start down that road.
 

Papabravo

Joined Feb 24, 2006
22,058
That topic is a little complex for a forum thread. So, here:

Good Compiler Textbook
Although the "Dragon" book is an autoritative reference it might be a bit much for the TS
I would suggest: Holub, A., Compiler Design in C
Compiler design in C (Prentice-Hall software series): Holub, Allen I.: 9780131550452: Amazon.com: Books

Also worthy of your attention is the LLVM project which posits a general purpose approach to developing a language front end and matching it with an arbitrary instuction set on the backend.
LLVM - Wikipedia
 

Gorbag

Joined Aug 29, 2020
15
Although the "Dragon" book is an autoritative reference it might be a bit much for the TS
I would suggest: Holub, A., Compiler Design in C
Compiler design in C (Prentice-Hall software series): Holub, Allen I.: 9780131550452: Amazon.com: Books
I agree that the Dragon book is probably too theoretical for OP. A better more modern treatment that I believe may be more practical and not limited to implementation in C:

Programming Language Pragmatics

Note that a new edition will be coming out in the Spring, but unless you need the updated materials, saving money on the current edition would make sense.
 
Top