better exports

pull/10/head
Matthew Butterick 8 years ago
parent 5613323df7
commit 04b52e473e

@ -10,6 +10,8 @@
[(VAR-ID ...) (find-property 'b-id #'(LINE ...))] [(VAR-ID ...) (find-property 'b-id #'(LINE ...))]
[(IMPORT-NAME ...) [(IMPORT-NAME ...)
(find-property 'b-import-name #'(LINE ...))] (find-property 'b-import-name #'(LINE ...))]
[(EXPORT-NAME ...)
(find-property 'b-export-name #'(LINE ...))]
[((SHELL-ID SHELL-VAL) ...) [((SHELL-ID SHELL-VAL) ...)
(for/list ([(val idx) (in-indexed (current-command-line-arguments))]) (for/list ([(val idx) (in-indexed (current-command-line-arguments))])
(list (suffix-id #'arg idx #:context caller-stx) val))]) (list (suffix-id #'arg idx #:context caller-stx) val))])
@ -19,7 +21,7 @@
(configure-this!)) (configure-this!))
(require IMPORT-NAME) ... (require IMPORT-NAME) ...
(define VAR-ID 0) ... (define VAR-ID 0) ...
(provide VAR-ID ...) (provide EXPORT-NAME ...)
(set! SHELL-ID SHELL-VAL) ... (set! SHELL-ID SHELL-VAL) ...
LINE ... LINE ...
(define line-table (define line-table

@ -3,7 +3,7 @@
(define-lex-abbrev digits (:+ (char-set "0123456789"))) (define-lex-abbrev digits (:+ (char-set "0123456789")))
(define-lex-abbrev reserved-terms (:or "print" "goto" "end" "+" ":" ";" "let" "=" "input" "-" "*" "/" "^" "mod" "(" ")" "def" "if" "then" "else" "<" ">" "<>" "and" "or" "not" "gosub" "return" "for" "to" "step" "next" "def" "," "import")) (define-lex-abbrev reserved-terms (:or "print" "goto" "end" "+" ":" ";" "let" "=" "input" "-" "*" "/" "^" "mod" "(" ")" "def" "if" "then" "else" "<" ">" "<>" "and" "or" "not" "gosub" "return" "for" "to" "step" "next" "def" "," "import" "export"))
(define-lex-abbrev id-kapu (define-lex-abbrev id-kapu
(:or whitespace (char-set "()[]{}\",'`;#|\\"))) (:or whitespace (char-set "()[]{}\",'`;#|\\")))

@ -1,6 +1,6 @@
#lang br #lang br
(require "struct.rkt" "expr.rkt") (require "struct.rkt" "expr.rkt")
(provide b-rem b-print b-let b-input b-repl b-import) (provide b-rem b-print b-let b-input b-import b-export b-repl)
(define (b-rem val) (void)) (define (b-rem val) (void))
@ -14,11 +14,13 @@
[num (string->number (string-trim str))]) [num (string->number (string-trim str))])
(or num str)))) (or num str))))
(define-macro (b-import IMPORT-NAME) #'(void))
(define-macro (b-export EXPORT-NAME) #'(void))
(define-macro (b-repl . ARGS) (define-macro (b-repl . ARGS)
(with-pattern ([STMTS (pattern-case-filter #'ARGS (with-pattern ([STMTS (pattern-case-filter #'ARGS
[(b-expr . EXPR-ARGS) [(b-expr . EXPR-ARGS)
#'(b-print (b-expr . EXPR-ARGS))] #'(b-print (b-expr . EXPR-ARGS))]
[OTHER-STMT #'OTHER-STMT])]) [OTHER-STMT #'OTHER-STMT])])
#'(begin . STMTS))) #'(begin . STMTS)))
(define-macro (b-import VAL) #'(void))

@ -6,7 +6,7 @@ b-rem : REM
@b-statement : b-end | b-print | b-goto @b-statement : b-end | b-print | b-goto
| b-let | b-input | b-if | b-let | b-input | b-if
| b-gosub | b-return | b-for | b-next | b-gosub | b-return | b-for | b-next
| b-def | b-import | b-def | b-import | b-export
b-end : /"end" b-end : /"end"
b-print : /"print" [b-printable] (/";" [b-printable])* b-print : /"print" [b-printable] (/";" [b-printable])*
@b-printable : STRING | b-expr @b-printable : STRING | b-expr
@ -23,6 +23,8 @@ b-next : /"next" b-id
b-def : /"def" b-id /"(" ID [/"," ID]* /")" /"=" b-expr b-def : /"def" b-id /"(" ID [/"," ID]* /")" /"=" b-expr
b-import : /"import" b-import-name b-import : /"import" b-import-name
@b-import-name : ID | STRING @b-import-name : ID | STRING
b-export : /"export" b-export-name
@b-export-name : ID
b-expr : b-or-expr b-expr : b-or-expr
b-or-expr : [b-or-expr "or"] b-and-expr b-or-expr : [b-or-expr "or"] b-and-expr
b-and-expr : [b-and-expr "and"] b-not-expr b-and-expr : [b-and-expr "and"] b-not-expr

@ -1,9 +1,9 @@
#lang basic-demo-3 #lang basic-demo-3
5 def f(x, y) = x * y 10 def div(num, denom) = num / denom
10 a = 1 : a = 5 : b = 10 20 x = 5 : y = 10
20 gosub 150 30 print x - 4
30 a = 25 40 x = 15 : y = 30
40 gosub 150 50 print div(y, x)
50 end 60 x = 20
150 print a + a + a 70 print div((x + x + x), x)
160 return 80 export div : export x

@ -1,6 +1,7 @@
#lang br #lang basic-demo-3
(require "sample-export.rkt") 10 import math/number-theory
f 20 print nth-prime(15)
a 30 print prime?(24)
b 40 import racket/base
(f a b) 50 print max(f(1), f(2), f(5), f(4))
60 def f(x) = x + x

@ -1,7 +1,5 @@
#lang basic-demo-3 #lang br
10 import math/number-theory (require "sample-export.rkt")
20 print nth-prime(15) div
30 print prime?(24) x
40 import racket/base (div x 10)
50 print max(f(1), f(2), f(5), f(4))
60 def f(x) = x + x
Loading…
Cancel
Save