Ask me something about creating a programming language!
Hi. I am willing to answer anything you might have a question about relating to creating/building a programming language!
Just drop the question below and I will reply to it and explain it step by step(if necessary)!
P.S: Don't mind the pinned repl
Alright, I have made a language so I am slightly biased but I want to see how other's did it.
I made it go index by index and create tokens (a
struct) along the way. How did you do it? regex?
I used recursive descent. Apparently node.js uses it as well. What did you use? A parser combinator?
I first resolved everything (checked types and stuff) before interpreting it, which doubled execution time but also saved a lot of work as well. What did you do?
Alright, 3 questions, hope to get new insights after your answer!
For the lexer, I made it to where it went character by character. I had the lexer pick up and 'tokenize' each keyword that it found, as well as 'tokenize' simple things like '+' and '=' etc
The parser was just the syntax setter for my programming language. I strongly tied the lexer and parser together, every time a new token was found(from the lexer), the parser would automatically work on the syntax depending on what that current token was.
The parser was the 'trial and error' for figuring out the syntax of the language, as well as picking up extra information(like variable names/variable assignment values) for the runtime.
I made it to where the runtime has a struct that holds the current token type, variable name, variable value and other ideal information that could possible be useful.
Depending on the token type(the token type can be something like: int, or can be something like a function declaration or a 'built-in' method like a printing statement) the runtime would then 'check over' the information.
I made the runtime to where it would check variable definition information as well as values and make sure the variable definition information matches up.
If it did, then the runtime would then move onto the next token.
The way I made my language, the runtime was working at the same time as the parser(only when the parser was parsing something like a variable definition or a function declaration etc).
If the parser had just gotten to the end of a function that, lets say, was setting up the syntax for the function, we would then pass information onto the runtime struct and call the "checking" function for the runtime.
My version of a "runtime" is basically just double-checking everything. The only thing my runtime does in terms of actually having an effect on the programming language is making built-in methods do things within the language.
The runtime step is a very confusing step. Very confusing to explain because the way I make my runtime is so so much different in terms of how and why I do it
BUT, I hope this kinda gives you an insight on how exactly I approach each step of building a programming language!
@Coder100 Yes, actually. I found it easier to just link the parser to the lexer right off the bat giving a little head start on the runtime so that in the end not only did we just go through a file and tokenize it(keyword by keyword, punctuation by punctuation), but we also shot that sun of a gun through 2 other steps right away in a matter of bang bop boom lol
this board is for asking questions, but you are in a way 'asking' indirectly if anyone needs help, so I guess thats fine lol
Hi there! I know this post is like 9 months old but I need some help with my programming language (https://replit.com/@JacobMcPherson1/Blade#run/parser.py), I've made most of the basic stuff like output, variables, and basic math, but I dont know how the heck im gonna do all the advanced stuff like functions, loops, and conditionals. Can you please give me some tips and help? Thanks!
@python88 Here is a documentation I found:
I don't write Java, I used to. This is what I always referenced when I wrote Java.
Hope this helps!
@JosephSanthosh You want to know about the Python Shell?
A Shell in Python: Also known as "Python Interactive Shell", can execute just one line of python code at a time and is ran inside a terminal.
Basically, just a terminal version of the language that executes line by line.
I think that answers the question..if not please let me know
@k9chelsea2 Well, I have never really done anything related to building a language in Python. I believe that there is a library where you can append keyword names to a list though, however I am not sure what that library is called.
If I find the post where the 2 people were talking about it I will let you know, but other than that I do not know much about defining keywords in Python..
@k9chelsea2 I know I said I would ping you to a post, but forget that I found some documentation!
There is a Python Library named PLY that is heavily used for defining language keywords for a programming language that is going to be written in Python.
I think that if anyone was smart enough, they would use PLY if they attempted to create a language in Python.
Here is the documentation: https://www.dabeaz.com/ply/ply.html
If you need any help, please let me know
How does a makefile work and how do I make one in C? I have tried to make one but it didn't work...