0

I am expanding my knowledge in C++ and would like to write my own scripting language as a means to challenge myself and also as a project to use for casual scripts etc. I saw some old posts on stackoverflow on this but they're pretty dated and was wondering if anybody could give any newer sources examples etc...?

2
  • 1
    Really, write your own scripting language? This is not for the faint of heart. Search the internet for "Compiler design theory" and also "computer language theory". You need to write a Lexer, Parser and interpreter. In schools, this can be a year long course. Good luck! Commented Oct 12, 2016 at 23:19
  • 2
    Voting to close - too broad. Instructions for writing languages cannot fit in the answer section for one question. There are 1000 page books already written on this topic, search for "Compiler Design book Aho", often nicknamed "the dragon book". Commented Oct 12, 2016 at 23:21

1 Answer 1

4

In a nutshell:

Define Your Language
You will need to define all the commands and their syntaxes.
After defining them, you can group them by syntax patterns.

Design the Lexer
The Lexer is the part that scans the input for language elements and converts them to tokens. The tokens are then fed to the Parser.

Design the Parser
The Parser is the part that evaluates the tokens, such as their order and number of parameters.

Design the Interpreter
The Interpreter is the part that executes the output from the Parser.
You should think of it as a very high level model of a computer. For example, will you be needing variables, registers, input, output, math instructions, etc.

A complex interpreter is a BASIC language interpreter (or Visual BASIC). Java has a JVM which interprets byte-codes. There are also LISP interpreters.

You may want to review the Python interpreter source code if you can get it.

Also, review the source code for the GNU and CLanguage compilers.

Compilers and interpreters are usually written by teams of people (to reduce the development time). Be prepared to spend a long time with this project.

Sign up to request clarification or add additional context in comments.

1 Comment

37 elapsed years and counting for C++. I'd hate to see what that is in person-years.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.