2020-08-11 02:35:25 +00:00
|
|
|
import { WorkerError, CodeListingMap, SourceLocation, SourceLine } from "../workertypes";
|
2020-08-05 04:48:29 +00:00
|
|
|
|
2020-08-11 17:29:31 +00:00
|
|
|
export interface BASICOptions {
|
|
|
|
dialectName : string; // use this to select the dialect
|
|
|
|
// SYNTAX AND PARSING
|
|
|
|
asciiOnly : boolean; // reject non-ASCII chars?
|
|
|
|
uppercaseOnly : boolean; // convert everything to uppercase?
|
|
|
|
optionalLabels : boolean; // can omit line numbers and use labels?
|
|
|
|
optionalWhitespace : boolean; // can "crunch" keywords?
|
2020-08-13 17:51:35 +00:00
|
|
|
varNaming : 'A'|'A1'|'AA'|'*'; // only allow A0-9 for numerics, single letter for arrays/strings
|
|
|
|
squareBrackets : boolean; // "[" and "]" interchangable with "(" and ")"?
|
2020-08-11 17:29:31 +00:00
|
|
|
tickComments : boolean; // support 'comments?
|
2020-08-12 15:51:18 +00:00
|
|
|
hexOctalConsts : boolean; // support &H and &O integer constants?
|
2020-08-11 17:29:31 +00:00
|
|
|
validKeywords : string[]; // valid keywords (or null for accept all)
|
|
|
|
validFunctions : string[]; // valid functions (or null for accept all)
|
|
|
|
validOperators : string[]; // valid operators (or null for accept all)
|
|
|
|
// VALUES AND OPERATORS
|
|
|
|
defaultValues : boolean; // initialize unset variables to default value? (0 or "")
|
|
|
|
stringConcat : boolean; // can concat strings with "+" operator?
|
|
|
|
typeConvert : boolean; // type convert strings <-> numbers?
|
|
|
|
checkOverflow : boolean; // check for overflow of numerics?
|
|
|
|
bitwiseLogic : boolean; // -1 = TRUE, 0 = FALSE, AND/OR/NOT done with bitwise ops
|
|
|
|
maxStringLength : number; // maximum string length in chars
|
|
|
|
maxDefArgs : number; // maximum # of arguments for user-defined functions
|
|
|
|
// ARRAYS
|
|
|
|
staticArrays : boolean; // can only DIM with constant value? (and never redim)
|
|
|
|
sharedArrayNamespace : boolean; // arrays and variables have same namespace? (TODO)
|
|
|
|
defaultArrayBase : number; // arrays start at this number (0 or 1)
|
|
|
|
defaultArraySize : number; // arrays are allocated w/ this size (starting @ 0)
|
|
|
|
maxDimensions : number; // max number of dimensions for arrays
|
2020-08-13 17:51:35 +00:00
|
|
|
arraysContainChars : boolean; // HP BASIC array-slicing syntax
|
2020-08-11 17:29:31 +00:00
|
|
|
// PRINTING
|
|
|
|
printZoneLength : number; // print zone length
|
|
|
|
numericPadding : boolean; // " " or "-" before and " " after numbers?
|
|
|
|
// CONTROL FLOW
|
|
|
|
testInitialFor : boolean; // can we skip a NEXT statement? (can't interleave tho)
|
2020-08-12 15:11:10 +00:00
|
|
|
optionalNextVar : boolean; // can do NEXT without variable
|
2020-08-12 16:57:54 +00:00
|
|
|
multipleNextVars : boolean; // NEXT J,I
|
|
|
|
checkOnGotoIndex : boolean; // fatal error when ON..GOTO index out of bounds
|
2020-08-13 17:51:35 +00:00
|
|
|
computedGoto : boolean; // non-const expr GOTO label (and GOTO..OF expression)
|
2020-08-12 16:57:54 +00:00
|
|
|
restoreWithLabel : boolean; // RESTORE <label>
|
2020-08-13 17:51:35 +00:00
|
|
|
endStmtRequired : boolean; // need END at end?
|
2020-08-11 17:29:31 +00:00
|
|
|
// MISC
|
|
|
|
commandsPerSec? : number; // how many commands per second?
|
|
|
|
}
|
|
|
|
|
2020-08-05 04:48:29 +00:00
|
|
|
export interface SourceLocated {
|
2020-08-11 02:35:25 +00:00
|
|
|
$loc?: SourceLine;
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 17:29:31 +00:00
|
|
|
export class CompileError extends Error {
|
2020-08-12 16:57:54 +00:00
|
|
|
$loc : SourceLocation;
|
|
|
|
constructor(msg: string, loc: SourceLocation) {
|
2020-08-05 04:48:29 +00:00
|
|
|
super(msg);
|
|
|
|
Object.setPrototypeOf(this, CompileError.prototype);
|
2020-08-12 16:57:54 +00:00
|
|
|
this.$loc = loc;
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lexer regular expression -- each (capture group) handles a different token type
|
2020-08-14 04:34:54 +00:00
|
|
|
// FLOAT INT HEXOCTAL REMARK IDENT STRING RELOP EXP OPERATORS OTHER WS
|
|
|
|
const re_toks = /([0-9.]+[E][+-]?\d+|\d+[.][E0-9]*|[.][E0-9]+)|[0]*(\d+)|&([OH][0-9A-F]+)|(['].*)|(\w+[$]?)|(".*?")|([<>]?[=<>#])|(\*\*)|([-+*/^,;:()\[\]?\\])|(\S+)|(\s+)/gi;
|
2020-08-05 04:48:29 +00:00
|
|
|
|
|
|
|
export enum TokenType {
|
|
|
|
EOL = 0,
|
2020-08-14 04:34:54 +00:00
|
|
|
Float,
|
2020-08-05 04:48:29 +00:00
|
|
|
Int,
|
2020-08-12 15:51:18 +00:00
|
|
|
HexOctalInt,
|
2020-08-05 04:48:29 +00:00
|
|
|
Remark,
|
|
|
|
Ident,
|
|
|
|
String,
|
|
|
|
Relational,
|
2020-08-13 17:51:35 +00:00
|
|
|
DoubleStar,
|
2020-08-05 04:48:29 +00:00
|
|
|
Operator,
|
|
|
|
CatchAll,
|
2020-08-14 04:34:54 +00:00
|
|
|
Whitespace,
|
2020-08-05 04:48:29 +00:00
|
|
|
_LAST,
|
|
|
|
}
|
|
|
|
|
|
|
|
export type ExprTypes = BinOp | UnOp | IndOp | Literal;
|
|
|
|
|
2020-08-10 01:40:17 +00:00
|
|
|
export type Expr = ExprTypes; // & SourceLocated;
|
2020-08-05 04:48:29 +00:00
|
|
|
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
export type Opcode = string;
|
2020-08-05 04:48:29 +00:00
|
|
|
|
|
|
|
export type Value = string | number;
|
|
|
|
|
|
|
|
export interface Literal {
|
|
|
|
value: Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface BinOp {
|
|
|
|
op: Opcode;
|
|
|
|
left: Expr;
|
|
|
|
right: Expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface UnOp {
|
2020-08-09 16:23:49 +00:00
|
|
|
op: 'neg' | 'lnot' | 'bnot';
|
2020-08-05 04:48:29 +00:00
|
|
|
expr: Expr;
|
|
|
|
}
|
|
|
|
|
2020-08-10 01:40:17 +00:00
|
|
|
export interface IndOp {
|
2020-08-05 04:48:29 +00:00
|
|
|
name: string;
|
|
|
|
args: Expr[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface PRINT_Statement {
|
|
|
|
command: "PRINT";
|
|
|
|
args: Expr[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface LET_Statement {
|
|
|
|
command: "LET";
|
|
|
|
lexpr: IndOp;
|
|
|
|
right: Expr;
|
|
|
|
}
|
|
|
|
|
2020-08-09 02:36:21 +00:00
|
|
|
export interface DIM_Statement {
|
|
|
|
command: "DIM";
|
|
|
|
args: IndOp[];
|
|
|
|
}
|
|
|
|
|
2020-08-05 04:48:29 +00:00
|
|
|
export interface GOTO_Statement {
|
|
|
|
command: "GOTO";
|
|
|
|
label: Expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface GOSUB_Statement {
|
|
|
|
command: "GOSUB";
|
|
|
|
label: Expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RETURN_Statement {
|
|
|
|
command: "RETURN";
|
|
|
|
}
|
|
|
|
|
2020-08-13 17:51:35 +00:00
|
|
|
export interface ONGO_Statement {
|
2020-08-10 13:07:09 +00:00
|
|
|
command: "ONGOTO" | "ONGOSUB";
|
2020-08-09 02:36:21 +00:00
|
|
|
expr: Expr;
|
|
|
|
labels: Expr[];
|
|
|
|
}
|
|
|
|
|
2020-08-05 04:48:29 +00:00
|
|
|
export interface IF_Statement {
|
|
|
|
command: "IF";
|
|
|
|
cond: Expr;
|
|
|
|
}
|
|
|
|
|
2020-08-09 02:36:21 +00:00
|
|
|
export interface ELSE_Statement {
|
|
|
|
command: "ELSE";
|
|
|
|
}
|
|
|
|
|
2020-08-05 04:48:29 +00:00
|
|
|
export interface FOR_Statement {
|
|
|
|
command: "FOR";
|
|
|
|
lexpr: IndOp;
|
|
|
|
initial: Expr;
|
|
|
|
target: Expr;
|
|
|
|
step?: Expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface NEXT_Statement {
|
|
|
|
command: "NEXT";
|
|
|
|
lexpr?: IndOp;
|
|
|
|
}
|
|
|
|
|
2020-08-12 16:57:54 +00:00
|
|
|
export interface WHILE_Statement {
|
|
|
|
command: "WHILE";
|
|
|
|
cond: Expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface WEND_Statement {
|
|
|
|
command: "WEND";
|
|
|
|
}
|
|
|
|
|
2020-08-05 04:48:29 +00:00
|
|
|
export interface INPUT_Statement {
|
|
|
|
command: "INPUT";
|
|
|
|
prompt: Expr;
|
|
|
|
args: IndOp[];
|
|
|
|
}
|
|
|
|
|
2020-08-09 02:36:21 +00:00
|
|
|
export interface DATA_Statement {
|
|
|
|
command: "DATA";
|
2020-08-14 04:34:54 +00:00
|
|
|
datums: Literal[];
|
2020-08-09 02:36:21 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 04:48:29 +00:00
|
|
|
export interface READ_Statement {
|
2020-08-09 02:36:21 +00:00
|
|
|
command: "READ";
|
2020-08-05 04:48:29 +00:00
|
|
|
args: IndOp[];
|
|
|
|
}
|
|
|
|
|
2020-08-12 16:57:54 +00:00
|
|
|
export interface RESTORE_Statement {
|
|
|
|
command: "RESTORE";
|
|
|
|
label: Expr;
|
|
|
|
}
|
|
|
|
|
2020-08-05 04:48:29 +00:00
|
|
|
export interface DEF_Statement {
|
|
|
|
command: "DEF";
|
|
|
|
lexpr: IndOp;
|
|
|
|
def: Expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface OPTION_Statement {
|
|
|
|
command: "OPTION";
|
|
|
|
optname: string;
|
|
|
|
optargs: string[];
|
|
|
|
}
|
|
|
|
|
2020-08-12 16:57:54 +00:00
|
|
|
export interface GET_Statement { // applesoft only?
|
2020-08-09 02:36:21 +00:00
|
|
|
command: "GET";
|
|
|
|
lexpr: IndOp;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface NoArgStatement {
|
|
|
|
command: string;
|
|
|
|
}
|
|
|
|
|
2020-08-05 04:48:29 +00:00
|
|
|
export type StatementTypes = PRINT_Statement | LET_Statement | GOTO_Statement | GOSUB_Statement
|
2020-08-09 02:36:21 +00:00
|
|
|
| IF_Statement | FOR_Statement | NEXT_Statement | DIM_Statement
|
2020-08-13 17:51:35 +00:00
|
|
|
| INPUT_Statement | READ_Statement | DEF_Statement | ONGO_Statement
|
2020-08-12 16:57:54 +00:00
|
|
|
| DATA_Statement | OPTION_Statement | GET_Statement | RESTORE_Statement
|
|
|
|
| NoArgStatement;
|
2020-08-05 04:48:29 +00:00
|
|
|
|
|
|
|
export type Statement = StatementTypes & SourceLocated;
|
|
|
|
|
|
|
|
export interface BASICLine {
|
|
|
|
label: string;
|
|
|
|
stmts: Statement[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface BASICProgram {
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
opts: BASICOptions;
|
2020-08-05 04:48:29 +00:00
|
|
|
lines: BASICLine[];
|
|
|
|
}
|
|
|
|
|
|
|
|
class Token {
|
|
|
|
str: string;
|
|
|
|
type: TokenType;
|
|
|
|
$loc: SourceLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
const OPERATORS = {
|
2020-08-09 16:23:49 +00:00
|
|
|
'IMP': {f:'bimp',p:4},
|
|
|
|
'EQV': {f:'beqv',p:5},
|
|
|
|
'XOR': {f:'bxor',p:6},
|
2020-08-11 17:29:31 +00:00
|
|
|
'OR': {f:'bor',p:7}, // or "lor" for logical
|
|
|
|
'AND': {f:'band',p:8}, // or "land" for logical
|
|
|
|
'||': {f:'lor',p:17}, // not used
|
|
|
|
'&&': {f:'land',p:18}, // not used
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
'=': {f:'eq',p:50},
|
2020-08-13 17:51:35 +00:00
|
|
|
//'==': {f:'eq',p:50},
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
'<>': {f:'ne',p:50},
|
2020-08-13 17:51:35 +00:00
|
|
|
'><': {f:'ne',p:50},
|
|
|
|
//'!=': {f:'ne',p:50},
|
|
|
|
'#': {f:'ne',p:50},
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
'<': {f:'lt',p:50},
|
|
|
|
'>': {f:'gt',p:50},
|
|
|
|
'<=': {f:'le',p:50},
|
|
|
|
'>=': {f:'ge',p:50},
|
2020-08-13 17:51:35 +00:00
|
|
|
'MIN': {f:'min',p:75},
|
|
|
|
'MAX': {f:'max',p:75},
|
2020-08-05 04:48:29 +00:00
|
|
|
'+': {f:'add',p:100},
|
|
|
|
'-': {f:'sub',p:100},
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
'%': {f:'mod',p:140},
|
|
|
|
'\\': {f:'idiv',p:150},
|
2020-08-05 04:48:29 +00:00
|
|
|
'*': {f:'mul',p:200},
|
|
|
|
'/': {f:'div',p:200},
|
2020-08-13 17:51:35 +00:00
|
|
|
'^': {f:'pow',p:300},
|
|
|
|
'**': {f:'pow',p:300},
|
2020-08-05 04:48:29 +00:00
|
|
|
};
|
|
|
|
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
function getOperator(op: string) {
|
|
|
|
return OPERATORS[op];
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPrecedence(tok: Token): number {
|
|
|
|
switch (tok.type) {
|
|
|
|
case TokenType.Operator:
|
2020-08-13 17:51:35 +00:00
|
|
|
case TokenType.DoubleStar:
|
2020-08-05 04:48:29 +00:00
|
|
|
case TokenType.Relational:
|
|
|
|
case TokenType.Ident:
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
let op = getOperator(tok.str);
|
2020-08-05 04:48:29 +00:00
|
|
|
if (op) return op.p;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// is token an end of statement marker? (":" or end of line)
|
|
|
|
function isEOS(tok: Token) {
|
2020-08-09 02:36:21 +00:00
|
|
|
return tok.type == TokenType.EOL || tok.type == TokenType.Remark
|
|
|
|
|| tok.str == ':' || tok.str == 'ELSE'; // TODO: only ELSE if ifElse==true
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function stripQuotes(s: string) {
|
|
|
|
// TODO: assert
|
|
|
|
return s.substr(1, s.length-2);
|
|
|
|
}
|
|
|
|
|
|
|
|
///// BASIC PARSER
|
|
|
|
|
|
|
|
export class BASICParser {
|
2020-08-13 17:51:35 +00:00
|
|
|
opts : BASICOptions = DIALECTS['DEFAULT'];
|
2020-08-05 04:48:29 +00:00
|
|
|
errors: WorkerError[];
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
listings: CodeListingMap;
|
2020-08-05 04:48:29 +00:00
|
|
|
labels: { [label: string]: BASICLine };
|
|
|
|
targets: { [targetlabel: string]: SourceLocation };
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
refs: { [name: string]: SourceLocation }; // references
|
|
|
|
|
2020-08-09 21:32:52 +00:00
|
|
|
path : string;
|
2020-08-05 04:48:29 +00:00
|
|
|
lineno : number;
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
tokens: Token[];
|
|
|
|
eol: Token;
|
2020-08-05 04:48:29 +00:00
|
|
|
curlabel: string;
|
|
|
|
lasttoken: Token;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.labels = {};
|
|
|
|
this.targets = {};
|
|
|
|
this.errors = [];
|
|
|
|
this.lineno = 0;
|
|
|
|
this.curlabel = null;
|
|
|
|
this.listings = {};
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
this.refs = {};
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
compileError(msg: string, loc?: SourceLocation) {
|
|
|
|
if (!loc) loc = this.peekToken().$loc;
|
2020-08-12 15:11:10 +00:00
|
|
|
this.errors.push({path:loc.path, line:loc.line, label:this.curlabel, start:loc.start, end:loc.end, msg:msg});
|
2020-08-12 16:57:54 +00:00
|
|
|
throw new CompileError(msg, loc);
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
dialectError(what: string, loc?: SourceLocation) {
|
2020-08-10 16:08:43 +00:00
|
|
|
this.compileError(`The selected BASIC dialect (${this.opts.dialectName}) doesn't support ${what}.`, loc); // TODO
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
consumeToken(): Token {
|
|
|
|
var tok = this.lasttoken = (this.tokens.shift() || this.eol);
|
|
|
|
return tok;
|
|
|
|
}
|
2020-08-09 16:23:49 +00:00
|
|
|
expectToken(str: string, msg?: string) : Token {
|
2020-08-05 04:48:29 +00:00
|
|
|
var tok = this.consumeToken();
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
var tokstr = tok.str;
|
2020-08-05 04:48:29 +00:00
|
|
|
if (str != tokstr) {
|
2020-08-09 16:23:49 +00:00
|
|
|
this.compileError(msg || `There should be a "${str}" here.`);
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
return tok;
|
|
|
|
}
|
2020-08-12 15:11:10 +00:00
|
|
|
expectTokens(strlist: string[], msg?: string) : Token {
|
|
|
|
var tok = this.consumeToken();
|
|
|
|
var tokstr = tok.str;
|
|
|
|
if (strlist.indexOf(tokstr) < 0) {
|
2020-08-12 15:51:18 +00:00
|
|
|
this.compileError(msg || `There should be a ${strlist.map((s) => `"${s}"`).join(' or ')} here.`);
|
2020-08-12 15:11:10 +00:00
|
|
|
}
|
|
|
|
return tok;
|
|
|
|
}
|
2020-08-05 04:48:29 +00:00
|
|
|
peekToken(): Token {
|
|
|
|
var tok = this.tokens[0];
|
|
|
|
return tok ? tok : this.eol;
|
|
|
|
}
|
|
|
|
pushbackToken(tok: Token) {
|
|
|
|
this.tokens.unshift(tok);
|
|
|
|
}
|
|
|
|
parseOptLabel(line: BASICLine) {
|
|
|
|
let tok = this.consumeToken();
|
|
|
|
switch (tok.type) {
|
2020-08-09 02:36:21 +00:00
|
|
|
case TokenType.Ident:
|
|
|
|
if (this.opts.optionalLabels) {
|
|
|
|
if (this.peekToken().str == ':') { // is it a label:
|
|
|
|
this.consumeToken(); // eat the ":"
|
|
|
|
// fall through to the next case
|
|
|
|
} else {
|
|
|
|
this.pushbackToken(tok); // nope
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else this.dialectError(`optional line numbers`);
|
2020-08-05 04:48:29 +00:00
|
|
|
case TokenType.Int:
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
if (this.labels[tok.str] != null) this.compileError(`There's a duplicated label "${tok.str}".`);
|
2020-08-05 04:48:29 +00:00
|
|
|
this.labels[tok.str] = line;
|
|
|
|
line.label = tok.str;
|
|
|
|
this.curlabel = tok.str;
|
|
|
|
break;
|
2020-08-12 15:51:18 +00:00
|
|
|
case TokenType.HexOctalInt:
|
2020-08-14 04:34:54 +00:00
|
|
|
case TokenType.Float:
|
2020-08-09 01:03:48 +00:00
|
|
|
this.compileError(`Line numbers must be positive integers.`);
|
|
|
|
break;
|
2020-08-05 04:48:29 +00:00
|
|
|
default:
|
2020-08-09 02:36:21 +00:00
|
|
|
if (this.opts.optionalLabels) this.compileError(`A line must start with a line number, command, or label.`);
|
|
|
|
else this.compileError(`A line must start with a line number.`);
|
2020-08-05 04:48:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parseFile(file: string, path: string) : BASICProgram {
|
2020-08-09 21:32:52 +00:00
|
|
|
this.path = path;
|
2020-08-14 04:34:54 +00:00
|
|
|
var txtlines = file.split(/\n|\r\n/);
|
2020-08-13 17:51:35 +00:00
|
|
|
var pgmlines = txtlines.map((line) => this.parseLine(line));
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
var program = { opts: this.opts, lines: pgmlines };
|
|
|
|
this.checkAll(program);
|
2020-08-05 04:48:29 +00:00
|
|
|
this.listings[path] = this.generateListing(file, program);
|
|
|
|
return program;
|
|
|
|
}
|
|
|
|
parseLine(line: string) : BASICLine {
|
|
|
|
try {
|
|
|
|
this.tokenize(line);
|
|
|
|
return this.parse();
|
|
|
|
} catch (e) {
|
|
|
|
if (!(e instanceof CompileError)) throw e; // ignore compile errors since errors[] list captures them
|
|
|
|
return {label:null, stmts:[]};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tokenize(line: string) : void {
|
|
|
|
this.lineno++;
|
|
|
|
this.tokens = [];
|
2020-08-12 16:57:54 +00:00
|
|
|
// split identifier regex (if token-crunching enabled)
|
2020-08-13 23:53:11 +00:00
|
|
|
let splitre = this.opts.optionalWhitespace && new RegExp('('+this.opts.validKeywords.map(s => `${s}`).join('|')+')');
|
2020-08-12 16:57:54 +00:00
|
|
|
// iterate over each token via re_toks regex
|
2020-08-14 04:34:54 +00:00
|
|
|
var lastTokType = TokenType.CatchAll;
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
var m : RegExpMatchArray;
|
2020-08-05 04:48:29 +00:00
|
|
|
while (m = re_toks.exec(line)) {
|
2020-08-14 04:34:54 +00:00
|
|
|
for (var i = 1; i <= lastTokType; i++) {
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
let s : string = m[i];
|
2020-08-05 04:48:29 +00:00
|
|
|
if (s != null) {
|
2020-08-11 17:29:31 +00:00
|
|
|
let loc = { path: this.path, line: this.lineno, start: m.index, end: m.index+s.length, label: this.curlabel };
|
2020-08-09 02:36:21 +00:00
|
|
|
// maybe we don't support unicode in 1975?
|
|
|
|
if (this.opts.asciiOnly && !/^[\x00-\x7F]*$/.test(s))
|
|
|
|
this.dialectError(`non-ASCII characters`);
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
// uppercase all identifiers, and maybe more
|
2020-08-14 04:34:54 +00:00
|
|
|
if (i == TokenType.Ident || i == TokenType.HexOctalInt || this.opts.uppercaseOnly) {
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
s = s.toUpperCase();
|
2020-08-14 04:34:54 +00:00
|
|
|
// DATA statement captures whitespace too
|
|
|
|
if (s == 'DATA') lastTokType = TokenType.Whitespace;
|
|
|
|
// REM means ignore rest of statement
|
|
|
|
if (lastTokType == TokenType.CatchAll && s.startsWith('REM')) {
|
|
|
|
s = 'REM';
|
|
|
|
lastTokType = TokenType.EOL;
|
|
|
|
}
|
|
|
|
}
|
2020-08-13 17:51:35 +00:00
|
|
|
// convert brackets
|
|
|
|
if (s == '[' || s == ']') {
|
|
|
|
if (!this.opts.squareBrackets) this.dialectError(`square brackets`);
|
|
|
|
if (s == '[') s = '(';
|
|
|
|
if (s == ']') s = ')';
|
|
|
|
}
|
2020-08-13 23:53:11 +00:00
|
|
|
// un-crunch tokens?
|
|
|
|
if (splitre && i == TokenType.Ident) {
|
|
|
|
var splittoks = s.split(splitre);
|
|
|
|
splittoks.forEach((ss) => {
|
|
|
|
if (ss != '') {
|
|
|
|
// leftover might be integer
|
|
|
|
i = /^[0-9]+$/.test(ss) ? TokenType.Int : TokenType.Ident;
|
|
|
|
// disable crunching after this token?
|
|
|
|
if (ss == 'DATA' || ss == 'OPTION')
|
|
|
|
splitre = null;
|
|
|
|
this.tokens.push({str: ss, type: i, $loc:loc});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// add token to list
|
|
|
|
this.tokens.push({str: s, type: i, $loc:loc});
|
2020-08-11 17:29:31 +00:00
|
|
|
}
|
2020-08-05 04:48:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-10 01:40:17 +00:00
|
|
|
this.eol = { type: TokenType.EOL, str: "", $loc: { path: this.path, line: this.lineno, start: line.length, label: this.curlabel } };
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
parse() : BASICLine {
|
|
|
|
var line = {label: null, stmts: []};
|
|
|
|
// not empty line?
|
|
|
|
if (this.tokens.length) {
|
|
|
|
this.parseOptLabel(line);
|
2020-08-09 01:03:48 +00:00
|
|
|
if (this.tokens.length) {
|
|
|
|
line.stmts = this.parseCompoundStatement();
|
|
|
|
}
|
2020-08-10 01:40:17 +00:00
|
|
|
this.curlabel = null;
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
parseCompoundStatement(): Statement[] {
|
|
|
|
var list = this.parseList(this.parseStatement, ':');
|
2020-08-09 02:36:21 +00:00
|
|
|
var next = this.peekToken();
|
|
|
|
if (!isEOS(next))
|
|
|
|
this.compileError(`Expected end of line or ':'`, next.$loc);
|
|
|
|
if (next.str == 'ELSE')
|
|
|
|
return list.concat(this.parseCompoundStatement());
|
|
|
|
else
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
validKeyword(keyword: string) : string {
|
|
|
|
return (this.opts.validKeywords && this.opts.validKeywords.indexOf(keyword) < 0) ? null : keyword;
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
parseStatement(): Statement | null {
|
|
|
|
var cmdtok = this.consumeToken();
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
var cmd = cmdtok.str;
|
2020-08-05 04:48:29 +00:00
|
|
|
var stmt;
|
|
|
|
switch (cmdtok.type) {
|
|
|
|
case TokenType.Remark:
|
2020-08-13 23:53:11 +00:00
|
|
|
if (cmdtok.str.startsWith("'") && !this.opts.tickComments) this.dialectError(`tick remarks`);
|
2020-08-05 04:48:29 +00:00
|
|
|
return null;
|
2020-08-09 02:36:21 +00:00
|
|
|
case TokenType.Operator:
|
|
|
|
if (cmd == this.validKeyword('?')) cmd = 'PRINT';
|
2020-08-05 04:48:29 +00:00
|
|
|
case TokenType.Ident:
|
2020-08-14 04:34:54 +00:00
|
|
|
// ignore remarks
|
|
|
|
if (cmd == 'REM') return null;
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
// look for "GO TO" and "GO SUB"
|
2020-08-05 04:48:29 +00:00
|
|
|
if (cmd == 'GO' && this.peekToken().str == 'TO') {
|
|
|
|
this.consumeToken();
|
|
|
|
cmd = 'GOTO';
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
} else if (cmd == 'GO' && this.peekToken().str == 'SUB') {
|
|
|
|
this.consumeToken();
|
|
|
|
cmd = 'GOSUB';
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
// lookup JS function for command
|
2020-08-05 04:48:29 +00:00
|
|
|
var fn = this['stmt__' + cmd];
|
|
|
|
if (fn) {
|
2020-08-09 02:36:21 +00:00
|
|
|
if (this.validKeyword(cmd) == null)
|
2020-08-05 04:48:29 +00:00
|
|
|
this.dialectError(`the ${cmd} keyword`);
|
|
|
|
stmt = fn.bind(this)() as Statement;
|
|
|
|
break;
|
|
|
|
} else if (this.peekToken().str == '=' || this.peekToken().str == '(') {
|
|
|
|
// 'A = expr' or 'A(X) = expr'
|
|
|
|
this.pushbackToken(cmdtok);
|
|
|
|
stmt = this.stmt__LET();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TokenType.EOL:
|
|
|
|
default:
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
this.compileError(`There should be a command here.`);
|
2020-08-05 04:48:29 +00:00
|
|
|
return null;
|
|
|
|
}
|
2020-08-10 01:40:17 +00:00
|
|
|
if (stmt) stmt.$loc = { path: cmdtok.$loc.path, line: cmdtok.$loc.line, start: cmdtok.$loc.start, end: this.peekToken().$loc.start, label: this.curlabel };
|
2020-08-05 04:48:29 +00:00
|
|
|
return stmt;
|
|
|
|
}
|
2020-08-09 01:25:58 +00:00
|
|
|
parseVarSubscriptOrFunc(): IndOp {
|
2020-08-05 04:48:29 +00:00
|
|
|
var tok = this.consumeToken();
|
|
|
|
switch (tok.type) {
|
|
|
|
case TokenType.Ident:
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
this.refs[tok.str] = tok.$loc;
|
2020-08-05 04:48:29 +00:00
|
|
|
let args = null;
|
|
|
|
if (this.peekToken().str == '(') {
|
|
|
|
this.expectToken('(');
|
|
|
|
args = this.parseExprList();
|
2020-08-09 16:23:49 +00:00
|
|
|
this.expectToken(')', `There should be another expression or a ")" here.`);
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
2020-08-10 01:40:17 +00:00
|
|
|
return { name: tok.str, args: args };
|
2020-08-05 04:48:29 +00:00
|
|
|
default:
|
2020-08-09 01:25:58 +00:00
|
|
|
this.compileError(`There should be a variable name here.`);
|
2020-08-05 04:48:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-08-09 01:25:58 +00:00
|
|
|
parseLexpr(): IndOp {
|
|
|
|
var lexpr = this.parseVarSubscriptOrFunc();
|
|
|
|
this.validateVarName(lexpr);
|
|
|
|
return lexpr;
|
|
|
|
}
|
2020-08-11 17:29:31 +00:00
|
|
|
parseForNextLexpr() : IndOp {
|
|
|
|
var lexpr = this.parseLexpr();
|
|
|
|
if (lexpr.args || lexpr.name.endsWith('$'))
|
|
|
|
this.compileError(`A FOR ... NEXT loop can only use numeric variables.`);
|
|
|
|
return lexpr;
|
|
|
|
}
|
2020-08-05 04:48:29 +00:00
|
|
|
parseList<T>(parseFunc:()=>T, delim:string): T[] {
|
|
|
|
var sep;
|
|
|
|
var list = [];
|
|
|
|
do {
|
2020-08-09 01:25:58 +00:00
|
|
|
var el = parseFunc.bind(this)(); // call parse function
|
|
|
|
if (el != null) list.push(el); // add parsed element to list
|
|
|
|
sep = this.consumeToken(); // consume seperator token
|
2020-08-05 04:48:29 +00:00
|
|
|
} while (sep.str == delim);
|
|
|
|
this.pushbackToken(sep);
|
|
|
|
return list;
|
|
|
|
}
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
parseLexprList(): IndOp[] {
|
2020-08-13 17:51:35 +00:00
|
|
|
return this.parseList(this.parseLexpr, ',');
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
parseExprList(): Expr[] {
|
|
|
|
return this.parseList(this.parseExpr, ',');
|
|
|
|
}
|
|
|
|
parseLabelList(): Expr[] {
|
|
|
|
return this.parseList(this.parseLabel, ',');
|
|
|
|
}
|
|
|
|
parseLabel() : Expr {
|
2020-08-13 17:51:35 +00:00
|
|
|
// parse full expr?
|
|
|
|
if (this.opts.computedGoto)
|
|
|
|
return this.parseExpr();
|
|
|
|
// parse a single number or ident label
|
2020-08-05 04:48:29 +00:00
|
|
|
var tok = this.consumeToken();
|
|
|
|
switch (tok.type) {
|
2020-08-09 02:36:21 +00:00
|
|
|
case TokenType.Ident:
|
|
|
|
if (!this.opts.optionalLabels) this.dialectError(`labels other than line numbers`)
|
2020-08-05 04:48:29 +00:00
|
|
|
case TokenType.Int:
|
2020-08-09 02:36:21 +00:00
|
|
|
var label = tok.str;
|
2020-08-05 04:48:29 +00:00
|
|
|
this.targets[label] = tok.$loc;
|
|
|
|
return {value:label};
|
|
|
|
default:
|
2020-08-09 02:36:21 +00:00
|
|
|
if (this.opts.optionalLabels) this.compileError(`There should be a line number or label here.`);
|
|
|
|
else this.compileError(`There should be a line number here.`);
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-14 04:34:54 +00:00
|
|
|
parseDatumList(): Literal[] {
|
|
|
|
return this.parseList(this.parseDatum, ',');
|
|
|
|
}
|
|
|
|
parseDatum(): Literal {
|
|
|
|
var tok = this.consumeToken();
|
|
|
|
// get rid of leading whitespace
|
|
|
|
while (tok.type == TokenType.Whitespace)
|
|
|
|
tok = this.consumeToken();
|
|
|
|
if (isEOS(tok)) this.compileError(`There should be a datum here.`);
|
|
|
|
// parse constants
|
|
|
|
if (tok.type <= TokenType.HexOctalInt) {
|
|
|
|
return this.parseValue(tok);
|
|
|
|
}
|
|
|
|
if (tok.str == '-' && this.peekToken().type <= TokenType.HexOctalInt) {
|
|
|
|
tok = this.consumeToken();
|
|
|
|
return { value: -this.parseValue(tok).value };
|
|
|
|
}
|
|
|
|
if (tok.str == '+' && this.peekToken().type <= TokenType.HexOctalInt) {
|
|
|
|
tok = this.consumeToken();
|
|
|
|
return this.parseValue(tok);
|
|
|
|
}
|
|
|
|
// concat all stuff including whitespace
|
|
|
|
// TODO: should trim whitespace only if not quoted string
|
|
|
|
var s = '';
|
|
|
|
while (!isEOS(tok) && tok.str != ',') {
|
|
|
|
s += this.parseValue(tok).value;
|
|
|
|
tok = this.consumeToken();
|
|
|
|
}
|
|
|
|
this.pushbackToken(tok);
|
|
|
|
return { value: s }; // trim leading and trailing whitespace
|
|
|
|
}
|
|
|
|
parseValue(tok: Token): Literal {
|
2020-08-05 04:48:29 +00:00
|
|
|
switch (tok.type) {
|
2020-08-12 15:51:18 +00:00
|
|
|
case TokenType.HexOctalInt:
|
|
|
|
if (!this.opts.hexOctalConsts) this.dialectError(`hex/octal constants`);
|
|
|
|
let base = tok.str.startsWith('H') ? 16 : 8;
|
|
|
|
return { value: parseInt(tok.str.substr(1), base) };
|
2020-08-05 04:48:29 +00:00
|
|
|
case TokenType.Int:
|
2020-08-14 04:34:54 +00:00
|
|
|
case TokenType.Float:
|
2020-08-12 15:51:18 +00:00
|
|
|
return { value: this.parseNumber(tok.str) };
|
2020-08-05 04:48:29 +00:00
|
|
|
case TokenType.String:
|
2020-08-12 15:51:18 +00:00
|
|
|
return { value: stripQuotes(tok.str) };
|
2020-08-14 04:34:54 +00:00
|
|
|
default:
|
|
|
|
return { value: tok.str }; // only used in DATA statement
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parsePrimary(): Expr {
|
|
|
|
let tok = this.consumeToken();
|
|
|
|
switch (tok.type) {
|
|
|
|
case TokenType.HexOctalInt:
|
|
|
|
case TokenType.Int:
|
|
|
|
case TokenType.Float:
|
|
|
|
case TokenType.String:
|
|
|
|
return this.parseValue(tok);
|
2020-08-05 04:48:29 +00:00
|
|
|
case TokenType.Ident:
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
if (tok.str == 'NOT') {
|
|
|
|
let expr = this.parsePrimary();
|
2020-08-09 16:23:49 +00:00
|
|
|
return { op: this.opts.bitwiseLogic ? 'bnot' : 'lnot', expr: expr };
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
} else {
|
|
|
|
this.pushbackToken(tok);
|
2020-08-09 01:25:58 +00:00
|
|
|
return this.parseVarSubscriptOrFunc();
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
}
|
2020-08-05 04:48:29 +00:00
|
|
|
case TokenType.Operator:
|
|
|
|
if (tok.str == '(') {
|
|
|
|
let expr = this.parseExpr();
|
2020-08-09 16:23:49 +00:00
|
|
|
this.expectToken(')', `There should be another expression or a ")" here.`);
|
2020-08-05 04:48:29 +00:00
|
|
|
return expr;
|
|
|
|
} else if (tok.str == '-') {
|
|
|
|
let expr = this.parsePrimary(); // TODO: -2^2=-4 and -2-2=-4
|
|
|
|
return { op: 'neg', expr: expr };
|
|
|
|
} else if (tok.str == '+') {
|
2020-08-09 16:23:49 +00:00
|
|
|
return this.parsePrimary(); // ignore unary +
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
2020-08-13 17:51:35 +00:00
|
|
|
default:
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
this.compileError(`The expression is incomplete.`);
|
|
|
|
return;
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
this.compileError(`There was an unexpected "${tok.str}" in this expression.`);
|
|
|
|
}
|
|
|
|
parseNumber(str: string) : number {
|
|
|
|
var n = parseFloat(str);
|
|
|
|
if (isNaN(n))
|
|
|
|
this.compileError(`The number ${str} is not a valid floating-point number.`);
|
|
|
|
if (this.opts.checkOverflow && !isFinite(n))
|
|
|
|
this.compileError(`The number ${str} is too big to fit into a floating-point value.`);
|
|
|
|
return n;
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
parseExpr1(left: Expr, minPred: number): Expr {
|
|
|
|
let look = this.peekToken();
|
|
|
|
while (getPrecedence(look) >= minPred) {
|
|
|
|
let op = this.consumeToken();
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
if (this.opts.validOperators && this.opts.validOperators.indexOf(op.str) < 0)
|
|
|
|
this.dialectError(`the "${op.str}" operator`);
|
2020-08-05 04:48:29 +00:00
|
|
|
let right: Expr = this.parsePrimary();
|
|
|
|
look = this.peekToken();
|
|
|
|
while (getPrecedence(look) > getPrecedence(op)) {
|
|
|
|
right = this.parseExpr1(right, getPrecedence(look));
|
|
|
|
look = this.peekToken();
|
|
|
|
}
|
2020-08-09 16:23:49 +00:00
|
|
|
var opfn = getOperator(op.str).f;
|
2020-08-11 17:29:31 +00:00
|
|
|
// use logical operators instead of bitwise?
|
|
|
|
if (!this.opts.bitwiseLogic && op.str == 'AND') opfn = 'land';
|
|
|
|
if (!this.opts.bitwiseLogic && op.str == 'OR') opfn = 'lor';
|
2020-08-09 16:23:49 +00:00
|
|
|
left = { op:opfn, left: left, right: right };
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
return left;
|
|
|
|
}
|
|
|
|
parseExpr(): Expr {
|
|
|
|
return this.parseExpr1(this.parsePrimary(), 0);
|
|
|
|
}
|
2020-08-09 01:25:58 +00:00
|
|
|
validateVarName(lexpr: IndOp) {
|
2020-08-11 17:29:31 +00:00
|
|
|
switch (this.opts.varNaming) {
|
2020-08-13 17:51:35 +00:00
|
|
|
case 'A': // TINY BASIC, no strings
|
|
|
|
if (!/^[A-Z]$/i.test(lexpr.name))
|
|
|
|
this.dialectError(`variable names other than a single letter`);
|
|
|
|
break;
|
2020-08-11 17:29:31 +00:00
|
|
|
case 'A1':
|
|
|
|
if (lexpr.args == null && !/^[A-Z][0-9]?[$]?$/i.test(lexpr.name))
|
|
|
|
this.dialectError(`variable names other than a letter followed by an optional digit`);
|
|
|
|
if (lexpr.args != null && !/^[A-Z]?[$]?$/i.test(lexpr.name))
|
|
|
|
this.dialectError(`array names other than a single letter`);
|
|
|
|
break;
|
|
|
|
case 'AA':
|
|
|
|
if (lexpr.args == null && !/^[A-Z][A-Z0-9]?[$]?$/i.test(lexpr.name))
|
|
|
|
this.dialectError(`variable names other than a letter followed by an optional letter or digit`);
|
|
|
|
break;
|
2020-08-13 17:51:35 +00:00
|
|
|
case '*':
|
|
|
|
break;
|
2020-08-09 01:25:58 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-05 04:48:29 +00:00
|
|
|
|
|
|
|
//// STATEMENTS
|
|
|
|
|
|
|
|
stmt__LET(): LET_Statement {
|
2020-08-09 01:25:58 +00:00
|
|
|
var lexpr = this.parseLexpr();
|
2020-08-05 04:48:29 +00:00
|
|
|
this.expectToken("=");
|
|
|
|
var right = this.parseExpr();
|
|
|
|
return { command: "LET", lexpr: lexpr, right: right };
|
|
|
|
}
|
|
|
|
stmt__PRINT(): PRINT_Statement {
|
|
|
|
var sep, lastsep;
|
|
|
|
var list = [];
|
|
|
|
do {
|
|
|
|
sep = this.peekToken();
|
|
|
|
if (isEOS(sep)) {
|
|
|
|
break;
|
|
|
|
} else if (sep.str == ';') {
|
|
|
|
this.consumeToken();
|
|
|
|
lastsep = sep;
|
|
|
|
} else if (sep.str == ',') {
|
|
|
|
this.consumeToken();
|
|
|
|
list.push({value:'\t'});
|
|
|
|
lastsep = sep;
|
|
|
|
} else {
|
|
|
|
list.push(this.parseExpr());
|
|
|
|
lastsep = null;
|
|
|
|
}
|
|
|
|
} while (true);
|
|
|
|
if (!(lastsep && (lastsep.str == ';' || sep.str != ','))) {
|
|
|
|
list.push({value:'\n'});
|
|
|
|
}
|
|
|
|
return { command: "PRINT", args: list };
|
|
|
|
}
|
2020-08-13 17:51:35 +00:00
|
|
|
stmt__GOTO(): GOTO_Statement | GOSUB_Statement | ONGO_Statement {
|
|
|
|
return this.__GO("GOTO");
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
2020-08-13 17:51:35 +00:00
|
|
|
stmt__GOSUB(): GOTO_Statement | GOSUB_Statement | ONGO_Statement {
|
|
|
|
return this.__GO("GOSUB");
|
|
|
|
}
|
|
|
|
__GO(cmd: "GOTO"|"GOSUB"): GOTO_Statement | GOSUB_Statement | ONGO_Statement {
|
|
|
|
var expr = this.parseLabel();
|
|
|
|
// GOTO (expr) OF (labels...)
|
|
|
|
if (this.opts.computedGoto && this.peekToken().str == 'OF') {
|
|
|
|
this.expectToken('OF');
|
|
|
|
let newcmd : 'ONGOTO'|'ONGOSUB' = (cmd == 'GOTO') ? 'ONGOTO' : 'ONGOSUB';
|
|
|
|
return { command:newcmd, expr:expr, labels:this.parseLabelList() };
|
|
|
|
}
|
|
|
|
// regular GOTO or GOSUB
|
|
|
|
return { command: cmd, label: expr };
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
stmt__IF(): IF_Statement {
|
|
|
|
var cond = this.parseExpr();
|
|
|
|
var iftrue: Statement[];
|
2020-08-10 16:08:43 +00:00
|
|
|
// we accept GOTO or THEN if line number provided
|
2020-08-12 15:11:10 +00:00
|
|
|
var thengoto = this.expectTokens(['THEN','GOTO']);
|
2020-08-05 04:48:29 +00:00
|
|
|
var lineno = this.peekToken();
|
|
|
|
// assume GOTO if number given after THEN
|
2020-08-12 16:57:54 +00:00
|
|
|
if (lineno.type == TokenType.Int) {
|
2020-08-05 04:48:29 +00:00
|
|
|
this.pushbackToken({type:TokenType.Ident, str:'GOTO', $loc:lineno.$loc});
|
|
|
|
}
|
|
|
|
// add fake ":"
|
|
|
|
this.pushbackToken({type:TokenType.Operator, str:':', $loc:lineno.$loc});
|
|
|
|
return { command: "IF", cond: cond };
|
|
|
|
}
|
2020-08-09 02:36:21 +00:00
|
|
|
stmt__ELSE(): ELSE_Statement {
|
|
|
|
var lineno = this.peekToken();
|
|
|
|
// assume GOTO if number given after ELSE
|
|
|
|
if (lineno.type == TokenType.Int) {
|
|
|
|
this.pushbackToken({type:TokenType.Ident, str:'GOTO', $loc:lineno.$loc});
|
|
|
|
}
|
|
|
|
// add fake ":"
|
|
|
|
this.pushbackToken({type:TokenType.Operator, str:':', $loc:lineno.$loc});
|
|
|
|
return { command: "ELSE" };
|
|
|
|
}
|
2020-08-05 04:48:29 +00:00
|
|
|
stmt__FOR() : FOR_Statement {
|
2020-08-11 17:29:31 +00:00
|
|
|
var lexpr = this.parseForNextLexpr();
|
2020-08-05 04:48:29 +00:00
|
|
|
this.expectToken('=');
|
|
|
|
var init = this.parseExpr();
|
|
|
|
this.expectToken('TO');
|
|
|
|
var targ = this.parseExpr();
|
|
|
|
if (this.peekToken().str == 'STEP') {
|
|
|
|
this.consumeToken();
|
|
|
|
var step = this.parseExpr();
|
|
|
|
}
|
|
|
|
return { command:'FOR', lexpr:lexpr, initial:init, target:targ, step:step };
|
|
|
|
}
|
|
|
|
stmt__NEXT() : NEXT_Statement {
|
|
|
|
var lexpr = null;
|
2020-08-12 16:57:54 +00:00
|
|
|
// NEXT var might be optional
|
|
|
|
if (!this.opts.optionalNextVar || !isEOS(this.peekToken())) {
|
2020-08-11 17:29:31 +00:00
|
|
|
lexpr = this.parseForNextLexpr();
|
2020-08-12 16:57:54 +00:00
|
|
|
// convert ',' to ':' 'NEXT'
|
|
|
|
if (this.opts.multipleNextVars && this.peekToken().str == ',') {
|
|
|
|
this.consumeToken(); // consume ','
|
|
|
|
this.tokens.unshift({type:TokenType.Ident, str:'NEXT', $loc:this.peekToken().$loc});
|
|
|
|
this.tokens.unshift({type:TokenType.Operator, str:':', $loc:this.peekToken().$loc});
|
|
|
|
}
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
return { command:'NEXT', lexpr:lexpr };
|
|
|
|
}
|
2020-08-12 16:57:54 +00:00
|
|
|
stmt__WHILE(): WHILE_Statement {
|
|
|
|
var cond = this.parseExpr();
|
|
|
|
return { command:'WHILE', cond:cond };
|
|
|
|
}
|
|
|
|
stmt__WEND(): WEND_Statement {
|
|
|
|
return { command:'WEND' };
|
|
|
|
}
|
2020-08-05 04:48:29 +00:00
|
|
|
stmt__DIM() : DIM_Statement {
|
2020-08-09 01:25:58 +00:00
|
|
|
var lexprs = this.parseLexprList();
|
|
|
|
lexprs.forEach((arr) => {
|
|
|
|
if (arr.args == null || arr.args.length == 0)
|
|
|
|
this.compileError(`An array defined by DIM must have at least one dimension.`)
|
|
|
|
else if (arr.args.length > this.opts.maxDimensions)
|
|
|
|
this.dialectError(`more than ${this.opts.maxDimensions} dimensional arrays`);
|
|
|
|
});
|
|
|
|
return { command:'DIM', args:lexprs };
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
stmt__INPUT() : INPUT_Statement {
|
|
|
|
var prompt = this.consumeToken();
|
|
|
|
var promptstr;
|
|
|
|
if (prompt.type == TokenType.String) {
|
2020-08-12 15:11:10 +00:00
|
|
|
this.expectTokens([';', ',']);
|
2020-08-05 04:48:29 +00:00
|
|
|
promptstr = stripQuotes(prompt.str);
|
|
|
|
} else {
|
|
|
|
this.pushbackToken(prompt);
|
|
|
|
promptstr = "";
|
|
|
|
}
|
2020-08-10 01:40:17 +00:00
|
|
|
return { command:'INPUT', prompt:{ value: promptstr }, args:this.parseLexprList() };
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
2020-08-13 17:51:35 +00:00
|
|
|
/* for HP BASIC only */
|
|
|
|
stmt__ENTER() : INPUT_Statement {
|
|
|
|
var secs = this.parseExpr();
|
|
|
|
this.expectToken(',');
|
|
|
|
var result = this.parseLexpr(); // TODO: this has to go somewheres
|
|
|
|
this.expectToken(',');
|
|
|
|
return this.stmt__INPUT();
|
|
|
|
}
|
2020-08-14 01:50:41 +00:00
|
|
|
// TODO: DATA statement doesn't read unquoted strings
|
2020-08-05 04:48:29 +00:00
|
|
|
stmt__DATA() : DATA_Statement {
|
2020-08-14 04:34:54 +00:00
|
|
|
return { command:'DATA', datums:this.parseDatumList() };
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
2020-08-09 02:36:21 +00:00
|
|
|
stmt__READ() : READ_Statement {
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
return { command:'READ', args:this.parseLexprList() };
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
2020-08-12 16:57:54 +00:00
|
|
|
stmt__RESTORE() : RESTORE_Statement {
|
|
|
|
var label = null;
|
|
|
|
if (this.opts.restoreWithLabel && !isEOS(this.peekToken()))
|
|
|
|
label = this.parseLabel();
|
|
|
|
return { command:'RESTORE', label:label };
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
stmt__RETURN() {
|
|
|
|
return { command:'RETURN' };
|
|
|
|
}
|
|
|
|
stmt__STOP() {
|
|
|
|
return { command:'STOP' };
|
|
|
|
}
|
|
|
|
stmt__END() {
|
|
|
|
return { command:'END' };
|
|
|
|
}
|
2020-08-13 17:51:35 +00:00
|
|
|
stmt__ON() : ONGO_Statement {
|
2020-08-05 04:48:29 +00:00
|
|
|
var expr = this.parseExpr();
|
2020-08-10 13:07:09 +00:00
|
|
|
var gotok = this.consumeToken();
|
|
|
|
var cmd = {GOTO:'ONGOTO', GOSUB:'ONGOSUB'}[gotok.str];
|
|
|
|
if (!cmd) this.compileError(`There should be a GOTO or GOSUB here.`);
|
2020-08-05 04:48:29 +00:00
|
|
|
var labels = this.parseLabelList();
|
2020-08-10 13:07:09 +00:00
|
|
|
return { command:cmd, expr:expr, labels:labels };
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
stmt__DEF() : DEF_Statement {
|
2020-08-09 01:25:58 +00:00
|
|
|
var lexpr = this.parseVarSubscriptOrFunc();
|
2020-08-09 02:36:21 +00:00
|
|
|
if (lexpr.args && lexpr.args.length > this.opts.maxDefArgs)
|
|
|
|
this.compileError(`There can be no more than ${this.opts.maxDefArgs} arguments to a function or subscript.`);
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
if (!lexpr.name.startsWith('FN')) this.compileError(`Functions defined with DEF must begin with the letters "FN".`)
|
2020-08-05 04:48:29 +00:00
|
|
|
this.expectToken("=");
|
|
|
|
var func = this.parseExpr();
|
|
|
|
return { command:'DEF', lexpr:lexpr, def:func };
|
|
|
|
}
|
2020-08-09 02:36:21 +00:00
|
|
|
stmt__POP() : NoArgStatement {
|
|
|
|
return { command:'POP' };
|
|
|
|
}
|
|
|
|
stmt__GET() : GET_Statement {
|
|
|
|
var lexpr = this.parseLexpr();
|
|
|
|
return { command:'GET', lexpr:lexpr };
|
|
|
|
}
|
2020-08-10 13:07:09 +00:00
|
|
|
stmt__CLEAR() : NoArgStatement {
|
|
|
|
return { command:'CLEAR' };
|
|
|
|
}
|
2020-08-12 16:57:54 +00:00
|
|
|
stmt__RANDOMIZE() : NoArgStatement {
|
|
|
|
return { command:'RANDOMIZE' };
|
|
|
|
}
|
2020-08-09 02:36:21 +00:00
|
|
|
// TODO: CHANGE A TO A$ (4th edition, A(0) is len and A(1..) are chars)
|
2020-08-05 04:48:29 +00:00
|
|
|
stmt__OPTION() : OPTION_Statement {
|
|
|
|
var tokname = this.consumeToken();
|
2020-08-09 02:36:21 +00:00
|
|
|
if (tokname.type != TokenType.Ident) this.compileError(`There must be a name after the OPTION statement.`)
|
2020-08-05 04:48:29 +00:00
|
|
|
var list : string[] = [];
|
|
|
|
var tok;
|
|
|
|
do {
|
|
|
|
tok = this.consumeToken();
|
|
|
|
if (isEOS(tok)) break;
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
list.push(tok.str);
|
2020-08-05 04:48:29 +00:00
|
|
|
} while (true);
|
2020-08-09 01:03:48 +00:00
|
|
|
this.pushbackToken(tok);
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
var stmt : OPTION_Statement = { command:'OPTION', optname:tokname.str, optargs:list };
|
|
|
|
this.parseOptions(stmt);
|
|
|
|
return stmt;
|
|
|
|
}
|
|
|
|
parseOptions(stmt: OPTION_Statement) {
|
2020-08-10 03:19:27 +00:00
|
|
|
var arg = stmt.optargs[0];
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
switch (stmt.optname) {
|
|
|
|
case 'BASE':
|
2020-08-10 03:19:27 +00:00
|
|
|
let base = parseInt(arg);
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
if (base == 0 || base == 1) this.opts.defaultArrayBase = base;
|
|
|
|
else this.compileError("OPTION BASE can only be 0 or 1.");
|
|
|
|
break;
|
|
|
|
case 'DIALECT':
|
2020-08-10 03:19:27 +00:00
|
|
|
let dname = arg || "";
|
2020-08-09 02:36:21 +00:00
|
|
|
let dialect = DIALECTS[dname.toUpperCase()];
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
if (dialect) this.opts = dialect;
|
2020-08-10 03:19:27 +00:00
|
|
|
else this.compileError(`OPTION DIALECT ${dname} is not supported by this compiler.`);
|
|
|
|
break;
|
|
|
|
case 'CPUSPEED':
|
|
|
|
if (!(this.opts.commandsPerSec = Math.min(1e7, arg=='MAX' ? Infinity : parseFloat(arg))))
|
|
|
|
this.compileError(`OPTION CPUSPEED takes a positive number or MAX.`);
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
2020-08-11 17:29:31 +00:00
|
|
|
// maybe it's one of the options?
|
|
|
|
var name = Object.getOwnPropertyNames(this.opts).find((n) => n.toUpperCase() == stmt.optname);
|
|
|
|
if (name != null) switch (typeof this.opts[name]) {
|
|
|
|
case 'boolean' : this.opts[name] = arg ? true : false; return;
|
|
|
|
case 'number' : this.opts[name] = parseFloat(arg); return;
|
|
|
|
case 'string' : this.opts[name] = arg; return;
|
|
|
|
case 'object' :
|
|
|
|
if (Array.isArray(this.opts[name]) && arg == 'ALL') {
|
|
|
|
this.opts[name] = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
this.compileError(`OPTION ${stmt.optname} is not supported by this compiler.`);
|
|
|
|
break;
|
|
|
|
}
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// for workermain
|
|
|
|
generateListing(file: string, program: BASICProgram) {
|
|
|
|
var srclines = [];
|
|
|
|
var pc = 0;
|
2020-08-13 17:51:35 +00:00
|
|
|
var laststmt : Statement;
|
2020-08-05 04:48:29 +00:00
|
|
|
program.lines.forEach((line, idx) => {
|
2020-08-11 02:35:25 +00:00
|
|
|
line.stmts.forEach((stmt) => {
|
2020-08-13 17:51:35 +00:00
|
|
|
laststmt = stmt;
|
2020-08-11 02:35:25 +00:00
|
|
|
var sl = stmt.$loc;
|
|
|
|
sl.offset = pc++; // TODO: could Statement have offset field?
|
|
|
|
srclines.push(sl);
|
|
|
|
});
|
2020-08-05 04:48:29 +00:00
|
|
|
});
|
2020-08-13 17:51:35 +00:00
|
|
|
if (this.opts.endStmtRequired && (laststmt == null || laststmt.command != 'END'))
|
|
|
|
this.dialectError(`programs without an final END statement`);
|
2020-08-05 04:48:29 +00:00
|
|
|
return { lines: srclines };
|
|
|
|
}
|
|
|
|
getListings() : CodeListingMap {
|
|
|
|
return this.listings;
|
|
|
|
}
|
|
|
|
|
|
|
|
// LINT STUFF
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
checkAll(program : BASICProgram) {
|
|
|
|
this.checkLabels();
|
|
|
|
}
|
2020-08-05 04:48:29 +00:00
|
|
|
checkLabels() {
|
|
|
|
for (let targ in this.targets) {
|
|
|
|
if (this.labels[targ] == null) {
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
this.compileError(`There isn't a line number ${targ}.`, this.targets[targ]);
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///// BASIC DIALECTS
|
|
|
|
|
|
|
|
export const ECMA55_MINIMAL : BASICOptions = {
|
2020-08-09 02:36:21 +00:00
|
|
|
dialectName: "ECMA55",
|
|
|
|
asciiOnly : true,
|
2020-08-05 04:48:29 +00:00
|
|
|
uppercaseOnly : true,
|
2020-08-09 01:03:48 +00:00
|
|
|
optionalLabels : false,
|
2020-08-11 17:29:31 +00:00
|
|
|
optionalWhitespace : false,
|
|
|
|
varNaming : "A1",
|
|
|
|
staticArrays : true,
|
2020-08-05 04:48:29 +00:00
|
|
|
sharedArrayNamespace : true,
|
|
|
|
defaultArrayBase : 0,
|
|
|
|
defaultArraySize : 11,
|
|
|
|
defaultValues : false,
|
|
|
|
stringConcat : false,
|
|
|
|
typeConvert : false,
|
|
|
|
maxDimensions : 2,
|
2020-08-09 02:36:21 +00:00
|
|
|
maxDefArgs : 255,
|
|
|
|
maxStringLength : 255,
|
2020-08-05 04:48:29 +00:00
|
|
|
tickComments : false,
|
2020-08-12 15:51:18 +00:00
|
|
|
hexOctalConsts : false,
|
2020-08-12 16:57:54 +00:00
|
|
|
validKeywords : [
|
|
|
|
'BASE','DATA','DEF','DIM','END',
|
2020-08-05 04:48:29 +00:00
|
|
|
'FOR','GO','GOSUB','GOTO','IF','INPUT','LET','NEXT','ON','OPTION','PRINT',
|
|
|
|
'RANDOMIZE','READ','REM','RESTORE','RETURN','STEP','STOP','SUB','THEN','TO'
|
2020-08-11 17:29:31 +00:00
|
|
|
],
|
2020-08-12 16:57:54 +00:00
|
|
|
validFunctions : [
|
|
|
|
'ABS','ATN','COS','EXP','INT','LOG','RND','SGN','SIN','SQR','TAB','TAN'
|
|
|
|
],
|
|
|
|
validOperators : [
|
|
|
|
'=', '<>', '<', '>', '<=', '>=', '+', '-', '*', '/', '^'
|
|
|
|
],
|
2020-08-05 04:48:29 +00:00
|
|
|
printZoneLength : 15,
|
2020-08-09 02:36:21 +00:00
|
|
|
numericPadding : true,
|
2020-08-05 04:48:29 +00:00
|
|
|
checkOverflow : true,
|
2020-08-11 17:29:31 +00:00
|
|
|
testInitialFor : true,
|
2020-08-12 15:11:10 +00:00
|
|
|
optionalNextVar : false,
|
2020-08-12 16:57:54 +00:00
|
|
|
multipleNextVars : false,
|
2020-08-09 16:23:49 +00:00
|
|
|
bitwiseLogic : false,
|
2020-08-12 16:57:54 +00:00
|
|
|
checkOnGotoIndex : true,
|
2020-08-13 17:51:35 +00:00
|
|
|
computedGoto : false,
|
|
|
|
restoreWithLabel : false,
|
|
|
|
squareBrackets : false,
|
|
|
|
arraysContainChars : false,
|
|
|
|
endStmtRequired : true,
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: only integers supported
|
|
|
|
export const TINY_BASIC : BASICOptions = {
|
|
|
|
dialectName: "TINY",
|
|
|
|
asciiOnly : true,
|
|
|
|
uppercaseOnly : true,
|
|
|
|
optionalLabels : false,
|
|
|
|
optionalWhitespace : false,
|
|
|
|
varNaming : "A",
|
|
|
|
staticArrays : false,
|
|
|
|
sharedArrayNamespace : true,
|
|
|
|
defaultArrayBase : 0,
|
|
|
|
defaultArraySize : 0,
|
|
|
|
defaultValues : true,
|
|
|
|
stringConcat : false,
|
|
|
|
typeConvert : false,
|
|
|
|
maxDimensions : 0,
|
|
|
|
maxDefArgs : 255,
|
|
|
|
maxStringLength : 255,
|
|
|
|
tickComments : false,
|
|
|
|
hexOctalConsts : false,
|
|
|
|
validKeywords : [
|
|
|
|
'OPTION',
|
|
|
|
'PRINT','IF','THEN','GOTO','INPUT','LET','GOSUB','RETURN','CLEAR','END'
|
|
|
|
],
|
|
|
|
validFunctions : [
|
|
|
|
],
|
|
|
|
validOperators : [
|
|
|
|
'=', '<>', '><', '<', '>', '<=', '>=', '+', '-', '*', '/',
|
|
|
|
],
|
|
|
|
printZoneLength : 1,
|
|
|
|
numericPadding : false,
|
|
|
|
checkOverflow : false,
|
|
|
|
testInitialFor : false,
|
|
|
|
optionalNextVar : false,
|
|
|
|
multipleNextVars : false,
|
|
|
|
bitwiseLogic : false,
|
|
|
|
checkOnGotoIndex : false,
|
|
|
|
computedGoto : true,
|
2020-08-12 16:57:54 +00:00
|
|
|
restoreWithLabel : false,
|
2020-08-13 17:51:35 +00:00
|
|
|
squareBrackets : false,
|
|
|
|
arraysContainChars : false,
|
|
|
|
endStmtRequired : false,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const HP_TIMESHARED_BASIC : BASICOptions = {
|
|
|
|
dialectName: "HPTSB",
|
|
|
|
asciiOnly : true,
|
|
|
|
uppercaseOnly : false,
|
|
|
|
optionalLabels : false,
|
|
|
|
optionalWhitespace : false,
|
|
|
|
varNaming : "A1",
|
|
|
|
staticArrays : true,
|
|
|
|
sharedArrayNamespace : false,
|
|
|
|
defaultArrayBase : 1,
|
|
|
|
defaultArraySize : 11,
|
|
|
|
defaultValues : false,
|
|
|
|
stringConcat : false,
|
|
|
|
typeConvert : false,
|
|
|
|
maxDimensions : 2,
|
|
|
|
maxDefArgs : 255,
|
|
|
|
maxStringLength : 255,
|
|
|
|
tickComments : false, // TODO: HP BASIC has 'hh char constants
|
|
|
|
hexOctalConsts : false,
|
|
|
|
validKeywords : [
|
|
|
|
'BASE','DATA','DEF','DIM','END',
|
|
|
|
'FOR','GO','GOSUB','GOTO','IF','INPUT','LET','NEXT','OPTION','PRINT',
|
|
|
|
'RANDOMIZE','READ','REM','RESTORE','RETURN','STEP','STOP','SUB','THEN','TO',
|
|
|
|
'ENTER','MAT','CONVERT','OF','IMAGE','USING'
|
|
|
|
],
|
|
|
|
validFunctions : [
|
|
|
|
'ABS','ATN','BRK','COS','CTL','EXP','INT','LEN','LIN','LOG','NUM',
|
|
|
|
'POS','RND','SGN','SIN','SPA','SQR','TAB','TAN','TIM','TYP','UPS$' // TODO: POS,
|
|
|
|
],
|
|
|
|
validOperators : [
|
|
|
|
'=', '<>', '<', '>', '<=', '>=', '+', '-', '*', '/', '^',
|
|
|
|
'**', '#', 'NOT', 'AND', 'OR', 'MIN', 'MAX',
|
|
|
|
],
|
|
|
|
printZoneLength : 15,
|
|
|
|
numericPadding : true,
|
|
|
|
checkOverflow : false,
|
|
|
|
testInitialFor : true,
|
|
|
|
optionalNextVar : false,
|
|
|
|
multipleNextVars : false,
|
|
|
|
bitwiseLogic : false,
|
|
|
|
checkOnGotoIndex : false,
|
|
|
|
computedGoto : true,
|
|
|
|
restoreWithLabel : true,
|
|
|
|
squareBrackets : true,
|
|
|
|
arraysContainChars : true,
|
|
|
|
endStmtRequired : true,
|
|
|
|
// TODO: max line number, array index 9999
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 17:29:31 +00:00
|
|
|
export const BASICODE : BASICOptions = {
|
|
|
|
dialectName: "BASICODE",
|
2020-08-09 02:36:21 +00:00
|
|
|
asciiOnly : true,
|
2020-08-13 17:32:47 +00:00
|
|
|
uppercaseOnly : false,
|
2020-08-09 01:03:48 +00:00
|
|
|
optionalLabels : false,
|
2020-08-11 17:29:31 +00:00
|
|
|
optionalWhitespace : true,
|
|
|
|
varNaming : "AA",
|
|
|
|
staticArrays : true,
|
|
|
|
sharedArrayNamespace : false,
|
|
|
|
defaultArrayBase : 0,
|
|
|
|
defaultArraySize : 11,
|
|
|
|
defaultValues : false,
|
|
|
|
stringConcat : true,
|
|
|
|
typeConvert : false,
|
|
|
|
maxDimensions : 2,
|
|
|
|
maxDefArgs : 255,
|
|
|
|
maxStringLength : 255,
|
|
|
|
tickComments : false,
|
2020-08-12 15:51:18 +00:00
|
|
|
hexOctalConsts : false,
|
2020-08-12 16:57:54 +00:00
|
|
|
validKeywords : [
|
|
|
|
'BASE','DATA','DEF','DIM','END',
|
2020-08-11 17:29:31 +00:00
|
|
|
'FOR','GO','GOSUB','GOTO','IF','INPUT','LET','NEXT','ON','OPTION','PRINT',
|
2020-08-13 23:53:11 +00:00
|
|
|
'READ','REM','RESTORE','RETURN','STEP','STOP','SUB','THEN','TO',
|
|
|
|
'AND', 'NOT', 'OR'
|
2020-08-11 17:29:31 +00:00
|
|
|
],
|
2020-08-12 16:57:54 +00:00
|
|
|
validFunctions : [
|
|
|
|
'ABS','ASC','ATN','CHR$','COS','EXP','INT','LEFT$','LEN','LOG',
|
|
|
|
'MID$','RIGHT$','SGN','SIN','SQR','TAB','TAN','VAL'
|
|
|
|
],
|
|
|
|
validOperators : [
|
|
|
|
'=', '<>', '<', '>', '<=', '>=', '+', '-', '*', '/', '^', 'AND', 'NOT', 'OR'
|
|
|
|
],
|
2020-08-11 17:29:31 +00:00
|
|
|
printZoneLength : 15,
|
|
|
|
numericPadding : true,
|
|
|
|
checkOverflow : true,
|
|
|
|
testInitialFor : true,
|
2020-08-12 15:11:10 +00:00
|
|
|
optionalNextVar : false,
|
2020-08-12 16:57:54 +00:00
|
|
|
multipleNextVars : false,
|
2020-08-11 17:29:31 +00:00
|
|
|
bitwiseLogic : false,
|
2020-08-12 16:57:54 +00:00
|
|
|
checkOnGotoIndex : true,
|
2020-08-13 17:51:35 +00:00
|
|
|
computedGoto : false,
|
2020-08-12 16:57:54 +00:00
|
|
|
restoreWithLabel : false,
|
2020-08-13 17:51:35 +00:00
|
|
|
squareBrackets : false,
|
|
|
|
arraysContainChars : false,
|
|
|
|
endStmtRequired : false,
|
2020-08-11 17:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const ALTAIR_BASIC41 : BASICOptions = {
|
|
|
|
dialectName: "ALTAIR41",
|
|
|
|
asciiOnly : true,
|
|
|
|
uppercaseOnly : true,
|
|
|
|
optionalLabels : false,
|
|
|
|
optionalWhitespace : true,
|
|
|
|
varNaming : "*", // or AA
|
|
|
|
staticArrays : false,
|
2020-08-05 04:48:29 +00:00
|
|
|
sharedArrayNamespace : true,
|
|
|
|
defaultArrayBase : 0,
|
|
|
|
defaultArraySize : 11,
|
2020-08-09 02:36:21 +00:00
|
|
|
defaultValues : true,
|
|
|
|
stringConcat : true,
|
2020-08-05 04:48:29 +00:00
|
|
|
typeConvert : false,
|
2020-08-09 02:36:21 +00:00
|
|
|
maxDimensions : 128, // "as many as will fit on a single line" ... ?
|
|
|
|
maxDefArgs : 255,
|
|
|
|
maxStringLength : 255,
|
2020-08-05 04:48:29 +00:00
|
|
|
tickComments : false,
|
2020-08-12 15:51:18 +00:00
|
|
|
hexOctalConsts : false,
|
2020-08-11 17:29:31 +00:00
|
|
|
validKeywords : [
|
|
|
|
'OPTION',
|
|
|
|
'CONSOLE','DATA','DEF','DEFUSR','DIM','END','ERASE','ERROR',
|
|
|
|
'FOR','GOTO','GOSUB','IF','THEN','ELSE','INPUT','LET','LINE',
|
|
|
|
'PRINT','LPRINT','USING','NEXT','ON','OUT','POKE',
|
|
|
|
'READ','REM','RESTORE','RESUME','RETURN','STOP','SWAP',
|
2020-08-12 16:57:54 +00:00
|
|
|
'TROFF','TRON','WAIT',
|
|
|
|
'TO','STEP',
|
2020-08-13 23:53:11 +00:00
|
|
|
'AND', 'NOT', 'OR', 'XOR', 'IMP', 'EQV', 'MOD'
|
2020-08-12 16:57:54 +00:00
|
|
|
],
|
2020-08-13 17:51:35 +00:00
|
|
|
validFunctions : [
|
|
|
|
'ABS','ASC','ATN','CDBL','CHR$','CINT','COS','ERL','ERR',
|
|
|
|
'EXP','FIX','FRE','HEX$','INP','INSTR','INT',
|
|
|
|
'LEFT$','LEN','LOG','LPOS','MID$',
|
|
|
|
'OCT$','POS','RIGHT$','RND','SGN','SIN','SPACE$','SPC',
|
|
|
|
'SQR','STR$','STRING$','TAB','TAN','USR','VAL','VARPTR'
|
|
|
|
],
|
|
|
|
validOperators : [
|
2020-08-13 23:53:11 +00:00
|
|
|
'=', '<>', '<', '>', '<=', '>=', '+', '-', '*', '/', '^', '\\',
|
|
|
|
'AND', 'NOT', 'OR', 'XOR', 'IMP', 'EQV', 'MOD'
|
2020-08-13 17:51:35 +00:00
|
|
|
],
|
2020-08-05 04:48:29 +00:00
|
|
|
printZoneLength : 15,
|
2020-08-09 02:36:21 +00:00
|
|
|
numericPadding : true,
|
|
|
|
checkOverflow : true,
|
2020-08-11 17:29:31 +00:00
|
|
|
testInitialFor : false,
|
2020-08-12 15:11:10 +00:00
|
|
|
optionalNextVar : true,
|
2020-08-12 16:57:54 +00:00
|
|
|
multipleNextVars : true,
|
2020-08-09 16:23:49 +00:00
|
|
|
bitwiseLogic : true,
|
2020-08-12 16:57:54 +00:00
|
|
|
checkOnGotoIndex : false,
|
2020-08-13 17:51:35 +00:00
|
|
|
computedGoto : false,
|
2020-08-12 16:57:54 +00:00
|
|
|
restoreWithLabel : false,
|
2020-08-13 17:51:35 +00:00
|
|
|
squareBrackets : false,
|
|
|
|
arraysContainChars : false,
|
|
|
|
endStmtRequired : false,
|
2020-08-09 02:36:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const APPLESOFT_BASIC : BASICOptions = {
|
|
|
|
dialectName: "APPLESOFT",
|
|
|
|
asciiOnly : true,
|
|
|
|
uppercaseOnly : false,
|
|
|
|
optionalLabels : false,
|
2020-08-11 17:29:31 +00:00
|
|
|
optionalWhitespace : true,
|
|
|
|
varNaming : "*", // or AA
|
|
|
|
staticArrays : false,
|
2020-08-09 02:36:21 +00:00
|
|
|
sharedArrayNamespace : false,
|
|
|
|
defaultArrayBase : 0,
|
2020-08-11 17:29:31 +00:00
|
|
|
defaultArraySize : 11,
|
2020-08-09 02:36:21 +00:00
|
|
|
defaultValues : true,
|
|
|
|
stringConcat : true,
|
|
|
|
typeConvert : false,
|
|
|
|
maxDimensions : 88,
|
|
|
|
maxDefArgs : 1, // TODO: no string FNs
|
|
|
|
maxStringLength : 255,
|
|
|
|
tickComments : false,
|
2020-08-12 15:51:18 +00:00
|
|
|
hexOctalConsts : false,
|
2020-08-10 13:07:09 +00:00
|
|
|
validKeywords : [
|
2020-08-10 16:08:43 +00:00
|
|
|
'OPTION',
|
2020-08-11 17:29:31 +00:00
|
|
|
'CLEAR','LET','DIM','DEF','GOTO','GOSUB','RETURN','ON','POP',
|
2020-08-12 16:57:54 +00:00
|
|
|
'FOR','NEXT','IF','THEN','END','STOP','ONERR','RESUME',
|
2020-08-10 13:07:09 +00:00
|
|
|
'PRINT','INPUT','GET','HOME','HTAB','VTAB',
|
|
|
|
'INVERSE','FLASH','NORMAL','TEXT',
|
|
|
|
'GR','COLOR','PLOT','HLIN','VLIN',
|
|
|
|
'HGR','HGR2','HPLOT','HCOLOR','AT',
|
|
|
|
'DATA','READ','RESTORE',
|
2020-08-12 16:57:54 +00:00
|
|
|
'REM','TRACE','NOTRACE',
|
|
|
|
'TO','STEP',
|
2020-08-13 23:53:11 +00:00
|
|
|
'AND', 'NOT', 'OR'
|
2020-08-12 16:57:54 +00:00
|
|
|
],
|
2020-08-10 13:07:09 +00:00
|
|
|
validFunctions : [
|
|
|
|
'ABS','ATN','COS','EXP','INT','LOG','RND','SGN','SIN','SQR','TAN',
|
|
|
|
'LEN','LEFT$','MID$','RIGHT$','STR$','VAL','CHR$','ASC',
|
2020-08-12 16:57:54 +00:00
|
|
|
'FRE','SCRN','PDL','PEEK','POS'
|
|
|
|
],
|
|
|
|
validOperators : [
|
2020-08-13 23:53:11 +00:00
|
|
|
'=', '<>', '<', '>', '<=', '>=', '+', '-', '*', '/', '^',
|
|
|
|
'AND', 'NOT', 'OR'
|
2020-08-12 16:57:54 +00:00
|
|
|
],
|
2020-08-09 02:36:21 +00:00
|
|
|
printZoneLength : 16,
|
|
|
|
numericPadding : false,
|
|
|
|
checkOverflow : true,
|
2020-08-11 17:29:31 +00:00
|
|
|
testInitialFor : false,
|
2020-08-12 15:11:10 +00:00
|
|
|
optionalNextVar : true,
|
2020-08-12 16:57:54 +00:00
|
|
|
multipleNextVars : true,
|
2020-08-09 16:23:49 +00:00
|
|
|
bitwiseLogic : false,
|
2020-08-12 16:57:54 +00:00
|
|
|
checkOnGotoIndex : false,
|
2020-08-13 17:51:35 +00:00
|
|
|
computedGoto : false,
|
2020-08-12 16:57:54 +00:00
|
|
|
restoreWithLabel : false,
|
2020-08-13 17:51:35 +00:00
|
|
|
squareBrackets : false,
|
|
|
|
arraysContainChars : false,
|
|
|
|
endStmtRequired : false,
|
2020-08-12 16:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const BASIC80 : BASICOptions = {
|
|
|
|
dialectName: "BASIC80",
|
|
|
|
asciiOnly : true,
|
|
|
|
uppercaseOnly : false,
|
|
|
|
optionalLabels : false,
|
|
|
|
optionalWhitespace : true,
|
|
|
|
varNaming : "*",
|
|
|
|
staticArrays : false,
|
|
|
|
sharedArrayNamespace : true,
|
|
|
|
defaultArrayBase : 0,
|
|
|
|
defaultArraySize : 11,
|
|
|
|
defaultValues : true,
|
|
|
|
stringConcat : true,
|
|
|
|
typeConvert : false,
|
|
|
|
maxDimensions : 255,
|
|
|
|
maxDefArgs : 255,
|
|
|
|
maxStringLength : 255,
|
|
|
|
//maxElements : 32767, // TODO
|
|
|
|
tickComments : true,
|
|
|
|
hexOctalConsts : true,
|
|
|
|
validKeywords : [
|
|
|
|
'OPTION',
|
|
|
|
'CONSOLE','DATA','DEF','DEFUSR','DIM','END','ERASE','ERROR',
|
|
|
|
'FOR','GOTO','GOSUB','IF','THEN','ELSE','INPUT','LET','LINE',
|
|
|
|
'PRINT','LPRINT','USING','NEXT','ON','OUT','POKE',
|
|
|
|
'READ','REM','RESTORE','RESUME','RETURN','STOP','SWAP',
|
|
|
|
'TROFF','TRON','WAIT',
|
|
|
|
'CALL','CHAIN','COMMON','WHILE','WEND','WRITE','RANDOMIZE',
|
|
|
|
'TO','STEP',
|
2020-08-13 23:53:11 +00:00
|
|
|
'AND', 'NOT', 'OR', 'XOR', 'IMP', 'EQV', 'MOD'
|
2020-08-12 16:57:54 +00:00
|
|
|
],
|
|
|
|
validFunctions : [
|
|
|
|
'ABS','ASC','ATN','CDBL','CHR$','CINT','COS','CSNG','CVI','CVS','CVD',
|
|
|
|
'EOF','EXP','FIX','FRE','HEX$','INP','INPUT$','INSTR','INT',
|
|
|
|
'LEFT$','LEN','LOC','LOG','LPOS','MID$','MKI$','MKS$','MKD$',
|
|
|
|
'OCT$','PEEK','POS','RIGHT$','RND','SGN','SIN','SPACE$','SPC',
|
|
|
|
'SQR','STR$','STRING$','TAB','TAN','USR','VAL','VARPTR'
|
|
|
|
],
|
2020-08-13 23:53:11 +00:00
|
|
|
validOperators : [
|
|
|
|
'=', '<>', '<', '>', '<=', '>=', '+', '-', '*', '/', '^', '\\',
|
|
|
|
'AND', 'NOT', 'OR', 'XOR', 'IMP', 'EQV', 'MOD'
|
|
|
|
],
|
2020-08-12 16:57:54 +00:00
|
|
|
printZoneLength : 14,
|
|
|
|
numericPadding : true,
|
|
|
|
checkOverflow : false, // TODO: message displayed when overflow, division by zero = ok
|
|
|
|
testInitialFor : true,
|
|
|
|
optionalNextVar : true,
|
|
|
|
multipleNextVars : true,
|
|
|
|
bitwiseLogic : true,
|
|
|
|
checkOnGotoIndex : false,
|
2020-08-13 17:51:35 +00:00
|
|
|
computedGoto : false,
|
2020-08-12 16:57:54 +00:00
|
|
|
restoreWithLabel : true,
|
2020-08-13 17:51:35 +00:00
|
|
|
squareBrackets : false,
|
|
|
|
arraysContainChars : false,
|
|
|
|
endStmtRequired : false,
|
2020-08-09 02:36:21 +00:00
|
|
|
}
|
|
|
|
|
2020-08-10 16:08:43 +00:00
|
|
|
export const MODERN_BASIC : BASICOptions = {
|
|
|
|
dialectName: "MODERN",
|
2020-08-09 02:36:21 +00:00
|
|
|
asciiOnly : false,
|
|
|
|
uppercaseOnly : false,
|
|
|
|
optionalLabels : true,
|
2020-08-11 17:29:31 +00:00
|
|
|
optionalWhitespace : false,
|
|
|
|
varNaming : "*",
|
|
|
|
staticArrays : false,
|
2020-08-09 02:36:21 +00:00
|
|
|
sharedArrayNamespace : false,
|
|
|
|
defaultArrayBase : 0,
|
2020-08-11 17:29:31 +00:00
|
|
|
defaultArraySize : 0, // DIM required
|
2020-08-09 16:23:49 +00:00
|
|
|
defaultValues : false,
|
2020-08-09 02:36:21 +00:00
|
|
|
stringConcat : true,
|
|
|
|
typeConvert : true,
|
|
|
|
maxDimensions : 255,
|
2020-08-10 16:08:43 +00:00
|
|
|
maxDefArgs : 255,
|
2020-08-11 17:29:31 +00:00
|
|
|
maxStringLength : 2048, // TODO?
|
2020-08-09 02:36:21 +00:00
|
|
|
tickComments : true,
|
2020-08-12 15:51:18 +00:00
|
|
|
hexOctalConsts : true,
|
2020-08-09 02:36:21 +00:00
|
|
|
validKeywords : null, // all
|
2020-08-09 16:23:49 +00:00
|
|
|
validFunctions : null, // all
|
|
|
|
validOperators : null, // all
|
2020-08-11 17:29:31 +00:00
|
|
|
printZoneLength : 16,
|
2020-08-09 02:36:21 +00:00
|
|
|
numericPadding : false,
|
2020-08-05 04:48:29 +00:00
|
|
|
checkOverflow : true,
|
2020-08-11 17:29:31 +00:00
|
|
|
testInitialFor : true,
|
2020-08-12 15:11:10 +00:00
|
|
|
optionalNextVar : true,
|
2020-08-12 16:57:54 +00:00
|
|
|
multipleNextVars : true,
|
2020-08-09 16:23:49 +00:00
|
|
|
bitwiseLogic : true,
|
2020-08-13 23:53:11 +00:00
|
|
|
checkOnGotoIndex : true,
|
|
|
|
computedGoto : true,
|
2020-08-12 16:57:54 +00:00
|
|
|
restoreWithLabel : true,
|
2020-08-13 17:51:35 +00:00
|
|
|
squareBrackets : true,
|
|
|
|
arraysContainChars : false,
|
|
|
|
endStmtRequired : false,
|
2020-08-05 04:48:29 +00:00
|
|
|
}
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
|
2020-08-09 02:36:21 +00:00
|
|
|
// TODO: integer vars
|
2020-08-11 17:29:31 +00:00
|
|
|
// TODO: DEFINT/DEFSTR
|
2020-08-09 02:36:21 +00:00
|
|
|
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
export const DIALECTS = {
|
2020-08-11 17:29:31 +00:00
|
|
|
"DEFAULT": ALTAIR_BASIC41,
|
|
|
|
"ALTAIR": ALTAIR_BASIC41,
|
2020-08-13 17:51:35 +00:00
|
|
|
"ALTAIR4": ALTAIR_BASIC41,
|
2020-08-11 17:29:31 +00:00
|
|
|
"ALTAIR41": ALTAIR_BASIC41,
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
"ECMA55": ECMA55_MINIMAL,
|
|
|
|
"MINIMAL": ECMA55_MINIMAL,
|
2020-08-13 17:51:35 +00:00
|
|
|
"HPTSB": HP_TIMESHARED_BASIC,
|
|
|
|
"HPB": HP_TIMESHARED_BASIC,
|
|
|
|
"HP2000": HP_TIMESHARED_BASIC,
|
|
|
|
"HPBASIC": HP_TIMESHARED_BASIC,
|
|
|
|
"HPACCESS": HP_TIMESHARED_BASIC,
|
2020-08-11 17:29:31 +00:00
|
|
|
"BASICODE": BASICODE,
|
2020-08-09 02:36:21 +00:00
|
|
|
"APPLESOFT": APPLESOFT_BASIC,
|
2020-08-12 16:57:54 +00:00
|
|
|
"BASIC80": BASIC80,
|
2020-08-10 16:08:43 +00:00
|
|
|
"MODERN": MODERN_BASIC,
|
2020-08-13 17:51:35 +00:00
|
|
|
"TINY": TINY_BASIC,
|
basic: added operators, check inputs, better line feed, fixed return, FOR stack, moved OPTION to compile-time, fixed DEFs, uppercase, hot-loading (43, 45, 36)
2020-08-08 16:22:56 +00:00
|
|
|
};
|