Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

24 hours later - FSharp Gotham 2015

757 views

Published on

Compiler introduction talk at F# Gotham in NYC hosted by Jet.com

Published in: Software
  • Be the first to comment

24 hours later - FSharp Gotham 2015

  1. 1. 24 HOURS LATER Phillip Trelford, @ptrelford #fsharpgotham NYC, 2015
  2. 2. THIS TALK IS *NOT* About how to write a compiler the hard way All theory For the faint of heart
  3. 3. THIS TALK *IS* ABOUT Domain Specific Languages Abstract Syntax Trees Parsing Interpreters Code Generation
  4. 4. LANGUAGE DESIGN (CONSIDERED OPTIONAL) Adhoc •PHP •JavaScript •Scala Copy&Delete •Java •J •Go Copy&Add •C# •F# •Haskell
  5. 5. TO THE TURTLES CODE Phillip Trelford, @ptrelford #fsharpgotham NYC, 2015
  6. 6. TURTLE LANGUAGE repeat 10 [right 36 repeat 5 [forward 54 right 72]]
  7. 7. TURTLE AST type command = | Forward of arg | Turn of arg | Repeat of arg * command list
  8. 8. THINGS YOU SHOULD NEVER DO Custom Operators Funny picture
  9. 9. TWO GIRLS (5 & 7YRS) + TURTLE
  10. 10. 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
  11. 11. SMALL BASIC AST /// Small Basic expression type 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 instruction type 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
  12. 12. 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.
  13. 13. http://tinyurl.com/funbasi c FUN BASIC - WINDOWS STORE APP
  14. 14. FUN SHARP RUNNING ON RASPIAN http://github.com/ptrelford/f unsharp
  15. 15. RESOURCES Phillip Trelford, @ptrelford #fsharpgotham NYC, 2015
  16. 16. 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 __
  17. 17. TRYFSHARP.ORG
  18. 18. BUY THE BOOK
  19. 19. QUESTIONS? Twitter: @ptrelford Blog: http://trelford.com/blog Turtle: http://fssnip.net/nN

×