Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/expression/Expression.atg @ 19289:62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 03 Feb 2015 15:07:07 +0100 |
parents | 08aa0372dad4 |
children | 65d29fa81397 |
rev | line source |
---|---|
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 /* |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 * This is the grammar for DSL expressions that is used to automatically generate the Parser.java and Scanner.java |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 * files. You can download the parser generator Coco/R from http://ssw.jku.at/coco/. Then run |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 * "java -jar Coco.jar Expression.atg" |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 */ |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 COMPILER Expression |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 CHARACTERS |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
34 letter = 'A' .. 'Z' + 'a' .. 'z' + '_' + '$'. |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 nonZeroDigit = "123456789". |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
36 digit = '0' + nonZeroDigit . |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 TOKENS |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 identifier = letter {letter | digit}. |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 numericLiteral = "0" | nonZeroDigit { digit }. |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 PRAGMAS |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 PRODUCTIONS |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 Expression<out DSLExpression result> |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 = |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
50 LogicFactor<out result> |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
51 . |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
52 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
53 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
54 LogicFactor<out DSLExpression result> |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
55 = |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
56 ComparisonFactor<out result> |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
57 [ |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
58 ("||") (. Token op = t; .) |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
59 ComparisonFactor<out DSLExpression right> (. result = new Binary(op.val, result, right); .) |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
60 ] |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
61 . |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
62 |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
63 ComparisonFactor<out DSLExpression result> |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
64 = |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 NegateFactor<out result> |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
66 [ |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
67 ("<" | "<=" | ">" | ">=" | "==" | "!=" ) (. Token op = t; .) |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
68 NegateFactor<out DSLExpression right> (. result = new Binary(op.val, result, right); .) |
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
69 ] |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 . |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
72 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 NegateFactor<out DSLExpression result> |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 = (. boolean negated = false; .) |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 [ |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 "!" (. negated = true; .) |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 ] |
19289
62c43fcf5be2
Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19283
diff
changeset
|
78 Factor<out result> (. result = negated ? new Negate(result) : result;.) |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 . |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 Factor<out DSLExpression result> |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 = (. result = null; .) |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
84 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
85 ( |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
86 MemberExpression<out result, result> |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
87 | |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
88 numericLiteral (. result = new IntLiteral(t.val); .) |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
89 | |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
90 "(" |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
91 Expression<out result> |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
92 ")" |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
93 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
94 ) |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
95 . |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
96 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
97 MemberExpression<out DSLExpression result, DSLExpression receiver> |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
98 = (. result = null; .) |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
99 ( |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
100 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
101 identifier (. Variable variable = new Variable(receiver, t.val); .) |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
102 (. result = variable; .) |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
103 [ |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
104 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 "(" (. List<DSLExpression> parameters = new ArrayList<>(); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
106 DSLExpression parameter; .) |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
107 [ |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
108 Expression<out parameter> (. parameters.add(parameter); .) |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
109 { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
110 "," |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
111 Expression<out parameter> (. parameters.add(parameter); .) |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
112 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
113 ] |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
114 ")" (. result = new Call(variable.getReceiver(), variable.getName(), parameters); .) |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
115 ] |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
116 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
117 ) |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
118 [ |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
119 "." MemberExpression<out result, result> |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
120 ] |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
121 . |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
122 END Expression. |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
123 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
124 |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
125 |