A JavaScript parser in JavaScript generated by Jison

Comment

Multiline comment
/*
This is a Multiline comment.
  
複数行のコメント
  
  
// ほげほげ
  
  
*/
Singleline comment
// Singleline comment.
  
// 一行のコメント
  
//  /*
//  
//    複数行コメントとの
//    合わせ
//  
//  */

Statement

If Statement
if (2000 > 100) {
  console.log('\if文/');
}
Expression Statement
10 + 20 * 30;
For Statement
for (var i = 0; i < 100; i++ ) {
  console.log(i);
}
While Statement
var i = 100;
while (i > 0) {
  i -= 1;
}
 
while (true) {
  i++;
  if (i > 100) break;
}
 
LABEL: while (false) {
}
 
Try Statement
try {
  throw "an error occured!!!";
} catch (e) {
  console.log(e);
} finally {
  console.log('finally...');
}

Variable Declaration

Number
var n = 100;
String literal
var s = "this is a string literal";
  
  
var difficult_string = "hoge\n /* not a comment // here */  hoo #! baz/^[a-z]*/  ";
 
RegExp literal
var r = /^a[a-z][A-Z]$"/ig;
Object literal
var obj = {
  s: "string hogehoge",
  num: 100,
  arr: [ 1000, 2000, 3000 ],
  if: function () {
  },
};
 
var ecma5obj = {
  set i (n) {
    console.log('setter of i called with ' + n);
    if (n < 0) 
      throw 'invalid value for i : ' + n.toString();
    this._i = n;
  },
  get i () {
    console.log('getter of i called');
    return this._i;
  }
};
Assignment Expression
var x = 50 + 50 * Math.sin(50),
    y = 10,
    b = true;
 
 
b |= x > 10 & x < 80;
 
x += 10;
 
y %= x++;
 
s = x > 3 ? "Yes" : "No";
Multi declaration
var x = 10,
    i = 20 + x,
    j = 30 + ++i,
    r = /^abc[a-z]*/i,
    foo = function () {
      return 100;
    },
    nu = null,
    self = this,
    b = true,
    a = [
      100,
      "hogehoge",
      /abc/i
    ],
    print = console.log,
    $ = jQuery,
    obj = new Object;

Function Declaration

Function Declaration
function f () {
  return 100;
}
Recursive Declaration
function fact (x) {
  if (x < 1) return 1;
  else return x * fact(x - 1);
}
Many arguments
function foo (s, t, u, v) {
  console.log(s);
  return u;
}
Closure
var f = (function () {
  var i = 0;
  return function () {
    i++;
    console.log('i is ' + i);
    return i;
  };
})();

Semicolon Insertion

Before new line
x = 10
y = 20
z = 30
Before }
if (this) { console.log(100) };
f = function (x) { return x * x };
Return statement
function f () {
  return
    1000;
}
Break statement
i = 100;
W: while (true) {
  if (!i--) break
  W;
}
semicolon insertion: