24 hours later - ndc london 2014
TRANSCRIPT
![Page 1: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/1.jpg)
24 HOURS LATER Phillip Trelford, @ptrelford
#NDCLondon, 2014
![Page 2: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/2.jpg)
THIS TALK IS *NOT*
About how to write a compiler the hard way
All theory
For the faint of heart
![Page 3: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/3.jpg)
THIS TALK *IS* ABOUT
Abstract Syntax Trees
Parsing
Domain Specific
Languages
Interpreters
Code Generation
![Page 4: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/4.jpg)
LANGUAGE FAMILIES
Lisp
C
ML
BASIC
![Page 5: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/5.jpg)
LANGUAGE DESIGN (CONSIDERED OPTIONAL)
Adhoc
•PHP
•JavaScript
•Scala
Copy&Delete
•Java
•J
•Go
Copy&Add
•C#
•F#
•Haskell
![Page 6: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/6.jpg)
TO THE TURTLESCODE
Phillip Trelford, @ptrelford
#NDCLondon, 2014
![Page 7: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/7.jpg)
TURTLE LANGUAGE
repeat 10
[right 36 repeat 5
[forward 54 right 72]]
![Page 8: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/8.jpg)
TURTLE AST
module AST
type arg = int
type command =
| Forward of arg
| Turn of arg
| Repeat of arg * command list
![Page 9: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/9.jpg)
TWO GIRLS (5 & 7YRS) + TURTLE
![Page 10: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/10.jpg)
SMALL BASIC SAMPLE
Sub Init
gw = 598
gh = 428
GraphicsWindow.BackgroundColor = "DodgerBlue"
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
color = "1=Orange;2=Cyan;3=Lime;"
size = "1=20;2=16;3=12;"
passed = 0
cd = "False" ' collision detected
EndSub
![Page 11: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/11.jpg)
SMALL BASIC AST
/// Small Basic expressiontype expr =
| Literal of value| Identifier of identifier| GetAt of location| Func of invoke| Neg of expr| Arithmetic of expr * arithmetic * expr| Comparison of expr * comparison * expr| Logical of expr * logical * expr
/// Small Basic instructiontype instruction =
| Assign of assign| SetAt of location * expr| PropertySet of string * string * expr| Action of invoke| For of assign * expr * expr| EndFor| If of expr| ElseIf of expr| Else| EndIf| While of expr| EndWhile| Sub of identifier * string list| EndSub| Label of label| Goto of label
![Page 12: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/12.jpg)
C# COMPILER IN 24 DAYS
Oh Yes! Neil Danson (aka The Do)
Now, I didn’t do any compiler theory in uni, I’ve never written a compiler before and I’ve only ever looked at Reflection Emit in anger. But despite these limitations I have a fairly capable C# 0.5 compiler (in that it is a subset of the C# 1 compiler). Which means you can do it too – it took me less than a month.
![Page 13: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/13.jpg)
RESOURCES Phillip Trelford, @ptrelford
#NDCLondon, 2014
![Page 14: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/14.jpg)
F# KOANS
[<Koan>]
let SquareEvenNumbersWithPipelineOperator() =
(* In F#, you can use the pipeline operator to get the benefit of the parens style with the readability of the statement style. *)
let result =
[0..5]
|> List.filter isEven
|> List.map square
AssertEquality result __
![Page 15: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/15.jpg)
TRYFSHARP.ORG
![Page 16: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/16.jpg)
BUY THE BOOK
![Page 17: 24 Hours Later - NDC London 2014](https://reader030.vdocuments.us/reader030/viewer/2022032419/55a2d55c1a28abdb278b4819/html5/thumbnails/17.jpg)
QUESTIONS?
Twitter: @ptrelford
Blog:
http://trelford.com/blog
Turtle: http://fssnip.net/nN