What should I learn in order to create my own scripting language, eg. JavaScript? Even if I am able to create one, what's the procedure to convince browsers to make it a standard?
This question may sound dumb but it's important for beginners like me to understand how it all starts.
Creating a scripting language as an alternative to JavaScript requires you to:
If you managed to do all that, you need to propose your specification to an organization like TC39. Convincing them is probably the hardest part of all, since companies have heavily invested in EcmaScript. Aside from that, if your proposition were to be accepted, it would require A LOT of money, since browser developers all around the world would need to implement your specification.
Since scripts and compiled languages are not that different at the first 2 steps, I would take a look into the cool compiler which has actual lessons about NFA to DFA transformations, separation of steps, left and right recursive algorithms, the AST and so on.
theory.stanford.edu/~aiken/software/cool/cool.html youtube.com/watch
You can leave the compiler step and just build an interpreter so you stay in the NFA and usually if you take python or PHP you could just create a certain OP/Byte-Code as cache so you could skip the lexer and parser and directly go to the Interpreter after the first two steps have been processed. (caching of prepared code)
You could go for the atomic bursts concept which was common in PHP till version 5.6-ng where the AST was firstly introduced, this is only to give a "popular" language example without AST, but I would go for the AST (abstract syntax tree) if possible. You can have better possibilities to optimize via discrete math (Graph analysis) as well as JIT
a really nice talk about language design esp about a functional recursion is this one: https://www.youtube.com/watch?v=Nlqv6NtBXcA
if you go for the llvm as marco suggested https://www.youtube.com/watch?v=FnGCDLhaxKU this is a nice talk about the C++ compiler not really about language synthesis but still a nice optimization step talk.
In my opinion, first you should start with simple declarative syntax which means you don't need to handle variables which makes a lot of things easier.
so don't go for JS don't go for anything complicated try to implement a calculator first and try to add basic function to it without handling variable in memory.
Understand the history of programming don't just jump into something heavy first try to understand the basics:
those things on their own are huge improvement on your coding skills because you understand how languages do work.
Use eval function to run javascript codes 1.translate (CustomSynatx) to JS 2.run returned(function return) string with eval function < ?php echo "endl" ? >
Marco Alka
Software Engineer, Technical Consultant & Mentor
As a beginner, you might want to get started by reading existing specifications, like the ECMAScript standard, so you get a gist of what stuff you have to include and think about when designing a new language.
Next is starting to work on your language. There are a lot of languages out there already, so I would propose you start by investigating in what way your language stands out. What are some pros of your language you want to implement? Why should anyone use it? If you plan on replacing JS, your arguments are better darn good. Just one example: Rust tries to replace C++. Rust has memory safety and a few more compile-time analysis advantages (which are not possible in C++) on top of low-level code and C-like performance. Make sure to offer the same core feature set and then add something important to it without making it too complicated. Rust, when coming from C, C++, C#, Java, is very complicated, so it might not have the same drive some other language has. Its salvation is that it is backed by Mozilla (who rebuild Firefox, a big product used by a lot of people, in Rust).
Next, write a proof of concept interpreter. I suggest using a more simple language to implement the interpreter, so you can change stuff easily without worrying about memory leaks, type-hell, linker-hell, etc. I'd use Python+Pypy. For your PoC, performance does not matter, so your code might look messy and be slow, but the important part is that simple programs in your new language work as intended and you can show off the nice new features you want to introduce.
Convincing browser vendors to implement your language will actually not happen. Microsoft failed that with JScript and VBS. Google failed it with Dart. There are experts who say that adding a new language does not make any sense, as JS will stay (backward compatibility) and a new language would require a new VM which has to share memory with the JS VM. Implementing such a construct is very difficult and it will slow down overall performance. That's why we have emscripten. That's why people work on WebAssembly. We write stuff and then transpile it to JS, or something we can feed to the JS VM. Instead of trying to replace JS, write a Babel plugin to convert your language to sane JS and convince people to use your language (like TypeScript did)
Instead of planning to replace JS, you might, however, establish your language for different purposes. Just like there is a community for LOLCODE, you might make a general-purpose language which is liked by certain people. You could write a compiler based on LLVM to compile it to a binary executable. Alternatively, you could write a VM, which is installed alongside the program and executes it, just like .NET or the JVM. That way, you do not need to have your language be approved by anyone. You can roam free and do whatever you like! Maybe you work on an entirely different project. Like a learning software for kids. You could use your language there to enable scripting. It would be something like Scratch.