VBScript code cleaner

Results 1 to 2 of 2

Thread: VBScript code cleaner

  1. #1
    Jeremy Lowery Guest

    Default VBScript code cleaner

    I&#039;m currently working on a vbscript class that color codes vbscript and properly indents it.<BR><BR>First off, I broke the input file into tokens using a re.<BR>My first attempt was to just increase an indent variable every time it saw a keyword that called for indention ("if", "sub", "class", etc.) and decresed the indent when it saw an appropriate keyword. "end", "loop", "etc." Of course, this method just didn&#039;t work at all. There are way too many "special cases" that can occur. Like for example an if statemenet on only one line with no end if clause.<BR><BR>So my second attempt was a bit more robust. It&#039;s ended up looking like some weird recursive-descent parser. Stuff like this.<BR><BR>Private Function ParseExpression()<BR>&#039;// An Expression is a line that contains a blocking structure<BR>&#039;// This function DOES NOT write the end of line or indention.<BR>&#039;// This function assumes that the Current character is the character<BR>&#039;// at the beginning of a line<BR>&#039;// This would be faster using numeric symbols. Oh well.<BR>Select Case LCase(Current)<BR>Case "for":<BR> ParseForExpression()<BR>Case "if":<BR> ParseIfExpression()<BR>Case "do":<BR>ParseDoExpression()<BR>Case "while":<BR> ParseWhileExpression()<BR>Case "sub", "function", "class", "public", "private":<BR> ParseBlockExpression()<BR>Case Else<BR> If Current = VBCCEOF Then<BR> Exit Function<BR> End If<BR> ParseStatement()<BR>End Select<BR>&#039;// Current = vbCrLf<BR>End Function<BR><BR>Private Function ParseWhileExpression()<BR>&#039;// Current = while<BR>&#039;// Construct : while &#060;statement&#062;<BR>&#039;// &#060;expression&#062;*<BR>&#039;// wend<BR>ParseStatement() &#039;// while &#060;statement&#062;<BR>IncreaseIndent()<BR>Do Until AtEOF()<BR> ParseExpression() &#039;// &#060;expression&#062;*<BR> If LCase(PeerNext()) = "wend" Then Exit Do<BR> WriteEndOfLine()<BR> GetNext()<BR>Loop<BR>&#039;// Current = wend<BR>GetNext()<BR>DecreaseIndent()<BR>WriteEndO fLine()<BR>ParseStatement() &#039;// wend<BR>&#039;// Current = vbCrLf<BR>End Function<BR><BR>This method does fine, though it is EXTREMELY SLOW. Given a script that is over 600 lines long, the dev machine times out (even on crazy timeout times like 4 minutes) or it runs out of stack space because well..uhhh. it&#039;s recursive descent ;) I couldn&#039;t imagine what it&#039;d do to a server&#039;s cpu.<BR><BR>So here&#039;s my question. Is there any way to make this thing faster and reduce the stack size? No, I can&#039;t put it in a component.<BR><BR>I was thinking that maybe it&#039;s because of all the string testing. The only other option I could think of was to make a full blown lexer for it and generate Token constants to make all of the testing numeric. This seems like a lot of work (I don&#039;t know of anything like yylex for vb!), and I don&#039;t know if it will speed things up.<BR><BR>Or maybe someone has a better idea for how to do this? I&#039;m open to anything innovative. One "crazy" idea I had was turning the script into an XML hierarchal file and parsing it with XSLT, but err..that&#039;d probably be slower.<BR><BR>Thanks,<BR>Jeremy<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: VBScript code cleaner

    Well, I think you&#039;re right... XML will be tons slower. And I think you&#039;re right when you say it&#039;s all the string concats... VBScript is horrible with that.<BR><BR>If you don&#039;t have access to components, maybe a Java Class file? Maybe switch some code to JavaScript?<BR><BR>I&#039;m curious... what are you implementing this on to? Windows Notepad or something?<BR><BR>If you just want a color coded editor, http://www.ultradev.com is pretty good... just no indenting.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts