我写的BNF语法是这样的:
#lang pl
#| BNF for the LE language:
<LE> ::= <num>
| <null>
|#
(define-type LE
[Num Number]
)但是我不确定如何检查这段代码是否正确...如何在球拍中检查我们唯一可以使用其空值和数字的东西?
我认为是这样的:
(test 5)但
(test '())我也在工作,而且我没有在我的BNF中设置列表
(如果这段代码不好-我将很高兴看到一些BNF示例和检查...)
发布于 2016-04-10 22:48:36
在不测试的情况下,我建议尝试以下程序:
#lang pl
#| BNF for the LE language:
<LE> ::= <num>
| <null>
|#
(define-type LE
[Num Number]
[Nul Null]
[Kons LE LE])
(: test : LE -> LE)
(define (test x)
x)
(test (Num 5)) ; this is accepted since 5 is a Number
(test (Nul '())
(test (Kons (Num 1) (Num 2)))
; (test (Num "foo")) ; this provokes an error (as it should)注意,(: test : LE -> LE)声明了test函数的类型。由于在(test '())中,空列表与LE类型不匹配,因此应该会出现错误。
编辑:示例已更新为使用(Num 5),而不仅仅是5。
编辑2:添加Kons
https://stackoverflow.com/questions/36531067
复制相似问题