Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: Parse::JavaScript

by OeufMayo (Curate)
on Aug 27, 2002 at 08:45 UTC ( #193103=note: print w/ replies, xml ) Need Help??


in reply to Re: Parse::JavaScript
in thread JavaScript::Parse::PurePerl (was Parse::JavaScript)

Thanks for your input podmaster. Here are a few valid JavaScript samples that don't parse too well.

Regexes

var foo = 3 / 4 + 1 / 2;

is parsed as :

var foo = 3; / 4 + 1 /; 2;

var foo = (3/4) + 1 / 2; is not parsed at all (though I suspect it could be fixed by adjusting the precedence)

Elisions (though I have yet to see this construct in a real script)

var foo = foo[ , , bar];

Wrong parsing

bar ++foo;

Is parsed as:

bar++; foo;

Which is wrong. the parser should give an error (no line terminator allowed between 'bar' and '++') or be nice and get parse it as bar++;foo;

The following code is found in one of the the mozilla/js test script, but it doesn't seem to be valid, according to the specs (and obviously, doesn't parse).

try { //some stuff }catch (e if e == 3){ /* do stuff */ }

There are probably some more bugs, but the regex/division confusion is by far the most annoying

Update here is another major bugs due to the Optional Semicolon:

return a + b

Should be:

return; a + b;

But it is parsed as

return a + b;

This bug is mainly due to the fact that line terminators are silently skipped by the lexer

Update 2002-09-01: I'm glad to say that all these bugs are now fixed in the current version of this node (except for the elision.)

-- 
briac


Comment on Re: Re: Parse::JavaScript
Select or Download Code
Re: Re: Re: Parse::JavaScript
by Corion (Pope) on Aug 27, 2002 at 19:47 UTC

    Very interesting code and discussion - but my internal parser parses

    bar++ foo;
    as
    bar+ +foo;

    which would be instantly valid. But on the other side, I don't know much about JavaScript (and C-style) operator syntax, and maybe two pluses automatically mean postincrement / preincrement operator ...

    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://193103]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-09-16 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (11 votes), past polls