Changeset 3261
- Timestamp:
- 12/18/07 12:46:51 (5 years ago)
- Location:
- lang/javascript/jsruby/trunk/src
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/jsruby/trunk/src/head.js
r3087 r3261 40 40 RubyEngine.RESERVED = { 41 41 "if":true, "then":true, "elsif":true, "else":true, "end":true, 42 "while":true, "unless":true, "until":true, 42 "while":true, "unless":true, "until":true, "def":true, 43 43 "nil":true 44 44 } -
lang/javascript/jsruby/trunk/src/interpreter.js
r3183 r3261 104 104 } else if (RubyEngine.Node.Operator.prototype.isPrototypeOf(x)) { 105 105 switch (x.name) { 106 case " neg":106 case "-@": 107 107 stk.push(stk.pop().neg()); 108 108 break; -
lang/javascript/jsruby/trunk/src/parse.js
r3183 r3261 12 12 RubyEngine.Parser.prototype.compstmt = function() { 13 13 var x; 14 while(this.term()); 14 15 if ((x=this.stmt())==undefined) return undefined; 15 16 var ret = [x]; … … 141 142 } 142 143 143 // Primary : ('-'|'+') Primary | Primary2 ( '[' Args ']' | '.'Operation ('(' Args ')')? ('{' ('|'Varname'|')? CompStmt '}')? )* Args?144 // # for removing left recursions of Primary in BNF of Ruby144 // Primary : ('-'|'+') Primary 145 // | Primary2 ( '['Args']' | '.'Operation ('('Args')')? ('{' ('|'Varname'|')? CompStmt '}')? )* Args? 145 146 RubyEngine.Parser.prototype.primary = function() { 146 147 //console.log(this.body);console.trace();if(!confirm("continue?")) exit(); … … 151 152 if ((y=this.primary())!=undefined) { 152 153 if (x=='+') return y; 153 return new RubyEngine.Node.Expression([new RubyEngine.Node.Operator('neg'), y]); 154 } 155 this.body = prebody; 156 } 154 return new RubyEngine.Node.Expression([new RubyEngine.Node.Operator('-@'), y]); 155 } 156 this.body = prebody; 157 } 158 157 159 var prim = this.primary2(); 158 160 while(prim != undefined) { … … 198 200 prebody = this.body; 199 201 this.body = RegExp.rightContext; 200 y = this.blockvars(); 201 while(this.term()); 202 y=this.blockvars(); // it is maybe 'undefined' 202 203 z=this.compstmt(); 203 204 if (z==undefined) z=null; … … 219 220 220 221 // Primary2: '(' Expr ')' | Literal | Reference | '[' Args ']' 221 // if Arg Then CompStmt (elsif Arg Then CompStmt)* (else CompStmt)? end 222 // | if Arg Then CompStmt (elsif Arg Then CompStmt)* (else CompStmt)? end 223 // | def Operation ArgDecl CompStmt end 222 224 // Literal: / $INT:push | $JS_STRING:push /, 223 225 RubyEngine.Parser.prototype.primary2 = function() { … … 271 273 x = RegExp.$1; 272 274 if ((y = this.arg())!=undefined && this.then()) { 273 while (this.term());274 275 if (z=this.compstmt()) { 275 276 var args = [y, z]; … … 278 279 this.body = RegExp.rightContext; 279 280 if ((y = this.arg()) && this.then()) { 280 while (this.term());281 281 if (!(z=this.compstmt())) { this.body = prebody2; break; } 282 282 args.push(y, z) … … 286 286 var prebody2 = this.body; 287 287 this.body = RegExp.rightContext; 288 while (this.term());289 288 if (z=this.compstmt()) { 290 289 args.push(true, z) … … 301 300 this.body = prebody; 302 301 } 303 return undefined; 302 303 // def Fname ArgDecl CompStmt end 304 if (this.body.match(/^[ \t]*def/)) { 305 this.body=RegExp.rightContext; 306 x=this.operation(); 307 y=this.argdecl(); 308 z=this.compstmt(); 309 if(x!=undefined && z!=undefined && this.body.match(/^[ \s]*(end)/)) { 310 this.body = RegExp.rightContext; 311 ret = new RubyEngine.Node.Method("def", null, [new RubyEngine.RubyObject.String(x)]); 312 ret.block = new RubyEngine.Node.Block(y, z); 313 return ret; 314 } 315 this.body = prebody; 316 } 317 318 return undefined; 319 } 320 321 // ArgDecl : `(' ArgList `)' | ArgList Term 322 RubyEngine.Parser.prototype.argdecl = function() { 323 //console.log(this.body);console.trace();if(!confirm("continue?")) exit(); 324 var x; 325 var prebody = this.body; 326 if (this.body.match(/^[ \t]*\(/)) { 327 this.body=RegExp.rightContext; 328 if ((x=this.arglist())!=undefined && this.body.match(/^[ \t]*\)/) ) { 329 this.body=RegExp.rightContext; 330 return x; 331 } 332 } else { 333 if ((x=this.arglist())!=undefined && this.term() ) return x; 334 } 335 this.body=prebody; 336 return undefined; 337 } 338 339 // ArgList : varname(`,'varname)*[`,'`*'[varname]][`,'`&'varname] | `*'varname[`,'`&'varname] | [`&'varname] 340 RubyEngine.Parser.prototype.arglist = function() { 341 var x; 342 if ((x=this.varname())==undefined) return []; 343 var ret=[x], prebody=this.body; 344 while (this.body.match(/^[ \t]*,/)) { 345 prebody=this.body; 346 this.body=RegExp.rightContext; 347 if ((x=this.varname())==undefined) break; 348 ret.push(x); 349 } 350 this.body=prebody; 351 return ret; 304 352 } 305 353
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)