My own programming language
Posted by iloveduckstoomuch@reddit | Python | View on Reddit | 46 comments
I made my own interpreted programming language in Python.
Its called Pear, and i somehow got it to support library's that are easy to create.
You can check it out here: Pear.
I desperately need feedback, so please go check it out.
bDrwx@reddit
Oh, thank you very much. I am looking for a simple project to learn. Yours looks interesting. Can i help you?
iloveduckstoomuch@reddit (OP)
If you want to! Help is very open
iloveduckstoomuch@reddit (OP)
I need error handling lol.
prpetrator@reddit
whyd you choose python
iloveduckstoomuch@reddit (OP)
Because
bpg2001bpg@reddit
Have you considered using Pear to write a new programming language? You could call it 'Pie.'
iloveduckstoomuch@reddit (OP)
Stupid but i love it! Ill create some file i/o library probably
zenverak@reddit
Create a few and then wrap it around to creating Python itself , and then use that to create your language again
amyrasheldon@reddit
R vs Python in Machine Learning
LardPi@reddit
I think you should try to solve some problems with your language to find it's limitations, and also flesh out the library. What are you trying to learn here? I would encourage you to turn this into a compiler as I think you would learn a lot from it. Also you could add a bit more syntax (infix operations for example) and learn more about parsers.
LardPi@reddit
I am not sure what is the intention here, but honestly pear is way to simple for that purpose. Lua or Wren or Monkey would actually make sense for this sentence.
Reasonable-Ladder300@reddit
What is the exact purpose or benefit over using an interpreted language like python directly?
LardPi@reddit
Who is doing "real world use case" as side project? I am writing a terminal emulator for fun, do you expect me to pretend it is going to replace Kitty and Ghosty? I have probably 200 side projects on my computer, the one I use regularly are usually 200 lines of python wipped up in 20 minutes to solve a specific problem and improved incrementally. These are not worth sharing. Obviously OP's side project is not supposed to replace python since it is written in it.
iloveduckstoomuch@reddit (OP)
It isn't supposed to have any real purpose.
Its just a little random project i made.
plenihan@reddit
This language is 146 lines of code and Python is 1.5 million lines of code. By my calculations Pear is wildly less bloated than Python. Even if you compare just the core language and the runtime Pear is still about 3,400x smaller. Definitely might have some use cases for microcontrollers. Its even tinier than Lua.
phonomir@reddit
Is this a joke? It's literally written in Python, meaning it requires those 1.5 million lines of Python code in order to run anything. It's just a thin abstraction layer on top of Python.
plenihan@reddit
Its no joke. Pear is experimental but looks like it can fit on really tiny chips with 1KB RAM. Definitely a game changer.
ZCEyPFOYr0MWyHDQJZO4@reddit
Thanks for letting us know you know nothing about embedded development
plenihan@reddit
It says gullible on the ceiling.
iloveduckstoomuch@reddit (OP)
Uhh i dont think that, because in that case it would also need a python interpreter on it.
iloveduckstoomuch@reddit (OP)
I could make a C++ version. Ive been learning it lately
JimmyJuly@reddit
Sometimes you just test things for fun and they end up someplace quite nice.
Example: Linus Torvalds.
"I was testing the task-switching capabilities, so what I did was I just made two processes and made them write to the screen and had a timer that switched tasks. One process wrote A, the other wrote B, so I saw AAAA BBBB and so on. The first two months the amount of code I wrote was very small, because it was a lot of details, totally new CPU, I've never programmed Intel before.
At some point I just noticed that hey, I almost have this [kernel] functionality because the two original processes that I did to write out A and B, I changed those two processes to work like a terminal emulation package. You have one process that is reading from the keyboard, and sending to the modem, and the other is reading from the modem and sending to the screen. I had keyboard drivers because I obviously needed some way to communicate with this thing I was writing, and I had driver for text mode VGA and I wrote a driver for the serial line so that I could phone up the University and read news. That was really what I was initially doing, just reading news over a modem."
B3d3vtvng69@reddit
It seems like this is a toy project, but I think this could be refactored and extended into a nice, simple scripting language.
-lq_pl-@reddit
Oh, you mean like... Python?
B3d3vtvng69@reddit
lmao
-lq_pl-@reddit
Some people just do things to learn and that is fine. My experience is that I only really understand something if I (re)build it from scratch.
DevSynth@reddit
Not so much a programming language, moreso a turing machine
Negative-Mass66@reddit
Okay, I was not the only one confused by this project. I expected a higher-level programming language. Something along the following lines. Assume this is the content of a file named script.pear
```
fun hello(v)
display v
end
define v = 3
hello(v)
```
Then, I will run the script with the command `python3 pear.py script.pear`
oversts@reddit
taking a look :)
B3d3vtvng69@reddit
Some tips:
Seperate your logic! Don’t put everything in one function, create seperate functions (or classes if you’re planning on extending your language) for getting the next token, deciding on what to do with the next token and actually executing instructions.
If you want to extend your language: create seperate classes for tokenizing, parsing the programm (checking syntax etc.) and constructing an abstract syntax tree and the actual interpreter that just walks that abstract syntax tree, executing it in the process.
If you want to take a look at a bigger Compiler Project, you can check out my Python to C++ Compiler pytocpp here Also hit me up if you need any advice.
OhYourFuckingGod@reddit
Remember: there is a rat in separate.
travisdoesmath@reddit
I like that. The mnemonic I learned was 2 a’s 2 e’s
B3d3vtvng69@reddit
Oops, english isn’t my first language lmao
OhYourFuckingGod@reddit
Nothing to worry about. It ain't mine either, hence the mnemonic.
JimmyJuly@reddit
There's also a rat in seperate (sic). I'm clearly missing the point of your comment. Maybe a comment has been editted?
brain_eel@reddit
Not who you're responding to, but I think they should've stressed that there's "a rat" in "separate", as opposed to "e rat"
JimmyJuly@reddit
Perfect! I understand now. Thanks!
Salamandar3500@reddit
Shebangs ! That way you can just run
./myscript.pr
iloveduckstoomuch@reddit (OP)
I think if you compiled the interpreter to something that your OS can execute, you could run it like that
Salamandar3500@reddit
No need for that.
B3d3vtvng69@reddit
You can simply put a shebang into the interpreter file and then copy it into /usr/local/bin so that it works as a shebang and you can just use it as a command
timwaaagh@reddit
Perhaps try to cythonize it for performance.
robobrobro@reddit
Why is it called Pear?
iloveduckstoomuch@reddit (OP)
I must say, i have no idea.
Jaguar_AI@reddit
subbing.
100721@reddit
I’d recommend doing a chip8 emulator as the next step to this r/emudev