basic
Differences
This shows you the differences between two versions of the page.
basic [2020/07/11 10:45] – created perlfan | basic [2021/03/25 17:23] (current) – removed hc9 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== BASIC ===== | ||
- | === The basics of BASIC === | ||
- | |||
- | BASIC, which stands for **B**eginners **A**ll-Purpose **S**ymbolic **I**nstruction **C**ode is a programming language which was created at Dartmouth University by John Kemeny and Thomas Kurtz in the early 1960' | ||
- | |||
- | One of the difficulties in learning BASIC lies in the wide array of BASIC compilers and interpreters that are currently in circulation. Each one of these programs comes with their own nuances and extensions to the BASIC programming language. The good news is that there is a lot of commonality between the various versions of BASIC, and once you've gained familiarity with one you can move to another pretty quickly. Best of all, there is a common thread which runs through all the various BASICs, and that is where we will begin. We'll start with a minimal subset of the language, one which will get you up and running with all the interpreters available on SDF. | ||
- | |||
- | Let's start with a simple working example. A classic one which children the world over have typed into computers since the dawn of the 80's! | ||
- | |||
- | 10 PRINT " | ||
- | 20 GOTO 10 | ||
- | |||
- | If this is run through a BASIC interpreter, | ||
- | |||
- | HELLO | ||
- | HELLO | ||
- | HELLO | ||
- | HELLO | ||
- | .... and so on off into infinity | ||
- | |||
- | In fact, why don't we try this out in one of our several BASIC interpreters! Go ahead and fire up bwbasic. To do this, just type " | ||
- | |||
- | ######## | ||
- | ## ## | ||
- | ## ## | ||
- | ######## | ||
- | ## ## | ||
- | ## ## | ||
- | ######## | ||
- | |||
- | ######## | ||
- | ## ## | ||
- | ## ## | ||
- | ######## | ||
- | ## ## ######### | ||
- | ## ## ## ## ## ## ## ## ## | ||
- | ######## | ||
- | |||
- | Bywater BASIC Interpreter, | ||
- | Copyright (c) 1993, Ted A. Campbell | ||
- | Copyright (c) 1995-1997, Jon B. Volkoff | ||
- | Copyright (c) 2014-2015, Howard Wulf, AF5NE | ||
- | |||
- | bwBASIC: 10 PRINT " | ||
- | bwBASIC: 20 GOTO 10 | ||
- | bwBASIC: RUN | ||
- | HELLO | ||
- | HELLO | ||
- | HELLO | ||
- | HELLO | ||
- | HELLO | ||
- | HELLO | ||
- | HELLO | ||
- | HELLO | ||
- | HELLO | ||
- | HELLO | ||
- | HELLO | ||
- | Program interrupted at line 10 | ||
- | bwBASIC: | ||
- | |||
- | To exit bwbasic, just type " | ||
- | |||
- | === Structure of BASIC Lines of Code === | ||
- | |||
- | Ok, so let's unpack what we just did a little bit. The basic layout of a BASIC statement works like this: | ||
- | |||
- | LINE_NUMBER | ||
- | |||
- | Each of these parts serves a specific purpose. | ||
- | |||
- | * LINE_NUMBER - Present in most BASICS. This serves as a label for the line so you can refer to it later, and in some BASICs it also serves as a method of editing lines. (more on this later!) | ||
- | * COMMAND - This is what you want your program to do. There are lots of these, we'll discuss them in detail later. | ||
- | * PARAMETERS - Most commands require some additional information. That's what this one is about. | ||
- | |||
- | So now with that in mind, let's take a look at our happy little program! The first line | ||
- | |||
- | 10 PRINT " | ||
- | |||
- | is line number 10. The command that we are using is " | ||
- | |||
- | Now, what about the next line? | ||
- | |||
- | 20 GOTO 10 | ||
- | |||
- | GOTO is a command which tells them computer what line to execute next. Normally, the computer will just step through the lines of the program in order, but when it hits a GOTO, that's your chance to send it somewhere else. Here, we are sending it back to line 10. This causes it to print out " | ||
- | |||
- | === The BASIC Line Editor === | ||
- | |||
- | Before we go any further with the language, we should explore what's going on with those line numbers. The answer lies in BASIC' | ||
- | |||
- | First and foremost, these line numbers provide a guide for sequencing the program. The computer sorts them into increasing order. They need not be consecutive, | ||
- | |||
- | 15 PRINT " | ||
- | |||
- | Now, we can take a look at what the computer thinks the program is by using the LIST command: | ||
- | |||
- | LIST | ||
- | 10 PRINT " | ||
- | 15 PRINT " | ||
- | 20 GOTO 10 | ||
- | |||
- | You can also use the line number to change the lines: | ||
- | |||
- | 15 PRINT ": | ||
- | |||
- | Or you can delete lines all together | ||
- | |||
- | 15 | ||
- | |||
- | So in short, these line numbers are both your labels in your program, and they are also a means to edit your program. Of course, I should mention that not all BASIC interpreters support this sort of direct editing. In those cases, you'll want to edit your program in a standard text editor (like ed!) [ok, or vi or emacs]. But for that old-school feel, you'll want to use line number editing. | ||
- | |||
- | === Available BASIC Interpreters at SDF === | ||
- | |||
- | * bwbasic | ||
- | * yabasic | ||
- | * brandy | ||
- | * .. //This is exactly how to use BASIC at SDF with a plethora of fun and interesting programming examples just for you!//$Id: basic-language.html, |
basic.1594464301.txt.gz · Last modified: 2020/07/11 10:45 by perlfan