BASIC Syntaxer v1.01 with Syntaxer Editor for C64 (C) Hódi Gyula, Hungary, 1988,1991 This software package is now declared to FREEWARE. Please share it without making modifications. Introduction Most of us has already written BASIC programs. Suppose you are testing your new program, you have entered a lot of data, or use it for several minutes, and once it halted with the well known and beloved "Syntax error in ..." message. You see the given line, and say "Dam'd, I left out a colon here!", start again the whole test. Five minutes later: "Oh God, I didn't close this parenthesis!", and see above. Familiar? Unfortunately the C64 OS discovers the errors only when runs the program, although the most of them could be found before starting execution. So the BASIC Syntaxer is written to check syntactically the program lines just when they're entered, or later. Essentially the method is making comparison between the program lines and a data sequence stored in memory, which is depicting the forms of all possible program lines. When a program line does not fit to any of the legal cases then the line is incorrect. If we change the encoded form description then Syntaxer will be able to check program lines written in other languages, like Simon's BASIC, or a self-made BASIC extension wedge. For making changes of this kind the Syntaxer Editor is presented. -------------------------------------------------------------------------- BASIC Syntaxer Use this program to check the program lines one-by-one, immediately after entering them, or to check the whole program, later, at any time. The Syntaxer can identify SYNTAX ERRORs and TYPE MISMATCH ERRORs, and can mark their places. Loading Simply load and run the SYNTAXER, it will load and set up the remaining part of the program. But if you don't want to damage a BASIC program already loaded then follow these steps: LOAD "SXR1",8,1 LOAD "SXR2",8,1 LOAD "DEFAULT .SX64",8,1 (or other) LOAD "OLD*",8,1 NEW SYS 680 With these you load the components of the Syntaxer, and the OLD, which resets the main BASIC pointers and revives the previously loaded program. Instructions Usage: SYS 53000 This way you turn Syntaxer on or off. Usage: SYS 53000, parameters The 'parameters' can be composed of the followings: B : during the process the screen border is filled with stripes NB : disable 'B' (border) function W : when an error is detected the screen flashes, and a gong sounds NW : disable 'W' (warning) function E : in case of error an error message is displayed NE : disable 'E' (error) function Error messages ?:ERROR (i.e. syntax or type mismatch error) ):BRACKET ERROR ":NOT UNQUOTED ERROR *:TOO COMPLEX TO CHECK (try to simplify the program line) P : in case of error the program marks the last point till where the line seems to be acceptable; the real place of the error is often somewhere before that NP : disable 'P' (point) function X : turn off Syntaxer (you can turn it on again) number - number : check the program lines in the given interval (use line numbers as in LIST commands); always runs in NW,E,NP mode. To check the complete program give a single '-'. If you try to disable all warnings with NW and NP parameters then the program automatically switches to W mode. You don't have to turn on Syntaxer with a separate command, it's done when you define the functions. When turn off, none of the functions are changed, turning on again you get the last status. The default status is B,W,NE,NP. The elements of the 'parameters' may (but don't have to) be separated with spaces or commas. For example: SYS 53000,NB, W NE,P SYS 53000,NBWNEP SYS 53000,- (check all lines) SYS 53000,1-17 (check only this interval) SYS 53000,NB-110,P130B191- (check from top to line 110 and line 130 in NB mode, from line 191 to bottom in B mode, and finally switch on P mode, keep B mode on) SYS 53000,NB,-110,130,B,191-,P (same as above) SYS 53000 If Syntaxer is on, then every program line (beginning with number) will be checked immediately after you entered that, but it will be stored in the program however, independently of errors. So you also can enter incorrect lines (maybe written in extended BASIC), and ignore warnings. Syntaxer checks the lines till their first errors only. Syntaxer passes nearly all grammatic structures which are departing from the official BASIC language rules but are accepted by the interpreter. There are some harmless but useless, probably mistaken statements, which produce error warnings, e.g: INPUT : PRINT A<>=B : ON A GOTO , : etc. Some of the BASIC extensions use the same memory area as one of the Syntaxer's components. This means you can't use Syntaxer to check such kind of your programs while editing them, you have to check them occasionally, in a separate action, after you deactivated the BASIC extension. -------------------------------------------------------------------------- Syntaxer Editor BNF descriptive language For shortly defining the syntax rules a special code language is used, it's called BNF (Backus-Naur form). A BNF description consists of labels, each label stands for a defini- tion. The possible elements of a definition are labels, characters and BNF symbols. Where you see a label in a definition, there Syntaxer substitutes that with the definition which it's stands for. Let's see an example: Book ::= Cover«Page»Backcover Page ::= «Sentence» Sentence ::= Initialword« Word»<...|.|!|?> (see that space?) Initialword ::= Capital«Letter» Word ::= Letter«Letter» Letter ::= : exactly one of those three signs must be used (read as sign1 or sign2 or sign3) [sign] : the sign is optional, not required (option-brackets) «sign» : the sign is optional, and may be repeated at will (repeat-brackets) (Remember: bold []!) {text} : the number of opening and closing round parentheses has to be the same between these curly brackets With these symbols and tools you can describe all the rules of the language you use, and you can use it with Syntaxer to check your programs. Probably you should study the descriptions placed on disk with Editor for better understanding this method. Don't forget: when you design a descrip- tion, you must try to compose phrases which define all the legal cases and pass none of the illegal cases of that programming language. Always take care of using BNF symbols in correct order and well nested, otherwise the Syntaxer will surely make mistakes. Use C=/V function to avoid this type of errors when editing (see later). When there is a simple character (not a label or BNF symbol) in a definition then this character is required, exactly at that point of program lines. Programs can contain any type of characters, that's why Editor uses special attributes for labels and BNF symbols. Working with Syntaxer Editor You can load and run this program on the normal way. The Editor deactivates extension wedges, but tries to leave fast loaders. Editor starts in Catalog Mode. Here you can move on existing labels, make new labels, delete needless ones, use disk or tape devices, etc. On the bottom of the screen you see the number of current label (within its group), the current group, the number of free bytes and free labels. When you select a label and press Return, you switch to Editor Mode, where the selected label's definition can be edited. The labels are arranged into four groups: (auxiliary) definitions (DEF), statements (STM), numeric functions (FN%), string functions (FN$). This way in a definition you can refer to all labels in STM, FN% or FN$ group by using one collective label. For instance: in "numkif" (numeric expression) definition you will see the label " fn% " which means any of the numeric functions found in FN% group. The description's entry point (this was "Book" in the example above) is always the label named " line ", this means 'a program line'. Syntaxer will start the analyzing process with each line right here, so this label is strictly needed, that's why you can't delete this one. In Editor Mode all constant characters will appear in green, labels in inverted blue and BNF symbols in light green. If you enter a character which has a code out of $21-$5F range (i.e. not a letter, number or common type- writer character), then it will be displayed by its code, in inverted red field and in hexadecimal form. This is because you need to define BASIC expressions in exactly the same shape as they are stored in memory. C64 BASIC (and many extensions) uses tokens for statements and operators, which have special codes, and this is the easiest way to identify them by sight. (The tokens' codetable can be found in BASIC Reference Books.) But if you enter a character with its code in this $21-$5F range then Editor will display it in its common character shape. Never place a 'space' ($20) in a definition to separate elements of a line or an expression, because the interpreter and also the Syntaxer steps over space characters. BASIC uses $00 to mark End-of-line, so neither use that in your definitions. There are some special "principal" labels, which you can't make or find in Catalog (with " line " excepted), and which can be entered in a definition by hotkeys. Here they are: " line " : program line, this is the description's entry point " stm " : statement, initiating element of BASIC line segments " fn% " : numeric function, which returns a number " fn$ " : string function, which returns a string " num " : digit (0-9) " abc " : letter (A-Z) " chr " : any character except $00 and $22 (") " byt " : any character except $00 When you finished editing a definition then pressing C=/Return you can switch back to Catalog Mode. If you made any changes in that definition then the Editor automatically keeps the new version (only), and searches every labels of this definition in the Catalog. If a not existing label is found, the program will automatically create that in DEF group, and Editor warns you with a flashing of screen. If there isn't enough free space to register changes, program stays in Editor Mode. Deleting a label (in Catalog Mode) requires the greatest care, because if you make a mistake here, you need a hard work to correct it. You can delete only an empty label (which has totally empty definition). If you deleted a label which is referred from elsewhere, then looking at those definitions you will see " ?" labels standing for this deleted one, but only until you edit them. When you re-create the deleted label in Catalog, the Editor can not see the connection between the new and the relief labels, so it does not correct automatically the definitions, you have to do it manually. Never leave disconnected or empty labels in a description, because this may cause fault analysis or endless loop for Syntaxer. The complete description can be saved on disk or tape. If you want to use it with Syntaxer then load this (".SX64"-ended) file instead of "DEFAULT*", as you've seen above. There are four complete descriptions in this package. DEFAULT is for standard C64 BASIC, the others for Simon's BASIC, Graphics BASIC and Supergrafik. Try these files, and if you find any problem with your versions then you can make appropriate changes with Editor. Main functions in Catalog Mode (abbreviations: = -> C= , c -> Ctrl , | -> or) F1 | Right : next group right F2 | Left : next group left F3 | Down : step down in same group F4 | Up : step up in same group Home : jump to first label in group Clr : jump to last label in group letter | number: jump to next label starting with this character =Home : jump to " line " label Return : edit the selected label's definition (Editor Mode) Space : enter new label (type its name, and Return) =- then Del : delete selected (!) label =N : jump to next empty label (displayed in red) =V : check nesting order of brackets (in case of error Editor Mode follows with the wrong definition) @ : display DOS message (of disk drive) =@ : edit and send DOS command =4 : list disk directory on screen =L : load description file =S : save description into file =Stop : exit Syntaxer Editor (no warning about changes) Main functions in Editor Mode c,|c.|c/|c:| : enter one of BNF symbols |c;|c*|c^|c8|c9 Space : enter a label cA|cB|cC|cL| : enter one of "principal" labels |cN|cS|c4|c5 cDel : enter a character by its hex code Del : erase character at left to cursor (backspace) Crsr... : cursor moving F5 | Clr : jump to end of definition F6 | Home : jump to start of definition =Return : exit Editor Mode, keep changes =LeftArrow : quit Editor Mode, lose changes F1...F4 : same as in Catalog Mode (changes are kept) =- : cut (and store on clipboard) all text from cursor position to the end of definition =+ : insert (paste) clipboard's content at cursor position =V : check nesting order of brackets in current definition (in case of error the border is red, cursor is at the error point) Additional comments With this Editor you can make descriptions only for languages which use the same internal program structure as C64 BASIC. The programs (in memory or in file) are divided into lines. Each line has to begin with four indiffer- ent bytes (pointer and line number), and has to end with $00. The end of program is marked with $0000. Some systems (e.g: Logo, Forth, Prolog) are designed for different structure. When you create a new description file, it's recommended to begin with DEFAULT, and make changes on its copy. Modifying STM, FN% or FN$ groups and their labels is not too dangerous, but be careful when changing DEF group, there are important basic definitions. If you find Syntaxer working for seconds with one line, and the border shows a repetitive series of stripes (or a single colour), then the description has a section which fits infinitely long to a part of that program line. Break the process with Stop/Restore, and improve the description with Editor. For example: if you place a «» element in a definition (repeat-brackets around nothing) then Syntaxer can repeat the 'nothing' infinitely and still finds no departure from the current program line segment. Let's see some other considerations. If there are two texts in 'or' connection and one is the other's first part (e.g: ) then put the longer text on first place. If Syntaxer would check an "abc" line based on an incorrect "" definition, then "ab" part would be passed, and "c" part should be compared with the next (and maybe not existing) segment of this definition, which means a mistaken analysis. Suppose there is a definition containing "«(»(numexp)" pattern. Here you can see an appearance of "(" after a repetitive definition of the same sign. When Syntaxer tries to analyze "(A+2)*3" expression by this definition, the opening parenthesis is passed as the repetitive item allows it, but then the remaining obligatory parenthesis does not fit to the following "A" sign, so an error warning will be displayed. (Remark: Syntaxer follows a preorder 'backtrack' algorithm, but backtracks only till the actual parenthesis level. If the description's graph is not a regular tree, or the defined code is infinite or not left-prefix, then the comparison could fail or cause an endless loop.) The components of the Syntaxer are loaded to the following areas: $CC2E-CFF0 (SXR1), E000-E52E (SXR2), A000-... (*.SX64).