Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ValiantParsing

 ValiantParsing

Kazuhiro Ichikawa

August 02, 2019
Tweet

More Decks by Kazuhiro Ichikawa

Other Decks in Programming

Transcript

  1. Valiant Parsing
    ཧ࿦্࠷଎ͷจ຺ࣗ༝ݴޠͷߏจղੳख๏

    View full-size slide

  2. ߏจղੳ
    ೖྗจࣈྻ ݴޠ จࣈྻͷू߹

    ग़ྗจࣈྻ͕ݴޠʹଐ͔͢Ͳ͏͔

    View full-size slide

  3. จ຺ࣗ༝ݴޠ
    ͋Δจࣈྻ͕ͦͷݴޠʹଐ͔͢Ͳ͏
    ͔͸ɺपΓͷจ຺ʹґଘ͠ͳ͍
    ม਺ଋറͱ͔͸දݱෆՄೳ

    View full-size slide

  4. จ຺ࣗ༝จ๏
    จ຺ࣗ༝ݴޠͱ͍͏ू߹ͷੜ੒نଇ
    όοΧεɾφ΢Ξه๏Ͱهड़

    View full-size slide

  5. νϣϜεΩʔඪ४ܗ
    "#$ " # $ඇऴ୺ه߸

    "Ћ Ћऴ୺ه߸

    4Џ 4։࢝ه߸ Џۭ

    View full-size slide

  6. ߏจղੳͷҰൠతղ๏
    ऴ୺ه߸Λඇऴ୺ه߸ʹม͑Δ
    ྡΓ߹͏ඇऴ୺ه߸ಉ࢜Λ߹੒͢Δ
    ։࢝ه߸ʹḷΓ͚ͭ͹BDDFQU

    View full-size slide

  7. S → E
    E → E + E
    E → T
    T → T * T
    T → Num
    จ๏

    View full-size slide

  8. S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *
    S → E
    E → E + E
    E → T
    T → T * T
    T → Num
    จ๏
    ඪ४ܗ

    View full-size slide

  9. 1 + 2 * 3 * 4
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  10. 1 + 2 * 3 * 4
    T,E,S
    N1
    T,E,S
    N2
    T,E,S
    N2
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  11. 1 + 2 * 3 * 4
    T,E,S -
    N1
    T,E,S
    N2
    T,E,S
    N2
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  12. 1 + 2 * 3 * 4
    T,E,S -
    N1
    E1
    T,E,S
    N2
    T,E,S
    N2
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  13. 1 + 2 * 3 * 4
    T,E,S -
    N1
    E1
    T,E,S -
    N2
    T,E,S
    N2
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  14. 1 + 2 * 3 * 4
    T,E,S -
    N1
    E1
    T,E,S -
    N2
    T1
    T,E,S
    N2
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  15. 1 + 2 * 3 * 4
    T,E,S -
    N1
    E1
    T,E,S -
    N2
    T1
    T,E,S -
    N2
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  16. 1 + 2 * 3 * 4
    T,E,S -
    N1
    E1
    T,E,S -
    N2
    T1
    T,E,S -
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  17. 1 + 2 * 3 * 4
    T,E,S - E,S
    N1
    E1
    T,E,S -
    N2
    T1
    T,E,S -
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  18. 1 + 2 * 3 * 4
    T,E,S - E,S
    N1
    E1
    -
    T,E,S -
    N2
    T1
    T,E,S -
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  19. 1 + 2 * 3 * 4
    T,E,S - E,S
    N1
    E1
    -
    T,E,S - T,E,S
    N2
    T1
    T,E,S -
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  20. 1 + 2 * 3 * 4
    T,E,S - E,S
    N1
    E1
    -
    T,E,S - T,E,S
    N2
    T1
    -
    T,E,S -
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  21. 1 + 2 * 3 * 4
    T,E,S - E,S
    N1
    E1
    -
    T,E,S - T,E,S
    N2
    T1
    -
    T,E,S - T,E,S
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  22. 1 + 2 * 3 * 4
    T,E,S - E,S -
    N1
    E1
    -
    T,E,S - T,E,S
    N2
    T1
    -
    T,E,S - T,E,S
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  23. 1 + 2 * 3 * 4
    T,E,S - E,S -
    N1
    E1
    - E1
    T,E,S - T,E,S
    N2
    T1
    -
    T,E,S - T,E,S
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  24. 1 + 2 * 3 * 4
    T,E,S - E,S -
    N1
    E1
    - E1
    T,E,S - T,E,S -
    N2
    T1
    -
    T,E,S - T,E,S
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  25. 1 + 2 * 3 * 4
    T,E,S - E,S -
    N1
    E1
    - E1
    T,E,S - T,E,S -
    N2
    T1
    - T1
    T,E,S - T,E,S
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  26. 1 + 2 * 3 * 4
    T,E,S - E,S - E,S
    N1
    E1
    - E1
    T,E,S - T,E,S -
    N2
    T1
    - T1
    T,E,S - T,E,S
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  27. 1 + 2 * 3 * 4
    T,E,S - E,S - E,S
    N1
    E1
    - E1
    -
    T,E,S - T,E,S -
    N2
    T1
    - T1
    T,E,S - T,E,S
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  28. 1 + 2 * 3 * 4
    T,E,S - E,S - E,S
    N1
    E1
    - E1
    -
    T,E,S - T,E,S - T,E,S
    N2
    T1
    - T1
    T,E,S - T,E,S
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  29. 1 + 2 * 3 * 4
    T,E,S - E,S - E,S -
    N1
    E1
    - E1
    -
    T,E,S - T,E,S - T,E,S
    N2
    T1
    - T1
    T,E,S - T,E,S
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  30. 1 + 2 * 3 * 4
    T,E,S - E,S - E,S -
    N1
    E1
    - E1
    - E1
    T,E,S - T,E,S - T,E,S
    N2
    T1
    - T1
    T,E,S - T,E,S
    N2
    T1
    T,E,S
    S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *

    View full-size slide

  31. S → E E1
    E → E E1
    S → T T1
    E → T T1
    T → T T1
    E1
    → N1
    E
    T1
    → N2
    T
    S → Num
    E → Num
    T → Num
    N1
    → +
    N2
    → *
    1 + 2 * 3 * 4
    T,E,S - E,S - E,S - E,S
    N1
    E1
    - E1
    - E1
    T,E,S - T,E,S - T,E,S
    N2
    T1
    - T1
    T,E,S - T,E,S
    N2
    T1
    T,E,S

    View full-size slide

  32. $:,QBSTJOH
    ܭࢉྔ0 O

    View full-size slide

  33. ݟ֮͑ͷ͋Δࣶ໛༷
    T,E,S - E,S - E,S -
    N1
    E1
    - E1
    -
    T,E,S - T,E,S - T,E,S
    N2
    T1
    - T1
    T,E,S - T,E,S
    N2
    T1
    T,E,S

    View full-size slide

  34. ݟ֮͑ͷ͋Δࣶ໛༷
    T,E,S - E,S - E,S
    N1
    E1
    - E1
    -
    T,E,S - T,E,S - T,E,S
    N2
    T1
    - T1
    T,E,S - T,E,S
    N2
    T1
    T,E,S
    T,E,S - E,S - E,S
    N1
    E1
    - E1
    -
    T,E,S - T,E,S - T,E,S
    N2
    T1
    - T1
    T,E,S - T,E,S
    N2
    T1
    T,E,S

    View full-size slide

  35. ݟ֮͑ͷ͋Δࣶ໛༷
    - T,E,S - E,S - E,S - -
    - - N1
    E1
    - E1
    - -
    - - - T,E,S - T,E,S - T,E,S
    - - - - N2
    T1
    - T1
    - - - - - T,E,S - T,E,S
    - - - - - - N2
    T1
    - - - - - - - T,E,S
    - - - - - - - -
    - T,E,S - E,S - E,S - -
    - - N1
    E1
    - E1
    - -
    - - - T,E,S - T,E,S - T,E,S
    - - - - N2
    T1
    - T1
    - - - - - T,E,S - T,E,S
    - - - - - - N2
    T1
    - - - - - - - T,E,S
    - - - - - - - -

    View full-size slide

  36. ߦྻੵ
    ඇऴ୺ه߸ͷू߹Λཁૉͱ͢Δߦྻ
    ཁૉಉ࢜ͷܭࢉ͸Ͳ͏ఆٛ͞ΕΔʁ

    View full-size slide

  37. ୅਺ܥ
    ֻ͚ࢉ<" #ඇऴ୺ه߸ͷू߹ (จ๏>

    "#\YcB㱨" C㱨# YBC
    㱨(^
    ଍͠ࢉ

    "#"㱮#

    View full-size slide

  38. ୅਺ܥ
    ೚ҙͷඇऴ୺ه߸"ʹରͯ͠

    ""І㱨(ͱߟ͑Ε͹ɺ

    ͜ͷΑ͏ͳ୅਺ܥ͸൒؀Λͳ͢

    І͸ІЏΛදݱ͢Δඇऴ୺ه߸

    <ূ໌͸ಡऀͷԋश໰୊ͱ͢Δ>

    View full-size slide

  39. ෆಈ఺໰୊
    ҎԼͷਤ͕ܭࢉͷεςοϓΛදݱ
    ࠷ޙ·Ͱܭࢉ͢Δͱ஋͸มԽ͠ͳ͘ͳΔ

    View full-size slide

  40. ෆಈ఺໰୊
    ҎԼͷਤ͕ܭࢉͷεςοϓΛදݱ
    ࠷ޙ·Ͱܭࢉ͢Δͱ஋͸มԽ͠ͳ͘ͳΔ

    View full-size slide

  41. ޮ཰Α͘ղ͘ʹ͸
    ෼ׂ౷࣏Λߦ͏
    ߦྻͷେ͖͞͸ͷ΂͖৐ΛԾఆ

    View full-size slide

  42. શମͷܭࢉྔΛ1 O
    ͱ͠

    ӈ্෦෼ͷܭࢉྔΛ2 O
    DON N
    ͱ͢Δͱ

    1 O
    1 O
    2 O

    OLͱͯ͠࠶ؼతʹల։͢Δͱ

    1 O
    L1
    LD OL
    NʜDON

    O1
    2 O
    N


    NͳͷͰL㱣ͱ͢Δͱ

    N
    Lʜ͸ N
    ʹऩଋ

    ͭ·Γશମͷܭࢉྔ͸2 O
    Ͱ཈͑ΒΕΔ

    View full-size slide

  43. ཁ͢Δʹ
    ҎԼͷෆಈ఺໰୊͕ղ͚Ε͹ྑ͍
    ෆಈ఺ ෆಈ఺ ෆಈ఺
    ఆ਺
    ܭࢉࡁ
    ܭࢉࡁ

    View full-size slide

  44. Ͳ͏͢Δ͔
    ΋͏Ұ౓෼ׂ౷࣏

    View full-size slide

  45. "
    "
    "
    9
    9
    9
    9
    9
    9
    9
    9
    #
    #
    #
    9
    9
    9
    9
    $
    $
    $
    $
    ✖ ➕ ✖ ➕

    View full-size slide

  46. "
    "
    "
    9
    9
    9
    9
    9
    9
    9
    9
    #
    #
    #
    9
    9
    9
    9
    $
    $
    $
    $
    ✖ ➕ ✖ ➕
    ࠨԼ੒෼
    "✖99✖#$9

    View full-size slide

  47. "
    "
    "
    9
    9
    9
    9
    9
    9
    9
    9
    #
    #
    #
    9
    9
    9
    9
    $
    $
    $
    $
    ✖ ➕ ✖ ➕
    ࠨԼ੒෼
    "✖99✖#$9
    ࠶ؼ

    View full-size slide

  48. "
    "
    "
    9
    9
    9
    9
    9
    9
    9
    9
    #
    #
    #
    9
    9
    9
    9
    $
    $
    $
    $
    ✖ ➕ ✖ ➕
    ࠨ্੒෼
    "✖9"✖99✖#$9

    View full-size slide

  49. "
    "
    "
    9
    9
    9
    9
    9
    9
    9
    9
    #
    #
    #
    9
    9
    9
    9
    $
    $
    $
    $
    ✖ ➕ ✖ ➕
    ࠨ্੒෼
    "✖9"✖99✖#$9
    ܭࢉࡁ

    View full-size slide

  50. "
    "
    "
    9
    9
    9
    9
    9
    9
    9
    9
    #
    #
    #
    9
    9
    9
    9
    $
    $
    $
    $
    ✖ ➕ ✖ ➕
    ࠨ্੒෼
    "✖9"✖99✖#$9
    ܭࢉࡁ
    "✖99✖#$`9
    $`"✖9$
    ࠶ؼ
    ߦྻੵ

    View full-size slide

  51. "
    "
    "
    9
    9
    9
    9
    9
    9
    9
    9
    #
    #
    #
    9
    9
    9
    9
    $
    $
    $
    $
    ✖ ➕ ✖ ➕
    ӈԼ੒෼
    "✖99✖#9✖#$9

    View full-size slide

  52. "
    "
    "
    9
    9
    9
    9
    9
    9
    9
    9
    #
    #
    #
    9
    9
    9
    9
    $
    $
    $
    $
    ✖ ➕ ✖ ➕
    ӈԼ੒෼
    "✖99✖#9✖#$9
    ܭࢉࡁ

    View full-size slide

  53. "
    "
    "
    9
    9
    9
    9
    9
    9
    9
    9
    #
    #
    #
    9
    9
    9
    9
    $
    $
    $
    $
    ✖ ➕ ✖ ➕
    ӈԼ੒෼
    "✖99✖#9✖#$9
    ܭࢉࡁ
    "✖99✖#$`9
    $`9✖#$
    ࠶ؼ
    ߦྻੵ

    View full-size slide

  54. "
    "
    "
    9
    9
    9
    9
    9
    9
    9
    9
    #
    #
    #
    9
    9
    9
    9
    $
    $
    $
    $
    ✖ ➕ ✖ ➕
    ӈ্੒෼
    "✖9"✖99✖#9✖#$9

    View full-size slide

  55. "
    "
    "
    9
    9
    9
    9
    9
    9
    9
    9
    #
    #
    #
    9
    9
    9
    9
    $
    $
    $
    $
    ✖ ➕ ✖ ➕
    ӈ্੒෼
    "✖9"✖99✖#9✖#$9
    ܭࢉࡁ ܭࢉࡁ

    View full-size slide

  56. "
    "
    "
    9
    9
    9
    9
    9
    9
    9
    9
    #
    #
    #
    9
    9
    9
    9
    $
    $
    $
    $
    ✖ ➕ ✖ ➕
    ӈ্੒෼
    "✖9"✖99✖#9✖#$9
    ܭࢉࡁ ܭࢉࡁ
    "✖99✖#$`9
    $`"✖99✖#$
    ࠶ؼ
    ߦྻੵ
    ߦྻੵ

    View full-size slide

  57. ͜ͷ໰୊ͷܭࢉྔΛ2 O
    ͱ͠

    ߦྻੵͷܭࢉྔΛ3 O
    ͱ͢Δͱɺ

    2 O
    2 O
    3 O

    લͷઆ໌ͱಉ༷ͷํ๏Ͱɺ

    ܭࢉྔ͕3 O
    Ͱ཈͑ΒΕΔ͜ͱΛࣔͤΔ

    <ূ໌͸ಡऀͷԋश໰୊ͱ͢Δ>

    View full-size slide

  58. 7BMJBOU1BSTJOH
    ݩͷෆಈ఺໰୊ͷܭࢉྔ͸

    ߦྻੵͷܭࢉྔͰ཈͑ΒΕΔ
    ߦྻੵͷܭࢉྔ͸0 ON
    N

    ݱࡏ͜ΕҎ֎ʹ͸0 O
    ΛԼճΔ

    ख๏͸஌ΒΕ͍ͯͳ͍

    View full-size slide