Post Reply 
HP-71 BASIC funny quirks
01-28-2023, 02:51 PM
Post: #10
RE: HP-71 BASIC funny quirks
(01-28-2023 04:03 AM)brouhaha Wrote:  Either shunting yard or operator precedence parsing of expressions is fine, or even recursive descent, but it's far from the whole story. Even ignoring overall statement syntax, dealing with variable names, which have to be looked up, is slower than dealing with variable addresses assigned at statement entry time (even if a hash table is used at runtime), and dealing with numeric values that weren't parsed at statement entry is also very time consuming. And even though the rest of the parsing is fairly efficient, it's still usually a win to do it at entry time rather than every time the statement is executed.

I think I need to clarify a few points to complement my reply.

Operator precedence parsing overhead is indeed peanuts compared to everything else that can be, and should be, optimized in a BASIC interpreter, including variable lookup.

There is more nuance with respect to variable allocation and lookup.

BASIC interpreters that support subroutines with local variables and arguments passed by value or by reference typically have reduced performance. Locals require an extra stack or stack space. Local and non-local variable lookup in subroutines require lookups similar to dynamic scoping (which is largely abandoned in favor of lexical scoping in modern programming languages.) Alternatively, the extra lookup cost of locals can be eliminated with a stack to save non-locals at subroutine entry and restore them at subroutine exit, but this moves the extra cost to the allocation and deallocation side of locals at the entry and exit points. Again, there's a lot more to it than I want to discuss here. Variable addresses are not efficiently determinable at runtime by interpreters. By contrast, compilers determine local and non-local variable addresses for efficient execution, an important factor in the speed of compiled BASIC.

Back in the early 80s I did a fair amount of work with the Philips P2000 home computer, Apple IIe (which has actually two BASIC interpreters, a simple integer BASIC by Wozniak and AppleSoft BASIC) and occasional C64. Both AppleSoft and MS BASIC on the P2000 were much more developed, while still being compact. Back then I was curious what the differences were so I looked at the memory management of these interpreters, as well as discovered various forms of operator precedence parsing, before reading about it in college (later I taught programming languages and compilers for two decades to undergraduate and graduate students. It's not difficult to write a BASIC interpreter or a compiler for C as a project in a few weeks these days.)

Putting BASIC aside for a moment, for speed, Pascal on the Apple II was nice, but requires swapping floppy discs to edit the program, compile, and finally assemble it. Also Sweet16 on the Apple was great, also by Wozniak. I still have all his assembly listings that I studied back then to learn 6502 as well as "Programming the 6502" and "Programming the Z80" by the unforgettable Rodnay Zaks.

- Rob

"I count on old friends" -- HP 71B,Prime|Ti VOY200,Nspire CXII CAS|Casio fx-CG50...|Sharp PC-G850,E500,2500,1500,14xx,13xx,12xx...
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP-71 BASIC funny quirks - J-F Garnier - 01-27-2023, 08:55 AM
RE: HP-71 BASIC funny quirks - Albert Chan - 01-27-2023, 02:56 PM
RE: HP-71 BASIC funny quirks - J-F Garnier - 01-27-2023, 04:21 PM
RE: HP-71 BASIC funny quirks - robve - 01-27-2023, 10:35 PM
RE: HP-71 BASIC funny quirks - robve - 01-28-2023, 02:55 AM
RE: HP-71 BASIC funny quirks - Albert Chan - 01-28-2023, 12:39 PM
RE: HP-71 BASIC funny quirks - J-F Garnier - 01-28-2023, 05:03 PM
RE: HP-71 BASIC funny quirks - brouhaha - 01-28-2023, 04:03 AM
RE: HP-71 BASIC funny quirks - robve - 01-28-2023 02:51 PM



User(s) browsing this thread: 2 Guest(s)