177 lines
3.9 KiB
Text
177 lines
3.9 KiB
Text
==========================================
|
|
function calls
|
|
==========================================
|
|
|
|
x.theMethod(5, 6);
|
|
|
|
---
|
|
|
|
(program (expression_statement
|
|
(function_call
|
|
(member_access (identifier) (identifier))
|
|
(arguments (number) (number)))))
|
|
|
|
==========================================
|
|
constructor calls
|
|
==========================================
|
|
|
|
var x = new Node(5, new Node(3, null));
|
|
new Thing;
|
|
|
|
---
|
|
|
|
(program
|
|
(var_declaration (var_assignment
|
|
(identifier)
|
|
(constructor_call (identifier) (arguments
|
|
(number)
|
|
(constructor_call (identifier) (arguments
|
|
(number)
|
|
(null)))))))
|
|
(expression_statement (constructor_call (identifier))))
|
|
|
|
==========================================
|
|
property access with dot notation
|
|
==========================================
|
|
|
|
object.property = "the-value";
|
|
object.property;
|
|
|
|
---
|
|
|
|
(program
|
|
(expression_statement
|
|
(assignment (member_access (identifier) (identifier)) (string)))
|
|
(expression_statement
|
|
(member_access (identifier) (identifier))))
|
|
|
|
==========================================
|
|
property access across lines
|
|
==========================================
|
|
|
|
object
|
|
.someProperty
|
|
.otherProperty
|
|
|
|
---
|
|
|
|
(program (expression_statement
|
|
(member_access
|
|
(member_access (identifier) (identifier))
|
|
(identifier))))
|
|
|
|
===========================================
|
|
dynamic property access
|
|
==========================================
|
|
|
|
object[propertyName()] = propertyValue();
|
|
object[propertyName()];
|
|
|
|
---
|
|
|
|
(program
|
|
(expression_statement
|
|
(assignment
|
|
(subscript_access (identifier) (function_call (identifier) (arguments)))
|
|
(function_call (identifier) (arguments))))
|
|
(expression_statement
|
|
(subscript_access (identifier) (function_call (identifier) (arguments)))))
|
|
|
|
==========================================
|
|
ternary expressions
|
|
==========================================
|
|
|
|
isDone() ? stuff : otherStuff;
|
|
|
|
---
|
|
|
|
(program (expression_statement
|
|
(ternary (function_call (identifier) (arguments)) (identifier) (identifier))))
|
|
|
|
==========================================
|
|
mathematical operators
|
|
==========================================
|
|
|
|
a++ + b * c - d / e--
|
|
|
|
---
|
|
|
|
(program (expression_statement
|
|
(math_op
|
|
(math_op
|
|
(math_op (identifier))
|
|
(math_op (identifier) (identifier)))
|
|
(math_op
|
|
(identifier)
|
|
(math_op (identifier))))))
|
|
|
|
==========================================
|
|
boolean operators
|
|
=========================================
|
|
|
|
!a || !(b && c)
|
|
|
|
---
|
|
|
|
(program (expression_statement
|
|
(bool_op
|
|
(bool_op (identifier))
|
|
(bool_op
|
|
(bool_op (identifier) (identifier))))))
|
|
|
|
===========================================
|
|
type operators
|
|
===========================================
|
|
|
|
(x instanceof Array) || (typeof x === "string")
|
|
|
|
---
|
|
|
|
(program (expression_statement
|
|
(bool_op
|
|
(type_op (identifier) (identifier))
|
|
(rel_op (type_op (identifier)) (string)))))
|
|
|
|
============================================
|
|
the 'in' operator
|
|
===========================================
|
|
|
|
print(x in y)
|
|
|
|
---
|
|
|
|
(program (expression_statement
|
|
(function_call
|
|
(identifier)
|
|
(arguments (type_op (identifier) (identifier))))))
|
|
|
|
============================================
|
|
assignment operators
|
|
============================================
|
|
|
|
x += 1;
|
|
x -= 1;
|
|
x *= 2;
|
|
x /= 2;
|
|
|
|
---
|
|
|
|
(program
|
|
(expression_statement (math_assignment (identifier) (number)))
|
|
(expression_statement (math_assignment (identifier) (number)))
|
|
(expression_statement (math_assignment (identifier) (number)))
|
|
(expression_statement (math_assignment (identifier) (number))))
|
|
|
|
============================================
|
|
property access and operators
|
|
============================================
|
|
|
|
print(x.y.z && a.b.c)
|
|
|
|
---
|
|
|
|
(program (expression_statement
|
|
(function_call (identifier)
|
|
(arguments (bool_op
|
|
(member_access (member_access (identifier) (identifier)) (identifier))
|
|
(member_access (member_access (identifier) (identifier)) (identifier)))))))
|