11 /*----------------------------------------------------------------------------
12 ChucK Concurrent, On-the-fly Audio Programming Language
13 Compiler and Virtual Machine
15 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
16 http://chuck.cs.princeton.edu/
17 http://soundlab.cs.princeton.edu/
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 2 of the License, or
22 (at your option) any later version.
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License for more details.
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, write to the Free Software
31 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 -----------------------------------------------------------------------------*/
35 //-----------------------------------------------------------------------------
39 // author: Ge Wang (gewang.cs.princeton.edu) - generated by lex
40 // Perry R. Cook (prc@cs.princeton.edu)
42 // based on the ansi C grammar by Jeff Lee, maintained by Jutta Degener
45 //-----------------------------------------------------------------------------
49 #include "chuck_utils.h"
50 #include "chuck_absyn.h"
51 #include "chuck_errmsg.h"
53 #ifndef __PLATFORM_WIN32__
54 #include "chuck.tab.h"
56 #include "chuck_win32.h"
62 extern YYSTYPE yylval;
65 // define error handling
66 #define YY_FATAL_ERROR(msg) EM_error2( 0, msg )
68 #if defined(_cplusplus) || defined(__cplusplus)
74 c_str strip_lit( c_str str );
75 c_str alloc_str( c_str str );
76 long htol( c_str str );
80 #if defined(_cplusplus) || defined(__cplusplus)
99 c_str strip_lit( c_str str )
101 str[strlen(str)-1] = '\0';
106 c_str alloc_str( c_str str )
108 c_str s = (c_str)malloc( strlen(str) + 1 );
115 long htol( c_str str )
127 case '1': case '2': case '3': case '4': case '5':
128 case '6': case '7': case '8': case '9': case '0':
132 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
136 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
146 // block comment hack (thanks to unput/yytext_ptr inconsistency)
147 #define block_comment_hack loop: \
148 while ((c = input()) != '*' && c != 0 && c != EOF ) \
149 if( c == '\n' ) EM_newline(); \
150 if( c == EOF ) adjust(); \
151 else if( (c1 = input()) != '/' && c != 0 ) \
156 if( c != 0 ) adjust();
159 #define comment_hack \
160 while ((c = input()) != '\n' && c != '\r' && c != 0 && c != EOF ); \
163 if (c == '\n') EM_newline(); \
166 // .*\-\-> { adjust(); continue; }
172 "//" { char c; adjust(); comment_hack; continue; }
173 "<--" { char c; adjust(); comment_hack; continue; }
174 "/*" { char c, c1; adjust(); block_comment_hack; continue; }
175 " " { adjust(); continue; }
176 "\t" { adjust(); continue; }
177 "\r\n" { adjust(); EM_newline(); continue; }
178 "\n" { adjust(); EM_newline(); continue; }
180 "++" { adjust(); return PLUSPLUS; }
181 "--" { adjust(); return MINUSMINUS; }
182 "#(" { adjust(); return POUNDPAREN; }
183 "%(" { adjust(); return PERCENTPAREN; }
185 "," { adjust(); return COMMA; }
186 ":" { adjust(); return COLON; }
187 "." { adjust(); return DOT; }
188 "+" { adjust(); return PLUS; }
189 "-" { adjust(); return MINUS; }
190 "*" { adjust(); return TIMES; }
191 "/" { adjust(); return DIVIDE; }
192 "%" { adjust(); return PERCENT; }
193 "#" { adjust(); return POUND; }
194 "$" { adjust(); return DOLLAR; }
196 "::" { adjust(); return COLONCOLON; }
197 "==" { adjust(); return EQ; }
198 "!=" { adjust(); return NEQ; }
199 "<" { adjust(); return LT; }
200 ">" { adjust(); return GT; }
201 "<=" { adjust(); return LE; }
202 ">=" { adjust(); return GE; }
203 "&&" { adjust(); return AND; }
204 "||" { adjust(); return OR; }
205 "&" { adjust(); return S_AND; }
206 "|" { adjust(); return S_OR; }
207 "^" { adjust(); return S_XOR; }
208 ">>" { adjust(); return SHIFT_RIGHT; }
209 "<<" { adjust(); return SHIFT_LEFT; }
210 "=" { adjust(); return ASSIGN; }
211 "(" { adjust(); return LPAREN; }
212 ")" { adjust(); return RPAREN; }
213 "[" { adjust(); return LBRACK; }
214 "]" { adjust(); return RBRACK; }
215 "{" { adjust(); return LBRACE; }
216 "}" { adjust(); return RBRACE; }
217 ";" { adjust(); return SEMICOLON; }
218 "?" { adjust(); return QUESTION; }
219 "!" { adjust(); return EXCLAMATION; }
220 "~" { adjust(); return TILDA; }
221 for { adjust(); return FOR; }
222 while { adjust(); return WHILE; }
223 until { adjust(); return UNTIL; }
224 repeat { adjust(); return LOOP; }
225 continue { adjust(); return CONTINUE; }
226 break { adjust(); return BREAK; }
227 if { adjust(); return IF; }
228 else { adjust(); return ELSE; }
229 do { adjust(); return DO; }
230 "<<<" { adjust(); return L_HACK; }
231 ">>>" { adjust(); return R_HACK; }
233 return { adjust(); return RETURN; }
235 function { adjust(); return FUNCTION; }
236 fun { adjust(); return FUNCTION; }
237 new { adjust(); return NEW; }
238 class { adjust(); return CLASS; }
239 interface { adjust(); return INTERFACE; }
240 extends { adjust(); return EXTENDS; }
241 implements { adjust(); return IMPLEMENTS; }
242 public { adjust(); return PUBLIC; }
243 protected { adjust(); return PROTECTED; }
244 private { adjust(); return PRIVATE; }
245 static { adjust(); return STATIC; }
246 pure { adjust(); return ABSTRACT; }
247 const { adjust(); return CONST; }
248 spork { adjust(); return SPORK; }
249 typeof { adjust(); return TYPEOF; }
251 "=>" { adjust(); return CHUCK; }
252 "=<" { adjust(); return UNCHUCK; }
253 "!=>" { adjust(); return UNCHUCK; }
254 "=^" { adjust(); return UPCHUCK; }
255 "@=>" { adjust(); return AT_CHUCK; }
256 "+=>" { adjust(); return PLUS_CHUCK; }
257 "-=>" { adjust(); return MINUS_CHUCK; }
258 "*=>" { adjust(); return TIMES_CHUCK; }
259 "/=>" { adjust(); return DIVIDE_CHUCK; }
260 "&=>" { adjust(); return S_AND_CHUCK; }
261 "|=>" { adjust(); return S_OR_CHUCK; }
262 "^=>" { adjust(); return S_XOR_CHUCK; }
263 ">>=>" { adjust(); return SHIFT_RIGHT_CHUCK; }
264 "<<=>" { adjust(); return SHIFT_LEFT_CHUCK; }
265 "%=>" { adjust(); return PERCENT_CHUCK; }
266 "@" { adjust(); return AT_SYM; }
267 "@@" { adjust(); return ATAT_SYM; }
268 "->" { adjust(); return ARROW_RIGHT; }
269 "<-" { adjust(); return ARROW_LEFT; }
271 0[xX][0-9a-fA-F]+{IS}? { adjust(); yylval.ival=htol(yytext); return NUM; }
272 0[cC][0-7]+{IS}? { adjust(); yylval.ival=atoi(yytext); return NUM; }
273 [0-9]+{IS}? { adjust(); yylval.ival=atoi(yytext); return NUM; }
274 ([0-9]+"."[0-9]*)|([0-9]*"."[0-9]+) { adjust(); yylval.fval=atof(yytext); return FLOAT; }
275 [A-Za-z_][A-Za-z0-9_]* { adjust(); yylval.sval=alloc_str(yytext); return ID; }
276 \"(\\.|[^\\"])*\" { adjust(); yylval.sval=alloc_str(strip_lit(yytext)); return STRING_LIT; }
278 . { adjust(); EM_error( EM_tokPos, "illegal token" ); }
288 while ((c = yyinput()) != '\n' && c != '\r' && c != 0 && c != EOF );
292 if (c == '\n') EM_newline();
304 while ((c = yyinput()) != '*' && c != 0 && c != EOF )
305 if( c == '\n' ) EM_newline();
313 if( (c1 = yyinput()) != '/' && c != 0 )
319 if( c != 0 ) adjust();