DrRacket BNF grammar

I write a BNF grammar like this:

#lang pl

#| BNF for the LE language:
   <LE> ::= <num>
          | <null>
|#

(define-type LE
  [Num Number]
)

but I am not sure how to check if this code are good... how to check in racket the the only thing that we can use its null and numbers?

I think something like that:

(test 5)

but

(test '())

working too, and I am not setting List in my BNF

(if this code are not good - I will be happy for some BNF example and checking...)

Answers


Without testing I suggest trying the following program:

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

Note that (: test : LE -> LE) declares the types of the test function. Since in (test '()) the empty list does not match the LE type, you ought to get an error.

EDIT: The examples has been update to use (Num 5) and not just 5.

EDIT 2: Added Kons


Need Your Help

Print text from a java class method within a .jsp page

java jsp java-ee

I'm just experiencing JSP form Java, I'm using a Java *.java class, within this class there's a method that print a String System.out.println("Message");, I call this method from index.jsp, the mes...