Share your repls and programming experiences

← Back to all posts
I Created a JavaScript Simulator in Python SLY!
ELDER054

After finding someone’s project that used SLY (Sly Lex Yacc), I decided this would help me be able to create a programming language. So I picked my strongest language: JavaScript, and tried to recreate it in Python.

Link to SLY project I saw is https://repl.it/@sugarfi/Parser-Template

You can create integer or string variables, use comments, and print things so far in my JavaScript.
WARNING: this JS simulator requires you to put a semicolon (;) at the end of statements
You can easily extend and replace these syntax rules to create your own language! I will also try to use this as a reference for a future programming language I’m trying to create!

Voters
iocoder
Stoten
FECW
TheJamCoder
TheCheeseCoder
EpicRaisin
mariocat
KENNETHTRIPP
CodingGoose
elipie
Comments
hotnewtop
Silverdawn2520

cool!

ELDER054

Glad you like it, @Silverdawn2520

JonDoeBeep

nice :))

ELDER054

Thank you, @JonDoeBeep

iocoder

@Elderosa

just as a side note, I forked this and when i did

it said

is there a fix for that?

ELDER054

sorry, I’ll fix that, @ridark

ELDER054

If you refork it, it should work, @ridark

iocoder

@Elderosa ik
also i created a language with this template, its here:
avol

iocoder

@Elderosa also instead of

you can just do

but thats up to u

ELDER054

We need to look up p.NAME1 in the dictionary of names tho? @ridark

ELDER054

Like if I wanted to set a variable to another variable, @Elderosa

iocoder

@Elderosa well it could pottentially either way, but self.names is a more stable way (wont give as many or any errors)

TheCheeseCoder

someone mde Python in js, now Python has made js!

this is coool

HoogidyBoogidy

Are you gonna finish this project? If you are, let me know! I want to see this work just like javascript!

ELDER054

I’m working on a separate project, but when I get all the details in the other project, I will bring them here as JavaScript @HoogidyBoogidy

HoogidyBoogidy

@Elderosa Awesome!

elipie

also, console is kinda like a class(judging how you came from python, I will try to explain it in python) and log is a function. So kinda like this:

See?

JBloves27

REALLY COOL BRO! I love it!

ELDER054

Thank you so much @JBYT27

JBloves27
elipie

uhm, javascript has ; at end of lines btw

BrutalBucket

@elipie Javascript does not need ; in it only when you are using it like console.log("Sdasdadas");console.log("Jsjiidhsiakd"); in one line

ELDER054

I made it require “;”s because it’s good practice to do it in JS, @BrutalBucket

elipie

@BrutalBucket Yes you do need ; at the end of the line, if you don't it will generate an error, that won't be shown, then it will kinda auto-correct your own line. So take this for example:

After running it it would turn into:

But your code would stay the same

ELDER054

Yeh, it is also preferred to use a semicolon, @elipie

ELDER054

If you don’t, it will take care of it for you though, @Elderosa

elipie
ELDER054

Can you test the alert function I just created. It doesn’t look too promising tho :( @elipie

CSharpIsGud

@elipie In JS and other languages that don't mandate ; newlines essentially function the same way as semicolons, so the only situation you need a semicolon is if you for some reason need multiple statements on one line. Otherwise they just keep going like normal.

HoogidyBoogidy

Can you allow single quotes? Please?

ELDER054

Sure, I just did! @HoogidyBoogidy

programmeruser

Nice!
Maybe try doing it from scratch next time?

ELDER054

Like, by not using [email protected]

programmeruser
ELDER054

I’ve tried doing it handwritten, and it is a lot harder. I think using this tool is quick and easier to understand, @programmeruser

programmeruser

@Elderosa eh, I think handwritten is pretty easy after you learn it, and probably easier than parser tools imo since it gives you more freedom in how you do it.
Example of a handwritten Lua interpreter that I wrote: https://repl.it/@programmeruser/lua-interpreter

ELDER054

I guess, but sometimes using the handwritten tools (constantly checking next token, regex, etc...) it is sometimes limited just as [email protected]

ELDER054

I’ve tried creating a regex parser and I soon found it was hard to add new things onto [email protected]

ELDER054

But if you think it is easy, go right ahead :)@programmeruser

KENNETHTRIPP

Could you show us how to do handwritten? (I've been wanting to learn how to make a language as well) @programmeruser

programmeruser

@KENNETHTRIPP first, you lex the code into tokens, then you parse the tokens with a parsing technique such as recursive descent (which I use), then you interpret the AST (abstract syntax tree).

ELDER054

One way to create a handwritten is using RegEx matching, which you soon will realize it is quite limited (I’m not sure which way @programmeruser does it )KENNETHTRIPP

programmeruser

@Elderosa wdym handwritten parsers are limiting?

ELDER054

Oh, that’s a great way to do it! Which language do you use? @programmeruser

ELDER054

I only said regex matcher are [email protected]

programmeruser

@Elderosa I use JavaScript (and I haven't had a chance to use C++ but I'll use it later since it's faster).

AntimatterRtc

@Elderosa of course, because in lexing and parsing regex is rarely used, and usually it's just used for removing unwanted characters (chars)

programmeruser

@AntimatterRtc handwritten lexers, parsers, and interpreters are much better than using parser tools.

CSharpIsGud

@programmeruser I have one of those too https://repl.it/@CSharpIsGud/LuaInterpreter2
But mine is very buggy since I made it in a day.