Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit4ba4adfb8d41833ab32fcd1ca111ff18c98abecf (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-09-27 01:50:24 +0300
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-09-27 01:50:24 +0300
Filesb0c9438880262a1c9b8558594a6a25a99979a2e3
IPL-4ba4adfb8d41833ab32fcd1ca111ff18c98abecf.tar
IPL-4ba4adfb8d41833ab32fcd1ca111ff18c98abecf.tar.gz
IPL-4ba4adfb8d41833ab32fcd1ca111ff18c98abecf.zip
Parentda6026ee7147a3800900e1ce2520d560d5a06a6f (diff)
Expanded the grammars
1 files changed, 84 insertions, 6 deletions
-rw-r--r--website/content/slides/01_dragons/_index.md90
diff --git a/website/content/slides/01_dragons/_index.md b/website/content/slides/01_dragons/_index.md
index df52f22..b311f65 100644
--- a/website/content/slides/01_dragons/_index.md
+++ b/website/content/slides/01_dragons/_index.md
@@ -109,13 +109,68 @@ Recognizes the rules from stream of tokens and builds the AST of the program.
- parser generation tool
---
-###### Parser
+###### Grammars
-# TODO: Expand
+The grammar of a languages defines the structure of correct sentences and how to
+derive their meaning.
+
+---
+###### CFG
+
+Context Free Grammars
+
+ <expr> := <expr> <op> <expr> | (<expr>) | <term>
+ <op> := + | - | * | /
+ <term> := [0-9]+
+
+---
+###### PEG
+
+Parser Expression Grammars are similar to CFG, but are more convinient for
+parsing, since the `|` operator is not ambigious.
+
+- CFG allows selecting any matching variant and can have more than one parse
+ tree.
+ - parsing algorithms try to resolve this
+- PEG pritizes the variants in the order that they are written.
+
+---
+###### PEG
+
+ <expr> := <sum>
+ <sum> := <prod> ([+-] <prod>)*
+ <prod> := <value> ([*/] <value>)*
+ <value> := [0-9]+ / '(' <expr> ')'
+
+- That is a CFG as well, so for some grammars there is no difference.
+- Some languages can be expressed only with ambigious grammars.
+
+---
+###### CFG vs PEG
+
+Where the else goes?
+
+ <if> := if <expr> <stmnt> else <stmnt>
+ | if <expr> <stmnt>
+
+
+ if x0 if x1 s1 else s2
+
+ if x0 { if x1 s1 } else s2 // 1
+ if x0 { if x1 s1 else s2 } // 2
+
+- CFG - it is ambigious
+- PEG - 2 - because it is the first option
+
+---
+###### LALR(n)
+
+LR(n) and LALR(n) are family of parsing algorithms for CFG
+
+- n is the number of look ahead terminals
+- L - *left-to-right*,
+- R - *right-most derivation* - the right most non-terminal is replaced
-- CFG
-- PEG
-- LALR(n)
---
###### Program
@@ -158,6 +213,8 @@ that is convinient for:
- Static Single Assignment form
+# TODO: expand
+
---
### IR in LLVM
@@ -191,7 +248,26 @@ that is convinient for:
- AOT - less overhead, faster startup, generally better performance
- JIT - better chance for optimizations, since some of the program arguments
- will be contstants once the program has started
+ will be constants once the program has started, some of the virtual calls can
+ be devirtuallized at runtime
+
+---
+## Transpiler
+
+> Takes program written in one language and translates that to another language.
+
+- cfront
+- CoffeScript, TypeScript
+- nim
+
+---
+## Code transformation tools
+
+Lots of tools can be created based on the AST representation of a program
+
+- code formatting - *clang-format*, *gofmt*, *autopep8*
+- code transformation - *clang-modernize*
+- code analysis - *clang-tidy*
---
## Virtual Machine
@@ -210,6 +286,8 @@ collection and most of the standard library of the language.
---
### RPN as an interperter
+# TODO: expand
+
---
## What is a machine?