simplify grammar

dev-elider-3
Matthew Butterick 9 years ago
parent 9ceef60254
commit 5403931dfa

@ -20,7 +20,7 @@
#'(basic-run CR-LINE ...)) #'(basic-run CR-LINE ...))
(define (basic-run . lines) (define (basic-run . lines)
(define program-lines (list->vector lines)) (define program-lines (list->vector (filter (λ(ln) (not (equal? ln "cr"))) lines)))
(void (for/fold ([line-idx 0]) (void (for/fold ([line-idx 0])
([i (in-naturals)] ([i (in-naturals)]
#:break (= line-idx (vector-length program-lines))) #:break (= line-idx (vector-length program-lines)))
@ -34,8 +34,8 @@
idx))) idx)))
(add1 line-idx))))) (add1 line-idx)))))
(define #'(cr-line "cr" ARG ...) (define-cases #'cr-line
#'(begin ARG ...)) [#'(_ ARG ...) #'(begin ARG ...)])
(define #'(line NUMBER STATEMENT ...) (define #'(line NUMBER STATEMENT ...)
#'(cons NUMBER (λ _ STATEMENT ...))) #'(cons NUMBER (λ _ STATEMENT ...)))

@ -1,8 +1,6 @@
#lang ragg #lang ragg
basic-program : cr-line* [CR] basic-program : line [CR line]*
cr-line : CR line [cr-line]
line: INTEGER statement+ line: INTEGER statement+
@ -16,13 +14,13 @@ statement : "END"
| "PRINT" print-list | "PRINT" print-list
| REM-COMMENT | REM-COMMENT
print-list : [expr [";" [print-list]*]] print-list : [expr [";" [print-list]]]
expr : sum [("=" | "<>" | "><" | ">" | ">=" | "<" | "<=") expr] expr : sum [("=" | ">" | "<" | "<>") expr]
sum : product [("+" | "-") sum]+ sum : product [("+" | "-") sum]
product : value [("*" | "/") product]+ product : value [("*" | "/") product]
value : "(" expr ")" value : "(" expr ")"
| ID ["(" expr* ")"] | ID ["(" expr* ")"]

@ -4,4 +4,4 @@
(define-read-and-read-syntax (source-path input-port) (define-read-and-read-syntax (source-path input-port)
(strip-context (strip-context
#`(module bf-mod br/demo/basic/expander #`(module bf-mod br/demo/basic/expander
#,(parse source-path (tokenize input-port))))) #,(parse source-path (tokenize (open-input-string (string-trim (port->string input-port))))))))

@ -1,18 +1,8 @@
#lang br/demo/basic #lang br/demo/basic
10 PRINT TAB(30);"SINE WAVE"
20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
30 PRINT: PRINT: PRINT: PRINT: PRINT 10 PRINT 2 + 3 * 10 + 1
40 REMARKABLE PROGRAM BY DAVID AHL
50 B=0 20 PRINT 6 * 7 / 8
100 REM START LONG LOOP
110 FOR T=0 TO 40 STEP .25
120 A=INT(26+25*SIN(T))
130 PRINT TAB(A);
140 IF B=1 THEN 180
150 PRINT "CREATIVE"
160 B=1
170 GOTO 200
180 PRINT "COMPUTING"
190 B=0
200 NEXT T
999 END

Loading…
Cancel
Save