Re: Parsing a simple BASIC language

stephan@pcrm.win.tue.nl ()
10 Apr 2001 01:29:17 -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)
Re: Parsing a simple BASIC language michael@moria.de (2001-04-18)
Re: Parsing a simple BASIC language paul.dunn4@ntlworld.com (Dunny) (2001-04-22)
[1 later articles]
| List of all articles for this month |
From: stephan@pcrm.win.tue.nl ()
Newsgroups: comp.compilers
Date: 10 Apr 2001 01:29:17 -0400
Organization: Eindhoven University of Technology, The Netherlands
References: 01-04-014
Keywords: Basic, parse
Posted-Date: 10 Apr 2001 01:29:17 EDT

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


> 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.


A stack might not be the most appropriate data type, since it seems
that you do not approach the data Last In, First Out. Consider using
some other data type, e.g. an an array.


Of course, another question is how efficient your tokenizing
code is.


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


You do this before parsing? This is a strange approach, which I do not
fully understand.


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


Is this a hand-coded parser? Perhaps you wrote a parser that
backtracks when confronted with something it cannot handle? Such a
parser can be very slow, if it has to do lots of backtracking.


Consider using a parser generator tool, or try to rewrite your parser
so that it doesn't do any backtracking.




>1) How to parse a simple BASIC language (like Sinclair Basic) quickly,


I think there is a Lex/Yacc for Object Pascal.


>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.


I think your parser is not efficient. You can ditch the second step
once you have an efficient parser.


Another idea is to only do the syntax checking in the "idle" loop of
your application. In this way, when the user starts to type a line, it
will not be syntax checked until the computer has time to catch up
with the user.


Stephan
--
ir. Stephan H.M.J. Houben
tel. +31-40-2474358 / +31-40-2743497
e-mail: stephanh@win.tue.nl


Post a followup to this message

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