I think you should learn more mainstream programming languages before you make your own. You should try to understand code snippets written in programming language that you did not learn. (if you learned C++, you should be able to understand Java code without learning Java)
Programming language design knowledge is very important. You must know what is the point of making (and using) a programming language. (left as an exercise to the reader, hint: why we don't program Assembly, why we are not Real Programmers?)
(note: the key topics mentioned are in bold, you should Google them for tutorials)
After you gathered ideas, then learn how to parse. Regular languages and formal language theory are musts.
Also, learn about lexers such as lex
and also learn how to tokenize without a lexer.
A tokenizer splits a code to labeled chunks from
function factorial(n) {
if (n == 0) { return 1; }
else { return factorial(n - 1) * n }
}
to
[FUNCTION function] [IDENT factorial] [LEFT_PAREN (] [RIGHT_PAREN )] [LEFT_BRACE {]
[IF if] [LEFT_PAREN (] [IDENT n] [EQ ==] [INT 0] ... and so on
After that, learn about context-free grammars and parser generators such as yacc
and JavaCC.
A parser checks if tokens are places properly according to the set of rules ("grammar") and deal with them.
For example, a while statement is defined as "a while keyword, a left paren, an expression, a right paren, a block." You must transform it into a context-free grammar.
WhileStmt := WHILE LEFT_PAREN Expression RIGHT_PAREN Block
(Expression and Block defined separately)
And a parser generator transforms them into a source code that deals with the tokens.
By this time, a good exercise for you is to write a calculator program.
Beyond that, you should learn about abstract syntax tree (AST) generation and interpretation of ASTs. In Java, the tree generation tool is called JJTree
. Make a formula calculator with your knowledge.
After you mastered making interpreters, learn how to make compilers, and the fun part: bootstrapping: learn how did a Java compiler was written in Java.
I made a LOGO ripoff as an example: http://github.com/SHiNKiROU/DesignScript
Also check my own calculator: http://github.com/SHiNKiROU/ExprParser
And a simple reverse polish notation calculator (Turing-complete) that I made without any effort: http://github.com/SHiNKiROU/Qwerty-RPN
I think you don't need a computer science degree, since I'm grade 9 and I am still able to create a programming language. Google and self-study.
Sorry if my English is too weird, I said I'm grade 9 and I'm not a native English speaker.
Here are some links to some useful resources and examples: