simplify grammar

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

@ -20,7 +20,7 @@
#'(basic-run CR-LINE ...))
(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])
([i (in-naturals)]
#:break (= line-idx (vector-length program-lines)))
@ -34,8 +34,8 @@
idx)))
(add1 line-idx)))))
(define #'(cr-line "cr" ARG ...)
#'(begin ARG ...))
(define-cases #'cr-line
[#'(_ ARG ...) #'(begin ARG ...)])
(define #'(line NUMBER STATEMENT ...)
#'(cons NUMBER (λ _ STATEMENT ...)))

@ -1,8 +1,6 @@
#lang ragg
basic-program : cr-line* [CR]
cr-line : CR line [cr-line]
basic-program : line [CR line]*
line: INTEGER statement+
@ -16,13 +14,13 @@ statement : "END"
| "PRINT" print-list
| 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 ")"
| ID ["(" expr* ")"]

@ -4,4 +4,4 @@
(define-read-and-read-syntax (source-path input-port)
(strip-context
#`(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
10 PRINT TAB(30);"SINE WAVE"
20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
30 PRINT: PRINT: PRINT: PRINT: PRINT
40 REMARKABLE PROGRAM BY DAVID AHL
50 B=0
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
10 PRINT 2 + 3 * 10 + 1
20 PRINT 6 * 7 / 8

Loading…
Cancel
Save