Parsing a simple BASIC language

"paul.dunn4" <paul.dunn4@ntlworld.com>
4 Apr 2001 00:18:06 -0400

          From comp.compilers

Related articles
Parsing a simple BASIC language paul.dunn4@ntlworld.com (paul.dunn4) (2001-04-04)
Re: Parsing a simple BASIC language barry_j_kelly@hotmail.com (Barry Kelly) (2001-04-10)
Re: Parsing a simple BASIC language stephan@pcrm.win.tue.nl (2001-04-10)
Re: Parsing a simple BASIC language christl@fmi.uni-passau.de (2001-04-12)
Re: Parsing a simple BASIC language paul.dunn4@ntlworld.com (Dunny) (2001-04-12)
Re: Parsing a simple BASIC language barry_j_kelly@hotmail.com (Barry Kelly) (2001-04-14)
Re: Parsing a simple BASIC language marcov@toad.stack.nl (2001-04-18)
[3 later articles]
| List of all articles for this month |

From: "paul.dunn4" <paul.dunn4@ntlworld.com>
Newsgroups: comp.compilers
Date: 4 Apr 2001 00:18:06 -0400
Organization: ntlworld News Service
Keywords: parse, question
Posted-Date: 04 Apr 2001 00:18:05 EDT

Hello all,
        I have recently begun a new project, in line with the current "Retro"
trend which is buzzing around the net at the moment. I am writing a Sinclair
Spectrum BASIC interpreter - not a difficult task, interpretation is easy
enough, but what has got me stumped is parsing the text entered by the user
for errors.


        The method I am currently using is a kind of BNF form for keywords
(all statements begin with a keyword, and each statement is occupied
by one keyword only [except for IF..THEN statements] so the parsing
should be quite easy) and a rule reducer for expressions (# + #
becomes # etc) - I hope I'm making myself clear here, this is a new
project for me.


        The problem that I have is one of speed. When the user presses
return, the text is parsed and if it is correct, it's added to the
program listing. If not, the point that the mistake is made is
returned, and highlighted. This doesn't have to be fast. However, I
would like to create a simple syntax highlighter which displays a
syntax template (such as FOR <variable> = <Numexpr> TO <numexpr> ) and
highlights errors in red as you type. Unfortunately, it slows dow to
the point of unusability if you type over about 150 chars in the input
string.


        The parser performs the following steps to parse:


        1) tokenises the input string to Keywords (and function names), and
types (numerics, strings, symbols) into a stack.


        2) runs the resulting stack through the rule reducer to reduce all the
expressions to their base types (numexpr, stringexpr etc)


        3) runs the resulting (smaller) stack through the BNF parser using the
rule for that keyword. It is this part that performs error checking.


        As I said, this is very slow. I code in Delphi 5 (Object Pascal). Can
anyone point out:


1) How to parse a simple BASIC language (like Sinclair Basic) quickly,
2) Any better method than the one I'm using here. I used BNF for everything,
but that was even slower than the method I am using.


        Thanks,
                Paul.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.