annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Scanner.java @ 7517:b6743d7eb8d4

disabled auto-formatting of generated code
author Doug Simon <doug.simon@oracle.com>
date Tue, 22 Jan 2013 20:36:00 +0100
parents 213c1297a814
children 5e3d1a68664e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 /*
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
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
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
24 // The content of this file is automatically generated. DO NOT EDIT.
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;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
27
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
28 import java.io.InputStream;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
29 import java.io.IOException;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
30 import java.io.RandomAccessFile;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
31 import java.util.Map;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
32 import java.util.HashMap;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
33
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
34 // Checkstyle: stop
7517
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
35 // @formatter:off
7292
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
36 class Token {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
37
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
38 public int kind; // token kind
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
39 public int pos; // token position in bytes in the source text (starting at 0)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
40 public int charPos; // token position in characters in the source text (starting at 0)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
41 public int col; // token column (starting at 1)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
42 public int line; // token line (starting at 1)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
43 public String val; // token value
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
44 public Token next; // ML 2005-03-11 Peek tokens are kept in linked list
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
45 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
46
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 // Buffer
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
49 // -----------------------------------------------------------------------------------
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
50 class Buffer {
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 // This Buffer supports the following cases:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
53 // 1) seekable stream (file)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
54 // a) whole stream in buffer
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
55 // b) part of stream in buffer
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
56 // 2) non seekable stream (network, console)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
57
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
58 public static final int EOF = Character.MAX_VALUE + 1;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
59 private static final int MIN_BUFFER_LENGTH = 1024; // 1KB
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
60 private static final int MAX_BUFFER_LENGTH = MIN_BUFFER_LENGTH * 64; // 64KB
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
61 private byte[] buf; // input buffer
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
62 private int bufStart; // position of first byte in buffer relative to input stream
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
63 private int bufLen; // length of buffer
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
64 private int fileLen; // length of input stream (may change if stream is no file)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
65 private int bufPos; // current position in buffer
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
66 private RandomAccessFile file; // input stream (seekable)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
67 private InputStream stream; // growing input stream (e.g.: console, network)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
68
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
69 public Buffer(InputStream s) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
70 stream = s;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
71 fileLen = bufLen = bufStart = bufPos = 0;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
72 buf = new byte[MIN_BUFFER_LENGTH];
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
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
75 public Buffer(String fileName) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
76 try {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
77 file = new RandomAccessFile(fileName, "r");
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
78 fileLen = (int) file.length();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
79 bufLen = Math.min(fileLen, MAX_BUFFER_LENGTH);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
80 buf = new byte[bufLen];
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
81 bufStart = Integer.MAX_VALUE; // nothing in buffer so far
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
82 if (fileLen > 0)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
83 setPos(0); // setup buffer to position 0 (start)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
84 else
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
85 bufPos = 0; // index 0 is already after the file, thus setPos(0) is invalid
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
86 if (bufLen == fileLen)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
87 Close();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
88 } catch (IOException e) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
89 throw new FatalError("Could not open file " + fileName);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
90 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
91 }
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 // don't use b after this call anymore
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
94 // called in UTF8Buffer constructor
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
95 protected Buffer(Buffer b) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
96 buf = b.buf;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
97 bufStart = b.bufStart;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
98 bufLen = b.bufLen;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
99 fileLen = b.fileLen;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
100 bufPos = b.bufPos;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
101 file = b.file;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
102 stream = b.stream;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
103 // keep finalize from closing the file
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
104 b.file = null;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
105 }
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 @Override
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
108 protected void finalize() throws Throwable {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
109 super.finalize();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
110 Close();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
111 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
112
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
113 protected void Close() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
114 if (file != null) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
115 try {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
116 file.close();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
117 file = null;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
118 } catch (IOException e) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
119 throw new FatalError(e.getMessage());
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
120 }
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 }
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 public int Read() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
125 if (bufPos < bufLen) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
126 return buf[bufPos++] & 0xff; // mask out sign bits
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
127 } else if (getPos() < fileLen) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
128 setPos(getPos()); // shift buffer start to pos
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
129 return buf[bufPos++] & 0xff; // mask out sign bits
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
130 } else if (stream != null && ReadNextStreamChunk() > 0) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
131 return buf[bufPos++] & 0xff; // mask out sign bits
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
132 } else {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
133 return EOF;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
134 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
135 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
136
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
137 public int Peek() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
138 int curPos = getPos();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
139 int ch = Read();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
140 setPos(curPos);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
141 return ch;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
142 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
143
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
144 // beg .. begin, zero-based, inclusive, in byte
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
145 // end .. end, zero-based, exclusive, in byte
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
146 public String GetString(int beg, int end) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
147 int len = 0;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
148 char[] buffer = new char[end - beg];
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
149 int oldPos = getPos();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
150 setPos(beg);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
151 while (getPos() < end)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
152 buffer[len++] = (char) Read();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
153 setPos(oldPos);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
154 return new String(buffer, 0, len);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
155 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
156
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
157 public int getPos() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
158 return bufPos + bufStart;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
159 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
160
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
161 public void setPos(int value) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
162 if (value >= fileLen && stream != null) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
163 // Wanted position is after buffer and the stream
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
164 // is not seek-able e.g. network or console,
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
165 // thus we have to read the stream manually till
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
166 // the wanted position is in sight.
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
167 while (value >= fileLen && ReadNextStreamChunk() > 0) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
168 // nothing to do...
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
169 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
170 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
171
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
172 if (value < 0 || value > fileLen) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
173 throw new FatalError("buffer out of bounds access, position: " + value);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
174 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
175
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
176 if (value >= bufStart && value < bufStart + bufLen) { // already in buffer
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
177 bufPos = value - bufStart;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
178 } else if (file != null) { // must be swapped in
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
179 try {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
180 file.seek(value);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
181 bufLen = file.read(buf);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
182 bufStart = value;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
183 bufPos = 0;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
184 } catch (IOException e) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
185 throw new FatalError(e.getMessage());
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
186 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
187 } else {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
188 // set the position to the end of the file, Pos will return fileLen.
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
189 bufPos = fileLen - bufStart;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
190 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
191 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
192
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
193 // Read the next chunk of bytes from the stream, increases the buffer
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
194 // if needed and updates the fields fileLen and bufLen.
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
195 // Returns the number of bytes read.
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
196 private int ReadNextStreamChunk() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
197 int free = buf.length - bufLen;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
198 if (free == 0) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
199 // in the case of a growing input stream
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
200 // we can neither seek in the stream, nor can we
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
201 // foresee the maximum length, thus we must adapt
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
202 // the buffer size on demand.
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
203 byte[] newBuf = new byte[bufLen * 2];
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
204 System.arraycopy(buf, 0, newBuf, 0, bufLen);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
205 buf = newBuf;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
206 free = bufLen;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
207 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
208
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
209 int read;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
210 try {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
211 read = stream.read(buf, bufLen, free);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
212 } catch (IOException ioex) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
213 throw new FatalError(ioex.getMessage());
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
214 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
215
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
216 if (read > 0) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
217 fileLen = bufLen = (bufLen + read);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
218 return read;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
219 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
220 // end of stream reached
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
221 return 0;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
222 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
223 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
224
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
225 // -----------------------------------------------------------------------------------
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
226 // UTF8Buffer
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
227 // -----------------------------------------------------------------------------------
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
228 class UTF8Buffer extends Buffer {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
229
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
230 UTF8Buffer(Buffer b) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
231 super(b);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
232 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
233
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
234 @Override
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
235 public int Read() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
236 int ch;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
237 do {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
238 ch = super.Read();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
239 // until we find a utf8 start (0xxxxxxx or 11xxxxxx)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
240 } while ((ch >= 128) && ((ch & 0xC0) != 0xC0) && (ch != EOF));
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
241 if (ch < 128 || ch == EOF) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
242 // nothing to do, first 127 chars are the same in ascii and utf8
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
243 // 0xxxxxxx or end of file character
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
244 } else if ((ch & 0xF0) == 0xF0) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
245 // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
246 int c1 = ch & 0x07;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
247 ch = super.Read();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
248 int c2 = ch & 0x3F;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
249 ch = super.Read();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
250 int c3 = ch & 0x3F;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
251 ch = super.Read();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
252 int c4 = ch & 0x3F;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
253 ch = (((((c1 << 6) | c2) << 6) | c3) << 6) | c4;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
254 } else if ((ch & 0xE0) == 0xE0) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
255 // 1110xxxx 10xxxxxx 10xxxxxx
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
256 int c1 = ch & 0x0F;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
257 ch = super.Read();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
258 int c2 = ch & 0x3F;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
259 ch = super.Read();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
260 int c3 = ch & 0x3F;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
261 ch = (((c1 << 6) | c2) << 6) | c3;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
262 } else if ((ch & 0xC0) == 0xC0) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
263 // 110xxxxx 10xxxxxx
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
264 int c1 = ch & 0x1F;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
265 ch = super.Read();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
266 int c2 = ch & 0x3F;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
267 ch = (c1 << 6) | c2;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
268 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
269 return ch;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
270 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
271 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
272
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
273 // -----------------------------------------------------------------------------------
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
274 // StartStates -- maps characters to start states of tokens
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
275 // -----------------------------------------------------------------------------------
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
276 class StartStates {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
277
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
278 private static class Elem {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
279
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
280 public int key, val;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
281 public Elem next;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
282
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
283 public Elem(int key, int val) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
284 this.key = key;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
285 this.val = val;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
286 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
287 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
288
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
289 private Elem[] tab = new Elem[128];
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
290
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
291 public void set(int key, int val) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
292 Elem e = new Elem(key, val);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
293 int k = key % 128;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
294 e.next = tab[k];
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
295 tab[k] = e;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
296 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
297
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
298 public int state(int key) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
299 Elem e = tab[key % 128];
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
300 while (e != null && e.key != key)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
301 e = e.next;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
302 return e == null ? 0 : e.val;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
303 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
304 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
305
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
306 // -----------------------------------------------------------------------------------
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
307 // Scanner
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
308 // -----------------------------------------------------------------------------------
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
309 @SuppressWarnings({"rawtypes", "unchecked"})
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
310 public class Scanner {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
311
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
312 static final char EOL = '\n';
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
313 static final int eofSym = 0;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
314 static final int maxT = 25;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
315 static final int noSym = 25;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
316
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
317
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
318 public Buffer buffer; // scanner buffer
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
319
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
320 Token t; // current token
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
321 int ch; // current input character
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
322 int pos; // byte position of current character
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
323 int charPos; // position by unicode characters starting with 0
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
324 int col; // column number of current character
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
325 int line; // line number of current character
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
326 int oldEols; // EOLs that appeared in a comment;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
327 static final StartStates start; // maps initial token character to start state
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
328 static final Map literals; // maps literal strings to literal kinds
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
329
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
330 Token tokens; // list of tokens already peeked (first token is a dummy)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
331 Token pt; // current peek token
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
332
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
333 char[] tval = new char[16]; // token text used in NextToken(), dynamically enlarged
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
334 int tlen; // length of current token
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
335
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
336 static {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
337 start = new StartStates();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
338 literals = new HashMap();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
339 for (int i = 65; i <= 90; ++i) start.set(i, 1);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
340 for (int i = 97; i <= 122; ++i) start.set(i, 1);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
341 for (int i = 49; i <= 57; ++i) start.set(i, 4);
7517
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
342 start.set(34, 2);
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
343 start.set(48, 5);
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
344 start.set(123, 6);
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
345 start.set(125, 7);
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
346 start.set(40, 8);
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
347 start.set(41, 9);
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
348 start.set(61, 20);
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
349 start.set(59, 10);
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
350 start.set(60, 21);
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
351 start.set(62, 22);
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
352 start.set(33, 14);
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
353 start.set(43, 16);
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
354 start.set(45, 17);
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
355 start.set(42, 18);
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
356 start.set(47, 19);
7292
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
357 start.set(Buffer.EOF, -1);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
358 literals.put("function", new Integer(4));
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
359 literals.put("while", new Integer(7));
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
360 literals.put("print", new Integer(12));
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
361 literals.put("return", new Integer(13));
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
362 literals.put("time", new Integer(24));
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
363
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
364 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
365
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
366 public Scanner(String fileName) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
367 buffer = new Buffer(fileName);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
368 Init();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
369 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
370
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
371 public Scanner(InputStream s) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
372 buffer = new Buffer(s);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
373 Init();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
374 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
375
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
376 void Init() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
377 pos = -1;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
378 line = 1;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
379 col = 0;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
380 charPos = -1;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
381 oldEols = 0;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
382 NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
383 if (ch == 0xEF) { // check optional byte order mark for UTF-8
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
384 NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
385 int ch1 = ch;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
386 NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
387 int ch2 = ch;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
388 if (ch1 != 0xBB || ch2 != 0xBF) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
389 throw new FatalError("Illegal byte order mark at start of file");
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
390 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
391 buffer = new UTF8Buffer(buffer);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
392 col = 0;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
393 charPos = -1;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
394 NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
395 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
396 pt = tokens = new Token(); // first token is a dummy
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
397 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
398
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
399 void NextCh() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
400 if (oldEols > 0) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
401 ch = EOL;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
402 oldEols--;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
403 } else {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
404 pos = buffer.getPos();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
405 // buffer reads unicode chars, if UTF8 has been detected
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
406 ch = buffer.Read();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
407 col++;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
408 charPos++;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
409 // replace isolated '\r' by '\n' in order to make
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
410 // eol handling uniform across Windows, Unix and Mac
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
411 if (ch == '\r' && buffer.Peek() != '\n')
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
412 ch = EOL;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
413 if (ch == EOL) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
414 line++;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
415 col = 0;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
416 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
417 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
418
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
419 }
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 void AddCh() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
422 if (tlen >= tval.length) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
423 char[] newBuf = new char[2 * tval.length];
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
424 System.arraycopy(tval, 0, newBuf, 0, tval.length);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
425 tval = newBuf;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
426 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
427 if (ch != Buffer.EOF) {
7517
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
428 tval[tlen++] = (char)ch;
7292
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 NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
431 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
432 }
7517
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
433
7292
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
434
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
435 boolean Comment0() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
436 int level = 1, pos0 = pos, line0 = line, col0 = col, charPos0 = charPos;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
437 NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
438 if (ch == '/') {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
439 NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
440 for(;;) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
441 if (ch == 10) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
442 level--;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
443 if (level == 0) { oldEols = line - line0; NextCh(); return true; }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
444 NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
445 } else if (ch == Buffer.EOF) return false;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
446 else NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
447 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
448 } else {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
449 buffer.setPos(pos0); NextCh(); line = line0; col = col0; charPos = charPos0;
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 return false;
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
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
454 boolean Comment1() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
455 int level = 1, pos0 = pos, line0 = line, col0 = col, charPos0 = charPos;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
456 NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
457 if (ch == '*') {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
458 NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
459 for(;;) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
460 if (ch == '*') {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
461 NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
462 if (ch == '/') {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
463 level--;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
464 if (level == 0) { oldEols = line - line0; NextCh(); return true; }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
465 NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
466 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
467 } else if (ch == Buffer.EOF) return false;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
468 else NextCh();
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 } else {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
471 buffer.setPos(pos0); NextCh(); line = line0; col = col0; charPos = charPos0;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
472 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
473 return false;
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
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
477 void CheckLiteral() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
478 String val = t.val;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
479
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
480 Object kind = literals.get(val);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
481 if (kind != null) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
482 t.kind = ((Integer) kind).intValue();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
483 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
484 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
485
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
486 Token NextToken() {
7517
b6743d7eb8d4 disabled auto-formatting of generated code
Doug Simon <doug.simon@oracle.com>
parents: 7292
diff changeset
487 while (ch == ' ' ||
7292
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
488 ch >= 9 && ch <= 10 || ch == 13
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
489 ) NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
490 if (ch == '/' && Comment0() ||ch == '/' && Comment1()) return NextToken();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
491 int recKind = noSym;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
492 int recEnd = pos;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
493 t = new Token();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
494 t.pos = pos;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
495 t.col = col;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
496 t.line = line;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
497 t.charPos = charPos;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
498 int state = start.state(ch);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
499 tlen = 0;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
500 AddCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
501
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
502 loop: for (;;) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
503 switch (state) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
504 case -1: {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
505 t.kind = eofSym;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
506 break loop;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
507 } // NextCh already done
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
508 case 0: {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
509 if (recKind != noSym) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
510 tlen = recEnd - t.pos;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
511 SetScannerBehindT();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
512 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
513 t.kind = recKind;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
514 break loop;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
515 } // NextCh already done
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
516 case 1:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
517 recEnd = pos; recKind = 1;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
518 if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); state = 1; break;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
519 else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
520 case 2:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
521 if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); state = 2; break;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
522 else if (ch == '"') {AddCh(); state = 3; break;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
523 else {state = 0; break;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
524 case 3:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
525 {t.kind = 2; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
526 case 4:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
527 recEnd = pos; recKind = 3;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
528 if (ch >= '0' && ch <= '9') {AddCh(); state = 4; break;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
529 else {t.kind = 3; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
530 case 5:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
531 {t.kind = 3; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
532 case 6:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
533 {t.kind = 5; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
534 case 7:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
535 {t.kind = 6; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
536 case 8:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
537 {t.kind = 8; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
538 case 9:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
539 {t.kind = 9; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
540 case 10:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
541 {t.kind = 11; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
542 case 11:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
543 {t.kind = 16; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
544 case 12:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
545 {t.kind = 17; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
546 case 13:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
547 {t.kind = 18; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
548 case 14:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
549 if (ch == '=') {AddCh(); state = 15; break;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
550 else {state = 0; break;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
551 case 15:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
552 {t.kind = 19; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
553 case 16:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
554 {t.kind = 20; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
555 case 17:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
556 {t.kind = 21; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
557 case 18:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
558 {t.kind = 22; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
559 case 19:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
560 {t.kind = 23; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
561 case 20:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
562 recEnd = pos; recKind = 10;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
563 if (ch == '=') {AddCh(); state = 13; break;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
564 else {t.kind = 10; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
565 case 21:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
566 recEnd = pos; recKind = 14;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
567 if (ch == '=') {AddCh(); state = 11; break;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
568 else {t.kind = 14; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
569 case 22:
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
570 recEnd = pos; recKind = 15;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
571 if (ch == '=') {AddCh(); state = 12; break;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
572 else {t.kind = 15; break loop;}
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
573
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
574 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
575 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
576 t.val = new String(tval, 0, tlen);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
577 return t;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
578 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
579
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
580 private void SetScannerBehindT() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
581 buffer.setPos(t.pos);
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
582 NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
583 line = t.line;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
584 col = t.col;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
585 charPos = t.charPos;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
586 for (int i = 0; i < tlen; i++)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
587 NextCh();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
588 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
589
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
590 // get the next token (possibly a token already seen during peeking)
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
591 public Token Scan() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
592 if (tokens.next == null) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
593 return NextToken();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
594 } else {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
595 pt = tokens = tokens.next;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
596 return tokens;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
597 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
598 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
599
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
600 // get the next token, ignore pragmas
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
601 public Token Peek() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
602 do {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
603 if (pt.next == null) {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
604 pt.next = NextToken();
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
605 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
606 pt = pt.next;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
607 } while (pt.kind > maxT); // skip pragmas
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
608
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
609 return pt;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
610 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
611
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
612 // make sure that peeking starts at current scan position
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
613 public void ResetPeek() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
614 pt = tokens;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
615 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
616
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
617 // The following methods are used for the CLNG Editor and will be called with java.Reflection.
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
618 // If the editor won't be used these 3 functions are obsolete,
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
619 // otherwise changes within the signature of the methods will result in Syntax Highlighting not working properly
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
620 // anymore.
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
621
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
622 // get the offset of the next Token
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
623 public int getPeekTokenOffset() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
624 return pt.pos;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
625 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
626
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
627 // get the String value of the Token
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
628 public String getPeekTokenVal() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
629 return pt.val;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
630 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
631
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
632 // get the Kind value of the Token
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
633 public int getPeekTokenKind() {
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
634 return pt.kind;
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
635 }
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
636
213c1297a814 Simple Language: A simple dynamic programming language to demonstrate Truffle features
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
637 } // end Scanner