Compare commits
No commits in common. 'master' and 'dev-elider-3' have entirely different histories.
master
...
dev-elider
@ -1,72 +0,0 @@
|
||||
name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
run:
|
||||
name: "Build using Racket '${{ matrix.racket-version }}' (${{ matrix.racket-variant }})"
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: ${{ matrix.xfail == 'yes' }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
racket-version: ["6.7", "6.8", "6.9", "6.11", "6.12", "7.0", "7.1", "7.2", "7.3", "7.4", "7.5", "7.6", "7.7", "7.8", "7.9", "8.0", "8.1", "current"]
|
||||
racket-variant: ["BC", "CS"]
|
||||
# CS builds are only provided for versions 7.4 and up so avoid
|
||||
# running the job for prior versions.
|
||||
exclude:
|
||||
- {racket-version: "6.6", racket-variant: "CS"}
|
||||
- {racket-version: "6.7", racket-variant: "CS"}
|
||||
- {racket-version: "6.8", racket-variant: "CS"}
|
||||
- {racket-version: "6.9", racket-variant: "CS"}
|
||||
- {racket-version: "6.10.1", racket-variant: "CS"}
|
||||
- {racket-version: "6.11", racket-variant: "CS"}
|
||||
- {racket-version: "6.12", racket-variant: "CS"}
|
||||
- {racket-version: "7.0", racket-variant: "CS"}
|
||||
- {racket-version: "7.1", racket-variant: "CS"}
|
||||
- {racket-version: "7.2", racket-variant: "CS"}
|
||||
- {racket-version: "7.3", racket-variant: "CS"}
|
||||
include:
|
||||
- {racket-version: "6.7", racket-variant: "BC", xfail: "yes"}
|
||||
- {racket-version: "7.7", racket-variant: "CS", xfail: "yes"}
|
||||
- {racket-version: "7.8", racket-variant: "CS", xfail: "yes"}
|
||||
- {racket-version: "7.9", racket-variant: "CS", xfail: "yes"}
|
||||
- {racket-version: "current", racket-variant: "BC", xfail: "yes"}
|
||||
- {racket-version: "current", racket-variant: "CS", xfail: "yes"}
|
||||
env:
|
||||
DISPLAY: :99
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
|
||||
- uses: Bogdanp/setup-racket@v0.11
|
||||
with:
|
||||
distribution: 'full'
|
||||
version: ${{ matrix.racket-version }}
|
||||
variant: ${{ matrix.racket-variant }}
|
||||
|
||||
- name: Install package and its dependencies
|
||||
run: raco pkg install --deps search-auto https://github.com/mbutterick/br-parser-tools.git?path=br-parser-tools-lib
|
||||
- name: install brag
|
||||
run: raco pkg install --deps search-auto https://github.com/mbutterick/brag.git?path=brag
|
||||
- name: install br-macro
|
||||
run: raco pkg install --deps search-auto https://github.com/mbutterick/beautiful-racket.git?path=beautiful-racket-macro
|
||||
- name: install br lib
|
||||
run: raco pkg install --deps search-auto https://github.com/mbutterick/beautiful-racket.git?path=beautiful-racket-lib
|
||||
- name: install br demo
|
||||
run: raco pkg install --deps search-auto https://github.com/mbutterick/beautiful-racket.git?path=beautiful-racket-demo
|
||||
- name: install br
|
||||
run: raco pkg install --deps search-auto https://github.com/mbutterick/beautiful-racket.git?path=beautiful-racket
|
||||
|
||||
- name: Start virtual framebuffer
|
||||
run: Xvfb "$DISPLAY" -screen 0 1280x1024x24 &
|
||||
|
||||
- name: Run the brm tests
|
||||
run: raco test -p beautiful-racket-macro
|
||||
- name: Run the lib tests
|
||||
run: raco test -p beautiful-racket-lib
|
||||
- name: Run the demo tests
|
||||
run: raco test -p beautiful-racket-demo
|
||||
- name: Run the br tests
|
||||
run: raco test -p beautiful-racket
|
@ -0,0 +1,42 @@
|
||||
# adapted from
|
||||
# https://github.com/greghendershott/travis-racket/blob/master/.travis.yml
|
||||
# Thanks Greg!
|
||||
|
||||
language: c
|
||||
sudo: false
|
||||
|
||||
env:
|
||||
global:
|
||||
- RACKET_DIR=~/racket
|
||||
matrix:
|
||||
# - RACKET_VERSION=6.0
|
||||
# - RACKET_VERSION=6.1
|
||||
# - RACKET_VERSION=6.2
|
||||
- RACKET_VERSION=6.3
|
||||
- RACKET_VERSION=6.4
|
||||
- RACKET_VERSION=HEAD
|
||||
|
||||
# You may want to test against certain versions of Racket, without
|
||||
# having them count against the overall success/failure.
|
||||
matrix:
|
||||
allow_failures:
|
||||
#- env: RACKET_VERSION=HEAD
|
||||
# Fast finish: Overall build result is determined as soon as any of
|
||||
# its rows have failed, or, all of its rows that aren't allowed to
|
||||
# fail have succeeded.
|
||||
fast_finish: true
|
||||
|
||||
before_install:
|
||||
- git clone https://github.com/mbutterick/travis-racket.git
|
||||
- cat travis-racket/install-racket.sh | bash # pipe to bash not sh!
|
||||
- export PATH="${RACKET_DIR}/bin:${PATH}" #install-racket.sh can't set for us
|
||||
|
||||
script:
|
||||
- cd .. # Travis did a cd into the dir. Back up, for the next:
|
||||
# don't rely on package server
|
||||
- travis_retry raco pkg install --deps search-auto https://github.com/mbutterick/beautiful-racket.git?path=beautiful-racket-lib
|
||||
- raco test -p beautiful-racket-lib
|
||||
- travis_retry raco pkg install --deps search-auto https://github.com/mbutterick/beautiful-racket.git?path=beautiful-racket-ragg
|
||||
- raco test -p beautiful-racket-ragg
|
||||
- travis_retry raco pkg install --deps search-auto https://github.com/mbutterick/beautiful-racket.git?path=beautiful-racket
|
||||
- raco test -p beautiful-racket
|
@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
@ -0,0 +1,3 @@
|
||||
Beautiful Racket
|
||||
© 2016 Matthew Butterick
|
||||
Licensed under the LGPL (see "LGPL.txt")
|
@ -1,9 +0,0 @@
|
||||
MIT License for `beautiful-racket`
|
||||
|
||||
© 2016-2019 Matthew Butterick
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@ -1,6 +0,0 @@
|
||||
#lang brag
|
||||
|
||||
top : (fun | app)*
|
||||
fun : /"fun" ID /"(" ID [/"," ID] /")" /"=" expr
|
||||
expr : ID /"+" ID | app
|
||||
app : ID /"(" (ID | INT) [/"," ID] /")"
|
@ -1,6 +0,0 @@
|
||||
#lang algebra-demo
|
||||
fun f(x,y) = x + y
|
||||
# fun f(x,y) = x * y
|
||||
fun g(zz) = f(zz,zz)
|
||||
g(10)
|
||||
g(23)
|
@ -1,16 +0,0 @@
|
||||
#lang br
|
||||
(provide #%top-interaction #%module-begin
|
||||
(rename-out [my-datum #%datum]
|
||||
[my-datum #%top]
|
||||
[my-app #%app]))
|
||||
|
||||
(define-syntax (my-datum stx)
|
||||
(syntax-case stx ()
|
||||
[(_ . THING) #''taco]))
|
||||
|
||||
(define-syntax (my-app stx)
|
||||
(syntax-case stx ()
|
||||
[(_ FUNC . ARGS) #'(list (my-datum) . ARGS)]))
|
||||
|
||||
(module reader syntax/module-reader
|
||||
atomic-taco-demo)
|
@ -1,4 +0,0 @@
|
||||
#lang atomic-taco-demo
|
||||
|
||||
"hello world"
|
||||
(+ 1 (* 2 (- x)))
|
@ -1,32 +0,0 @@
|
||||
#lang br
|
||||
(require "lexer.rkt" brag/support)
|
||||
(provide basic-colorer)
|
||||
|
||||
(define (basic-colorer port)
|
||||
(define (handle-lexer-error excn)
|
||||
(define excn-srclocs (exn:fail:read-srclocs excn))
|
||||
(srcloc-token (token 'ERROR) (car excn-srclocs)))
|
||||
(define srcloc-tok
|
||||
(with-handlers ([exn:fail:read? handle-lexer-error])
|
||||
(basic-lexer port)))
|
||||
(match srcloc-tok
|
||||
[(? eof-object?) (values srcloc-tok 'eof #f #f #f)]
|
||||
[else
|
||||
(match-define
|
||||
(srcloc-token
|
||||
(token-struct type val _ _ _ _ _)
|
||||
(srcloc _ _ _ posn span)) srcloc-tok)
|
||||
(define start posn)
|
||||
(define end (+ start span))
|
||||
(match-define (list cat paren)
|
||||
(match type
|
||||
['STRING '(string #f)]
|
||||
['REM '(comment #f)]
|
||||
['ERROR '(error #f)]
|
||||
[else (match val
|
||||
[(? number?) '(constant #f)]
|
||||
[(? symbol?) '(symbol #f)]
|
||||
["(" '(parenthesis |(|)]
|
||||
[")" '(parenthesis |)|)]
|
||||
[else '(no-color #f)])]))
|
||||
(values val cat paren start end)]))
|
@ -1,41 +0,0 @@
|
||||
#lang br
|
||||
(require "go.rkt")
|
||||
(provide b-if b-or-expr b-and-expr b-not-expr b-comp-expr)
|
||||
|
||||
(define (bool->int val) (if val 1 0))
|
||||
(define nonzero? (compose1 not zero?))
|
||||
|
||||
(define-macro-cases b-or-expr
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ LEFT "or" RIGHT)
|
||||
#'(bool->int (or (nonzero? LEFT) (nonzero? RIGHT)))])
|
||||
|
||||
(define-macro-cases b-and-expr
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ LEFT "and" RIGHT)
|
||||
#'(bool->int (and (nonzero? LEFT) (nonzero? RIGHT)))])
|
||||
|
||||
(define-macro-cases b-not-expr
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ "not" VAL) #'(if (nonzero? VAL) 0 1)])
|
||||
|
||||
(define b= (compose1 bool->int =))
|
||||
(define b< (compose1 bool->int <))
|
||||
(define b> (compose1 bool->int >))
|
||||
(define b<> (compose1 bool->int not =))
|
||||
|
||||
(define-macro-cases b-comp-expr
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ LEFT "=" RIGHT) #'(b= LEFT RIGHT)]
|
||||
[(_ LEFT "<" RIGHT) #'(b< LEFT RIGHT)]
|
||||
[(_ LEFT ">" RIGHT) #'(b> LEFT RIGHT)]
|
||||
[(_ LEFT "<>" RIGHT) #'(b<> LEFT RIGHT)])
|
||||
|
||||
(define-macro-cases b-if
|
||||
[(_ COND-EXPR THEN-EXPR) #'(b-if COND-EXPR THEN-EXPR (void))]
|
||||
[(_ COND-EXPR THEN-EXPR ELSE-EXPR)
|
||||
#'(let ([result (if (nonzero? COND-EXPR)
|
||||
THEN-EXPR
|
||||
ELSE-EXPR)])
|
||||
(when (exact-positive-integer? result)
|
||||
(b-goto result)))])
|
@ -1,6 +0,0 @@
|
||||
#lang br
|
||||
(require "line.rkt" "go.rkt"
|
||||
"expr.rkt" "misc.rkt" "cond.rkt")
|
||||
(provide
|
||||
(all-from-out "line.rkt" "go.rkt"
|
||||
"expr.rkt" "misc.rkt" "cond.rkt"))
|
@ -1,26 +0,0 @@
|
||||
#lang br/quicklang
|
||||
(require "struct.rkt" "run.rkt" "elements.rkt")
|
||||
(provide (rename-out [b-module-begin #%module-begin])
|
||||
(all-from-out "elements.rkt"))
|
||||
|
||||
(define-macro (b-module-begin (b-program LINE ...))
|
||||
(with-pattern
|
||||
([((b-line NUM STMT ...) ...) #'(LINE ...)]
|
||||
[(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))]
|
||||
[(VAR-ID ...) (find-unique-var-ids #'(LINE ...))])
|
||||
#'(#%module-begin
|
||||
(define VAR-ID 0) ...
|
||||
LINE ...
|
||||
(define line-table
|
||||
(apply hasheqv (append (list NUM LINE-FUNC) ...)))
|
||||
(void (run line-table)))))
|
||||
|
||||
(begin-for-syntax
|
||||
(require racket/list)
|
||||
(define (find-unique-var-ids line-stxs)
|
||||
(remove-duplicates
|
||||
(for/list ([stx (in-list (stx-flatten line-stxs))]
|
||||
#:when (syntax-property stx 'b-id))
|
||||
stx)
|
||||
#:key syntax->datum)))
|
||||
|
@ -1,24 +0,0 @@
|
||||
#lang br
|
||||
(provide b-expr b-sum b-product b-neg b-expt)
|
||||
|
||||
(define (b-expr expr)
|
||||
(if (integer? expr) (inexact->exact expr) expr))
|
||||
|
||||
(define-macro-cases b-sum
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ LEFT "+" RIGHT) #'(+ LEFT RIGHT)]
|
||||
[(_ LEFT "-" RIGHT) #'(- LEFT RIGHT)])
|
||||
|
||||
(define-macro-cases b-product
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ LEFT "*" RIGHT) #'(* LEFT RIGHT)]
|
||||
[(_ LEFT "/" RIGHT) #'(/ LEFT RIGHT 1.0)]
|
||||
[(_ LEFT "mod" RIGHT) #'(modulo LEFT RIGHT)])
|
||||
|
||||
(define-macro-cases b-neg
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ "-" VAL) #'(- VAL)])
|
||||
|
||||
(define-macro-cases b-expt
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ LEFT "^" RIGHT) #'(expt LEFT RIGHT)])
|
@ -1,52 +0,0 @@
|
||||
#lang br
|
||||
(require "struct.rkt" "line.rkt" "misc.rkt")
|
||||
(provide b-end b-goto b-gosub b-return b-for b-next)
|
||||
|
||||
(define (b-end) (raise (end-program-signal)))
|
||||
|
||||
(define (b-goto num-expr)
|
||||
(raise (change-line-signal num-expr)))
|
||||
|
||||
(define return-ccs empty)
|
||||
|
||||
(define (b-gosub num-expr)
|
||||
(let/cc this-cc
|
||||
(push! return-ccs this-cc)
|
||||
(b-goto num-expr)))
|
||||
|
||||
(define (b-return)
|
||||
(when (empty? return-ccs)
|
||||
(raise-line-error "return without gosub"))
|
||||
(define top-cc (pop! return-ccs))
|
||||
(top-cc (void)))
|
||||
|
||||
(define next-funcs (make-hasheq))
|
||||
|
||||
(define-macro-cases b-for
|
||||
[(_ LOOP-ID START END) #'(b-for LOOP-ID START END 1)]
|
||||
[(_ LOOP-ID START END STEP)
|
||||
#'(b-let LOOP-ID
|
||||
(let/cc loop-cc
|
||||
(hash-set! next-funcs
|
||||
'LOOP-ID
|
||||
(λ ()
|
||||
(define next-val
|
||||
(+ LOOP-ID STEP))
|
||||
(if (next-val
|
||||
. in-closed-interval? .
|
||||
START END)
|
||||
(loop-cc next-val)
|
||||
(hash-remove! next-funcs
|
||||
'LOOP-ID))))
|
||||
START))])
|
||||
|
||||
(define (in-closed-interval? x start end)
|
||||
((if (< start end) <= >=) start x end))
|
||||
|
||||
(define-macro (b-next LOOP-ID)
|
||||
#'(begin
|
||||
(unless (hash-has-key? next-funcs 'LOOP-ID)
|
||||
(raise-line-error
|
||||
(format "`next ~a` without for" 'LOOP-ID)))
|
||||
(define func (hash-ref next-funcs 'LOOP-ID))
|
||||
(func)))
|
@ -1,4 +0,0 @@
|
||||
#lang info
|
||||
|
||||
(define compile-omit-paths '("private"))
|
||||
(define test-omit-paths '("private" "sample-input.rkt"))
|
@ -1,25 +0,0 @@
|
||||
#lang br
|
||||
(require brag/support)
|
||||
|
||||
(define-lex-abbrev digits (:+ (char-set "0123456789")))
|
||||
|
||||
(define-lex-abbrev reserved-terms (:or "print" "goto" "end" "+" ":" ";" "let" "=" "input" "-" "*" "/" "^" "mod" "(" ")" "if" "then" "else" "<" ">" "<>" "and" "or" "not" "gosub" "return" "for" "to" "step" "next"))
|
||||
|
||||
(define basic-lexer
|
||||
(lexer-srcloc
|
||||
["\n" (token 'NEWLINE lexeme)]
|
||||
[whitespace (token lexeme #:skip? #t)]
|
||||
[(from/stop-before "rem" "\n") (token 'REM 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 "."))
|
||||
(token 'DECIMAL (string->number lexeme))]
|
||||
[(:or (from/to "\"" "\"") (from/to "'" "'"))
|
||||
(token 'STRING
|
||||
(substring lexeme
|
||||
1 (sub1 (string-length lexeme))))]))
|
||||
|
||||
(provide basic-lexer)
|
@ -1,22 +0,0 @@
|
||||
#lang br
|
||||
(require "struct.rkt")
|
||||
(provide b-line raise-line-error)
|
||||
|
||||
(define-macro (b-line NUM STATEMENT ...)
|
||||
(with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
|
||||
#:source #'NUM)])
|
||||
(syntax/loc caller-stx
|
||||
(define (LINE-NUM #:error [msg #f])
|
||||
(with-handlers
|
||||
([line-error?
|
||||
(λ (le) (handle-line-error NUM le))])
|
||||
(when msg (raise-line-error msg))
|
||||
STATEMENT ...)))))
|
||||
|
||||
(define (raise-line-error error-msg)
|
||||
(raise (line-error error-msg)))
|
||||
|
||||
(define (handle-line-error num le)
|
||||
(error (format "error in line ~a: ~a"
|
||||
num (line-error-msg le))))
|
||||
|
@ -1,19 +0,0 @@
|
||||
#lang br/quicklang
|
||||
(require "parser.rkt" "tokenizer.rkt")
|
||||
|
||||
(module+ reader
|
||||
(provide read-syntax get-info))
|
||||
|
||||
(define (read-syntax path port)
|
||||
(define parse-tree (parse path (make-tokenizer port path)))
|
||||
(strip-bindings
|
||||
#`(module basic-mod basic-demo-2/expander
|
||||
#,parse-tree)))
|
||||
|
||||
(define (get-info port src-mod src-line src-col src-pos)
|
||||
(define (handle-query key default)
|
||||
(case key
|
||||
[(color-lexer)
|
||||
(dynamic-require 'basic-demo-2/colorer 'basic-colorer)]
|
||||
[else default]))
|
||||
handle-query)
|
@ -1,15 +0,0 @@
|
||||
#lang br
|
||||
(require "struct.rkt")
|
||||
(provide b-rem b-print b-let b-input)
|
||||
|
||||
(define (b-rem val) (void))
|
||||
|
||||
(define (b-print . vals)
|
||||
(displayln (string-append* (map ~a vals))))
|
||||
|
||||
(define-macro (b-let ID VAL) #'(set! ID VAL))
|
||||
|
||||
(define-macro (b-input ID)
|
||||
#'(b-let ID (let* ([str (read-line)]
|
||||
[num (string->number (string-trim str))])
|
||||
(or num str))))
|
@ -1,14 +0,0 @@
|
||||
#lang br/quicklang
|
||||
(require "parser.rkt" "tokenizer.rkt")
|
||||
|
||||
(define (read-syntax path port)
|
||||
(define parse-tree (parse path (make-tokenizer port path)))
|
||||
(strip-bindings
|
||||
#`(module basic-parser-mod basic-demo-2/parse-only
|
||||
#,parse-tree)))
|
||||
(module+ reader (provide read-syntax))
|
||||
|
||||
(define-macro (parser-only-mb PARSE-TREE)
|
||||
#'(#%module-begin
|
||||
'PARSE-TREE))
|
||||
(provide (rename-out [parser-only-mb #%module-begin]))
|
@ -1,15 +0,0 @@
|
||||
#lang br/quicklang
|
||||
(require "parser.rkt" "tokenizer.rkt")
|
||||
|
||||
(define (read-syntax path port)
|
||||
(define parse-tree (parse path (make-tokenizer port path)))
|
||||
(strip-bindings
|
||||
#`(module basic-parser-mod basic-demo-2/parse-stx
|
||||
#'#,parse-tree)))
|
||||
(module+ reader (provide read-syntax))
|
||||
|
||||
(define-macro (parser-only-mb PARSE-STX)
|
||||
#'(#%module-begin
|
||||
PARSE-STX))
|
||||
(provide (rename-out [parser-only-mb #%module-begin]))
|
||||
(provide syntax)
|
@ -1,32 +0,0 @@
|
||||
#lang brag
|
||||
b-program : [b-line] (/NEWLINE [b-line])*
|
||||
b-line : b-line-num [b-statement] (/":" [b-statement])* [b-rem]
|
||||
@b-line-num : INTEGER
|
||||
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-end : /"end"
|
||||
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-statement | b-expr)
|
||||
[/"else" (b-statement | b-expr)]
|
||||
b-input : /"input" b-id
|
||||
@b-id : ID
|
||||
b-gosub : /"gosub" b-expr
|
||||
b-return : /"return"
|
||||
b-for : /"for" b-id /"=" b-expr /"to" b-expr [/"step" b-expr]
|
||||
b-next : /"next" b-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
|
||||
b-not-expr : ["not"] b-comp-expr
|
||||
b-comp-expr : [b-comp-expr ("="|"<"|">"|"<>")] b-sum
|
||||
b-sum : [b-sum ("+"|"-")] b-product
|
||||
b-product : [b-product ("*"|"/"|"mod")] b-neg
|
||||
b-neg : ["-"] b-expt
|
||||
b-expt : [b-expt ("^")] b-value
|
||||
@b-value : b-number | b-id | /"(" b-expr /")"
|
||||
@b-number : INTEGER | DECIMAL
|
@ -1,8 +0,0 @@
|
||||
(define (30) (rem print "'ignored'"))
|
||||
(define (35) (void))
|
||||
(define (50) (print "never gets here"))
|
||||
(define (40) (end))
|
||||
(define (60) (print "three") (print (+ 1.0 3)))
|
||||
(define (70) (goto (+ 11 18.5 0.5)))
|
||||
(define (10) (print "one"))
|
||||
(define (20) (print) (goto 60) (end))
|
@ -1,23 +0,0 @@
|
||||
#lang br
|
||||
(require "line.rkt" "struct.rkt")
|
||||
(provide run)
|
||||
|
||||
(define (run line-table)
|
||||
(define line-vec
|
||||
(list->vector (sort (hash-keys line-table) <)))
|
||||
(with-handlers ([end-program-signal? (λ (exn-val) (void))])
|
||||
(for/fold ([line-idx 0])
|
||||
([i (in-naturals)]
|
||||
#:break (>= line-idx (vector-length line-vec)))
|
||||
(define line-num (vector-ref line-vec line-idx))
|
||||
(define line-func (hash-ref line-table line-num))
|
||||
(with-handlers
|
||||
([change-line-signal?
|
||||
(λ (cls)
|
||||
(define clsv (change-line-signal-val cls))
|
||||
(or
|
||||
(and (exact-positive-integer? clsv)
|
||||
(vector-member clsv line-vec))
|
||||
(line-func #:error (format "line ~a not found" clsv))))])
|
||||
(line-func)
|
||||
(add1 line-idx)))))
|
@ -1,8 +0,0 @@
|
||||
#lang basic-demo-2
|
||||
10 rem all results should be 1
|
||||
20 a = 5
|
||||
30 b = 10
|
||||
40 print a > 4
|
||||
50 print b = 10
|
||||
60 print b < 11
|
||||
70 print rem (b = 100)
|
@ -1,6 +0,0 @@
|
||||
#lang basic-demo-2
|
||||
10 for a = 1 to 3
|
||||
21 for b = 9 to 7 step -1
|
||||
22 print a ; b
|
||||
23 next b
|
||||
30 next a
|
@ -1,10 +0,0 @@
|
||||
#lang basic-demo-2
|
||||
10 gosub 41
|
||||
20 print "world"
|
||||
30 gosub 100
|
||||
31 print "hi"
|
||||
35 end
|
||||
40 return
|
||||
41 print "hello" : return
|
||||
100 print "third"
|
||||
110 goto 40
|
@ -1,4 +0,0 @@
|
||||
#lang basic-demo-2
|
||||
5 print "enter your name: "
|
||||
10 input A$
|
||||
20 print "hello, " ; A$ ; "!"
|
@ -1,9 +0,0 @@
|
||||
#lang basic-demo-2
|
||||
10 rem all results should be 1
|
||||
20 print 1 - 2 * 3 + 4 * 5 - 6 = 9
|
||||
30 print (1 - 2) * (3 + 4) * (5 - 6) = 7
|
||||
40 print 1 / 4 = .25
|
||||
50 print 2 ^ 3 = 8
|
||||
60 print 9 ^ 0.5 = 3
|
||||
70 print 6 mod 2 = 0
|
||||
80 print 5 mod 2 = 1
|
@ -1,8 +0,0 @@
|
||||
#lang basic-demo-2
|
||||
10 a = 1 : a = 5
|
||||
20 gosub 150
|
||||
30 a = 25
|
||||
40 gosub 150
|
||||
50 end
|
||||
150 print a + a + a
|
||||
160 return
|
@ -1,9 +0,0 @@
|
||||
#lang basic-demo-2
|
||||
30 rem print 'ignored'
|
||||
35
|
||||
50 print "never gets here"
|
||||
40 end
|
||||
60 print 'three' : print 1.0 + 3
|
||||
70 goto 11. + 18.5 + .5 rem ignored
|
||||
10 print "o" ; "n" ; "e"
|
||||
20 print : goto 60.0 : end
|
@ -1,8 +0,0 @@
|
||||
#lang br
|
||||
(provide (struct-out end-program-signal)
|
||||
(struct-out change-line-signal)
|
||||
(struct-out line-error))
|
||||
|
||||
(struct end-program-signal ())
|
||||
(struct change-line-signal (val))
|
||||
(struct line-error (msg))
|
@ -1,34 +0,0 @@
|
||||
#lang at-exp br
|
||||
(require br/test rackunit)
|
||||
|
||||
(check-equal? (run-source "sample.rkt") "one
|
||||
|
||||
three
|
||||
4
|
||||
")
|
||||
(check-equal? (run-source "sample-var.rkt") "15
|
||||
75
|
||||
")
|
||||
(check-equal? (run-source "sample-math.rkt") "1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
")
|
||||
(check-equal? (run-source "sample-gosub.rkt") "hello
|
||||
world
|
||||
third
|
||||
hi
|
||||
")
|
||||
(check-equal? (run-source "sample-for.rkt") "19
|
||||
18
|
||||
17
|
||||
29
|
||||
28
|
||||
27
|
||||
39
|
||||
38
|
||||
37
|
||||
")
|
@ -1,10 +0,0 @@
|
||||
#lang br
|
||||
(require "lexer.rkt" brag/support)
|
||||
|
||||
(define (make-tokenizer ip [path #f])
|
||||
(port-count-lines! ip)
|
||||
(lexer-file-path path)
|
||||
(define (next-token) (basic-lexer ip))
|
||||
next-token)
|
||||
|
||||
(provide make-tokenizer)
|
@ -1,6 +0,0 @@
|
||||
#lang br
|
||||
(require "line.rkt" "go.rkt"
|
||||
"expr.rkt" "misc.rkt")
|
||||
(provide
|
||||
(all-from-out "line.rkt" "go.rkt"
|
||||
"expr.rkt" "misc.rkt"))
|
@ -1,16 +0,0 @@
|
||||
#lang br/quicklang
|
||||
(require "struct.rkt" "run.rkt" "elements.rkt")
|
||||
(provide (rename-out [b-module-begin #%module-begin])
|
||||
(all-from-out "elements.rkt"))
|
||||
|
||||
(define-macro (b-module-begin (b-program LINE ...))
|
||||
(with-pattern
|
||||
([((b-line NUM STMT ...) ...) #'(LINE ...)]
|
||||
[(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))])
|
||||
#'(#%module-begin
|
||||
LINE ...
|
||||
(define line-table
|
||||
(apply hasheqv (append (list NUM LINE-FUNC) ...)))
|
||||
(void (run line-table)))))
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
#lang br
|
||||
(provide b-sum b-expr)
|
||||
|
||||
(define (b-sum . vals) (apply + vals))
|
||||
|
||||
(define (b-expr expr)
|
||||
(if (integer? expr) (inexact->exact expr) expr))
|
@ -1,8 +0,0 @@
|
||||
#lang br
|
||||
(require "struct.rkt" "line.rkt")
|
||||
(provide b-end b-goto)
|
||||
|
||||
(define (b-end) (raise (end-program-signal)))
|
||||
|
||||
(define (b-goto num-expr)
|
||||
(raise (change-line-signal num-expr)))
|
@ -1 +0,0 @@
|
||||
#lang info
|
@ -1,22 +0,0 @@
|
||||
#lang br
|
||||
(require brag/support)
|
||||
|
||||
(define-lex-abbrev digits (:+ (char-set "0123456789")))
|
||||
|
||||
(define basic-lexer
|
||||
(lexer-srcloc
|
||||
["\n" (token 'NEWLINE lexeme)]
|
||||
[whitespace (token lexeme #:skip? #t)]
|
||||
[(from/stop-before "rem" "\n") (token 'REM lexeme)]
|
||||
[(:or "print" "goto" "end"
|
||||
"+" ":" ";") (token lexeme lexeme)]
|
||||
[digits (token 'INTEGER (string->number lexeme))]
|
||||
[(:or (:seq (:? digits) "." digits)
|
||||
(:seq digits "."))
|
||||
(token 'DECIMAL (string->number lexeme))]
|
||||
[(:or (from/to "\"" "\"") (from/to "'" "'"))
|
||||
(token 'STRING
|
||||
(substring lexeme
|
||||
1 (sub1 (string-length lexeme))))]))
|
||||
|
||||
(provide basic-lexer)
|
@ -1,9 +0,0 @@
|
||||
#lang br
|
||||
(require "struct.rkt")
|
||||
(provide b-line)
|
||||
|
||||
(define-macro (b-line NUM STATEMENT ...)
|
||||
(with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
|
||||
#:source #'NUM)])
|
||||
(syntax/loc caller-stx
|
||||
(define (LINE-NUM) (void) STATEMENT ...))))
|
@ -1,11 +0,0 @@
|
||||
#lang br/quicklang
|
||||
(require "parser.rkt" "tokenizer.rkt")
|
||||
|
||||
(module+ reader
|
||||
(provide read-syntax))
|
||||
|
||||
(define (read-syntax path port)
|
||||
(define parse-tree (parse path (make-tokenizer port path)))
|
||||
(strip-bindings
|
||||
#`(module basic-mod basic-demo-2a/expander
|
||||
#,parse-tree)))
|
@ -1,8 +0,0 @@
|
||||
#lang br
|
||||
(require "struct.rkt")
|
||||
(provide b-rem b-print)
|
||||
|
||||
(define (b-rem val) (void))
|
||||
|
||||
(define (b-print . vals)
|
||||
(displayln (string-append* (map ~a vals))))
|
@ -1,13 +0,0 @@
|
||||
#lang brag
|
||||
b-program : [b-line] (/NEWLINE [b-line])*
|
||||
b-line : b-line-num [b-statement] (/":" [b-statement])* [b-rem]
|
||||
@b-line-num : INTEGER
|
||||
@b-statement : b-end | b-print | b-goto
|
||||
b-rem : REM
|
||||
b-end : /"end"
|
||||
b-print : /"print" [b-printable] (/";" [b-printable])*
|
||||
@b-printable : STRING | b-expr
|
||||
b-goto : /"goto" b-expr
|
||||
b-expr : b-sum
|
||||
b-sum : b-number (/"+" b-number)*
|
||||
@b-number : INTEGER | DECIMAL
|
@ -1,24 +0,0 @@
|
||||
#lang br
|
||||
(require "line.rkt" "struct.rkt")
|
||||
(provide run)
|
||||
|
||||
(define (run line-table)
|
||||
(define line-vec
|
||||
(list->vector (sort (hash-keys line-table) <)))
|
||||
(with-handlers ([end-program-signal? (λ (exn-val) (void))])
|
||||
(for/fold ([line-idx 0])
|
||||
([i (in-naturals)]
|
||||
#:break (>= line-idx (vector-length line-vec)))
|
||||
(define line-num (vector-ref line-vec line-idx))
|
||||
(define line-func (hash-ref line-table line-num))
|
||||
(with-handlers
|
||||
([change-line-signal?
|
||||
(λ (cls)
|
||||
(define clsv (change-line-signal-val cls))
|
||||
(or
|
||||
(and (exact-positive-integer? clsv)
|
||||
(vector-member clsv line-vec))
|
||||
(error (format "error in line ~a: line ~a not found"
|
||||
line-num clsv))))])
|
||||
(line-func)
|
||||
(add1 line-idx)))))
|
@ -1,9 +0,0 @@
|
||||
#lang basic-demo
|
||||
30 rem print 'ignored'
|
||||
35
|
||||
50 print "never gets here"
|
||||
40 end
|
||||
60 print 'three' : print 1.0 + 3
|
||||
70 goto 11. + 18.5 + .5 rem ignored
|
||||
10 print "o" ; "n" ; "e"
|
||||
20 print : goto 60.0 : end
|
@ -1,6 +0,0 @@
|
||||
#lang br
|
||||
(provide (struct-out end-program-signal)
|
||||
(struct-out change-line-signal))
|
||||
|
||||
(struct end-program-signal ())
|
||||
(struct change-line-signal (val))
|
@ -1,8 +0,0 @@
|
||||
#lang at-exp br
|
||||
(require br/test rackunit)
|
||||
|
||||
(check-equal? (run-source "sample.rkt") "one
|
||||
|
||||
three
|
||||
4
|
||||
")
|
@ -1,10 +0,0 @@
|
||||
#lang br
|
||||
(require "lexer.rkt" brag/support)
|
||||
|
||||
(define (make-tokenizer ip [path #f])
|
||||
(port-count-lines! ip)
|
||||
(lexer-file-path path)
|
||||
(define (next-token) (basic-lexer ip))
|
||||
next-token)
|
||||
|
||||
(provide make-tokenizer)
|
@ -1,2 +0,0 @@
|
||||
#lang br
|
||||
(current-command-line-arguments)
|
@ -1,32 +0,0 @@
|
||||
#lang br
|
||||
(require "lexer.rkt" brag/support)
|
||||
(provide basic-colorer)
|
||||
|
||||
(define (basic-colorer port)
|
||||
(define (handle-lexer-error excn)
|
||||
(define excn-srclocs (exn:fail:read-srclocs excn))
|
||||
(srcloc-token (token 'ERROR) (car excn-srclocs)))
|
||||
(define srcloc-tok
|
||||
(with-handlers ([exn:fail:read? handle-lexer-error])
|
||||
(basic-lexer port)))
|
||||
(match srcloc-tok
|
||||
[(? eof-object?) (values srcloc-tok 'eof #f #f #f)]
|
||||
[else
|
||||
(match-define
|
||||
(srcloc-token
|
||||
(token-struct type val _ _ _ _ _)
|
||||
(srcloc _ _ _ posn span)) srcloc-tok)
|
||||
(define start posn)
|
||||
(define end (+ start span))
|
||||
(match-define (list cat paren)
|
||||
(match type
|
||||
['STRING '(string #f)]
|
||||
['REM '(comment #f)]
|
||||
['ERROR '(error #f)]
|
||||
[else (match val
|
||||
[(? number?)'(constant #f)]
|
||||
[(? symbol?) '(symbol #f)]
|
||||
["(" '(parenthesis |(|)]
|
||||
[")" '(parenthesis |)|)]
|
||||
[else '(no-color #f)])]))
|
||||
(values val cat paren start end)]))
|
@ -1,41 +0,0 @@
|
||||
#lang br
|
||||
(require "go.rkt")
|
||||
(provide b-if b-or-expr b-and-expr b-not-expr b-comp-expr)
|
||||
|
||||
(define (bool->int val) (if val 1 0))
|
||||
(define nonzero? (compose1 not zero?))
|
||||
|
||||
(define-macro-cases b-or-expr
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ LEFT "or" RIGHT)
|
||||
#'(bool->int (or (nonzero? LEFT) (nonzero? RIGHT)))])
|
||||
|
||||
(define-macro-cases b-and-expr
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ LEFT "and" RIGHT)
|
||||
#'(bool->int (and (nonzero? LEFT) (nonzero? RIGHT)))])
|
||||
|
||||
(define-macro-cases b-not-expr
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ "not" VAL) #'(if (nonzero? VAL) 0 1)])
|
||||
|
||||
(define b= (compose1 bool->int =))
|
||||
(define b< (compose1 bool->int <))
|
||||
(define b> (compose1 bool->int >))
|
||||
(define b<> (compose1 bool->int not =))
|
||||
|
||||
(define-macro-cases b-comp-expr
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ LEFT "=" RIGHT) #'(b= LEFT RIGHT)]
|
||||
[(_ LEFT "<" RIGHT) #'(b< LEFT RIGHT)]
|
||||
[(_ LEFT ">" RIGHT) #'(b> LEFT RIGHT)]
|
||||
[(_ LEFT "<>" RIGHT) #'(b<> LEFT RIGHT)])
|
||||
|
||||
(define-macro-cases b-if
|
||||
[(_ COND-EXPR THEN-EXPR) #'(b-if COND-EXPR THEN-EXPR (void))]
|
||||
[(_ COND-EXPR THEN-EXPR ELSE-EXPR)
|
||||
#'(let ([result (if (nonzero? COND-EXPR)
|
||||
THEN-EXPR
|
||||
ELSE-EXPR)])
|
||||
(when (exact-positive-integer? result)
|
||||
(b-goto result)))])
|
@ -1,6 +0,0 @@
|
||||
#lang br
|
||||
(require "line.rkt" "go.rkt"
|
||||
"expr.rkt" "misc.rkt" "cond.rkt")
|
||||
(provide
|
||||
(all-from-out "line.rkt" "go.rkt"
|
||||
"expr.rkt" "misc.rkt" "cond.rkt"))
|
@ -1,58 +0,0 @@
|
||||
#lang br/quicklang
|
||||
(require "struct.rkt" "run.rkt" "elements.rkt" "setup.rkt")
|
||||
(provide (rename-out [b-module-begin #%module-begin])
|
||||
(all-from-out "elements.rkt"))
|
||||
|
||||
(define-macro (b-module-begin (b-program LINE ...))
|
||||
(with-pattern
|
||||
([((b-line NUM STMT ...) ...) #'(LINE ...)]
|
||||
[(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))]
|
||||
[(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-IDX) ...)
|
||||
(make-shell-ids-and-idxs caller-stx)]
|
||||
[(UNIQUE-ID ...)
|
||||
(unique-ids
|
||||
(syntax->list #'(VAR-ID ... SHELL-ID ...)))])
|
||||
#'(#%module-begin
|
||||
(module configure-runtime br
|
||||
(require basic-demo-3/setup)
|
||||
(do-setup!))
|
||||
(require IMPORT-NAME) ...
|
||||
(provide EXPORT-NAME ...)
|
||||
(define UNIQUE-ID 0) ...
|
||||
(let ([clargs (current-command-line-arguments)])
|
||||
(set! SHELL-ID (get-clarg clargs SHELL-IDX)) ...)
|
||||
LINE ...
|
||||
(define line-table
|
||||
(apply hasheqv (append (list NUM LINE-FUNC) ...)))
|
||||
(parameterize
|
||||
([current-output-port (basic-output-port)])
|
||||
(void (run line-table))))))
|
||||
|
||||
(define (get-clarg clargs idx)
|
||||
(if (<= (vector-length clargs) idx)
|
||||
0
|
||||
(let ([val (vector-ref clargs idx)])
|
||||
(or (string->number val) val))))
|
||||
|
||||
(begin-for-syntax
|
||||
(require racket/list)
|
||||
|
||||
(define (unique-ids stxs)
|
||||
(remove-duplicates stxs #:key syntax->datum))
|
||||
|
||||
(define (find-property which line-stxs)
|
||||
(unique-ids
|
||||
(for/list ([stx (in-list (stx-flatten line-stxs))]
|
||||
#:when (syntax-property stx which))
|
||||
stx)))
|
||||
|
||||
(define (make-shell-ids-and-idxs ctxt)
|
||||
(define arg-count 10)
|
||||
(for/list ([idx (in-range arg-count)])
|
||||
(list (suffix-id #'arg idx #:context ctxt) idx))))
|
||||
|
@ -1,45 +0,0 @@
|
||||
#lang br
|
||||
(require "line.rkt")
|
||||
(provide b-expr b-sum b-product b-neg b-expt b-def b-func)
|
||||
|
||||
(define (b-expr expr)
|
||||
(if (integer? expr) (inexact->exact expr) expr))
|
||||
|
||||
(define-macro-cases b-sum
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ LEFT "+" RIGHT) #'(+ LEFT RIGHT)]
|
||||
[(_ LEFT "-" RIGHT) #'(- LEFT RIGHT)])
|
||||
|
||||
(define-macro-cases b-product
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ LEFT "*" RIGHT) #'(* LEFT RIGHT)]
|
||||
[(_ LEFT "/" RIGHT) #'(/ LEFT RIGHT 1.0)]
|
||||
[(_ LEFT "mod" RIGHT) #'(modulo LEFT RIGHT)])
|
||||
|
||||
(define-macro-cases b-neg
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ "-" VAL) #'(- VAL)])
|
||||
|
||||
(define-macro-cases b-expt
|
||||
[(_ VAL) #'VAL]
|
||||
[(_ LEFT "^" RIGHT) #'(expt LEFT RIGHT)])
|
||||
|
||||
(define-macro (b-def FUNC-ID VAR-ID ... EXPR)
|
||||
(syntax-local-lift-expression
|
||||
#'(set! FUNC-ID (λ (VAR-ID ...) EXPR))))
|
||||
|
||||
(define-macro (b-func FUNC-ID ARG ...)
|
||||
#'(if (procedure? FUNC-ID)
|
||||
(convert-result (FUNC-ID ARG ...))
|
||||
(raise-line-error
|
||||
(format "expected ~a to be a function, got ~v"
|
||||
'FUNC-ID FUNC-ID))))
|
||||
|
||||
(define (convert-result result)
|
||||
(cond
|
||||
[(number? result) (b-expr result)]
|
||||
[(string? result) result]
|
||||
[(boolean? result) (if result 1 0)]
|
||||
[else
|
||||
(raise-line-error
|
||||
(format "unknown data type: ~v" result))]))
|
@ -1,52 +0,0 @@
|
||||
#lang br
|
||||
(require "struct.rkt" "line.rkt" "misc.rkt")
|
||||
(provide b-end b-goto b-gosub b-return b-for b-next)
|
||||
|
||||
(define (b-end) (raise (end-program-signal)))
|
||||
|
||||
(define (b-goto num-expr)
|
||||
(raise (change-line-signal num-expr)))
|
||||
|
||||
(define return-ccs empty)
|
||||
|
||||
(define (b-gosub num-expr)
|
||||
(let/cc this-cc
|
||||
(push! return-ccs this-cc)
|
||||
(b-goto num-expr)))
|
||||
|
||||
(define (b-return)
|
||||
(when (empty? return-ccs)
|
||||
(raise-line-error "return without gosub"))
|
||||
(define top-cc (pop! return-ccs))
|
||||
(top-cc (void)))
|
||||
|
||||
(define next-funcs (make-hasheq))
|
||||
|
||||
(define-macro-cases b-for
|
||||
[(_ LOOP-ID START END) #'(b-for LOOP-ID START END 1)]
|
||||
[(_ LOOP-ID START END STEP)
|
||||
#'(b-let LOOP-ID
|
||||
(let/cc loop-cc
|
||||
(hash-set! next-funcs
|
||||
'LOOP-ID
|
||||
(λ ()
|
||||
(define next-val
|
||||
(+ LOOP-ID STEP))
|
||||
(if (next-val
|
||||
. in-closed-interval? .
|
||||
START END)
|
||||
(loop-cc next-val)
|
||||
(hash-remove! next-funcs
|
||||
'LOOP-ID))))
|
||||
START))])
|
||||
|
||||
(define (in-closed-interval? x start end)
|
||||
((if (< start end) <= >=) start x end))
|
||||
|
||||
(define-macro (b-next LOOP-ID)
|
||||
#'(begin
|
||||
(unless (hash-has-key? next-funcs 'LOOP-ID)
|
||||
(raise-line-error
|
||||
(format "`next ~a` without for" 'LOOP-ID)))
|
||||
(define func (hash-ref next-funcs 'LOOP-ID))
|
||||
(func)))
|
@ -1,4 +0,0 @@
|
||||
#lang info
|
||||
|
||||
(define compile-omit-paths '("private"))
|
||||
(define test-omit-paths '("private" "sample-input.rkt"))
|
@ -1,31 +0,0 @@
|
||||
#lang br
|
||||
(require brag/support)
|
||||
|
||||
(define-lex-abbrev digits (:+ (char-set "0123456789")))
|
||||
|
||||
(define-lex-abbrev reserved-terms (:or "print" "goto" "end" "+" ":" ";" "let" "=" "input" "-" "*" "/" "^" "mod" "(" ")" "if" "then" "else" "<" ">" "<>" "and" "or" "not" "gosub" "return" "for" "to" "step" "next" "def" "," "import" "export"))
|
||||
|
||||
(define-lex-abbrev racket-id-kapu
|
||||
(:or whitespace (char-set "()[]{}\",'`;#|\\")))
|
||||
|
||||
(define basic-lexer
|
||||
(lexer-srcloc
|
||||
["\n" (token 'NEWLINE lexeme)]
|
||||
[whitespace (token lexeme #:skip? #t)]
|
||||
[(from/stop-before "rem" "\n") (token 'REM lexeme)]
|
||||
[(:seq "[" (:+ (:~ racket-id-kapu)) "]")
|
||||
(token 'RACKET-ID
|
||||
(string->symbol (trim-ends "[" 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 "."))
|
||||
(token 'DECIMAL (string->number lexeme))]
|
||||
[(:or (from/to "\"" "\"") (from/to "'" "'"))
|
||||
(token 'STRING
|
||||
(substring lexeme
|
||||
1 (sub1 (string-length lexeme))))]))
|
||||
|
||||
(provide basic-lexer)
|
@ -1,22 +0,0 @@
|
||||
#lang br
|
||||
(require "struct.rkt")
|
||||
(provide b-line raise-line-error)
|
||||
|
||||
(define-macro (b-line NUM STATEMENT ...)
|
||||
(with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
|
||||
#:source #'NUM)])
|
||||
(syntax/loc caller-stx
|
||||
(define (LINE-NUM #:error [msg #f])
|
||||
(with-handlers
|
||||
([line-error?
|
||||
(λ (le) (handle-line-error NUM le))])
|
||||
(when msg (raise-line-error msg))
|
||||
STATEMENT ...)))))
|
||||
|
||||
(define (raise-line-error error-msg)
|
||||
(raise (line-error error-msg)))
|
||||
|
||||
(define (handle-line-error num le)
|
||||
(error (format "error in line ~a: ~a"
|
||||
num (line-error-msg le))))
|
||||
|
@ -1,19 +0,0 @@
|
||||
#lang br/quicklang
|
||||
(require "parser.rkt" "tokenizer.rkt")
|
||||
|
||||
(module+ reader
|
||||
(provide read-syntax get-info))
|
||||
|
||||
(define (read-syntax path port)
|
||||
(define parse-tree (parse path (make-tokenizer port path)))
|
||||
(strip-bindings
|
||||
#`(module basic-mod basic-demo-3/expander
|
||||
#,parse-tree)))
|
||||
|
||||
(define (get-info port src-mod src-line src-col src-pos)
|
||||
(define (handle-query key default)
|
||||
(case key
|
||||
[(color-lexer)
|
||||
(dynamic-require 'basic-demo-3/colorer 'basic-colorer)]
|
||||
[else default]))
|
||||
handle-query)
|
@ -1,34 +0,0 @@
|
||||
#lang br
|
||||
(require "struct.rkt" "expr.rkt")
|
||||
(provide b-rem b-print b-let b-input b-import b-export b-repl)
|
||||
|
||||
(define (b-rem val) (void))
|
||||
|
||||
(define (b-print . vals)
|
||||
(displayln (string-append* (map ~a vals))))
|
||||
|
||||
(define-macro (b-let ID VAL) #'(set! ID VAL))
|
||||
|
||||
(define-macro (b-input ID)
|
||||
#'(b-let ID (let* ([str (read-line)]
|
||||
[num (string->number (string-trim str))])
|
||||
(or num str))))
|
||||
|
||||
(define-macro (b-import NAME) #'(void))
|
||||
|
||||
(define-macro (b-export NAME) #'(void))
|
||||
|
||||
(define-macro (b-repl . ALL-INPUTS)
|
||||
(with-pattern
|
||||
([INPUTS (pattern-case-filter #'ALL-INPUTS
|
||||
[(b-print . PRINT-ARGS)
|
||||
#'(b-print . PRINT-ARGS)]
|
||||
[(b-expr . EXPR-ARGS)
|
||||
#'(b-print (b-expr . EXPR-ARGS))]
|
||||
[(b-let ID VAL)
|
||||
#'(define ID VAL)]
|
||||
[(b-def FUNC-ID VAR-ID ... EXPR)
|
||||
#'(define (FUNC-ID VAR-ID ...) EXPR)]
|
||||
[ANYTHING-ELSE
|
||||
#'(error 'invalid-repl-input)])])
|
||||
#'(begin . INPUTS)))
|
@ -1,14 +0,0 @@
|
||||
#lang br/quicklang
|
||||
(require "parser.rkt" "tokenizer.rkt")
|
||||
|
||||
(define (read-syntax path port)
|
||||
(define parse-tree (parse path (make-tokenizer port path)))
|
||||
(strip-bindings
|
||||
#`(module basic-parser-mod basic-demo-3/parse-only
|
||||
#,parse-tree)))
|
||||
(module+ reader (provide read-syntax))
|
||||
|
||||
(define-macro (parser-only-mb PARSE-TREE)
|
||||
#'(#%module-begin
|
||||
'PARSE-TREE))
|
||||
(provide (rename-out [parser-only-mb #%module-begin]))
|
@ -1,15 +0,0 @@
|
||||
#lang br/quicklang
|
||||
(require "parser.rkt" "tokenizer.rkt")
|
||||
|
||||
(define (read-syntax path port)
|
||||
(define parse-tree (parse path (make-tokenizer port path)))
|
||||
(strip-bindings
|
||||
#`(module basic-parser-mod basic-demo-3/parse-stx
|
||||
#'#,parse-tree)))
|
||||
(module+ reader (provide read-syntax))
|
||||
|
||||
(define-macro (parser-only-mb PARSE-STX)
|
||||
#'(#%module-begin
|
||||
PARSE-STX))
|
||||
(provide (rename-out [parser-only-mb #%module-begin]))
|
||||
(provide syntax)
|
@ -1,40 +0,0 @@
|
||||
#lang brag
|
||||
b-program : [b-line] (/NEWLINE [b-line])* | b-statement /NEWLINE
|
||||
b-line : b-line-num [b-statement] (/":" [b-statement])* [b-rem]
|
||||
@b-line-num : INTEGER
|
||||
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-export
|
||||
b-end : /"end"
|
||||
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-statement | b-expr)
|
||||
[/"else" (b-statement | b-expr)]
|
||||
b-input : /"input" b-id
|
||||
@b-id : ID
|
||||
b-gosub : /"gosub" b-expr
|
||||
b-return : /"return"
|
||||
b-for : /"for" b-id /"=" b-expr /"to" b-expr [/"step" b-expr]
|
||||
b-next : /"next" b-id
|
||||
b-def : /"def" b-id /"(" ID [/"," ID]* /")" /"=" b-expr
|
||||
b-import : /"import" b-import-name
|
||||
@b-import-name : RACKET-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
|
||||
b-not-expr : ["not"] b-comp-expr
|
||||
b-comp-expr : [b-comp-expr ("="|"<"|">"|"<>")] b-sum
|
||||
b-sum : [b-sum ("+"|"-")] b-product
|
||||
b-product : [b-product ("*"|"/"|"mod")] b-neg
|
||||
b-neg : ["-"] b-expt
|
||||
b-expt : [b-expt ("^")] b-value
|
||||
@b-value : b-number | b-id | /"(" b-expr /")" | b-func
|
||||
b-func : (ID | RACKET-ID) /"(" b-expr [/"," b-expr]* /")"
|
||||
@b-number : INTEGER | DECIMAL
|
||||
b-repl : (b-statement | b-expr) (/":" [@b-repl])*
|
@ -1,8 +0,0 @@
|
||||
(define (30) (rem print "'ignored'"))
|
||||
(define (35) (void))
|
||||
(define (50) (print "never gets here"))
|
||||
(define (40) (end))
|
||||
(define (60) (print "three") (print (+ 1.0 3)))
|
||||
(define (70) (goto (+ 11 18.5 0.5)))
|
||||
(define (10) (print "one"))
|
||||
(define (20) (print) (goto 60) (end))
|
@ -1,5 +0,0 @@
|
||||
#lang basic-demo-3
|
||||
10 print "arg0 is " ; arg0
|
||||
20 print "arg1 + arg1 is " ; arg1 + arg1
|
||||
40 print "arg3 is " ; arg3
|
||||
50 print "arg4 is " ; arg4
|
@ -1,23 +0,0 @@
|
||||
#lang br
|
||||
(require "line.rkt" "struct.rkt")
|
||||
(provide run)
|
||||
|
||||
(define (run line-table)
|
||||
(define line-vec
|
||||
(list->vector (sort (hash-keys line-table) <)))
|
||||
(with-handlers ([end-program-signal? (λ (exn-val) (void))])
|
||||
(for/fold ([line-idx 0])
|
||||
([i (in-naturals)]
|
||||
#:break (>= line-idx (vector-length line-vec)))
|
||||
(define line-num (vector-ref line-vec line-idx))
|
||||
(define line-func (hash-ref line-table line-num))
|
||||
(with-handlers
|
||||
([change-line-signal?
|
||||
(λ (cls)
|
||||
(define clsv (change-line-signal-val cls))
|
||||
(or
|
||||
(and (exact-positive-integer? clsv)
|
||||
(vector-member clsv line-vec))
|
||||
(line-func #:error (format "line ~a not found" clsv))))])
|
||||
(line-func)
|
||||
(add1 line-idx)))))
|
@ -1,8 +0,0 @@
|
||||
#lang basic-demo-3
|
||||
10 rem all results should be 1
|
||||
20 a = 5
|
||||
30 b = 10
|
||||
40 print a > 4
|
||||
50 print b = 10
|
||||
60 print b < 11
|
||||
70 print rem (b = 100)
|
@ -1,7 +0,0 @@
|
||||
#lang basic-demo-3
|
||||
10 x = 2 : y = 3 : z = 5
|
||||
20 print f(3, 4)
|
||||
30 print f(f(3, g(2)), 2)
|
||||
40 def f(x, y) = x * y * z
|
||||
50 def g(i) = i + i
|
||||
60 print y
|
@ -1,9 +0,0 @@
|
||||
#lang basic-demo-3
|
||||
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 +0,0 @@
|
||||
#lang basic-demo-3
|
||||
10 for a = 1 to 3
|
||||
21 for b = 9 to 7 step -1
|
||||
22 print a : print b
|
||||
23 next b
|
||||
30 next a
|
@ -1,10 +0,0 @@
|
||||
#lang basic-demo-3
|
||||
10 gosub 41
|
||||
20 print "second"
|
||||
30 gosub 100
|
||||
31 print "fourth"
|
||||
35 end
|
||||
40 return
|
||||
41 print "first" : return
|
||||
100 print "third"
|
||||
110 goto 40
|
@ -1,7 +0,0 @@
|
||||
#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,5 +0,0 @@
|
||||
#lang br
|
||||
(require basic-demo-3/sample-exporter)
|
||||
div
|
||||
x
|
||||
(div x 10)
|
@ -1,4 +0,0 @@
|
||||
#lang basic-demo-3
|
||||
5 print "enter your name: "
|
||||
10 input A$
|
||||
20 print "hello, " ; A$ ; "!"
|
@ -1,9 +0,0 @@
|
||||
#lang basic-demo-3
|
||||
10 rem all results should be 1
|
||||
20 print 1 - 2 * 3 + 4 * 5 - 6 = 9
|
||||
30 print (1 - 2) * (3 + 4) * (5 - 6) = 7
|
||||
40 print 1 / 4 = .25
|
||||
50 print 2 ^ 3 = 8
|
||||
60 print 9 ^ 0.5 = 3
|
||||
70 print 6 mod 2 = 0
|
||||
80 print 5 mod 2 = 1
|
@ -1,6 +0,0 @@
|
||||
#lang br
|
||||
(require "sample-exporter.rkt")
|
||||
(provide (all-from-out "sample-exporter.rkt"))
|
||||
div
|
||||
x
|
||||
(div x 10)
|
@ -1,2 +0,0 @@
|
||||
#lang basic-demo-3
|
||||
10 print "got shell args: " ; arg0 ; arg1 ; arg2
|
@ -1,9 +0,0 @@
|
||||
#lang basic-demo-3
|
||||
30 rem print 'ignored'
|
||||
35
|
||||
50 print "never gets here"
|
||||
40 end
|
||||
60 print 'three' : print 1.0 + 3
|
||||
70 goto 11. + 18.5 + .5 rem ignored
|
||||
10 print "o" ; "n" ; "e"
|
||||
20 print : goto 60.0 : end
|
@ -1,19 +0,0 @@
|
||||
#lang br
|
||||
(require "parser.rkt" "tokenizer.rkt")
|
||||
(provide basic-output-port do-setup!)
|
||||
|
||||
(define basic-output-port
|
||||
(make-parameter (open-output-nowhere)))
|
||||
|
||||
(define repl-parse (make-rule-parser b-repl))
|
||||
|
||||
(define (read-one-line origin port)
|
||||
(define one-line (read-line port))
|
||||
(if (eof-object? one-line)
|
||||
eof
|
||||
(repl-parse
|
||||
(make-tokenizer (open-input-string one-line)))))
|
||||
|
||||
(define (do-setup!)
|
||||
(basic-output-port (current-output-port))
|
||||
(current-read-interaction read-one-line))
|
@ -1,8 +0,0 @@
|
||||
#lang br
|
||||
(provide (struct-out end-program-signal)
|
||||
(struct-out change-line-signal)
|
||||
(struct-out line-error))
|
||||
|
||||
(struct end-program-signal ())
|
||||
(struct change-line-signal (val))
|
||||
(struct line-error (msg))
|
@ -1,7 +0,0 @@
|
||||
#lang br
|
||||
(provide (all-defined-out))
|
||||
|
||||
(struct end-program-signal ())
|
||||
(struct change-line-signal (val))
|
||||
|
||||
(struct line-error (msg))
|
@ -1,72 +0,0 @@
|
||||
#lang at-exp br
|
||||
(require br/test rackunit)
|
||||
|
||||
(check-equal? (run-source "sample.rkt") "one
|
||||
|
||||
three
|
||||
4
|
||||
")
|
||||
|
||||
(check-equal? (run-source "sample-cond.rkt") "1
|
||||
1
|
||||
1
|
||||
|
||||
")
|
||||
|
||||
(check-equal? (run-source "sample-def.rkt") "60
|
||||
600
|
||||
3
|
||||
")
|
||||
|
||||
(check-equal? (run-source "sample-exporter.rkt") "1
|
||||
2
|
||||
3
|
||||
")
|
||||
|
||||
(check-equal? (run-source "sample-for.rkt") "1
|
||||
9
|
||||
1
|
||||
8
|
||||
1
|
||||
7
|
||||
2
|
||||
9
|
||||
2
|
||||
8
|
||||
2
|
||||
7
|
||||
3
|
||||
9
|
||||
3
|
||||
8
|
||||
3
|
||||
7
|
||||
")
|
||||
|
||||
(check-equal? (run-source "sample-gosub.rkt") "first
|
||||
second
|
||||
third
|
||||
fourth
|
||||
")
|
||||
|
||||
(check-equal? (run-source "sample-import.rkt") "53
|
||||
0
|
||||
10
|
||||
")
|
||||
|
||||
(check-equal? (run-source "sample-importer.rkt") "#<procedure:div>
|
||||
20
|
||||
2
|
||||
")
|
||||
|
||||
(check-equal? (run-source "sample-math.rkt") "1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
")
|
||||
|
||||
(check-equal? (run-source "sample-shell.rkt") "got shell args: 000\n")
|
||||
|
@ -1,14 +0,0 @@
|
||||
#lang br/quicklang
|
||||
(require "parser.rkt" "tokenizer.rkt" brag/support)
|
||||
|
||||
(define (read-syntax path port)
|
||||
(define tokens (apply-tokenizer-maker make-tokenizer port))
|
||||
(strip-bindings
|
||||
#`(module basic-parser-mod basic-demo-3/parse-only
|
||||
'#,tokens)))
|
||||
(module+ reader (provide read-syntax))
|
||||
|
||||
(define-macro (mb PARSE-TREE)
|
||||
#'(#%module-begin
|
||||
'PARSE-TREE))
|
||||
(provide (rename-out [mb #%module-begin]))
|
@ -1,10 +0,0 @@
|
||||
#lang br
|
||||
(require "lexer.rkt" brag/support)
|
||||
|
||||
(define (make-tokenizer ip [path #f])
|
||||
(port-count-lines! ip)
|
||||
(lexer-file-path path)
|
||||
(define (next-token) (basic-lexer ip))
|
||||
next-token)
|
||||
|
||||
(provide make-tokenizer)
|
@ -1,140 +0,0 @@
|
||||
#lang basic-demo-nth
|
||||
|
||||
10 PRINT TAB(28);"AMAZING PROGRAM"
|
||||
20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
|
||||
30 PRINT:PRINT:PRINT:PRINT
|
||||
100 INPUT "WHAT ARE YOUR WIDTH AND LENGTH";HMAX,VMAX
|
||||
102 IF HMAX<>1 AND VMAX<>1 THEN 110
|
||||
104 PRINT "MEANINGLESS DIMENSIONS. TRY AGAIN.":GOTO 100
|
||||
110 DIM W(HMAX,VMAX),V(HMAX,VMAX)
|
||||
120 PRINT
|
||||
130 PRINT
|
||||
140 PRINT
|
||||
150 PRINT
|
||||
160 Q=0:Z=0:X=INT(RND(1)*HMAX+1)
|
||||
165 FOR I=1 TO HMAX
|
||||
170 IF I=X THEN 173
|
||||
171 PRINT "+--";:GOTO 180
|
||||
173 PRINT "+ ";
|
||||
180 NEXT I
|
||||
190 PRINT "+"
|
||||
195 C=1:W(X,1)=C:C=C+1
|
||||
200 R=X:S=1:GOTO 260
|
||||
210 IF R<>HMAX THEN 240
|
||||
215 IF S<>VMAX THEN 230
|
||||
220 R=1:S=1:GOTO 250
|
||||
230 R=1:S=S+1:GOTO 250
|
||||
240 R=R+1
|
||||
250 IF W(R,S)=0 THEN 210
|
||||
260 IF R-1=0 THEN 530
|
||||
265 IF W(R-1,S)<>0 THEN 530
|
||||
270 IF S-1=0 THEN 390
|
||||
280 IF W(R,S-1)<>0 THEN 390
|
||||
290 IF R=HMAX THEN 330
|
||||
300 IF W(R+1,S)<>0 THEN 330
|
||||
310 X=INT(RND(1)*3+1)
|
||||
320 ON X GOTO 790,820,860
|
||||
330 IF S<>HMAX THEN 340
|
||||
334 IF Z=1 THEN 370
|
||||
338 Q=1:GOTO 350
|
||||
340 IF W(R,S+1)<>0 THEN 370
|
||||
350 X=INT(RND(1)*3+1)
|
||||
360 ON X GOTO 790,820,910
|
||||
370 X=INT(RND(1)*2+1)
|
||||
380 ON X GOTO 790,820
|
||||
390 IF R=HMAX THEN 470
|
||||
400 IF W(R+1,S)<>0 THEN 470
|
||||
405 IF S<>VMAX THEN 420
|
||||
410 IF Z=1 THEN 450
|
||||
415 Q=1:GOTO 430
|
||||
420 IF W(R,S+1)<>0 THEN 450
|
||||
430 X=INT(RND(1)*3+1)
|
||||
440 ON X GOTO 790,860,910
|
||||
450 X=INT(RND(1)*2+1)
|
||||
460 ON X GOTO 790,860
|
||||
470 IF S<>VMAX THEN 490
|
||||
480 IF Z=1 THEN 520
|
||||
485 Q=1:GOTO 500
|
||||
490 IF W(R,S+1)<>0 THEN 520
|
||||
500 X=INT(RND(1)*2+1)
|
||||
510 ON X GOTO 790,910
|
||||
520 GOTO 790
|
||||
530 IF S-1=0 THEN 670
|
||||
540 IF W(R,S-1)<>0 THEN 670
|
||||
545 IF R=HMAX THEN 610
|
||||
547 IF W(R+1,S)<>0 THEN 610
|
||||
550 IF S<>VMAX THEN 560
|
||||
552 IF Z=1 THEN 590
|
||||
554 Q=1:GOTO 570
|
||||
560 IF W(R,S+1)<>0 THEN 590
|
||||
570 X=INT(RND(1)*3+1)
|
||||
580 ON X GOTO 820,860,910
|
||||
590 X=INT(RND(1)*2+1)
|
||||
600 ON X GOTO 820,860
|
||||
610 IF S<>VMAX THEN 630
|
||||
620 IF Z=1 THEN 660
|
||||
625 Q=1:GOTO 640
|
||||
630 IF W(R,S+1)<>0 THEN 660
|
||||
640 X=INT(RND(1)*2+1)
|
||||
650 ON X GOTO 820,910
|
||||
660 GOTO 820
|
||||
670 IF R=HMAX THEN 740
|
||||
680 IF W(R+1,S)<>0 THEN 740
|
||||
685 IF S<>VMAX THEN 700
|
||||
690 IF Z=1 THEN 730
|
||||
695 Q=1:GOTO 830
|
||||
700 IF W(R,S+1)<>0 THEN 730
|
||||
710 X=INT(RND(1)*2+1)
|
||||
720 ON X GOTO 860,910
|
||||
730 GOTO 860
|
||||
740 IF S<>VMAX THEN 760
|
||||
750 IF Z=1 THEN 780
|
||||
755 Q=1:GOTO 770
|
||||
760 IF W(R,S+1)<>0 THEN 780
|
||||
770 GOTO 910
|
||||
780 GOTO 1000
|
||||
790 W(R-1,S)=C
|
||||
800 C=C+1:V(R-1,S)=2:R=R-1
|
||||
810 IF C=HMAX*VMAX+1 THEN 1010
|
||||
815 Q=0:GOTO 260
|
||||
820 W(R,S-1)=C
|
||||
830 C=C+1
|
||||
840 V(R,S-1)=1:S=S-1:IF C=HMAX*VMAX+1 THEN 1010
|
||||
850 Q=0:GOTO 260
|
||||
860 W(R+1,S)=C
|
||||
870 C=C+1:IF V(R,S)=0 THEN 880
|
||||
875 V(R,S)=3:GOTO 890
|
||||
880 V(R,S)=2
|
||||
890 R=R+1
|
||||
900 IF C=HMAX*VMAX+1 THEN 1010
|
||||
905 GOTO 530
|
||||
910 IF Q=1 THEN 960
|
||||
920 W(R,S+1)=C:C=C+1:IF V(R,S)=0 THEN 940
|
||||
930 V(R,S)=3:GOTO 950
|
||||
940 V(R,S)=1
|
||||
950 S=S+1:IF C=HMAX*VMAX+1 THEN 1010
|
||||
955 GOTO 260
|
||||
960 Z=1
|
||||
970 IF V(R,S)=0 THEN 980
|
||||
975 V(R,S)=3:Q=0:GOTO 1000
|
||||
980 V(R,S)=1:Q=0:R=1:S=1:GOTO 250
|
||||
1000 GOTO 210
|
||||
1010 FOR J=1 TO VMAX
|
||||
1011 PRINT "|";
|
||||
1012 FOR I=1 TO HMAX
|
||||
1013 IF V(I,J)<2 THEN 1030
|
||||
1020 PRINT " ";
|
||||
1021 GOTO 1040
|
||||
1030 PRINT " |";
|
||||
1040 NEXT I
|
||||
1041 PRINT
|
||||
1043 FOR I=1 TO HMAX
|
||||
1045 IF V(I,J)=0 THEN 1060
|
||||
1050 IF V(I,J)=2 THEN 1060
|
||||
1051 PRINT "+ ";
|
||||
1052 GOTO 1070
|
||||
1060 PRINT "+--";
|
||||
1070 NEXT I
|
||||
1071 PRINT "+"
|
||||
1072 NEXT J
|
||||
1073 END
|
@ -1,4 +0,0 @@
|
||||
#lang basic-demo-nth
|
||||
10 rem 20
|
||||
20 x = 42
|
||||
25 print x
|
@ -1,55 +0,0 @@
|
||||
#lang basic-demo-nth
|
||||
|
||||
10 PRINT TAB(33);"BOUNCE"
|
||||
20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
|
||||
30 PRINT:PRINT:PRINT
|
||||
90 DIM T(20)
|
||||
100 PRINT "THIS SIMULATION LETS YOU SPECIFY THE INITIAL VELOCITY"
|
||||
110 PRINT "OF A BALL THROWN STRAIGHT UP, AND THE COEFFICIENT OF"
|
||||
120 PRINT "ELASTICITY OF THE BALL. PLEASE USE A DECIMAL FRACTION"
|
||||
130 PRINT "COEFFICIENCY (LESS THAN 1)."
|
||||
131 PRINT
|
||||
132 PRINT "YOU ALSO SPECIFY THE TIME INCREMENT TO BE USED IN"
|
||||
133 PRINT "'STROBING' THE BALL'S FLIGHT (TRY .1 INITIALLY)."
|
||||
134 PRINT
|
||||
135 INPUT "TIME INCREMENT (SEC)";S2
|
||||
140 PRINT
|
||||
150 INPUT "VELOCITY (FPS)";V
|
||||
160 PRINT
|
||||
170 INPUT "COEFFICIENT";C
|
||||
180 PRINT
|
||||
182 PRINT "FEET"
|
||||
184 PRINT
|
||||
186 S1=INT(70/(V/(16*S2)))
|
||||
190 FOR I=1 TO S1
|
||||
200 T(I)=V*C^(I-1)/16
|
||||
210 NEXT I
|
||||
220 FOR H=INT(-16*(V/32)^2+V^2/32+.5) TO 0 STEP -.5
|
||||
221 IF INT(H)<>H THEN 225
|
||||
222 PRINT H;
|
||||
225 L=0
|
||||
230 FOR I=1 TO S1
|
||||
240 FOR TI=0 TO T(I) STEP S2
|
||||
245 L=L+S2
|
||||
250 IF ABS(H-(.5*(-32)*TI^2+V*C^(I-1)*TI))>.25 THEN 270
|
||||
260 PRINT TAB(L/S2);"0";
|
||||
270 NEXT TI
|
||||
275 TI=T(I+1)/2
|
||||
276 IF -16*TI^2+V*C^(I-1)*TI<H THEN 290
|
||||
280 NEXT I
|
||||
290 PRINT
|
||||
300 NEXT H
|
||||
310 PRINT TAB(1);
|
||||
320 FOR I=1 TO INT(L+1)/S2+1
|
||||
330 PRINT ".";
|
||||
340 NEXT I
|
||||
350 PRINT
|
||||
355 PRINT " 0";
|
||||
360 FOR I=1 TO INT(L+.9995)
|
||||
380 PRINT TAB(INT(I/S2));I;
|
||||
390 NEXT I
|
||||
400 PRINT
|
||||
410 PRINT TAB(INT(L+1)/(2*S2)-2);"SECONDS"
|
||||
420 PRINT
|
||||
430 GOTO 135
|
||||
440 END
|
@ -1,30 +0,0 @@
|
||||
#lang basic-demo-nth
|
||||
|
||||
3 print TAB(33);"Chemist"
|
||||
6 print TAB(15);"Creative Computing | Morristown, New Jersey"
|
||||
8 print:print:print
|
||||
10 print "The fictitious chemical kryptocyanic acid can only be"
|
||||
20 print "diluted by the ratio of 7 parts water to 3 parts acid."
|
||||
30 print "if any other ratio is attempted, the acid becomes unstable"
|
||||
40 print "and soon explodes. Given the amount of acid, you must"
|
||||
50 print "decide who much water to add for dilution. If you miss,"
|
||||
60 print "you face the consequences."
|
||||
100 A=INT(RND(50))
|
||||
110 W=7*A/3
|
||||
115 if A=1 then P="liter" else P="liters"
|
||||
120 print A; " "; P ; " of kryptocyanic acid. How much water?";
|
||||
130 input R
|
||||
140 D=ABS(W-R)
|
||||
150 if D>W/20 then 200
|
||||
160 print "Good job! You may breathe now, but don't inhale the fumes!"
|
||||
170 print
|
||||
180 goto 100
|
||||
200 print "Sizzle! You have just been desalinated into a blob"
|
||||
210 print "of quivering protoplasm!"
|
||||
220 T=T+1
|
||||
230 if T=3 then 260
|
||||
240 print "However, you may try again with another life."
|
||||
250 goto 100
|
||||
260 print "Your 3 lives are used, but you will be long remembered for"
|
||||
270 print "your contributions to the field of comic-book chemistry."
|
||||
280 end
|
@ -1,51 +0,0 @@
|
||||
#lang br
|
||||
(require brag/support syntax-color/racket-lexer racket/contract
|
||||
basic-demo/tokenizer sugar/coerce)
|
||||
|
||||
(define (color-basic ip)
|
||||
(define postok (basic-lexer ip))
|
||||
(define tok (position-token-token postok))
|
||||
(define-values (type val)
|
||||
(cond
|
||||
[(eof-object? tok) (values eof eof)]
|
||||
[(string? tok) (values 'string tok)]
|
||||
[else (values (token-struct-type tok)
|
||||
(format "~a" (token-struct-val tok)))]))
|
||||
(values val
|
||||
(caseq type
|
||||
[(WHITE) 'white-space]
|
||||
[(COMMENT) 'comment]
|
||||
[(NUMBER) 'constant]
|
||||
[(STRING) 'string]
|
||||
[else 'keyword])
|
||||
#f
|
||||
(position-offset (position-token-start-pos postok))
|
||||
(position-offset (position-token-end-pos postok))))
|
||||
|
||||
|
||||
#;(provide
|
||||
(contract-out
|
||||
[color-basic
|
||||
(input-port? . -> . (values
|
||||
(or/c string? eof-object?)
|
||||
symbol?
|
||||
(or/c symbol? #f)
|
||||
(or/c exact-positive-integer? #f)
|
||||
(or/c exact-positive-integer? #f)))]))
|
||||
|
||||
(define (apply-colorer colorer-proc str)
|
||||
(let loop ([p (open-input-string str)][color-recs empty])
|
||||
(define color-rec (values->list (colorer-proc p)))
|
||||
(if (eof-object? (car color-rec))
|
||||
(reverse color-recs)
|
||||
(loop p (cons color-rec color-recs)))))
|
||||
|
||||
(module+ main
|
||||
(define str #<<HERE
|
||||
10 rem 20
|
||||
20 x = 42
|
||||
30 print x
|
||||
HERE
|
||||
)
|
||||
|
||||
(apply-colorer color-basic str))
|
@ -1,7 +0,0 @@
|
||||
#lang basic-demo-nth
|
||||
|
||||
5 A=5
|
||||
10 DIM A(A)
|
||||
20 PRINT A /* this should print 5 */
|
||||
30 PRINT A(0)
|
||||
40 PRINT A(5)
|
@ -1,260 +0,0 @@
|
||||
#lang br/quicklang
|
||||
(require (for-syntax syntax/strip-context))
|
||||
(provide #%top-interaction #%app #%datum
|
||||
(rename-out [basic-module-begin #%module-begin])
|
||||
(all-defined-out))
|
||||
|
||||
; BASIC implementation details
|
||||
; http://www.atariarchives.org/basicgames/showpage.php?page=i12
|
||||
|
||||
(begin-for-syntax
|
||||
(require racket/list)
|
||||
(define (gather-unique-ids stx)
|
||||
(remove-duplicates (map syntax->datum (filter (λ(s) (syntax-property s 'id)) (syntax-flatten stx))) eq?)))
|
||||
|
||||
(define-macro (basic-module-begin (basic-program PROGRAM-LINE ...))
|
||||
(with-pattern ([(UNIQUE-ID ...)
|
||||
(map (compose1 syntax-local-introduce (λ(id) (datum->syntax #f id)))
|
||||
(gather-unique-ids #'(PROGRAM-LINE ...)))])
|
||||
#'(#%module-begin
|
||||
(define UNIQUE-ID 0) ...
|
||||
(provide UNIQUE-ID ...)
|
||||
(run (sort (cons (line +inf.0 (statement "end"))
|
||||
(list PROGRAM-LINE ...)) #:key $line-number <)))))
|
||||
|
||||
|
||||
(struct exn:line-not-found exn:fail ())
|
||||
(define (raise-line-not-found-error ln)
|
||||
(raise
|
||||
(exn:line-not-found
|
||||
(format "line number ~a not found in program" ln)
|
||||
(current-continuation-marks))))
|
||||
|
||||
(struct end-program-signal exn:fail ())
|
||||
(define (raise-end-program-signal)
|
||||
(raise (end-program-signal "" (current-continuation-marks))))
|
||||
|
||||
(struct end-line-signal exn:fail ())
|
||||
(define (raise-end-line-signal)
|
||||
(raise (end-line-signal "" (current-continuation-marks))))
|
||||
|
||||
(define (run line-list)
|
||||
(define lines (list->vector line-list))
|
||||
(define (find-index ln)
|
||||
(or
|
||||
(for/or ([idx (in-range (vector-length lines))])
|
||||
(and (= ($line-number (vector-ref lines idx)) ln)
|
||||
idx))
|
||||
(raise-line-not-found-error ln)))
|
||||
(void
|
||||
(with-handlers ([end-program-signal? void])
|
||||
(for/fold ([program-counter 0])
|
||||
([i (in-naturals)])
|
||||
(let* ([line-thunk ($line-thunk (vector-ref lines program-counter))]
|
||||
[maybe-line-number (line-thunk)])
|
||||
(if (number? maybe-line-number)
|
||||
(find-index maybe-line-number)
|
||||
(add1 program-counter)))))))
|
||||
|
||||
(define current-return-stack (make-parameter empty))
|
||||
|
||||
(define (basic:gosub where)
|
||||
(let/cc return-k
|
||||
(current-return-stack (cons return-k (current-return-stack)))
|
||||
(basic:goto where)))
|
||||
|
||||
(define current-line (make-parameter #f))
|
||||
(struct $line (number thunk) #:transparent)
|
||||
(define-macro (line NUMBER . STATEMENTS)
|
||||
#'($line NUMBER (λ ()
|
||||
(current-line NUMBER)
|
||||
(with-handlers ([end-line-signal? (λ _ #f)]
|
||||
[end-program-signal? raise]
|
||||
[exn:fail? (λ(exn)
|
||||
(displayln (format "in line ~a" NUMBER))
|
||||
(raise exn))])
|
||||
. STATEMENTS))))
|
||||
|
||||
(define-macro-cases statement
|
||||
[(statement ID "=" EXPR) #'(basic:let ID EXPR)]
|
||||
[(statement PROC-NAME . ARGS)
|
||||
(with-pattern
|
||||
([PROC-ID (prefix-id "basic:" #'PROC-NAME)])
|
||||
#'(PROC-ID . ARGS))])
|
||||
|
||||
(define-macro-cases basic:let
|
||||
[(_ (id-expr ID) EXPR)
|
||||
#'(set! ID EXPR)]
|
||||
[(_ (id-expr ID DIM-IDX ...) EXPR)
|
||||
#'(array-set! ID DIM-IDX ... EXPR)])
|
||||
|
||||
(define-macro-cases basic:if
|
||||
[(_ COND-EXPR TRUE-EXPR FALSE-EXPR)
|
||||
#'(if (true? COND-EXPR)
|
||||
TRUE-EXPR
|
||||
FALSE-EXPR)]
|
||||
[(_ COND-EXPR TRUE-EXPR)
|
||||
#'(if (true? COND-EXPR)
|
||||
TRUE-EXPR
|
||||
(raise-end-line-signal))]) ; special short-circuit rule for one-armed conditional
|
||||
|
||||
(define true? (compose1 not zero?))
|
||||
(define (cond->int cond) (if cond 1 0))
|
||||
(define (basic:and . args) (cond->int (andmap true? args)))
|
||||
(define (basic:or . args) (cond->int (ormap true? args)))
|
||||
|
||||
(define-macro-cases id-expr
|
||||
[(_ ID) #'(cond
|
||||
[(procedure? ID) (ID)]
|
||||
[(array? ID) (array-ref ID (make-vector (array-rank ID) 0))] ; no subscript => zeroth element
|
||||
[else ID])]
|
||||
[(_ ID EXPR0 EXPR ...) #'(cond
|
||||
[(procedure? ID) (ID EXPR0 EXPR ...)]
|
||||
[(array? ID) (array-ref ID EXPR0 EXPR ...)]
|
||||
[else (error 'id-expr-confused)])])
|
||||
|
||||
(define-macro-cases expr
|
||||
[(_ COMP-EXPR) #'COMP-EXPR]
|
||||
[(_ COMP-EXPR "and" SUBEXPR) #'(basic:and COMP-EXPR SUBEXPR)]
|
||||
[(_ COMP-EXPR "or" SUBEXPR) #'(basic:or COMP-EXPR SUBEXPR)])
|
||||
|
||||
(define-macro-cases comp-expr
|
||||
[(_ SUM) #'SUM]
|
||||
[(_ SUM "=" COMP-EXPR)
|
||||
#'(cond->int (equal? SUM COMP-EXPR))] ; special case because `=` is overloaded in basic
|
||||
[(_ SUM OP-STR COMP-EXPR)
|
||||
(with-pattern
|
||||
([OP (replace-context #'here (prefix-id #'OP-STR))])
|
||||
#'(cond->int (OP SUM COMP-EXPR)))])
|
||||
|
||||
(define <> (compose1 not equal?))
|
||||
|
||||
(define-macro-cases sum
|
||||
[(_ SUM) #'SUM]
|
||||
[(_ SUM "+" PRODUCT) #'(+ SUM PRODUCT)]
|
||||
[(_ SUM "-" PRODUCT) #'(- SUM PRODUCT)])
|
||||
|
||||
(define-macro-cases product
|
||||
[(_ "-" VALUE) #'(- VALUE)]
|
||||
[(_ VALUE) #'VALUE]
|
||||
[(_ PRODUCT "*" VALUE) #'(* PRODUCT VALUE)]
|
||||
[(_ PRODUCT "/" VALUE) #'(/ PRODUCT VALUE)])
|
||||
|
||||
(define-macro-cases power
|
||||
[(_ BASE) #'BASE]
|
||||
[(_ BASE POWER) #'(expt BASE POWER)])
|
||||
|
||||
(define-macro-cases maybe-negative-val
|
||||
[(_ "-" ID) #'(- ID)]
|
||||
[(_ ID) #'ID])
|
||||
|
||||
(define print-list list)
|
||||
|
||||
(define (basic:print [args #f])
|
||||
(define (println [x ""])
|
||||
(define xstr (format "~a" x))
|
||||
(displayln xstr)
|
||||
(current-print-position 0))
|
||||
(define (print x)
|
||||
(define xstr (format "~a" x))
|
||||
(display xstr)
|
||||
(current-print-position (+ (current-print-position) (string-length xstr))))
|
||||
|
||||
(match args
|
||||
[#f (println)]
|
||||
[(list print-list-items ... ";" pl)
|
||||
(begin
|
||||
(for-each
|
||||
(λ(pli)
|
||||
(print (if (number? pli)
|
||||
(format "~a " pli)
|
||||
pli)))
|
||||
print-list-items)
|
||||
(basic:print pl))]
|
||||
[(list print-list-items ... ";") (for-each print print-list-items)]
|
||||
[(list print-list-items ...)
|
||||
(for-each println print-list-items)]))
|
||||
|
||||
(define current-print-position (make-parameter 0))
|
||||
(define (TAB num) (make-string (max 0 (INT (- num (current-print-position)))) #\space))
|
||||
(define (INT num) (inexact->exact (truncate num)))
|
||||
(define (SIN num) (sin num))
|
||||
(define (ABS num) (inexact->exact (abs num)))
|
||||
(define (RND num) (* (random) num))
|
||||
(define (EXP num) (exp num))
|
||||
(define (SQR num) (sqrt num))
|
||||
|
||||
(define-macro-cases basic:input
|
||||
[(_ (print-list . PL-ITEMS) ID ...)
|
||||
#'(begin
|
||||
(basic:print (append (print-list . PL-ITEMS) (list ";")))
|
||||
(basic:input ID) ...)]
|
||||
[(_ ID ...) #'(begin
|
||||
(set! ID (let* ([str (read-line)]
|
||||
[num (string->number (string-trim str))])
|
||||
(or num str))) ...)])
|
||||
|
||||
(define (basic:goto where) where)
|
||||
|
||||
(define-macro-cases basic:on
|
||||
[(_ TEST-EXPR "goto" OPTION ...)
|
||||
#'(basic:goto (list-ref (list OPTION ...) (sub1 TEST-EXPR)))]
|
||||
[(_ TEST-EXPR "gosub" OPTION ...)
|
||||
#'(basic:gosub (list-ref (list OPTION ...) (sub1 TEST-EXPR)))])
|
||||
|
||||
|
||||
(define (basic:return)
|
||||
(define return-k (car (current-return-stack)))
|
||||
(current-return-stack (cdr (current-return-stack)))
|
||||
(return-k #f))
|
||||
|
||||
(define (basic:stop) (basic:end))
|
||||
(define (basic:end) (raise-end-program-signal))
|
||||
|
||||
(require srfi/25)
|
||||
|
||||
(define-macro (basic:dim (id-expr ID EXPR ...) ...)
|
||||
#'(begin
|
||||
(set! ID (make-array (apply shape (append (list 0 (add1 EXPR)) ...)))) ...))
|
||||
|
||||
(define current-for-stack (make-parameter empty))
|
||||
|
||||
(define (push-for-stack thunk)
|
||||
(current-for-stack (cons thunk (current-for-stack))))
|
||||
|
||||
(define (pop-for-stack)
|
||||
(current-for-stack (cdr (current-for-stack))))
|
||||
|
||||
(define (in-closed-interval? x left right)
|
||||
(define cmp (if (< left right) <= >=))
|
||||
(cmp left x right))
|
||||
|
||||
(define-macro-cases basic:for
|
||||
[(_ VAR START-VALUE END-VALUE)
|
||||
#'(basic:for VAR START-VALUE END-VALUE 1)]
|
||||
[(_ VAR START-VALUE END-VALUE STEP-VALUE)
|
||||
#'(begin
|
||||
(statement (id-expr VAR) "=" START-VALUE) ; initialize the loop counter
|
||||
(let/cc return-k ; create a return point
|
||||
(push-for-stack (cons 'VAR
|
||||
(λ () ; thunk that increments counter & teleports back to beginning of loop
|
||||
(define next-val (+ VAR STEP-VALUE))
|
||||
(if (next-val . in-closed-interval? . START-VALUE END-VALUE)
|
||||
(begin
|
||||
(set! VAR next-val)
|
||||
(return-k #f)) ; return value for subsequent visits to line
|
||||
(pop-for-stack)))))
|
||||
#f))]) ; return value for first visit to line
|
||||
|
||||
(define (handle-next [which #f])
|
||||
(unless (pair? (current-for-stack)) (error 'next "for-stack is empty"))
|
||||
(define for-thunk (cdr (if which
|
||||
(assq which (current-for-stack))
|
||||
(car (current-for-stack)))))
|
||||
(for-thunk))
|
||||
|
||||
(define-macro (basic:next VAR ...)
|
||||
#'(handle-next 'VAR ...))
|
||||
|
||||
(define-macro (basic:def DEF-ID LAMBDA-ID EXPR)
|
||||
#'(set! DEF-ID (λ (LAMBDA-ID) EXPR)))
|
@ -1,8 +0,0 @@
|
||||
#lang basic-demo-nth
|
||||
10 for A=1 to 3
|
||||
20 print A
|
||||
21 for B=5 to 8
|
||||
22 print B
|
||||
23 next B
|
||||
30 next A
|
||||
40 print "yay"
|
@ -1,9 +0,0 @@
|
||||
#lang basic-demo-nth
|
||||
10 GOSUB 50
|
||||
15 PRINT "2 of 3"
|
||||
17 GOSUB 30
|
||||
20 END
|
||||
30 PRINT "3 of 3"
|
||||
40 RETURN
|
||||
50 PRINT "1 of 3"
|
||||
55 RETURN
|
@ -1,2 +0,0 @@
|
||||
#lang racket
|
||||
(require "for.bas")
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue