107 lines
3.1 KiB
Text
107 lines
3.1 KiB
Text
==========================================
|
|
parses if statements
|
|
==========================================
|
|
if (isReady()) {
|
|
console.log(theData)
|
|
}
|
|
---
|
|
(program
|
|
(if_statement (function_call (identifier))
|
|
(statement_block (expression_statement (function_call (property_access (identifier) (identifier)) (identifier))))))
|
|
|
|
==========================================
|
|
parses if-else statements
|
|
==========================================
|
|
if (theCondition) {
|
|
firstFunction();
|
|
} else {
|
|
secondFunction();
|
|
}
|
|
---
|
|
(program (if_statement
|
|
(identifier)
|
|
(statement_block (expression_statement (function_call (identifier))))
|
|
(statement_block (expression_statement (function_call (identifier))))))
|
|
|
|
==================================================
|
|
parses if-else statements with multiple conditions
|
|
==================================================
|
|
if (firstValue) {
|
|
firstFunction();
|
|
} else if (secondValue)
|
|
secondFunction();
|
|
else {
|
|
thirdFunction();
|
|
}
|
|
---
|
|
(program
|
|
(if_statement (identifier)
|
|
(statement_block (expression_statement (function_call (identifier))))
|
|
(if_statement (identifier)
|
|
(expression_statement (function_call (identifier)))
|
|
(statement_block (expression_statement (function_call (identifier)))))))
|
|
|
|
==========================================
|
|
parses for loops
|
|
==========================================
|
|
for (var i = 1; someCondition(i); i = next()) {
|
|
doSomething();
|
|
}
|
|
---
|
|
(program (for_statement
|
|
(var_declaration (assignment (identifier) (number)))
|
|
(expression_statement (function_call (identifier) (identifier)))
|
|
(assignment (identifier) (function_call (identifier)))
|
|
(statement_block (expression_statement (function_call (identifier))))))
|
|
|
|
==========================================
|
|
parses while loops
|
|
==========================================
|
|
while (someCondition(i)) {
|
|
doSomething();
|
|
}
|
|
---
|
|
(program (while_statement
|
|
(function_call (identifier) (identifier))
|
|
(statement_block (expression_statement (function_call (identifier))))))
|
|
|
|
==========================================
|
|
parses try/catch statements
|
|
==========================================
|
|
try {
|
|
doSomething();
|
|
} catch (e) {
|
|
logError(e);
|
|
}
|
|
---
|
|
(program (try_statement
|
|
(statement_block (expression_statement (function_call (identifier))))
|
|
(identifier)
|
|
(statement_block (expression_statement (function_call (identifier) (identifier))))))
|
|
|
|
===========================================
|
|
parses switch statements
|
|
===========================================
|
|
switch(x) {
|
|
case "hello":
|
|
print("one");
|
|
break;
|
|
case z():
|
|
print("two");
|
|
break;
|
|
default:
|
|
print("three");
|
|
}
|
|
---
|
|
(program
|
|
(switch_statement (identifier)
|
|
(switch_case
|
|
(string)
|
|
(expression_statement (function_call (identifier) (string)))
|
|
(break_statement))
|
|
(switch_case
|
|
(function_call (identifier))
|
|
(expression_statement (function_call (identifier) (string)))
|
|
(break_statement))
|
|
(switch_case
|
|
(expression_statement (function_call (identifier) (string))))))
|