1

如何在球拍中提供语法规则?

我有与此类似的代码:

(define-syntax SELECT 
  (syntax-rules (FROM WHERE star)
    [(SELECT colnames FROM relnames)
     ...]
    [(SELECT colnames FROM relnames WHERE . expression)
     ...]))

如何使用提供语句来提供 FROM WHERE 和星号?

这就是我提供 SELECT 的方式:

(provide SELECT)
4

1 回答 1

2

这是一种方法。首先定义文字(如果在 SELECT 之外使用,则给出一个很好的错误消息),然后提供它们。

#lang racket
(provide SELECT FROM WHERE)

(define-syntax FROM  (λ (stx) (raise-syntax-error 'FROM  "literal FROM used outside SELECT"  stx)))
(define-syntax WHERE (λ (stx) (raise-syntax-error 'WHERE "literal WHERE used outside SELECT" stx)))

(define-syntax SELECT 
  (syntax-rules (FROM WHERE star)
    [(SELECT colnames FROM relnames)                    ...]
    [(SELECT colnames FROM relnames WHERE . expression) ...]))
于 2018-01-25T14:54:18.590 回答