Re: Parsing a simple BASIC language

christl@fmi.uni-passau.de (Timon Christl)
12 Apr 2001 02:43:09 -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)
Re: Parsing a simple BASIC language barry_j_kelly@hotmail.com (Barry Kelly) (2001-04-22)
| List of all articles for this month |

From: christl@fmi.uni-passau.de (Timon Christl)
Newsgroups: comp.compilers
Date: 12 Apr 2001 02:43:09 -0400
Organization: Compilers Central
References: 01-04-014 01-04-039
Keywords: Basic, parse
Posted-Date: 12 Apr 2001 02:43:09 EDT

On 10 Apr 2001 01:15:43 -0400, Barry Kelly wrote
>I'm not familiar with Sinclair Basic, but I have written many parsers
>in Object Pascal (Delphi). Might I suggest that you use a simple
>recursive descent parser (and change your grammar to LL(1), with
>context if necessary), and begin highlighting in red at the beginning
>of the first invalid token found by the parser?


I'm also writing a Scanner and Parser in Delphi, and want to contribute
my experience. It's my first serious attempt at a parser, so I use a
recursive descendant one to parse a small toy-language (basicallymixture of
C and Pascal . But I chose not to use a LL(1) grammar because
I have to look ahead two tokens in some productions. I use a small
fixed-size token stack to buffer the token stream so it's as fast as it
can get. Of course I could do a LL(1) grammar but why making the grammar
harder to read when this way works and is fast enough?


>For speed, the method I have found to work efficiently with Object
>Pascal, for lexical analysis, looks like this; It uses a little hack,
>similar to Classes.pas's TParser, which defines TToken as a character;
>this makes it easy to use for ':', ';' etc:


Yes, it is faster than my approach, but mine is definitely cleaner.
I use something like the record below for my tokens which greatly
aides to make a decent error reporting, which I miss with some
compilers out there.


type
    TToken=record
        Code:word;
        Line:integer;
        Col:integer;
        Text:string;
    end;


>One final note for speed; make sure you're using a hash table for lookup.
>I've got a fairly fast hashtable on
>http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=15171.


I'm going to give it a try, since my own hash table implementation sucks
pretty much, as it was written in about half an hour. Btw, is there
something like gperf for pascal?


--
Timon Christl <christl@fmi.uni-passau.de>


Post a followup to this message

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