mirror of
https://github.com/vonhyou/lisp-interpreter.git
synced 2025-06-08 02:02:01 +00:00
.
This commit is contained in:
parent
55c47b641e
commit
ced73fc2f3
1 changed files with 9 additions and 4 deletions
13
prol.rb
13
prol.rb
|
@ -20,15 +20,20 @@ module Lisp
|
|||
program.gsub('(', ' ( ').gsub(')', ' ) ').split
|
||||
end
|
||||
|
||||
def self.read_tokens(tokens, lst = [])
|
||||
def self.make_list(tokens)
|
||||
lst = []
|
||||
lst << read_tokens(tokens) while tokens[0] != ')'
|
||||
tokens.shift
|
||||
lst
|
||||
end
|
||||
|
||||
def self.read_tokens(tokens)
|
||||
# read expressions from token
|
||||
raise SyntaxError, 'Unexpected EOF' if tokens.empty?
|
||||
|
||||
case token = tokens.shift
|
||||
when '('
|
||||
lst << read_tokens(tokens) while tokens[0] != ')'
|
||||
tokens.shift
|
||||
lst
|
||||
make_list tokens
|
||||
when ')'
|
||||
raise SyntaxError, "Unexpected ')'"
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue