SupremeDeity
SupremeDeity

Reputation: 98

Questions about creating your own little language

So before you read this : know that i am just a child and try not to be too harsh on me please.

So i wanted to gain some experience and i wanted to start creating my own little language. Not anything too great. I already decided that i am going to work with java.

I want to create a interpreted language without using the already made lexer and parsers.

I already created something before that would have custom syntax and stuff and then would be transpilled to c++ and then that c++ code will be compiled to give the result. My question is: can this really be called a language?. Just writing code in custom syntax and then changing that code to another language so that i dont have to deal with compiling and stuff.

Second is how would i go about creating something that would take care of this compiling / interpreting rather than depending on another language and transpilling and stuff.

Edit: this is a example of something i created a while ago but just recently added to my github when i learned about it. https://github.com/SupremeDeity/MTL.

I know this cant be called anything close to a language. Also you can give me advice in java/ c++ / python and no langauge other than that. I am only comfortable working with those 3

Upvotes: 1

Views: 156

Answers (1)

Branco Medeiros
Branco Medeiros

Reputation: 759

You will probably need to define a syntax for your language and write a grammar for it. Then you will need to write your own lexer and parser and design the back-end, that is, the interpreter and/or the compiler.

Since you know about the concept of lexers and parsers, I'd suggest you read other people's code and see how they do it. Three resources come to mind that may give you ideas on how to proceed:

  1. MAL (Make yourself A Lisp) - the author suggests a simple appproch to develop a LISP-like language and guides you step by step. Fun part: you choose the language you will use to develop your version of MAL in. Even though LISP may not be your thing, each step is very informative and the result is amazing. There's even a Java implementation there.

  2. Rosetta Code - Parse EBNF - Rosetta Code presents chalenges that must be solved using your language of choice. In this particular chalenge, not many alternate languages were submited. A java implementation is missing, by the way. And since you will need a parser, why not one for EBNF, a language to describe languages?

  3. Crafting Interpreters - that is a great on-line book that is being written as we speak. The author covers very interesting and practical topics. It uses c++ as the base language, but I think you will feel quite at home there.

Good luck!

Upvotes: 1

Related Questions