|VBScript grammar firstname.lastname@example.org (2000-05-20)|
|Re: VBScript grammar email@example.com (Scott Nicol) (2000-05-22)|
|From:||Scott Nicol <firstname.lastname@example.org>|
|Date:||22 May 2000 23:02:39 -0400|
|Keywords:||Basic, parse, practice|
Anton Belov -- Customer Engineering wrote:
> Does anyone have or know where to get the grammar definition (in any
> form) for VBScript ? I know it has been asked before - but i didn't
> see any answers ...
I've never seen a grammar published. You can't trust the reference
manual either, because it lies. The only way to write a grammar is to
play with an implementation of the language.
I wrote a parser for VB (sorry, not available, I don't own the code),
and since VBScript is based on VB, I'll assume you'll run into similar
problems. Here are a few:
- End requires an extra lookahead, because End is different from
End If, End While, End Select, etc. Handle it in the scanner
so that End <something> is returned to the parser as one token,
- Line labels are a pain. I think I put some magic in the
scanner for this.
- There are a zillion reserved words, but some depend on context.
This can make tokenizing very difficult. For example, "In" is
a reserved word but can also be a variable name. I think I
fixed this by having YACC pass state info back to Lex, but
you have to be careful about lookahead. Another possible fix
is to allow a syntax error and try to recover in yyerror().
- Scoping rules are quite complex, and are subtly different for
variables and types.
- Parenthesis are significant at runtime, so don't throw them
away during the parse if you ever want to build a runtime.
In case you're wondering, parenthesis override references,
so even if a function/subroutine is written to accept a
parameter by reference, you can pass it by value by
enclosing the argument in parenthesis.
Writing a runtime is even more exciting...
Return to the
Search the comp.compilers archives again.