diff options
Diffstat (limited to 'CMP')
| -rwxr-xr-x | CMP/Compiler Construction.md | 72 | ||||
| -rwxr-xr-x | CMP/Typage & type checking.md | 0 |
2 files changed, 72 insertions, 0 deletions
diff --git a/CMP/Compiler Construction.md b/CMP/Compiler Construction.md new file mode 100755 index 0000000..d833d74 --- /dev/null +++ b/CMP/Compiler Construction.md @@ -0,0 +1,72 @@ +# Strategies +## Interpretation +- **Portability** : no need to compile +- **Impact on the input language** : first order eval function, dynamic everything + +## Virtual machines +Allows processor emulation to allow execution on any platform + +## Transpilation +Conversion from a language to another (e.g. Arduino $\rightarrow$ C) +## Compilation +**Ahead of time** compilation : produce a binary file that can be run in the targeted architecture +**Just in time** compilation : involves compilation during execution + +## Bytecode strategy +- portable +- low level +- no physical machine can understand it +- can be : + - compiled + - interpreted + - executed by a VM + +# Development tools + +- Use warnings +- Use **assert/static_assert** (C++11) +- {Address,Thread,Memory,Leaks}Sanitizer +- lcov +## Autotools + +- **autoconf** : package configuration +- **automake** : package build +- **libtool** : a portable build of shared libs +- **gettext** : + +# Lexical analysis + +$$ +chars \rightrightarrows SCAN \rightrightarrows tokens +$$ + +## Flex + +- **F**ast **L**exical Analyzer generator +- GNU version of Lex +- TC now uses RE/Flex +### Variables +- **yytext** : token text +- **yyleng** : size of token text +- **yylex** : starts the scanning +- **yywrap** : called when end of text is encountered, can be redefined if needed + +## Bison + +- **yyparse** +- **yyerror** + +## Coupling Flex & Bison + +```sh +$ bison -o parser.cc -d --graph tmp.yy +$ flex -o lexer.cc tmp.ll +$ g++ -std=c++20 lexer.cc parser.cc +$ echo "1+2+3+98" | ./a.out +104 +$ echo "1+2+3++98" | ./a.out +1.7: syntax error, unexpected +, expecting number +0 +``` +## Error recovery + diff --git a/CMP/Typage & type checking.md b/CMP/Typage & type checking.md new file mode 100755 index 0000000..e69de29 --- /dev/null +++ b/CMP/Typage & type checking.md |
