dcsimg
Results 1 to 22 of 22

Thread: [RESOLVED] Develop a JavaScript parser with VB6

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,598

    Resolved [RESOLVED] Develop a JavaScript parser with VB6

    Some people think that I always ask some crazy questions. I don't think so. I carefully thought about every question and thought they were feasible. But they don't include this question, which is a bit crazy I think too.

    I want to implement debugging for JavaScript in my code editor, so I'm thinking about whether I could write a JavaScript parser with VB6. I know it is very difficult to do this. I'd like to know what is the most difficult part? What steps are needed to develop a JavaScript parser? What tools are available to help develop it? Is there a JavaScript parser developed in C# or Python or Delphi? Is there a ready-made JavaScript parser that can be used by VB6?

    Any advice and suggestions would be greatly appreciated
    Last edited by dreammanor; Dec 24th, 2018 at 07:43 PM.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,516

    Re: Develop a JavaScript parser with VB6

    I don't know why it should be any more difficult in VB6 than using anything else aside from specialized tools designed for the purpose.

    There is far more involved than parsing however. You might want to read up on Lexical Analysis, Symbol Tables, and a list of other things that make up a language processor or a source-level debugger.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,598

    Re: Develop a JavaScript parser with VB6

    The information you provided is very useful, thank you, dilettante.

    The reason why I think it's very difficult is that I have not seen anyone using VB6 to develop a JavaScript parser, nor can I search the Internet for VB6 source code that can be referenced and learned.
    Last edited by dreammanor; Dec 25th, 2018 at 03:09 AM.

  4. #4
    Hyperactive Member
    Join Date
    Jun 2015
    Posts
    311

    Re: Develop a JavaScript parser with VB6

    [...]
    Last edited by dz32; Apr 26th, 2019 at 11:11 AM.

  5. #5
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,535

    Re: Develop a JavaScript parser with VB6

    There is a big difference between a parser and an interpreter. The parser usually generates a parse tree, while the interpreter deals with simplified parse tree turned to abstract syntax tree (AST) which is used either to be directly executed or to produce intermediate representation (IR) of instructions for a small virtual machine (VM) which is in turn executed.

    So the parser is the easiest step although a little boring as most of the code is very repetative and small changes/fixes to language grammar involve rewriting large swaths of boilerplate. This leads to the idea for prototyping to use parser generators, which are a class of tools that produce code from grammars written in a specific grammar langugae (CFG, PEG, etc.). When the grammar is stable and some more performance is need than a manual parser can be based on this generated code.

    Finally (here comes the obligatory self-promoting link) check out VbPeg - PEG parser generator for VB6. This translates Parsing Expression Grammars into recursive-descent parsers in VB6 .bas or .cls modules. For instance here is a sample grammar for kscope toy language which generates this cKscope.cls VB6 class modile with ~1500 generated lines of code.

    cheers,
    </wqw>

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,598

    Re: Develop a JavaScript parser with VB6

    @dz, @wqweto, thank you for the information you provided, they look very interesting, I need some time to learn them. Much appreciate.

  7. #7
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,910

    Re: Develop a JavaScript parser with VB6

    Quote Originally Posted by dreammanor View Post
    The information you provided is very useful, thank you, dilettante.

    The reason why I think it's very difficult is that I have not seen anyone using VB6 to develop a JavaScript parser, nor can I search the Internet for VB6 source code that can be referenced and learned.
    I would think the reason for that is that VB does not use nor support Java Script so there is not much need for it.
    I also think it is totally doable just not sure I would want to bother with it.

    If memory serves VB.Net has some support for Java Script built in.

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,516

    Re: Develop a JavaScript parser with VB6

    Well don't forget about the Microsoft Script Control. It can accept JScript and VBScript output of the box, as well as other scripting languages if you install an appropriate engine such as ActivePerl.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,598

    Re: Develop a JavaScript parser with VB6

    Quote Originally Posted by DataMiser View Post
    I would think the reason for that is that VB does not use nor support Java Script so there is not much need for it.
    I also think it is totally doable just not sure I would want to bother with it.

    If memory serves VB.Net has some support for Java Script built in.
    If we want to use VB6 to make some magical apps or web-related apps, then VB needs JavaScript. Hope some people could make some useful explorations in this regard.

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,598

    Re: Develop a JavaScript parser with VB6

    Quote Originally Posted by dilettante View Post
    Well don't forget about the Microsoft Script Control. It can accept JScript and VBScript output of the box, as well as other scripting languages if you install an appropriate engine such as ActivePerl.
    Hi dilettante, I know that Microsoft Script Control can handle JScript and VBScript. I also collected information about ActivePerl, but I don't know if Microsoft Script Control can handle JavaScript, especially ES6 (ECMAScript 6) with many new features.

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,598

    Re: Develop a JavaScript parser with VB6

    Quote Originally Posted by dilettante View Post
    Well don't forget about the Microsoft Script Control. It can accept JScript and VBScript output of the box, as well as other scripting languages if you install an appropriate engine such as ActivePerl.
    Hi dilettante, I know that Microsoft Script Control can handle JScript and VBScript. I also collected information about ActivePerl, but I don't know if Microsoft Script Control can handle JavaScript, especially ES6 (ECMAScript 6) with many new features.

    In addition, I hope to get the debugging information of the JavaScript output. If there is a JavaScript parser developed in VB6 (even if the parsing speed is not fast), that would be very exciting.

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,516

    Re: Develop a JavaScript parser with VB6

    Active Scripting lists a number of known Active Scripting engines.

    It even includes VBA in the list but I have not found a way to use that scripting engine from WScript, CScript, or the Script Control. It may not be a fully compliant engine or it may not make the necessary registry entries when Office is installed... or its place on the list at all may simply be in error.

    I don't see any flavor of ECMAScript listed there aside from JScript itself.

  13. #13
    Hyperactive Member
    Join Date
    Jun 2015
    Posts
    311

    Re: Develop a JavaScript parser with VB6

    [...]
    Last edited by dz32; Apr 26th, 2019 at 11:10 AM.

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,598

    Re: Develop a JavaScript parser with VB6

    Quote Originally Posted by dilettante View Post
    Active Scripting lists a number of known Active Scripting engines.

    It even includes VBA in the list but I have not found a way to use that scripting engine from WScript, CScript, or the Script Control. It may not be a fully compliant engine or it may not make the necessary registry entries when Office is installed... or its place on the list at all may simply be in error.

    I don't see any flavor of ECMAScript listed there aside from JScript itself.
    Hi dilettante,

    I'm back, sorry for the late reply. ECMAScript 2015 (ES6) not only adds a lot of new features, but also makes JavaScript more rigorous and standardized, which makes it easier for us to develop our own JavaScript parser. When IE WebBrowser and MSHTMLEdit open some HTML5 websites, they always make a lot of warnings and error messages.

  15. #15
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,535

    Re: Develop a JavaScript parser with VB6

    Quote Originally Posted by dreammanor View Post
    When IE WebBrowser and MSHTMLEdit open some HTML5 websites, they always make a lot of warnings and error messages.
    True when WebBrowser uses IE 7 compatibility mode (default) but HTML5 is very usable when set using IE 11 compatibility. This has been flogged to death in these forums.

    IE 11 has pretty capable HTML5 renderer. Not the latest and the greatest but still better than the non-existent in IE 7. . .

    cheers,
    </wqw>

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,598

    Re: Develop a JavaScript parser with VB6

    Quote Originally Posted by dz32 View Post
    I seem to remember the ms script control did not support some common javascript.

    The one that sticks in mind is not supporting myString[0] to access characters in a string by array offset and instead requiring .charAt(0).

    It seems like there were others too but I cant remember what they were. Can make trying to run complex code from 3rd parties hard. I also remember I could not run the js beautifier script as is, hard to strip the outer most enclosure. Some ast parsers designed for node didnít run either had to run in the duktape engine.

    I ran some tests on other suspects below but they were all ok

    Code:
    //---------------fail
    alert("test"[0]) 
    
    //--------------------- win10-xp ok
    function x(){
    	this.x  = "hi"
    	return this
    }
    
    alert(x().x)
    
    //--------------------- win10- xp ok
    
    var car = {type:"Fiat", model:"500", color:"white"}; 
    alert(car.type)
    
    //------------------------//win10-xp ok
    
    function x(){
      
      function y(){ return 21 }
    
      return y();
    
    }
    
    alert(x())
    
    //--------------------ok
    
    sum = new Function('a', 'b', 'return a + b');
    
    alert( sum(1, 2) ); // 3
    
    //-------------------ok
    
    var add = (function () {
      var counter = 0;
      return function () {counter += 1; return counter}
    })();
    
    add();
    add();
    alert(add())
    Hi dz32, sorry for the late reply. I'm exploring the possibility of writing a JavaScript Parser from scratch, which may take some time. After my WebPage Builder is completed, I'll continue to conduct in-depth research on this topic. Thank you for your information.

  17. #17

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,598

    Re: Develop a JavaScript parser with VB6

    Quote Originally Posted by wqweto View Post
    True when WebBrowser uses IE 7 compatibility mode (default) but HTML5 is very usable when set using IE 11 compatibility. This has been flogged to death in these forums.

    IE 11 has pretty capable HTML5 renderer. Not the latest and the greatest but still better than the non-existent in IE 7. . .

    cheers,
    </wqw>
    Very useful information. All my development work is done on XP. I'll test IE 11 compatibility on Win10, thank you very much, wqweto.

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,598

    Re: Develop a JavaScript parser with VB6

    Quote Originally Posted by wqweto View Post
    Finally (here comes the obligatory self-promoting link) check out VbPeg - PEG parser generator for VB6. This translates Parsing Expression Grammars into recursive-descent parsers in VB6 .bas or .cls modules. For instance here is a sample grammar for kscope toy language which generates this cKscope.cls VB6 class modile with ~1500 generated lines of code.

    cheers,
    </wqw>
    Hi wqweto, I'm learning your VbPeg, but I don't know how to use it. I saw an example of Java in your test folder. I'd to know if your VbPeg can be used to parse JavaScript or TypeScript? Thanks.

  19. #19
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,535

    Re: Develop a JavaScript parser with VB6

    Quote Originally Posted by dreammanor View Post
    I'd to know if your VbPeg can be used to parse JavaScript or TypeScript?
    I've never done it personally. Although both are not very complicated languages, writing a programming language parser is always non-trivial IMO.

    Be prepared for bugs in whatever parser generator you might be using too. VbPeg and (to some extent) ANTLR both could fail in whatever edge cases you force them to.

    cheers,
    </wqw>

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,598

    Re: Develop a JavaScript parser with VB6

    I see, thank you, wqweto.

  21. #21
    Hyperactive Member
    Join Date
    Feb 2019
    Posts
    392

    Re: [RESOLVED] Develop a JavaScript parser with VB6

    Have you seen Gold Parser? It has grammars for JavaScript/VBScript/VB.Net in various qualites, but not for VB6. It does have parsing engines for various languages, including VB6.

  22. #22

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,598

    Re: [RESOLVED] Develop a JavaScript parser with VB6

    Quote Originally Posted by qvb6 View Post
    Have you seen Gold Parser? It has grammars for JavaScript/VBScript/VB.Net in various qualites, but not for VB6. It does have parsing engines for various languages, including VB6.
    The information you provided is extremely useful to me. Thank you very much, qvb6.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width