2014-03-24 09:14:29 -07:00
|
|
|
==========================================
|
|
|
|
|
parses multiple statements
|
|
|
|
|
==========================================
|
|
|
|
|
var x = {};
|
|
|
|
|
{};
|
|
|
|
|
---
|
|
|
|
|
(program
|
2014-03-26 00:10:59 -07:00
|
|
|
(statement (assignment (identifier) (object)))
|
|
|
|
|
(statement (object)))
|
2014-03-24 09:14:29 -07:00
|
|
|
|
|
|
|
|
==========================================
|
|
|
|
|
parses if statements
|
|
|
|
|
==========================================
|
2014-03-25 23:40:53 -07:00
|
|
|
if (theCondition) {
|
2014-03-24 13:05:04 -07:00
|
|
|
var x = 2;
|
|
|
|
|
}
|
2014-03-24 09:14:29 -07:00
|
|
|
---
|
|
|
|
|
(program
|
2014-03-26 00:10:59 -07:00
|
|
|
(if_statement
|
|
|
|
|
(identifier)
|
|
|
|
|
(statement_block (statement (assignment (identifier) (number))))))
|
2014-03-24 09:14:29 -07:00
|
|
|
|
2014-03-25 23:40:53 -07:00
|
|
|
==========================================
|
|
|
|
|
parses if-else statements
|
|
|
|
|
==========================================
|
|
|
|
|
if (theCondition) {
|
|
|
|
|
var x = 2;
|
|
|
|
|
} else {
|
|
|
|
|
var x = 4;
|
|
|
|
|
}
|
|
|
|
|
---
|
2014-03-26 00:10:59 -07:00
|
|
|
(program (if_statement
|
|
|
|
|
(identifier)
|
|
|
|
|
(statement_block (statement (assignment (identifier) (number))))
|
|
|
|
|
(statement_block (statement (assignment (identifier) (number))))))
|
2014-03-25 23:40:53 -07:00
|
|
|
|
2014-03-26 08:23:13 -07:00
|
|
|
==============================================
|
|
|
|
|
parses if-else statements with many conditions
|
|
|
|
|
==============================================
|
|
|
|
|
if (conditionA) {
|
|
|
|
|
var x = 2;
|
|
|
|
|
} else if (conditionB)
|
|
|
|
|
var x = 4;
|
|
|
|
|
else {
|
|
|
|
|
var x = 8;
|
|
|
|
|
}
|
|
|
|
|
---
|
|
|
|
|
(program (if_statement
|
|
|
|
|
(identifier)
|
|
|
|
|
(statement_block (statement (assignment (identifier) (number))))
|
|
|
|
|
(if_statement
|
|
|
|
|
(identifier)
|
|
|
|
|
(statement (assignment (identifier) (number)))
|
|
|
|
|
(statement_block (statement (assignment (identifier) (number)))))))
|
|
|
|
|
|
|
|
|
|
==========================================
|
|
|
|
|
parses named functions
|
|
|
|
|
==========================================
|
2014-03-26 22:43:08 -07:00
|
|
|
var x = {
|
|
|
|
|
theMethod: function(argA, argB) {
|
|
|
|
|
var x = argA;
|
|
|
|
|
}
|
2014-03-26 08:23:13 -07:00
|
|
|
};
|
|
|
|
|
|
2014-03-26 22:43:08 -07:00
|
|
|
x.theMethod(5, 6);
|
2014-03-26 08:23:13 -07:00
|
|
|
---
|
|
|
|
|
(program
|
2014-03-26 22:43:08 -07:00
|
|
|
(statement (assignment
|
2014-03-26 08:23:13 -07:00
|
|
|
(identifier)
|
2014-03-26 22:43:08 -07:00
|
|
|
(object (identifier) (function_expression
|
|
|
|
|
(formal_parameters (identifier) (identifier))
|
|
|
|
|
(statement_block (statement (assignment (identifier) (identifier))))))))
|
|
|
|
|
(statement (function_call
|
|
|
|
|
(property_access (identifier) (identifier))
|
|
|
|
|
(number) (number))))
|
|
|
|
|
|