71 lines
2.1 KiB
Text
71 lines
2.1 KiB
Text
==========================================
|
|
parses multiple statements
|
|
==========================================
|
|
var x = {}
|
|
firstFunction(x)
|
|
secondFunction(x);
|
|
---
|
|
(program
|
|
(var_declaration (assignment (identifier) (object)))
|
|
(expression_statement (function_call (identifier) (identifier)))
|
|
(expression_statement (function_call (identifier) (identifier))))
|
|
|
|
==========================================
|
|
parses function expressions and calls
|
|
==========================================
|
|
var x = {
|
|
theMethod: function(argA, argB) {
|
|
var x = argA;
|
|
}
|
|
};
|
|
|
|
x.theMethod(5, 6);
|
|
---
|
|
(program
|
|
(var_declaration (assignment
|
|
(identifier)
|
|
(object (identifier) (function_expression
|
|
(formal_parameters (identifier) (identifier))
|
|
(statement_block (var_declaration (assignment (identifier) (identifier))))))))
|
|
(expression_statement (function_call
|
|
(property_access (identifier) (identifier))
|
|
(number) (number))))
|
|
|
|
==========================================
|
|
parses property access with dot notation
|
|
==========================================
|
|
object.property = "the-value";
|
|
print(object.property);
|
|
---
|
|
(program
|
|
(expression_statement (assignment
|
|
(property_access (identifier) (identifier))
|
|
(string)))
|
|
(expression_statement (function_call
|
|
(identifier)
|
|
(property_access (identifier) (identifier)))))
|
|
|
|
===========================================
|
|
parses dynamic property access
|
|
==========================================
|
|
object[propertName()] = propertyValue();
|
|
print(object[propertyName()]);
|
|
---
|
|
(program
|
|
(expression_statement (assignment
|
|
(property_access (identifier) (function_call (identifier)))
|
|
(function_call (identifier))))
|
|
(expression_statement (function_call
|
|
(identifier)
|
|
(property_access (identifier) (function_call (identifier))))))
|
|
|
|
==========================================
|
|
parses comments
|
|
==========================================
|
|
// this is another comment
|
|
stuff(); // this is a comment
|
|
---
|
|
(program
|
|
(comment)
|
|
(expression_statement (function_call (identifier)))
|
|
(comment))
|