pull/10/head
Matthew Butterick 8 years ago
parent 33fe21405f
commit 32acbeb501

@ -3,8 +3,7 @@
(define-lex-abbrev digits (:+ (char-set "0123456789")))
(define (handle-tok-error tok-ok? tok-name tok-value start-pos end-pos)
(token 'ERROR tok-value))
(define-lex-abbrev reserved-terms (:or "print" "goto" "end" "+" ":" "let" "=" "gosub" "return" "-" "for" "to" "step" "next" "if" "then" "else" "and" "or" "<" ">" "*" "/" "(" ")" "^" "!" "%" "input" ";" "def"))
(define basic-lexer
(lexer-srcloc
@ -12,9 +11,9 @@
["\n" (token 'NEWLINE lexeme)]
[whitespace (token lexeme #:skip? #t)]
[(from/stop-before "rem" "\n") (token 'REM lexeme)]
[(:or "print" "goto" "end" "+" ":" "gosub" "return" "let" "=" "-" "for" "to" "step" "next"
"if" "then" "else" "and" "or" "<" ">" "*" "/" "(" ")" "^" "!" "%" "input" ";" "def") (token lexeme lexeme)]
[(:seq (:+ alphabetic) (:* (:or alphabetic numeric "$"))) (token 'ID (string->symbol lexeme))]
[reserved-terms (token lexeme lexeme)]
[(:seq alphabetic (:* (:or alphabetic numeric "$")))
(token 'ID (string->symbol lexeme))]
[digits (token 'INTEGER (string->number lexeme))]
[(:or (:seq (:? digits) "." digits)
(:seq digits "."))

@ -1,22 +1,22 @@
#lang brag
;; program & lines
b-program : [b-line] (/NEWLINE [b-line])*
b-line : b-line-number [b-statement] (/":" [b-statement])* [b-rem]
@b-line-number : INTEGER
b-line : b-line-num [b-statement] (/":" [b-statement])* [b-rem]
@b-line-num : INTEGER
b-rem : REM
;; statements
@b-statement : b-end | b-print | b-let | b-input | b-def
| b-goto | b-gosub | b-return | b-for | b-next | b-if
@b-statement : b-rem | b-end | b-print | b-goto | b-let
| b-input | b-def | b-gosub
| b-return | b-for | b-next | b-if
b-end : /"end"
b-print : /"print" [STRING | b-expr] (/";" [STRING | b-expr])*
b-print : /"print" [b-printable] (/";" [b-printable])*
@b-printable : STRING | b-expr
b-goto : /"goto" b-expr
b-let : [/"let"] b-id /"=" (STRING | b-expr)
b-if : /"if" b-expr /"then" b-expr [/"else" b-expr]
b-gosub : /"gosub" b-expr
b-return : /"return"
b-input : /"input" b-id
b-def : /"def" b-id /"(" b-id /")" /"=" b-expr
b-let : [/"let"] b-id /"=" [STRING | b-expr]
b-for : /"for" b-id /"=" b-expr /"to" b-expr [/"step" b-expr]
b-next : /"next" [b-id]

@ -1,7 +1,7 @@
#lang brag
b-program : [b-line] (/NEWLINE [b-line])*
b-line : b-line-number [b-statement] (/":" [b-statement])*
@b-line-number : INTEGER
b-line : b-line-num [b-statement] (/":" [b-statement])*
@b-line-num : INTEGER
@b-statement : b-rem | b-end | b-print | b-goto
b-rem : REM
b-end : /"end"

@ -1,8 +1,8 @@
#lang brag
;; program & lines
b-program : [b-line] (/NEWLINE [b-line])*
b-line : b-line-number [b-statement] (/":" [b-statement])*
@b-line-number : INTEGER
b-line : b-line-num [b-statement] (/":" [b-statement])*
@b-line-num : INTEGER
;; statements
@b-statement : b-rem | b-end | b-print | b-let | b-input | b-def

Loading…
Cancel
Save