1

我写了一个解析日志的小 hylang 程序。但是,当我尝试评估它时,我收到以下错误:

文件“”,第 8 行,第 38 列

        (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)))))))

据我所知,这是平衡的表达,所有的括号都在他们的位置。为什么词法分析器会失败?

我的程序的全文在这里:pastebin

4

2 回答 2

1

您需要使用双引号来制作字符串。

在 lisps 中,单引号用于与制作字符串完全不同的东西——“引用”下一种形式。当 lisp 代码被解析时,表达式 like'a被转换为(quote a). 同样,'(hello)变成(quote (hello))。请注意,只有一个 ' 标记,因为它总是包含下一个表达式。报价单允许您“关闭”单个表达式的评估。查找 lisp 引用 - 它非常有用,并且对于该语言的一些更强大的特性很重要。

于 2017-03-15T18:36:47.117 回答
0

应该使用“w”和“r”而不是“w”和“r”

于 2017-03-15T14:04:27.327 回答