Mercurial > hg > graal-jvmci-8
diff graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SimpleLanguage.atg @ 18411:dc2e000bed40
SL: add basic support for creating objects and accessing properties
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Tue, 18 Nov 2014 23:02:58 +0100 |
parents | f444ef4684ec |
children | cfb85e1f4ca5 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SimpleLanguage.atg Tue Oct 21 15:11:32 2014 +0200 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SimpleLanguage.atg Tue Nov 18 23:02:58 2014 +0100 @@ -202,25 +202,10 @@ Factor<out SLExpressionNode result> = (. result = null; .) ( - identifier (. Token nameToken = t; .) - ( - "(" (. List<SLExpressionNode> parameters = new ArrayList<>(); - SLExpressionNode parameter; .) - [ - Expression<out parameter> (. parameters.add(parameter); .) - { - "," - Expression<out parameter> (. parameters.add(parameter); .) - } - ] - ")" (. Token finalToken = t; .) - (. result = factory.createCall(nameToken, parameters, finalToken); .) - | - "=" - Expression<out SLExpressionNode value> (. result = factory.createAssignment(nameToken, value); .) - | - (. result = factory.createRead(nameToken); .) - ) + identifier (. result = factory.createRead(t); .) + [ + MemberExpression<out result, result, null, t> + ] | stringLiteral (. result = factory.createStringLiteral(t); .) | @@ -234,4 +219,40 @@ . +MemberExpression<out SLExpressionNode result, SLExpressionNode receiver, SLExpressionNode assignmentReceiver, Token assignmentName> += (. result = null; + Token nestedAssignmentName = null; .) +( + "(" (. List<SLExpressionNode> parameters = new ArrayList<>(); + SLExpressionNode parameter; .) + [ + Expression<out parameter> (. parameters.add(parameter); .) + { + "," + Expression<out parameter> (. parameters.add(parameter); .) + } + ] + ")" (. Token finalToken = t; .) + (. result = factory.createCall(receiver, parameters, finalToken); .) +| + "=" + Expression<out SLExpressionNode value> (. if (assignmentName == null) { + SemErr("invalid assignment target"); + } else if (assignmentReceiver == null) { + result = factory.createAssignment(assignmentName, value); + } else { + result = factory.createWriteProperty(assignmentReceiver, assignmentName, value); + } .) +| + "." + identifier + (. result = factory.createReadProperty(receiver, t); .) + (. nestedAssignmentName = t; .) +) +[ + MemberExpression<out result, result, receiver, nestedAssignmentName> +] +. + + END SimpleLanguage.