Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would you go about writing a simple programming language? [duplicate]

Possible Duplicates:
Methodologies for designing a simple programming language
Learning to write a compiler

I would like to write a programming language with a syntax similar to QBasic but even simpler. I want it to be for beginning programmers. Its simplicity will encourage aspiring programmers not to give up and get them interested in programming. For example: Instead of QBasic's PRINT "Hello World!"

I would use

Write "Hello World!"

or a little more like VB

Write ("Hello World")

How would I go about adapting the basic syntax to make my language?

like image 433
RCProgramming Avatar asked Nov 03 '10 21:11

RCProgramming


1 Answers

This is not a simple task. Language parsing and compiler theory are pretty hefty subjects. Lots o' math. You also have to decide what platform you want to target, which will also determine whether your language is fully compiled (eg. C/C++, Pascal), compiled into bytecode (e.g. Python, Java), or interpreted at runtime (eg. VBScript, JavaScript). For specifying the language itself, brush up on the Backus-Naur format.

To help you along, there are several robust parser generators out there, including:

  • Lex/Yacc (Flex/Bison are the GNU Versions) - The old school industry standard. For developing a compiler in C/C++
  • ANTLR - If you're interested in creating a compiler using Java
  • Boost.Spirit - A different approach, allowing specification of the language using C++ itself.

And many more. A comparison can be found here, while yet another list can be found here

If you're really interested in the full theory, you want to check out The Dragon Book.

But I must reiterate: This is a big subject. There are many, many tools to help you along the way, but the rabbit hole goes pretty deep.

like image 56
rossipedia Avatar answered Jan 04 '23 05:01

rossipedia