Discuss Scratch

georgesbricks
Scratcher
19 posts

How to make a programming language

Hi everyone,

Does anyone here know how I could create a programming language with HTML5 and JavaScript?

Just a link to a tutorial would be really great!

Thankyou in advance

georgesbricks / http://bricks.georgesknowledge.com/



Keep Calm and Fly To Space

Keep Calm and Code On

Keep Calm and Make a Website

Keep Calm and Get It Done
YUM_YUM_YUM
Scratcher
28 posts

How to make a programming language

To create a programming language you need a parser and a lexer.

For example if you have a language were you can do “if”, “else” and “end if” the lexer would identify the three statements as objects then the parser would put the three objects together to form an “if” statement.

Hope this helped!

https://en.wikipedia.org/wiki/Parsing
https://www.codeproject.com/Articles/50377/Create-Your-Own-Programming-Language
YUM_YUM_YUM
Scratcher
28 posts

How to make a programming language

These are rely great tutorials: https://www.youtube.com/watch?v=LDDRn2f9fUk
georgesbricks
Scratcher
19 posts

How to make a programming language

Awesome!!! I'll check them out!!!!!!!!!!!!!!!!!!



Keep Calm and Fly To Space

Keep Calm and Code On

Keep Calm and Make a Website

Keep Calm and Get It Done
-Lite-
Scratcher
500+ posts

How to make a programming language

I'd recommend ANTLR. I built a few programming languages in it (Mainly in Java, but ANTLR supports JavaScript too).
Another excellent tool is Lex/Yacc, but that's probably not what you are looking for.
It's a parser-generator, meaning that it does all of the heavy lifting for you.
Example

if_stmt
: IF_KWD expression block (ELSE IF block)* (ELSE block)?
;

YUM_YUM_YUM wrote:

To create a programming language you need a parser and a lexer.

For example if you have a language were you can do “if”, “else” and “end if” the lexer would identify the three statements as objects then the parser would put the three objects together to form an “if” statement.

Hope this helped!

https://en.wikipedia.org/wiki/Parsing
https://www.codeproject.com/Articles/50377/Create-Your-Own-Programming-Language

It's incredibly more complex. You need to first tokenize, then you can lex, then you parse, then you create an Abstract Syntax Tree, then you walk the AST.
(this example is still oversimplified)

An example of

“There are two different types of people in the world: those who want to know, and those who want to believe.”
Friedrich Nietzsche
georgesbricks
Scratcher
19 posts

How to make a programming language

Thankyou, i'll try it!



Keep Calm and Fly To Space

Keep Calm and Code On

Keep Calm and Make a Website

Keep Calm and Get It Done
georgesbricks
Scratcher
19 posts

How to make a programming language

I've installed the python 3 version of ANTLR, but I can't find it on my computer . where can it be found?



Keep Calm and Fly To Space

Keep Calm and Code On

Keep Calm and Make a Website

Keep Calm and Get It Done
georgesbricks
Scratcher
19 posts

How to make a programming language

Wait, Is ANTLR just a library that i can use with the normal python shell? I'm not really that skilled with JavaScript but I am very confident about using python.



Keep Calm and Fly To Space

Keep Calm and Code On

Keep Calm and Make a Website

Keep Calm and Get It Done
-Lite-
Scratcher
500+ posts

How to make a programming language

georgesbricks wrote:

Wait, Is ANTLR just a library that i can use with the normal python shell? I'm not really that skilled with JavaScript but I am very confident about using python.
https://github.com/jszheng/py3antlr4book/blob/master/

“There are two different types of people in the world: those who want to know, and those who want to believe.”
Friedrich Nietzsche
georgesbricks
Scratcher
19 posts

How to make a programming language

There seem to be loads of links to download it. which one?



Keep Calm and Fly To Space

Keep Calm and Code On

Keep Calm and Make a Website

Keep Calm and Get It Done
-Lite-
Scratcher
500+ posts

How to make a programming language

georgesbricks wrote:

There seem to be loads of links to download it. which one?
The official website.
http://www.antlr.org/
(Make sure it is version 4.0 +)

And make sure you have the runtime installed for python
Open up a command line and type
pip install antlr4-python3-runtime

Last edited by -Lite- (June 28, 2017 18:41:36)


“There are two different types of people in the world: those who want to know, and those who want to believe.”
Friedrich Nietzsche
georgesbricks
Scratcher
19 posts

How to make a programming language

Is there a way to make it browser based, with HTML5 and JavaScript?



Keep Calm and Fly To Space

Keep Calm and Code On

Keep Calm and Make a Website

Keep Calm and Get It Done
-stache-
Scratcher
500+ posts

How to make a programming language

If you want to use JS, nearley is pretty cool.


3x3 pb: 13.240
3x3 avg: ~21-26
-Lite-
Scratcher
500+ posts

How to make a programming language

georgesbricks wrote:

Is there a way to make it browser based, with HTML5 and JavaScript?
Yes. Simply use the flag
-Dlanguage=JavaScript
when compiling your parser

(that's for being client sided)
If you want it to be server-sided, then any compilation target will work (Java, C++, Python, etc.)

Last edited by -Lite- (June 29, 2017 01:18:18)


“There are two different types of people in the world: those who want to know, and those who want to believe.”
Friedrich Nietzsche

Powered by DjangoBB