Re: RFC - VBS Grammar

"Scott Nicol" <>
4 Jan 2001 00:59:22 -0500

          From comp.compilers

Related articles
RFC - VBS Grammar (Larry Lewis) (2000-12-23)
Re: RFC - VBS Grammar (Joachim Durchholz) (2000-12-31)
Re: RFC - VBS Grammar (Scott Nicol) (2000-12-31)
Re: RFC - VBS Grammar (Scott Nicol) (2001-01-04)
Re: RFC - VBS Grammar (Arargh!) (2001-01-04)
| List of all articles for this month |

From: "Scott Nicol" <>
Newsgroups: comp.compilers
Date: 4 Jan 2001 00:59:22 -0500
Organization: APK Net
References: 00-12-104 00-12-118
Keywords: Basic, parse
Posted-Date: 04 Jan 2001 00:59:22 EST

"Joachim Durchholz" <> wrote in message
> Well, I once started to do something with a MS Basic (QuickBasic if
> anybody remembers), did a full analysis of the IF statement, and decided
> to scrap the project ;)

If it's any consolation, you attacked the most difficult part of the
QuickBasic syntax first (print expressions come in as a close second).

> 1. Expression parsing
> 2) Use operator precedence.

This is the easiest way, and it works.

> QuickBasic had a THEN-less form of IF, la
> IF expression statement [ELSE statement]

This is the one-line IF, and it does have a THEN, but everything has to
occur on one line, and there is no END IF. I don't know if VBS has this or
not. VB supports one-line IF. VBS is a stripped-down version of VB,
specifically designed for embedding scripts within web pages (sort of like
javascript). Among the concepts stripped out are types (all variables are
of type Variant), labels, GoTo and GoSub, so I wouldn't be surprised if
one-line IF is not supported. If you want to support one-line IF, it's not
_that_ difficult. You have to distinguish between ':' and end-of-line for
statement terminators, and play around with precedence of the two one-line
IF cases (with and without ELSE) and ':'. I think it took me a few days of
tinkering with the grammar to get it right.

> I decided to scrap my project when I was done with IF and realized that
> I'd have to analyze all the other statements - WHILE, FOR, SWITCH, etc.

These are all straightforward (I assume you mean SELECT instead of SWITCH).

> ... - an alternative might have been to parse just the documented syntax
> and simply declare an error on undocumented stuff.

But that's no fun! Besides, you'll end up breaking lots of code which
relies on all of this undocumented stuff.

Scott Nicol

Post a followup to this message

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