Help: Need to roll my own JS parser

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default Help: Need to roll my own JS parser




    I need a JavaScript parser. A search through CPAN didn't turn up
    anything (please correct me if I'm wrong!), so it looks like I'll
    have to roll my own. Are there any generic modules that could I
    use to make the task of writing a computer language parser somewhat
    easier?

    Thanks!

    -Irv
    Irving Kimura Guest

  2. Similar Questions and Discussions

    1. w3d roll over problem
      hi, my one project wich have one w3d file having 10 model and i want to display that model name when mouse over the model and that model's shader...
    2. Roll out
      I have noticed on a few flash sites that when i click on a button the stage 'rolls out' and the transition between one stage and the next is nice...
    3. roll over questions
      I just started using director 10 days ago and my brain is ready to snap. I'm building a very simple interactive CD for my furniture business and am...
    4. HTML-Parser / SGML-Parser
      Ok, silly question. I am writing a script to determine my router's WAN ip address and then to email me once an hour in case it changes. Currently...
    5. more than 36 photographs on a roll?
      I get 37 to 38 on a 36 exposure roll with my Nikon N70. Ross - Jan Keirse wrote:
  3. #2

    Default Re: Help: Need to roll my own JS parser

    Irving Kimura <irving_kimura@lycos.com> wrote in news:bgo8a7$e77$1
    @reader1.panix.com:
    > I need a JavaScript parser. A search through CPAN didn't turn up
    > anything (please correct me if I'm wrong!), so it looks like I'll
    > have to roll my own. Are there any generic modules that could I
    > use to make the task of writing a computer language parser somewhat
    > easier?
    >
    > Thanks!
    >
    > -Irv
    >
    There is Javascript.pm (by Claes Jacobsson I think).
    This allows embedding of Javascript into perl modules through interface to
    libjs from Mozilla.

    Claes gave a talk on this at the YAPC in Paris - so there may be some
    additional info in his slides etc.
    Lenonardo Guest

  4. #3

    Default Re: Help: Need to roll my own JS parser

    In <Xns93CE9BC8C930M3141T@193.38.113.46> Lenonardo <leonardo@duckpond.co.uk> writes:
    >Irving Kimura <irving_kimura@lycos.com> wrote in news:bgo8a7$e77$1
    >@reader1.panix.com:
    >> I need a JavaScript parser. A search through CPAN didn't turn up
    >> anything (please correct me if I'm wrong!), so it looks like I'll
    >> have to roll my own. Are there any generic modules that could I
    >> use to make the task of writing a computer language parser somewhat
    >> easier?
    >>
    >> Thanks!
    >>
    >> -Irv
    >>
    >There is Javascript.pm (by Claes Jacobsson I think).
    >This allows embedding of Javascript into perl modules through interface to
    >libjs from Mozilla.
    I'm not sure I understand your suggestion. How would Javascript.pm
    provide (or help me build) a parser for JavaScript?

    -Irv

    Irving Kimura Guest

  5. #4

    Default Re: Help: Need to roll my own JS parser

    Ah - I was assuming you only wanted to parse the Javascript in order to
    run it.

    Javascript.pm allows you to load javascript code and execute it (i.e.
    call javascript from perl) - and also call perl from javascript.

    If you want to parse Javascript so that you end up with a language tree
    or whatever then I don't know of anything - but libjs might provide such
    a method.

    Irving Kimura <irving_kimura@lycos.com> wrote in
    news:bgopk3$kso$1@reader1.panix.com:
    > In <Xns93CE9BC8C930M3141T@193.38.113.46> Lenonardo
    > <leonardo@duckpond.co.uk> writes:
    >
    >>Irving Kimura <irving_kimura@lycos.com> wrote in news:bgo8a7$e77$1
    >>@reader1.panix.com:
    >
    >>> I need a JavaScript parser. A search through CPAN didn't turn up
    >>> anything (please correct me if I'm wrong!), so it looks like I'll
    >>> have to roll my own. Are there any generic modules that could I
    >>> use to make the task of writing a computer language parser somewhat
    >>> easier?
    >>>
    >>> Thanks!
    >>>
    >>> -Irv
    >>>
    >
    >>There is Javascript.pm (by Claes Jacobsson I think).
    >>This allows embedding of Javascript into perl modules through
    >>interface to libjs from Mozilla.
    >
    > I'm not sure I understand your suggestion. How would Javascript.pm
    > provide (or help me build) a parser for JavaScript?
    >
    > -Irv
    >
    Lenonardo Guest

  6. #5

    Default Re: Help: Need to roll my own JS parser

    In article <bgo8a7$e77$1@reader1.panix.com>,
    Irving Kimura <irving_kimura@lycos.com> wrote:
    > I need a JavaScript parser. A search through CPAN didn't turn up
    > anything (please correct me if I'm wrong!), so it looks like I'll
    > have to roll my own. Are there any generic modules that could I
    > use to make the task of writing a computer language parser somewhat
    > easier?
    As you want to parse JS yourself (rather than simply use it, which the
    excellent Javascript.pm is more for, as suggested elsewhere on this
    thread) you'll need a definition of the language. Once you've got that
    you can decide how you want to implement the parser, and indeed whether
    you want to somehow do something with the parsed code.

    At one extreme you can implement the parser by reading a character from
    somewhere, and then reading another and another, and so on... all the
    time maintaining various state flags (such as 'in a comment', 'in a
    string', 'in a string but just got a backslash escape', 'expecting an
    alphabetic character or end of string' etc).

    At the other extreme, and certainly the route I'd recommend is to use
    something like the excellent Parse::Yapp. Basically you create a file
    that tells yapp how your syntax is logically built up, and you write a
    tokenizer, and yapp does the rest. I've used it to successfully build a
    parser for arbitrary expressions (such as

    foo.bar + (12.3 - foo('%s!', (w*2))) / baz

    See:
    [url]http://search.cpan.org/author/FDESAR/Parse-Yapp-1.05/[/url]

    P

    --
    pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
    Remove the tea to reply
    pkent Guest

  7. #6

    Default Re: Help: Need to roll my own JS parser

    That tokenizer approach that that person mentioned using Parse::Yapp is god. I cant believe that exists im about to try to read everything about that module, what i always did was just use regex, which is the approach he gave you before Yapp.
    Horacio Spinelli on FB Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139