summaryrefslogtreecommitdiff
path: root/CMP/Compiler Construction.md
diff options
context:
space:
mode:
authormartial.simon <martial.simon@epita.fr>2025-04-13 19:54:19 +0200
committermartial.simon <martial.simon@epita.fr>2025-04-13 19:54:19 +0200
commit66c3bbfa94d8a41e58adf154be25e6d86fee8e30 (patch)
tree9c5e998f324f2f60c1717759144da3f996c5ae1a /CMP/Compiler Construction.md
init: initial commit
Diffstat (limited to 'CMP/Compiler Construction.md')
-rwxr-xr-xCMP/Compiler Construction.md72
1 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
+