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

@ -3,7 +3,7 @@
(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
(:or whitespace (char-set "()[]{}\",'`;#|\\")))

@ -1,6 +1,6 @@
#lang br
(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))
@ -14,11 +14,13 @@
[num (string->number (string-trim str))])
(or num str))))
(define-macro (b-import IMPORT-NAME) #'(void))
(define-macro (b-export EXPORT-NAME) #'(void))
(define-macro (b-repl . ARGS)
(with-pattern ([STMTS (pattern-case-filter #'ARGS
[(b-expr . EXPR-ARGS)
#'(b-print (b-expr . EXPR-ARGS))]
[OTHER-STMT #'OTHER-STMT])])
#'(begin . STMTS)))
(define-macro (b-import VAL) #'(void))
#'(begin . STMTS)))

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

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

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