4 ms·
I'm not of the academic type and this type of vocabulary quickly loses me. Lots of words to describe something that, at its core, is pretty simple. Mind twistin
by vdupras 1y ago
I'm not of the academic type and this type of vocabulary quickly loses me. Lots of words to describe something that, at its core, is pretty simple. Mind twisting, but simple.
Infix notation parsing happens in ast.fs[1]. It parses tokens left to right and builds a tree (the structure is Lisp-like cons) describe the expression in such a way that expr.fs[2] then just has to recursively process the top tree node to have proper codegen.
In other words, operator precedence, prefix/postfix operators, etc. are all considered in ast.fs. Once in expr.fs is reached, all those things have been processed.
AST tests[3] give a good example of what ast.fs does.
I'm not sure I'd say that Forth being stack-based particularly help there. This logic is more "recursive-based" than anything. Lots of recursion all around.
[1]: https://git.sr.ht/~vdupras/duskos/tree/master/item/fs/comp/oberon/ast.fs https://git.sr.ht/~vdupras/duskos/tree/master/item/fs/comp/o...
[2]: https://git.sr.ht/~vdupras/duskos/tree/master/item/fs/comp/oberon/expr.fs https://git.sr.ht/~vdupras/duskos/tree/master/item/fs/comp/o...
[3]: https://git.sr.ht/~vdupras/duskos/tree/master/item/fs/tests/comp/oberon/ast.fs https://git.sr.ht/~vdupras/duskos/tree/master/item/fs/tests/...
- trealira 1y agoThanks for explaining and giving me an overview of your code. I guess I was overly focused on Forth being stack based, when it's also perfectly capable of processing trees recursively. Yeah, I just think parsers are really cool, and have read enough about different parsing algorithms that I'm used to vocab like that.