6

I am trying to create a VBScript parser. I was wondering what is the best way to go about it. I have researched and researched. The most popular way seems to be going for something like Gold Parser or ANTLR.

The feature I want to implement is to do dynamic checking of Syntax Errors in VBScript. I do not want to compile the entire VBS every time some text changes. How do I go about doing that? I tried to use Gold Parser, but i assume there is no incremental way of doing parsing through it, something like partial parse trees...Any ideas on how to implement a partial parse tree for such a scenario?

I have implemented VBscript Parsing via GOLD Parser. However it is still not a partial parser, parses the entire script after every text change. Is there a way to build such a thing.

thks

redDragonzz
  • 1,543
  • 2
  • 15
  • 33
  • 1
    Why do you object to reparsing the whole thing? VBScripts tend to be not very big. – Ira Baxter Mar 04 '11 at 22:55
  • Hmm... accr to http://www.cs.vu.nl/~dick/PTAPG.html partial parsers are possible and I was looking for a way to build the same. Pardon me if I seem a noob. I never worked on building a parser before .. – redDragonzz Mar 05 '11 at 02:48
  • 1
    It is possible to build "partial" or incremental parsers. It is considerably harder than building a parser for a full grammar. So, if you don't need one, you should skip it. For small VBScript documents, you can just apply a full parser to the string to see if it is OK. If you have large programs, then maybe this will matter. – Ira Baxter Mar 05 '11 at 06:14

2 Answers2

4

If you really want to do incremental parsing, consider this paper by Tim Wagner.

It is brilliant scheme to keep existing parse trees around, shuffling mixtures of string fragments at the points of editing and parse trees representing the parts of the source text that hasn't changed, and reintegrating the strings into the set of parse trees. It is done using an incremental GLR parser.

It isn't easy to implement; I did just the GLR part and never got around to the incremental part. The GLR part was well worth the trouble.

There are lots of papers on incremental parsing. This is one of the really good ones.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • Alright I shall try to do this way, what about ANTLR? I think it has the facility to build Abstract Syntax Trees partially. – redDragonzz Mar 07 '11 at 02:07
  • @redDragonz: I don't know enough about ANTLR. What I can tell you is that parser generators specifically and used primarily for parsing whole program (goal rules for the grammar) pretty much provide no meaningful way to do incremental parsing. Considering that ANTLR is in this category, I'd be surprised if it did provide such incremental support. Your mileage may vary. – Ira Baxter Mar 07 '11 at 03:00
2

I'd first look for an existing VBScript parser instead of writing your own, which is not a trivial task!

Theres a VBScript grammar in BNF format on this page: http://rosettacode.org/wiki/BNF_Grammar which you can translate into a ANTLR (or some other parser generator) grammar.

Before trying to do fancy things like re-parsing only a part of the source, I recommend you first create a parser that actually works.

Best of luck!

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
  • The Gold Parser allows for parsing VBScript http://www.devincook.com/goldparser/engine/dot-net/morozov/index.htm and I have implemented a parser based on it and the C# runtime written by morozov. So How do i go about creating a partial parser :) – redDragonzz Mar 04 '11 at 15:32
  • @redDragonzz, then you should update your original question with this info. – Bart Kiers Mar 04 '11 at 17:27