Debian Codegraph @

src/core/chuck_parse.h

raw symbols SCIP
1 /*----------------------------------------------------------------------------
2 ChucK Strongly-timed Audio Programming Language
3 Compiler, Virtual Machine, and Synthesis Engine
4
5 Copyright (c) 2003 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.stanford.edu/
7 http://chuck.cs.princeton.edu/
8
9 This program is free software; you can redistribute it and/or modify
10 it under the dual-license terms of EITHER the MIT License OR the GNU
11 General Public License (the latter as published by the Free Software
12 Foundation; either version 2 of the License or, at your option, any
13 later version).
14
15 This program is distributed in the hope that it will be useful and/or
16 interesting, but WITHOUT ANY WARRANTY; without even the implied warranty
17 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 MIT Licence and/or the GNU General Public License for details.
19
20 You should have received a copy of the MIT License and the GNU General
21 Public License (GPL) along with this program; a copy of the GPL can also
22 be obtained by writing to the Free Software Foundation, Inc., 59 Temple
23 Place, Suite 330, Boston, MA 02111-1307 U.S.A.
24 -----------------------------------------------------------------------------*/
25
26 //-----------------------------------------------------------------------------
27 // file: chuck_parse.h
28 // desc: chuck parser interface (using flex and bison)
29 //
30 // author: Ge Wang ([email protected] | [email protected])
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__
36
37 #include "chuck_def.h"
38 #include "chuck_absyn.h"
39
40 #include <stdio.h>
41 #include <string>
42
43
44 // 'C' specification necessary for windows to link properly
45 #ifdef __PLATFORM_WINDOWS__
46 extern "C" a_Program g_program;
47 #else
48 extern a_Program g_program;
49 #endif
50
51 // link with the parser
52 extern "C" int yyparse( void );
53 extern "C" void yyrestart( FILE * );
54 extern "C" void yyinitial( void );
55 extern "C" void yyflush( void );
56
57 struct yy_buffer_state;
58 typedef yy_buffer_state * YY_BUFFER_STATE;
59 extern "C" YY_BUFFER_STATE yy_scan_string( const char * );
60 extern "C" void yy_delete_buffer( YY_BUFFER_STATE );
61
62 // forward reference
63 struct Chuck_CompileTarget;
64 // parse ck file into abstract syntax tree
65 t_CKBOOL chuck_parse( Chuck_CompileTarget * target );
66 // reset the parser
67 void reset_parse();
68
69 // convert abstract syntax stmt to string
70 std::string absyn2str( a_Stmt stmt );
71 // convert abstract syntax expression to string
72 std::string absyn2str( a_Exp exp, t_CKBOOL appendSemicolon = TRUE );
73
74 // syntax highlighting tools
75 #include <vector>
76
77
78 // syntax types (for highlighting)
79 enum SyntaxType
80 {
81 COMMA = 0,
82 SEMICOLON,
83 DBLCOLON,
84 PAREN,
85 DOT,
86 CHUCK_OP,
87 OPERATOR,
88 KEYWORD,
89 DEBUG_PRINT,
90 SPORK,
91 INTEGER,
92 FLOATING,
93 STRING,
94 COMMENT,
95 OTHER,
96
97 NUM_SYNTAX_TYPES
98 };
99
100
101 // token info
102 struct SyntaxToken
103 {
104 // the token
105 std::string token;
106 // type
107 t_CKUINT type;
108
109 // from the beginning of line
110 std::string::size_type begin;
111 // from the beginning of line
112 std::string::size_type end;
113
114 // constructor
115 SyntaxToken() : type(0), begin(0), end(0) { }
116 // copy constructor
117 SyntaxToken( const SyntaxToken & rhs )
118 {
119 token = rhs.token;
120 type = rhs.type;
121 begin = rhs.begin;
122 end = rhs.end;
123 }
124 };
125
126
127 // token list
128 struct SyntaxTokenList
129 {
130 std::vector<SyntaxToken> list;
131 std::vector<SyntaxToken>::size_type howmany;
132 // copy constructor
133 SyntaxTokenList( const SyntaxTokenList & rhs )
134 {
135 // copy
136 howmany = rhs.howmany;
137 // allocate
138 list.resize( howmany );
139 // copy
140 for( std::vector<SyntaxToken>::size_type i = 0; i < howmany; i++ )
141 list[i] = rhs.list[i];
142 }
143 SyntaxTokenList() {
144 howmany = 0;
145 }
146 };
147
148
149 // token query
150 struct SyntaxQuery
151 {
152 public:
153 t_CKBOOL parseLine( const std::string & line,
154 SyntaxTokenList & tokens );
155 };
156
157
158 #endif