Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.java @ 19305:48bdad77afcd
Truffle-DSL: assumptions javadoc fixes.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 11 Feb 2015 21:51:26 +0100 |
parents | cfb85e1f4ca5 |
children |
rev | line source |
---|---|
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
1 /* |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
4 * |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
8 * |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
14 * |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
18 * |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
21 * questions. |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
22 */ |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
23 |
13763
cad8bed1a1ac
Fix Eclipse formatter issues
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
24 // The content of this file is automatically generated. DO NOT EDIT. |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
25 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
26 package com.oracle.truffle.sl.parser; |
12503
d7f8dd4fe876
minor reformatting based on 'mx eclipseformat'
Doug Simon <doug.simon@oracle.com>
parents:
11610
diff
changeset
|
27 |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
28 import java.util.*; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
29 |
16067
915ebb306fcc
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13836
diff
changeset
|
30 import com.oracle.truffle.api.source.*; |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.sl.*; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.sl.nodes.*; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
33 import com.oracle.truffle.sl.runtime.*; |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
34 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
35 // Checkstyle: stop |
7517
b6743d7eb8d4
disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents:
7503
diff
changeset
|
36 // @formatter:off |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
37 public class Parser { |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
38 public static final int _EOF = 0; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
39 public static final int _identifier = 1; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
40 public static final int _stringLiteral = 2; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
41 public static final int _numericLiteral = 3; |
18411
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
42 public static final int maxT = 31; |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
43 |
18962
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
44 static final boolean _T = true; |
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
45 static final boolean _x = false; |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
46 static final int minErrDist = 2; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
47 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
48 public Token t; // last recognized token |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
49 public Token la; // lookahead token |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
50 int errDist = minErrDist; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
51 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
52 public final Scanner scanner; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
53 public final Errors errors; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
54 private final SLNodeFactory factory; |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
55 |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
56 public Parser(SLContext context, Source source) { |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
57 this.scanner = new Scanner(source.getInputStream()); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
58 this.factory = new SLNodeFactory(context, source); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
59 errors = new Errors(); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
60 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
61 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
62 void SynErr(int n) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
63 if (errDist >= minErrDist) |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
64 errors.SynErr(la.line, la.col, n); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
65 errDist = 0; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
66 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
67 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
68 public void SemErr(String msg) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
69 if (errDist >= minErrDist) |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
70 errors.SemErr(t.line, t.col, msg); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
71 errDist = 0; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
72 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
73 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
74 void Get() { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
75 for (;;) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
76 t = la; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
77 la = scanner.Scan(); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
78 if (la.kind <= maxT) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
79 ++errDist; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
80 break; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
81 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
82 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
83 la = t; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
84 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
85 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
86 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
87 void Expect(int n) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
88 if (la.kind == n) |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
89 Get(); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
90 else { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
91 SynErr(n); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
92 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
93 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
94 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
95 boolean StartOf(int s) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
96 return set[s][la.kind]; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
97 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
98 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
99 void ExpectWeak(int n, int follow) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
100 if (la.kind == n) |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
101 Get(); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
102 else { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
103 SynErr(n); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
104 while (!StartOf(follow)) |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
105 Get(); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
106 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
107 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
108 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
109 boolean WeakSeparator(int n, int syFol, int repFol) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
110 int kind = la.kind; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
111 if (kind == n) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
112 Get(); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
113 return true; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
114 } else if (StartOf(repFol)) |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
115 return false; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
116 else { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
117 SynErr(n); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
118 while (!(set[syFol][kind] || set[repFol][kind] || set[0][kind])) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
119 Get(); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
120 kind = la.kind; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
121 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
122 return StartOf(syFol); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
123 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
124 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
125 |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
126 void SimpleLanguage() { |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
127 Function(); |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
128 while (la.kind == 4) { |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
129 Function(); |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
130 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
131 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
132 |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
133 void Function() { |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
134 Expect(4); |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
135 Expect(1); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
136 Token identifierToken = t; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
137 Expect(5); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
138 int bodyStartPos = t.charPos; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
139 factory.startFunction(identifierToken, bodyStartPos); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
140 if (la.kind == 1) { |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
141 Get(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
142 factory.addFormalParameter(t); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
143 while (la.kind == 6) { |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
144 Get(); |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
145 Expect(1); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
146 factory.addFormalParameter(t); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
147 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
148 } |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
149 Expect(7); |
13836
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
150 SLStatementNode body = Block(false); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
151 factory.finishFunction(body); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
152 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
153 |
13836
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
154 SLStatementNode Block(boolean inLoop) { |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
155 SLStatementNode result; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
156 factory.startBlock(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
157 List<SLStatementNode> body = new ArrayList<>(); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
158 Expect(8); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
159 int start = t.charPos; |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
160 while (StartOf(1)) { |
13836
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
161 SLStatementNode s = Statement(inLoop); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
162 body.add(s); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
163 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
164 Expect(9); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
165 int length = (t.charPos + t.val.length()) - start; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
166 result = factory.finishBlock(body, start, length); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
167 return result; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
168 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
169 |
13836
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
170 SLStatementNode Statement(boolean inLoop) { |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
171 SLStatementNode result; |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
172 result = null; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
173 switch (la.kind) { |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
174 case 13: { |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
175 result = WhileStatement(); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
176 break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
177 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
178 case 10: { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
179 Get(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
180 if (inLoop) { result = factory.createBreak(t); } else { SemErr("break used outside of loop"); } |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
181 Expect(11); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
182 break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
183 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
184 case 12: { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
185 Get(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
186 if (inLoop) { result = factory.createContinue(t); } else { SemErr("continue used outside of loop"); } |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
187 Expect(11); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
188 break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
189 } |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
190 case 14: { |
13836
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
191 result = IfStatement(inLoop); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
192 break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
193 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
194 case 16: { |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
195 result = ReturnStatement(); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
196 break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
197 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
198 case 1: case 2: case 3: case 5: { |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
199 result = Expression(); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
200 Expect(11); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
201 break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
202 } |
18411
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
203 default: SynErr(32); break; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
204 } |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
205 return result; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
206 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
207 |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
208 SLStatementNode WhileStatement() { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
209 SLStatementNode result; |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
210 Expect(13); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
211 Token whileToken = t; |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
212 Expect(5); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
213 SLExpressionNode condition = Expression(); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
214 Expect(7); |
13836
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
215 SLStatementNode body = Block(true); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
216 result = factory.createWhile(whileToken, condition, body); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
217 return result; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
218 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
219 |
13836
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
220 SLStatementNode IfStatement(boolean inLoop) { |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
221 SLStatementNode result; |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
222 Expect(14); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
223 Token ifToken = t; |
16685
888907296590
Backed out changeset: d654cd5ed05a
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16684
diff
changeset
|
224 Expect(5); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
225 SLExpressionNode condition = Expression(); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
226 Expect(7); |
13836
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
227 SLStatementNode thenPart = Block(inLoop); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
228 SLStatementNode elsePart = null; |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
229 if (la.kind == 15) { |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
230 Get(); |
13836
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
231 elsePart = Block(inLoop); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
232 } |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
233 result = factory.createIf(ifToken, condition, thenPart, elsePart); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
234 return result; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
235 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
236 |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
237 SLStatementNode ReturnStatement() { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
238 SLStatementNode result; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
239 Expect(16); |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
240 Token returnToken = t; |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
241 SLExpressionNode value = null; |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
242 if (StartOf(2)) { |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
243 value = Expression(); |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
244 } |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
245 result = factory.createReturn(returnToken, value); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
246 Expect(11); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
247 return result; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
248 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
249 |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
250 SLExpressionNode Expression() { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
251 SLExpressionNode result; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
252 result = LogicTerm(); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
253 while (la.kind == 17) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
254 Get(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
255 Token op = t; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
256 SLExpressionNode right = LogicTerm(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
257 result = factory.createBinary(op, result, right); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
258 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
259 return result; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
260 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
261 |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
262 SLExpressionNode LogicTerm() { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
263 SLExpressionNode result; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
264 result = LogicFactor(); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
265 while (la.kind == 18) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
266 Get(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
267 Token op = t; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
268 SLExpressionNode right = LogicFactor(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
269 result = factory.createBinary(op, result, right); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
270 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
271 return result; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
272 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
273 |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
274 SLExpressionNode LogicFactor() { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
275 SLExpressionNode result; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
276 result = Arithmetic(); |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
277 if (StartOf(3)) { |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
278 switch (la.kind) { |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
279 case 19: { |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
280 Get(); |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
281 break; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
282 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
283 case 20: { |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
284 Get(); |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
285 break; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
286 } |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
287 case 21: { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
288 Get(); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
289 break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
290 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
291 case 22: { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
292 Get(); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
293 break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
294 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
295 case 23: { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
296 Get(); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
297 break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
298 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
299 case 24: { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
300 Get(); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
301 break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
302 } |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
303 } |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
304 Token op = t; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
305 SLExpressionNode right = Arithmetic(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
306 result = factory.createBinary(op, result, right); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
307 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
308 return result; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
309 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
310 |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
311 SLExpressionNode Arithmetic() { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
312 SLExpressionNode result; |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
313 result = Term(); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
314 while (la.kind == 25 || la.kind == 26) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
315 if (la.kind == 25) { |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
316 Get(); |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
317 } else { |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
318 Get(); |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
319 } |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
320 Token op = t; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
321 SLExpressionNode right = Term(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
322 result = factory.createBinary(op, result, right); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
323 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
324 return result; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
325 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
326 |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
327 SLExpressionNode Term() { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
328 SLExpressionNode result; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
329 result = Factor(); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
330 while (la.kind == 27 || la.kind == 28) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
331 if (la.kind == 27) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
332 Get(); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
333 } else { |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
334 Get(); |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
335 } |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
336 Token op = t; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
337 SLExpressionNode right = Factor(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
338 result = factory.createBinary(op, result, right); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
339 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
340 return result; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
341 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
342 |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
343 SLExpressionNode Factor() { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
344 SLExpressionNode result; |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
345 result = null; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
346 if (la.kind == 1) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
347 Get(); |
18411
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
348 if (la.kind == 5 || la.kind == 29 || la.kind == 30) { |
18962
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
349 result = MemberExpression(null, null, t); |
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
350 } else if (StartOf(4)) { |
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
351 result = factory.createRead(t); |
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
352 } else SynErr(33); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
353 } else if (la.kind == 2) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
354 Get(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
355 result = factory.createStringLiteral(t); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
356 } else if (la.kind == 3) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
357 Get(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
358 result = factory.createNumericLiteral(t); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
359 } else if (la.kind == 5) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
360 Get(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
361 int start = t.charPos; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
362 result = Expression(); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
363 SLExpressionNode expr = result; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
364 Expect(7); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
365 int length = (t.charPos + t.val.length()) - start; |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
366 result = factory.createParenExpression(expr, start, length); |
18962
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
367 } else SynErr(34); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
368 return result; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
369 } |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
370 |
18962
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
371 SLExpressionNode MemberExpression(SLExpressionNode r, SLExpressionNode assignmentReceiver, Token assignmentName) { |
18411
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
372 SLExpressionNode result; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
373 result = null; |
18962
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
374 SLExpressionNode receiver = r; |
18411
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
375 Token nestedAssignmentName = null; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
376 if (la.kind == 5) { |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
377 Get(); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
378 List<SLExpressionNode> parameters = new ArrayList<>(); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
379 SLExpressionNode parameter; |
18962
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
380 if (receiver == null) { |
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
381 receiver = factory.createRead(assignmentName); |
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
382 } |
18411
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
383 if (StartOf(2)) { |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
384 parameter = Expression(); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
385 parameters.add(parameter); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
386 while (la.kind == 6) { |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
387 Get(); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
388 parameter = Expression(); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
389 parameters.add(parameter); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
390 } |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
391 } |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
392 Expect(7); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
393 Token finalToken = t; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
394 result = factory.createCall(receiver, parameters, finalToken); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
395 } else if (la.kind == 29) { |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
396 Get(); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
397 SLExpressionNode value = Expression(); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
398 if (assignmentName == null) { |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
399 SemErr("invalid assignment target"); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
400 } else if (assignmentReceiver == null) { |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
401 result = factory.createAssignment(assignmentName, value); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
402 } else { |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
403 result = factory.createWriteProperty(assignmentReceiver, assignmentName, value); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
404 } |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
405 } else if (la.kind == 30) { |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
406 Get(); |
18962
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
407 if (receiver == null) { |
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
408 receiver = factory.createRead(assignmentName); |
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
409 } |
18411
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
410 Expect(1); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
411 result = factory.createReadProperty(receiver, t); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
412 nestedAssignmentName = t; |
18962
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
413 } else SynErr(35); |
18411
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
414 if (la.kind == 5 || la.kind == 29 || la.kind == 30) { |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
415 result = MemberExpression(result, receiver, nestedAssignmentName); |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
416 } |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
417 return result; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
418 } |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
419 |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
420 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
421 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
422 public void Parse() { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
423 la = new Token(); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
424 la.val = ""; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
425 Get(); |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
426 SimpleLanguage(); |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
427 Expect(0); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
428 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
429 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
430 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
431 private static final boolean[][] set = { |
18962
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
432 {_T,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x}, |
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
433 {_x,_T,_T,_T, _x,_T,_x,_x, _x,_x,_T,_x, _T,_T,_T,_x, _T,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x}, |
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
434 {_x,_T,_T,_T, _x,_T,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x}, |
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
435 {_x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_T, _T,_T,_T,_T, _T,_x,_x,_x, _x,_x,_x,_x, _x}, |
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
436 {_x,_x,_x,_x, _x,_T,_T,_T, _x,_x,_x,_T, _x,_x,_x,_x, _x,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_x, _x} |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
437 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
438 }; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
439 |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
440 public static void parseSL(SLContext context, Source source) { |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16687
diff
changeset
|
441 Parser parser = new Parser(context, source); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
442 parser.Parse(); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
443 if (parser.errors.errors.size() > 0) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
444 StringBuilder msg = new StringBuilder("Error(s) parsing script:\n"); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
445 for (String error : parser.errors.errors) { |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
446 msg.append(error).append("\n"); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
447 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
448 throw new SLException(msg.toString()); |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
449 } |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
450 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
451 } // end Parser |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
452 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
453 class Errors { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
454 |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
455 protected final List<String> errors = new ArrayList<>(); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
456 public String errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
457 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
458 protected void printMsg(int line, int column, String msg) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
459 StringBuffer b = new StringBuffer(errMsgFormat); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
460 int pos = b.indexOf("{0}"); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
461 if (pos >= 0) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
462 b.delete(pos, pos + 3); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
463 b.insert(pos, line); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
464 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
465 pos = b.indexOf("{1}"); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
466 if (pos >= 0) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
467 b.delete(pos, pos + 3); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
468 b.insert(pos, column); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
469 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
470 pos = b.indexOf("{2}"); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
471 if (pos >= 0) |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
472 b.replace(pos, pos + 3, msg); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
473 errors.add(b.toString()); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
474 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
475 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
476 public void SynErr(int line, int col, int n) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
477 String s; |
12754
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
478 switch (n) { |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
479 case 0: s = "EOF expected"; break; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
480 case 1: s = "identifier expected"; break; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
481 case 2: s = "stringLiteral expected"; break; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
482 case 3: s = "numericLiteral expected"; break; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
483 case 4: s = "\"function\" expected"; break; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
484 case 5: s = "\"(\" expected"; break; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
485 case 6: s = "\",\" expected"; break; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
486 case 7: s = "\")\" expected"; break; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
487 case 8: s = "\"{\" expected"; break; |
7311354f5bf8
SL: fixed eclipse formatter problems.
Christian Humer <christian.humer@gmail.com>
parents:
12752
diff
changeset
|
488 case 9: s = "\"}\" expected"; break; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
489 case 10: s = "\"break\" expected"; break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
490 case 11: s = "\";\" expected"; break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
491 case 12: s = "\"continue\" expected"; break; |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
492 case 13: s = "\"while\" expected"; break; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
493 case 14: s = "\"if\" expected"; break; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
494 case 15: s = "\"else\" expected"; break; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
495 case 16: s = "\"return\" expected"; break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
496 case 17: s = "\"||\" expected"; break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
497 case 18: s = "\"&&\" expected"; break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
498 case 19: s = "\"<\" expected"; break; |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
499 case 20: s = "\"<=\" expected"; break; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13763
diff
changeset
|
500 case 21: s = "\">\" expected"; break; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
501 case 22: s = "\">=\" expected"; break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
502 case 23: s = "\"==\" expected"; break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
503 case 24: s = "\"!=\" expected"; break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
504 case 25: s = "\"+\" expected"; break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
505 case 26: s = "\"-\" expected"; break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
506 case 27: s = "\"*\" expected"; break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
507 case 28: s = "\"/\" expected"; break; |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
508 case 29: s = "\"=\" expected"; break; |
18411
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
509 case 30: s = "\".\" expected"; break; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
510 case 31: s = "??? expected"; break; |
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
16880
diff
changeset
|
511 case 32: s = "invalid Statement"; break; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
512 case 33: s = "invalid Factor"; break; |
18962
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
513 case 34: s = "invalid Factor"; break; |
cfb85e1f4ca5
Prevent polluting SLFunctionRegistry (via SLNodeFactory.createRead()) with LHS names of assignment
Paul Woegerer <paul.woegerer@oracle.com>
parents:
18411
diff
changeset
|
514 case 35: s = "invalid MemberExpression"; break; |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
515 default: |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
516 s = "error " + n; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
517 break; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
518 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
519 printMsg(line, col, s); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
520 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
521 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
522 public void SemErr(int line, int col, String s) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
523 printMsg(line, col, s); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
524 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
525 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
526 public void SemErr(String s) { |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
527 errors.add(s); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
528 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
529 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
530 public void Warning(int line, int col, String s) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
531 printMsg(line, col, s); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
532 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
533 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
534 public void Warning(String s) { |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
12754
diff
changeset
|
535 errors.add(s); |
7292
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
536 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
537 } // Errors |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
538 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
539 class FatalError extends RuntimeException { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
540 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
541 public static final long serialVersionUID = 1L; |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
542 |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
543 public FatalError(String s) { |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
544 super(s); |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
545 } |
213c1297a814
Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
546 } |