2014-07-07 13:35:55 -07:00
|
|
|
==========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
multiple statements
|
2014-07-07 13:35:55 -07:00
|
|
|
==========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-07-07 13:35:55 -07:00
|
|
|
var x = {}, z, i = 0;
|
|
|
|
|
firstFunction(x)
|
|
|
|
|
secondFunction(x);
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-07-07 13:35:55 -07:00
|
|
|
---
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-07-07 13:35:55 -07:00
|
|
|
(program
|
2015-08-23 10:42:06 -07:00
|
|
|
(var_declaration
|
|
|
|
|
(var_assignment (identifier) (object))
|
|
|
|
|
(identifier)
|
|
|
|
|
(var_assignment (identifier) (number)))
|
2015-09-02 13:05:31 -07:00
|
|
|
(expression_statement (function_call (identifier) (arguments (identifier))))
|
|
|
|
|
(expression_statement (function_call (identifier) (arguments (identifier)))))
|
2014-07-07 13:35:55 -07:00
|
|
|
|
2014-04-05 15:55:20 -07:00
|
|
|
==========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
if statements
|
2014-04-05 15:55:20 -07:00
|
|
|
==========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-04-05 15:55:20 -07:00
|
|
|
if (isReady()) {
|
2015-08-23 10:42:06 -07:00
|
|
|
console.log(theData)
|
2014-04-05 15:55:20 -07:00
|
|
|
}
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-04-05 15:55:20 -07:00
|
|
|
---
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2015-09-02 13:05:31 -07:00
|
|
|
(program (if_statement (function_call (identifier) (arguments))
|
2015-08-23 10:42:06 -07:00
|
|
|
(statement_block (expression_statement
|
2015-09-02 13:05:31 -07:00
|
|
|
(function_call (member_access (identifier) (identifier)) (arguments (identifier)))))))
|
2014-04-05 15:55:20 -07:00
|
|
|
|
|
|
|
|
==========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
if-else statements
|
2014-04-05 15:55:20 -07:00
|
|
|
==========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-04-05 15:55:20 -07:00
|
|
|
if (theCondition) {
|
2015-08-23 10:42:06 -07:00
|
|
|
firstFunction();
|
2014-04-05 15:55:20 -07:00
|
|
|
} else {
|
2015-08-23 10:42:06 -07:00
|
|
|
secondFunction();
|
2014-04-05 15:55:20 -07:00
|
|
|
}
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-04-05 15:55:20 -07:00
|
|
|
---
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2015-08-23 10:42:06 -07:00
|
|
|
(program (if_statement
|
|
|
|
|
(identifier)
|
2015-09-02 13:05:31 -07:00
|
|
|
(statement_block (expression_statement (function_call (identifier) (arguments))))
|
|
|
|
|
(statement_block (expression_statement (function_call (identifier) (arguments))))))
|
2014-04-05 15:55:20 -07:00
|
|
|
|
|
|
|
|
==================================================
|
2014-10-19 12:36:43 -07:00
|
|
|
if-else statements with multiple conditions
|
2014-04-05 15:55:20 -07:00
|
|
|
==================================================
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-04-05 15:55:20 -07:00
|
|
|
if (firstValue) {
|
2015-08-23 10:42:06 -07:00
|
|
|
firstFunction();
|
2014-04-05 15:55:20 -07:00
|
|
|
} else if (secondValue)
|
2015-08-23 10:42:06 -07:00
|
|
|
secondFunction();
|
2014-04-05 15:55:20 -07:00
|
|
|
else {
|
2015-08-23 10:42:06 -07:00
|
|
|
thirdFunction();
|
2014-04-05 15:55:20 -07:00
|
|
|
}
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-04-05 15:55:20 -07:00
|
|
|
---
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2015-08-23 10:42:06 -07:00
|
|
|
(program (if_statement (identifier)
|
2015-09-02 13:05:31 -07:00
|
|
|
(statement_block (expression_statement (function_call (identifier) (arguments))))
|
2015-08-23 10:42:06 -07:00
|
|
|
(if_statement (identifier)
|
2015-09-02 13:05:31 -07:00
|
|
|
(expression_statement (function_call (identifier) (arguments)))
|
|
|
|
|
(statement_block (expression_statement (function_call (identifier) (arguments)))))))
|
2014-04-05 15:55:20 -07:00
|
|
|
|
|
|
|
|
==========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
for loops
|
2014-04-05 15:55:20 -07:00
|
|
|
==========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-04-05 15:55:20 -07:00
|
|
|
for (var i = 1; someCondition(i); i = next()) {
|
2015-08-23 10:42:06 -07:00
|
|
|
doSomething();
|
2014-04-05 15:55:20 -07:00
|
|
|
}
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-04-05 15:55:20 -07:00
|
|
|
---
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2015-08-23 10:42:06 -07:00
|
|
|
(program (for_statement
|
|
|
|
|
(var_declaration (var_assignment (identifier) (number)))
|
2015-09-02 13:05:31 -07:00
|
|
|
(function_call (identifier) (arguments (identifier)))
|
|
|
|
|
(assignment (identifier) (function_call (identifier) (arguments)))
|
|
|
|
|
(statement_block (expression_statement (function_call (identifier) (arguments))))))
|
2014-04-05 15:55:20 -07:00
|
|
|
|
2014-07-07 13:35:55 -07:00
|
|
|
==========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
for-in loops
|
2014-07-07 13:35:55 -07:00
|
|
|
==========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-07-07 13:35:55 -07:00
|
|
|
for (var key in someObject)
|
2015-08-23 10:42:06 -07:00
|
|
|
doSomething();
|
2014-07-07 13:35:55 -07:00
|
|
|
for (key in someObject)
|
2015-08-23 10:42:06 -07:00
|
|
|
doSomethingElse();
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-07-07 13:35:55 -07:00
|
|
|
---
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-07-07 13:35:55 -07:00
|
|
|
(program
|
2015-08-23 10:42:06 -07:00
|
|
|
(for_in_statement
|
|
|
|
|
(identifier) (identifier)
|
2015-09-02 13:05:31 -07:00
|
|
|
(expression_statement (function_call (identifier) (arguments))))
|
2015-08-23 10:42:06 -07:00
|
|
|
(for_in_statement
|
|
|
|
|
(identifier) (identifier)
|
2015-09-02 13:05:31 -07:00
|
|
|
(expression_statement (function_call (identifier) (arguments)))))
|
2014-07-07 13:35:55 -07:00
|
|
|
|
2014-05-09 21:36:18 -07:00
|
|
|
==========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
while loops
|
2014-05-09 21:36:18 -07:00
|
|
|
==========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-05-09 21:36:18 -07:00
|
|
|
while (someCondition(i)) {
|
2015-08-23 10:42:06 -07:00
|
|
|
doSomething();
|
2014-05-09 21:36:18 -07:00
|
|
|
}
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-05-09 21:36:18 -07:00
|
|
|
---
|
2015-08-23 10:42:06 -07:00
|
|
|
|
|
|
|
|
(program (while_statement
|
2015-09-02 13:05:31 -07:00
|
|
|
(function_call (identifier) (arguments (identifier)))
|
|
|
|
|
(statement_block (expression_statement (function_call (identifier) (arguments))))))
|
2014-05-09 21:36:18 -07:00
|
|
|
|
|
|
|
|
==========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
try/catch statements
|
2014-05-09 21:36:18 -07:00
|
|
|
==========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-05-09 21:36:18 -07:00
|
|
|
try {
|
2015-08-23 10:42:06 -07:00
|
|
|
doSomething();
|
2014-05-09 21:36:18 -07:00
|
|
|
} catch (e) {
|
2015-08-23 10:42:06 -07:00
|
|
|
logError(e);
|
2014-05-09 21:36:18 -07:00
|
|
|
}
|
2014-06-11 11:28:49 -07:00
|
|
|
|
|
|
|
|
try {
|
2015-08-23 10:42:06 -07:00
|
|
|
doSomething();
|
2014-06-11 11:28:49 -07:00
|
|
|
} finally {
|
2015-08-23 10:42:06 -07:00
|
|
|
logError();
|
2014-06-11 11:28:49 -07:00
|
|
|
}
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-05-09 21:36:18 -07:00
|
|
|
---
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-06-11 11:28:49 -07:00
|
|
|
(program
|
2015-08-23 10:42:06 -07:00
|
|
|
(try_statement
|
2015-09-02 13:05:31 -07:00
|
|
|
(statement_block (expression_statement (function_call (identifier) (arguments))))
|
2015-08-23 10:42:06 -07:00
|
|
|
(catch (identifier)
|
2015-09-02 13:05:31 -07:00
|
|
|
(statement_block (expression_statement (function_call (identifier) (arguments (identifier)))))))
|
2015-08-23 10:42:06 -07:00
|
|
|
(try_statement
|
2015-09-02 13:05:31 -07:00
|
|
|
(statement_block (expression_statement (function_call (identifier) (arguments))))
|
2015-08-23 10:42:06 -07:00
|
|
|
(finally
|
2015-09-02 13:05:31 -07:00
|
|
|
(statement_block (expression_statement (function_call (identifier) (arguments)))))))
|
2014-05-09 21:36:18 -07:00
|
|
|
|
2014-04-05 15:55:20 -07:00
|
|
|
===========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
throw statements
|
2014-07-03 08:20:43 -07:00
|
|
|
===========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-07-03 08:20:43 -07:00
|
|
|
throw new Error("wtf");
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-07-03 08:20:43 -07:00
|
|
|
---
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2015-08-23 10:42:06 -07:00
|
|
|
(program
|
2015-09-02 13:05:31 -07:00
|
|
|
(throw_statement (constructor_call (identifier) (arguments (string)))))
|
2014-07-03 08:20:43 -07:00
|
|
|
|
|
|
|
|
===========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
indented code after blocks
|
2014-05-30 13:29:54 -07:00
|
|
|
===========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-05-30 13:29:54 -07:00
|
|
|
function x() {}
|
|
|
|
|
return z;
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-05-30 13:29:54 -07:00
|
|
|
---
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-05-30 13:29:54 -07:00
|
|
|
(program
|
2015-08-23 10:42:06 -07:00
|
|
|
(expression_statement
|
|
|
|
|
(function_expression (identifier) (statement_block)))
|
|
|
|
|
(return_statement (identifier)))
|
2014-06-11 14:01:38 -07:00
|
|
|
|
2014-05-30 13:29:54 -07:00
|
|
|
===========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
switch statements
|
2014-04-05 15:55:20 -07:00
|
|
|
===========================================
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-04-05 15:55:20 -07:00
|
|
|
switch(x) {
|
2015-08-23 10:42:06 -07:00
|
|
|
case "hello":
|
|
|
|
|
print("one");
|
|
|
|
|
break;
|
|
|
|
|
case z():
|
|
|
|
|
print("two");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
print("three");
|
2014-04-05 15:55:20 -07:00
|
|
|
}
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2014-04-05 15:55:20 -07:00
|
|
|
---
|
2014-10-19 12:36:43 -07:00
|
|
|
|
2015-08-23 10:42:06 -07:00
|
|
|
(program (switch_statement (identifier)
|
|
|
|
|
(case
|
|
|
|
|
(string)
|
2015-09-02 13:05:31 -07:00
|
|
|
(expression_statement (function_call (identifier) (arguments (string))))
|
2015-08-23 10:42:06 -07:00
|
|
|
(break_statement))
|
|
|
|
|
(case
|
2015-09-02 13:05:31 -07:00
|
|
|
(function_call (identifier) (arguments))
|
|
|
|
|
(expression_statement (function_call (identifier) (arguments (string))))
|
2015-08-23 10:42:06 -07:00
|
|
|
(break_statement))
|
|
|
|
|
(default
|
2015-09-02 13:05:31 -07:00
|
|
|
(expression_statement (function_call (identifier) (arguments (string)))))))
|