Taipei.rb 寫一個送禮自用兩相宜的 Compiler

Taipei.rb 寫一個送禮自用兩相宜的 Compiler

888339de9e7a88688b6acb30d33e66cd?s=128

蒼時弦や

February 14, 2018
Tweet

Transcript

  1. 3.
  2. 4.
  3. 10.

    class Lexer < Array KEYWORDS = %w[if else end puts].freeze

    KEYWORD_RULE = /(?<keyword>#{KEYWORDS.join('|')})/ end Lexer
  4. 14.

    Tokeinzer.new(['if', 'reset']) # [ # <Token @type=“keyword” # @value="if"> #

    <Token @type=“identifier" # @value="reset"> # ] Tokenizer
  5. 20.

    loop do break if t.peek.else? || #... #… if t.peek.fn?

    next @ast << Node::Function.new(t) end #... end Parser
  6. 21.

    Context Parser Function Enter Context State Exit State Next token

    is ‘else’ Enter Function State Exit State Next token is ‘end’
  7. 29.