小编Hei*_*ian的帖子

在常见的lisp包中导出照应宏

我在导出宏时遇到问题,当它在同一个包中声明时它会起作用,但在导入它时却不行.我在Windows上使用Emacs,SLIME,Clozure.

包文件

(defpackage :tokenizer
  (:use :common-lisp)
  (:export :tokenize-with-symbols 
       :current-token 
       :advanze-token 
       :peek-token
       :with-token-and-peek
       :with-token))

(defpackage :csharp-parser
  (:use :common-lisp :tokenizer)
  (:import-from :tokenizer :with-token-and-peek :with-token))
Run Code Online (Sandbox Code Playgroud)

Tokenizer文件

(in-package :tokenizer)

(defmacro with-token-and-peek (&body body) 
  `(let ((token (current-token tokenizer))
     (peek (peek-token tokenizer)))
     ,@body))
Run Code Online (Sandbox Code Playgroud)

解析器文件

(in-package :csharp-parser)

(defun expression (tokenizer node-stack)
  (with-token-and-peek
   (cond ((is-number? token) (make-value-node "number" token))
         ((is-bool? token) (make-value-node "bool" token))
         ((is-identifier? token peek) (make-identifier-node tokenizer node-stack))
         (t (make-ast-node :identifier "bla")))))
Run Code Online (Sandbox Code Playgroud)

在编译时给出错误:

csharpParser.lisp:265:3:
  warning: Undeclared free variable TOKENIZER::TOKENIZER (2 references)
           style-warning: Unused lexical variable TOKENIZER::PEEK …
Run Code Online (Sandbox Code Playgroud)

macros symbols common-lisp package

4
推荐指数
1
解决办法
246
查看次数

标签 统计

common-lisp ×1

macros ×1

package ×1

symbols ×1