|Parsing a simple BASIC language email@example.com (paul.dunn4) (2001-04-04)|
|Re: Parsing a simple BASIC language firstname.lastname@example.org (Barry Kelly) (2001-04-10)|
|Re: Parsing a simple BASIC language email@example.com (2001-04-10)|
|Re: Parsing a simple BASIC language firstname.lastname@example.org (2001-04-12)|
|Re: Parsing a simple BASIC language email@example.com (Dunny) (2001-04-12)|
|Re: Parsing a simple BASIC language firstname.lastname@example.org (Barry Kelly) (2001-04-14)|
|Re: Parsing a simple BASIC language email@example.com (2001-04-18)|
|[3 later articles]|
|Date:||4 Apr 2001 00:18:06 -0400|
|Organization:||ntlworld News Service|
|Posted-Date:||04 Apr 2001 00:18:05 EDT|
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
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
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.
Return to the
Search the comp.compilers archives again.