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:
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...)
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