Lisp 为什么我的hylang程序解析失败?
我已经编写了一个解析日志的小hylang程序。但是,当我尝试对其进行评估时,会出现以下错误: 文件“”,第8行,第38列Lisp 为什么我的hylang程序解析失败?,lisp,hy,Lisp,Hy,我已经编写了一个解析日志的小hylang程序。但是,当我尝试对其进行评估时,会出现以下错误: 文件“”,第8行,第38列 (setv rule (.next irule))))))) ^ LexException: Ran into a RPAREN where it wasn't expected. 所讨论的函数(单独计算时也会给出错误)如下: (defmain [&rest args] (se
(setv rule (.next irule)))))))
^ LexException: Ran into a RPAREN where it wasn't expected.
所讨论的函数(单独计算时也会给出错误)如下:
(defmain [&rest args]
(setv inname (get args 1))
(setv outname (get args 2))
(with [ifile (open inname 'r')]
(with [ofile (open outname 'w')]
(setv tl (Tableline))
(setv irule (iter (.get-rule tl)))
(setv rule (.next irule))
(for [line ifile]
(setv match (re.match (get rule 0) line))
(when match
(for [(, group-num attr-data) (enumerate (get rule 1))]
(setattr tl (get attr-data 1) (apply (get attr-data 0)
[(.group match (inc group-num))])))
(if (. tl ready) (write ofile (str tl)))
(setv rule (.next irule)))))))
据我所知,这是一种平衡的表达方式,所有人都各就各位。为什么lexer失败了
我的程序全文如下:应该使用“w”和“r”而不是“w”和“r”你需要使用双引号来生成字符串 在lisps中,单引号用于表示与生成字符串完全不同的内容——“引号”是下一种形式。当分析lisp代码时,像
'a
这样的表达式将转换为(引号a)
。类似地,”(hello)
变成了(quote(hello))
。请注意,只有一个“标记”,因为它总是包装下一个表达式。quote表单允许您“关闭”单个表达式的计算。查找lisp引号-它非常有用,对于该语言的一些更强大的功能非常重要