PavelF
PavelF

Reputation: 331

Writing a scripting language?

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...?

Upvotes: 0

Views: 2083

Answers (1)

Thomas Matthews
Thomas Matthews

Reputation: 57678

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.

Upvotes: 4

Related Questions