*** empty log message ***
[chuck-blob.git] / v2 / chuck_parse.h
blob1a2b644f4965f2f88e30b2255a5c949944da280a
1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 U.S.A.
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: chuck_parse.h
27 // desc: chuck parser interface (using flex and bison)
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
31 // date: Autumn 2002 - original in chuck_main.cpp
32 // Autumn 2005 - this file
33 //-----------------------------------------------------------------------------
34 #ifndef __CHUCK_PARSE_H__
35 #define __CHUCK_PARSE_H__
37 #include "chuck_def.h"
38 #include "chuck_absyn.h"
40 #include <stdio.h>
42 #include <string>
44 // 'C' specification necessary for windows to link properly
45 #ifdef __PLATFORM_WIN32__
46 extern "C" a_Program g_program;
47 #else
48 extern a_Program g_program;
49 #endif
51 // link with the parser
52 extern "C" int yyparse( void );
53 extern "C" void yyrestart( FILE * );
55 struct yy_buffer_state;
56 typedef yy_buffer_state * YY_BUFFER_STATE;
57 extern "C" YY_BUFFER_STATE yy_scan_string( const char * );
58 extern "C" void yy_delete_buffer( YY_BUFFER_STATE );
60 // open file with .ck append as appropriate
61 FILE * open_cat_ck( c_str filename );
62 // parse file
63 t_CKBOOL chuck_parse( c_constr fname, FILE * fd = NULL, c_constr code = NULL );
64 // reset the parser
65 void reset_parse( );
68 // syntax highlighting tools
69 #include <vector>
72 // syntax types (for highlighting)
73 enum SyntaxType
75 COMMA = 0,
76 SEMICOLON,
77 DBLCOLON,
78 PAREN,
79 DOT,
80 CHUCK_OP,
81 OPERATOR,
82 KEYWORD,
83 DEBUG_PRINT,
84 SPORK,
85 INTEGER,
86 FLOATING,
87 STRING,
88 COMMENT,
89 OTHER,
91 NUM_SYNTAX_TYPES
95 // token info
96 struct SyntaxToken
98 // the token
99 std::string token;
100 // type
101 t_CKUINT type;
103 // from the beginning of line
104 std::string::size_type begin;
105 // from the beginning of line
106 std::string::size_type end;
108 // constructor
109 SyntaxToken() : type(0) { }
110 // copy constructor
111 SyntaxToken( const SyntaxToken & rhs )
113 token = rhs.token;
114 type = rhs.type;
115 begin = rhs.begin;
116 end = rhs.end;
121 // token list
122 struct SyntaxTokenList
124 std::vector<SyntaxToken> list;
125 std::vector<SyntaxToken>::size_type howmany;
126 // copy constructor
127 SyntaxTokenList( const SyntaxTokenList & rhs )
129 // copy
130 howmany = rhs.howmany;
131 // allocate
132 list.resize( howmany );
133 // copy
134 for( std::vector<SyntaxToken>::size_type i = 0; i < howmany; i++ )
135 list[i] = rhs.list[i];
137 SyntaxTokenList() {
138 howmany = 0;
143 // token query
144 struct SyntaxQuery
146 public:
147 t_CKBOOL parseLine( const std::string & line,
148 SyntaxTokenList & tokens );
154 #endif