zoukankan      html  css  js  c++  java
  • spidermonkey和narcissus语法分析

    narcissus是js写的js解释器,但是底层还是依赖于spidermonkey,所以有了zaphod,zaphod可以方便的将firefox的spidermonkey切换到narcissus。

    现在narcissus只能在firefox的beta1-beta8上运行,所以首先要下到firefox的beta浏览器。参照网址https://mozillalabs.com/zaphod/ 

    -----------------------------------------zaphod for narcissus
    For day to day browsing, Narcissus does not offer any real advantages over SpiderMonkey.  However, Narcissus is an ideal tool for developing new ideas for the JavaScript language itself.

    Zaphod promises to be a great tool for getting hands-on experience with experimental JS language features. Initially, it will useful to us internally for rapidly piloting language features in the browser. Down the road, it may also become a vehicle for giving the community early access to these ideas, so they can try them out and give us feedback. And of course, it’s all open source, so anyone who wants to join in on the effort is most welcome.



    spidermonkey是firefox的js解释引擎。有一个parse的api,可以解析js
    -------------------------------------------spidermonkey parse api

    一个独立的spidermonkey脚本,在js中操纵js源码更加方便,如语法高亮,静态分析,解释,编译等
    https://developer.mozilla.org/en/SpiderMonkey/Parser_API

    安装 在ubuntu下
    先安装库
    sudo apt-get install libnspr4-dev

    源码安装手动----------------------这个最新的只有1.81,这个里面没有parse方法
    下载源码
    mkdir mozilla
    cd mozilla
    wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
    tar xzf js-1.7.0.tar.gz
    然后编译
    cd js/src
    make -f Makefile.ref
    现在在Linux_ALL_...文件夹下有个js,这个就是了。
    如何直接装到系统呢?http://ebixio.com/blog/2010/07/31/how-to-install-libjs-spidermonkey/

    源码安装简单的安装--------推荐这种方式最新1.85
    hg clone http://hg.mozilla.org/mozilla-central/
    cd js/src
    autoconf2.13
    ./configure
    make

    用法介绍
    https://developer.mozilla.org/En/SpiderMonkey/Introduction_to_the_JavaScript_shell

    js> Reflect.parse("
    function a(){
      var b=2;
      function c(){
        var ci=3;
    	ci+=b
    	}
    }
    	",{loc:false})
    

    结果

    ({
     
    type:"Program", 
    body:[
     {
      type:"FunctionDeclaration",
      id:{ type:"Identifier", name:"a"}, 
      params:[], 
      body:{ 
       type:"BlockStatement",
       body:[{
    	 type:"VariableDeclaration", 
    	 kind:"var", 
    	 declarations:
    	 [{
    	  type:"VariableDeclarator",
    	  id:{ type:"Identifier", name:"b"},
    	  init:{ type:"Literal", value:2}
    	  }]
    	 },
           {
    	 type:"FunctionDeclaration",
    	 id:{ type:"Identifier", name:"c"},
    	 params:[], 
    	 body:{
    	   type:"BlockStatement",
    	   body:[{
    		 type:"VariableDeclaration", 
    		 kind:"var", 
    		 declarations:[{
    		   type:"VariableDeclarator",
    		   id:{ type:"Identifier", name:"ci"}, 
    		   init:{ type:"Literal", value:3}}]}, 
    	    { 
    	  type:"ExpressionStatement", 
    	  expression:{ 
    	   type:"AssignmentExpression", 
    	   operator:"+=", 
    	   left:{  type:"Identifier", name:"ci"}, 
    	   right:{ type:"Identifier",  name:"b"}
    	             }
    	   }
    	   ]}, 
          generator:false, 
          expression:false
    	    }
    	  ]},
      generator:false, 
      expression:false
    }]
    
    })
    

  • 相关阅读:
    0603学术诚信和职业道德
    0602第二个冲刺
    0525《构建之法》8、9、10章读后感
    0525Sprint回顾
    实验三进程调度
    解决提问的问题
    阅读《构建之法》第13-17章
    阅读:第10、11、12章
    作业5.2(封装及测试)
    作业5.1
  • 原文地址:https://www.cnblogs.com/lunalord/p/2006597.html
Copyright © 2011-2022 走看看