6 ms·
Not looked at OPs code, but if you build this stuff how a compiler book tells you to... The front end of a interpreter and a compiler is the same. You build a A
by 0x07c0 10y ago
Not looked at OPs code, but if you build this stuff how a compiler book tells you to... The front end of a interpreter and a compiler is the same. You build a AST, if you interpret you well interpret that. If you have a compiler, the AST is turned into the target language, in most cases asm. The front end is the scanner/Lexer, the parser and most likely semantic analyser. So to answer you question :), if you make a non optimizing compiler, turning the AST into asm is trivial. The hard part of making compilers is the optimization. Most of the front end you do not need to write actually! There are compiler-compilers for that.
https://en.wikipedia.org/wiki/Abstract_syntax_tree https://en.wikipedia.org/wiki/Abstract_syntax_tree
https://en.wikipedia.org/wiki/Compiler#Front_end https://en.wikipedia.org/wiki/Compiler#Front_end
https://en.wikipedia.org/wiki/Lexical_analysis https://en.wikipedia.org/wiki/Lexical_analysis
https://en.wikipedia.org/wiki/Parsing https://en.wikipedia.org/wiki/Parsing
https://en.wikipedia.org/wiki/Semantic_analysis_%28compilers%29 https://en.wikipedia.org/wiki/Semantic_analysis_%28compilers...
- groovy2shoes 10y agoIn fact, you can write a naïve interpreter or compiler completely in lex and yacc :)