-
Notifications
You must be signed in to change notification settings - Fork 0
Spindle: The Parser:
It details how the project itself works, not how to write code in it. If you would like to know how to write code in Spindle, please look at the user documentation!
With that out of the way, this document will lay out how Spindle works and will help you contribute to it.
The parser adds meaning to your code by analysing the tokens generated by the lexer. While the lexer simply looks for "IF" and creates an "IF" token, the parser knows what an IF statement is, and in what order the tokens need to be in to make one. It denotes expressions, and so much more. As an example, it tells Spindle to handle a specific group of tokens as a for loop, and tells the interpreter to handle all the logic for it. The Interpreter is the next step after the lexer. Syntax checking is a lot more rigorous in the Parser, and this is where syntax errors usually come from. The Parser is the largest and most complicated part of Spindle, as it literally handles your program's logic. Because of its size and complexity, I will have to summarize it here. If you wish, you may expand upon this.
It also tells Spindle what do to if it encounters a "RETURN" statement.
In a sense, it turns:
[INT:10,PLUS,INT:5]
Into [INT: 15].