Successfully reported this slideshow.
Your SlideShare is downloading. ×

自作コンパイラのお話

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 53 Ad

More Related Content

Slideshows for you (19)

Similar to 自作コンパイラのお話 (18)

Advertisement

Recently uploaded (20)

Advertisement

自作コンパイラのお話

  1. 1. Swift 
 freddi 1
  2. 2. (@freddi_kit)
 
 
 
 
 Python
 Perl Swift
  3. 3. • Swift •
  4. 4. • 
 = • • 
 • •
  5. 5. Swift • •
  6. 6. • • C -> ( ) -> • Swift -> (SIL) -> LLVM IR • C -> Python
  7. 7. • • 

  8. 8. • • 
 • 

  9. 9. • 
 
 
 
 
 
 
 
 

  10. 10. • 
 
 
 
 
 
 
 
 

  11. 11. • • 
 •
  12. 12. 
 (ab,aa )
  13. 13. 
 • • let( ) letlet( ) 
 
 ( )
 let[ ]a … → let 
 letlet[ ]a …→ letlet
  14. 14. 
 • • 
 • 

  15. 15. 
 : >> let a = 10; // l ”l” (accept) accept(Braph.QKeyWord, Braph.TokenNode.identifier(Optional("l"))) ["l"] // e ”le” accept(Braph.QKeyWord, Braph.TokenNode.identifier(Optional("le"))) ["l", "e"] // e ”let” accept(Braph.QForIndetifier, Braph.TokenNode.keyword(Braph.TokenNode.KeyWordType.declaration, Optional("let"))) ["l", "e", "t"] // (undefined).
 // ”let” undefined ["l", "e", "t", " "] // accept(Braph.QForSeparator, Braph.TokenNode.separator) [" "]
 //
  16. 16. • • • 

  17. 17. • (Syntax) •Syntax Error •   • ( )
  18. 18. < expr > ::= <expr> <+- > <term> <expr> < term > ::= <term> <*/ > <factor> <factor> < factor > ::= literal 10 1
  19. 19. int a = 10 + 5 - 10;
  20. 20. int a = 10 + 5 - 10;
  21. 21. int a = 10 + 5 - 10; 

  22. 22. int a = 10 + 5 - 10; + 

  23. 23. int a = 10 + 5 - 10; + +

  24. 24. int a = 10 + 5 - 10; + +
 := `=` := `+` or

  25. 25.
  26. 26. Swift Tour tuple BNF( )
  27. 27. • BNF
  28. 28. • BNF) •
  29. 29.  
 < statement > ::= <declaration> <expr> <return> <assign>
  30. 30. < expr > ::= <expr> + <term> <expr> < term > ::= <term> * <factor> <factor> < factor > ::= literal
  31. 31. < initializer > ::= = <expr> < assign > ::= identifier <initializer> < declaration > ::= let identifier <initializer> var identifier <initializer>
  32. 32.
  33. 33. •LL •SLR •LR •LALR
  34. 34. • LL • • 
 = OK
  35. 35. • 
 ( ) < expr > ::= <expr> + <term>
 <expr> • 
 → 

  36. 36. •LR SLR LALR • • OK • LR 
 C++
  37. 37. • •
  38. 38. • 
 • 

  39. 39. • LR(1) • 1 
 LALR(1) LL(1)
  40. 40. •BNF • • -> • -> LR
  41. 41. 
 
 https://github.com/freddi-kit/Braph

  42. 42. 
 ->
  43. 43. 
 
 https://github.com/freddi-kit/Braph

  44. 44. ω v
  45. 45. • • •
  46. 46. • 
 
 

  47. 47. • 
 https://books.rakuten.co.jp/rb/12932375/ • LR parsing 
 https://www.slideshare.net/ichikaz3/lr-parsing • LLVM 
 LLVM IR clang Brainf**k 
 https://itchyny.hatenablog.com/entry/2017/02/27/100000
  48. 48. https://github.com/freddi-kit/Braph

×