So I have been messing around with the new blocks and started wondering if it would be possible to build a programming language(very basic one) in GKC. Would be a cool project, plus it will teach many things and allow us to build fully fledged calculators. So who would like to help me out?
Explanation on building the programming language:
In a programming language you first need to create the lexer/tokenizer. This phase is overall quite simple but can be complicated when dealing with very low-level language grammar like C++. It should be very easy for a basic calculator, but maybe not…
A lexer/tokenizer is supposed to loop through all the source code and then check what the current character in the source code is. We always like to check for whitespace so we can skip through it by incrementing the position in the source code. At the end of the lexer/tokenizer we return a “list” of tokens that are the building blocks for our programming language. A calculator should only have these tokens:
DIGIT(for numbers), PLUS(for +), MINUS(for -), MUL(for *), DIV(for /), LPAREN(for “(” ), RPAREN(for “)” ), and maybe even EXPO(for ^).
After we finish the lexer/tokenizer we need to build the parser. The parser takes as input all of the tokens and loops through them. The parser normally returns an AST(abstract syntax tree), but for the sake of simplicity it will simply loop through the tokens and return the expected result.
Time for an example!
First the lexer will take in the input as:
5+5*(30/3)
Then it will return:
[{type: "DIGIT", value: "5"}, {type: "PLUS"}, {type: "DIGIT", value: "5"}, {type: "MUL"}, {type: "LPAREN"}, {type: "DIGIT", value: "30"}, {type: "DIV"}, {type: "DIGIT", value: "3"}, {type: "RPAREN", value: "3"}]
Then this code is parsed and returns:
55
Easy right? Well not really…but maybe it will be! So can someone help me out please? @Blackhole927 and @getrithekd and @Shdwy