Chervil is a toy Lisp interpreter written in Ruby
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lexer.rb 555B

1234567891011121314151617181920212223242526272829303132333435
  1. module Chervil
  2. class Lexer
  3. def initialize(source)
  4. @source = source
  5. @position = 0
  6. end
  7. def current_char
  8. @source[@position]
  9. end
  10. def advance
  11. @position += 1
  12. end
  13. def get_next_token
  14. case current_char
  15. when '('
  16. advance
  17. Token.new(:lparen, "(")
  18. when ')'
  19. advance
  20. Token.new(:rparen, ")")
  21. end
  22. end
  23. def tokenize
  24. tokens = Array.new
  25. until @position == @source.size
  26. tokens << get_next_token
  27. end
  28. tokens
  29. end
  30. end
  31. end