Initial revision
[blender.git] / source / gameengine / Expressions / InputParser.h
1 /*
2  * Parser.h: interface for the CParser class.
3  * Eindhoven University of Technology 1997
4  * OOPS team (Serge vd Boom, Erwin Coumans, Tom Geelen, Wynke Stuylemeier)
5  * $Id$
6  * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
7  *
8  * Permission to use, copy, modify, distribute and sell this software
9  * and its documentation for any purpose is hereby granted without fee,
10  * provided that the above copyright notice appear in all copies and
11  * that both that copyright notice and this permission notice appear
12  * in supporting documentation.  Erwin Coumans makes no
13  * representations about the suitability of this software for any
14  * purpose.  It is provided "as is" without express or implied warranty.
15  *
16  */
17 #ifndef __INPUTPARSER_H__
18 #define __INPUTPARSER_H__
19
20 class CParser;
21 #include "Expression.h"
22
23
24 class CParser
25 {
26 public:
27         CParser();
28         virtual                         ~CParser();
29
30         float                           GetFloat(STR_String txt);
31         CValue*                         GetValue(STR_String txt, bool bFallbackToText=false);
32         CExpression*            ProcessText(STR_String intext);
33         void                            SetContext(CValue* context);
34
35 private:
36         enum symbols {
37                 errorsym,
38                 lbracksym,
39                 rbracksym,
40                 cellsym,
41                 commasym,
42                 opsym,
43                 constsym,
44                 sumsym,
45                 ifsym,
46                 whocodedsym,
47                 eolsym,
48                 idsym
49         };                      // all kinds of symbols
50
51         enum optype {
52                 OPplus,
53                 OPminus,
54                 OPtimes,
55                 OPdivide,
56                 OPand,
57                 OPor,
58                 OPequal,
59                 OPunequal,
60                 OPgreater,
61                 OPless,
62                 OPgreaterequal,
63                 OPlessequal,
64                 OPnot
65         };              // all kinds of operators
66
67         enum consttype {
68                 booltype,
69                 inttype,
70                 floattype,
71                 stringtype
72         };              // all kinds of constants
73         
74         int sym,                                        // current symbol
75                 opkind,                                 // kind of operator, if symbol is an operator
76                 constkind;                              // kind of operator, if symbol is a constant
77         
78         char ch;                                        // current character
79         int chcount;                            // index to character in input string
80         CExpression *errmsg;            // contains a errormessage, if scanner error
81         
82         STR_String text,                                // contains a copy of the original text
83                 const_as_string;                // string representation of the symbol, if symbol is a constant
84         bool boolvalue;                         // value of the boolean, if symbol is a constant of type boolean
85         CValue* m_identifierContext;// context in which identifiers are looked up
86         
87         
88         void ScanError(STR_String str);
89         CExpression* Error(STR_String str);
90         void NextCh();
91         void TermChar(char c);
92         void DigRep();
93         void CharRep();
94         void GrabString(int start);
95         void NextSym();
96         int MakeInt();
97         STR_String Symbol2Str(int s);
98         void Term(int s);
99         int Priority(int optor);
100         CExpression *Ex(int i);
101         CExpression *Expr();
102
103 };
104
105 #endif