svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r20849:20855
[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(const char *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                 OPmodulus,
53                 OPplus,
54                 OPminus,
55                 OPtimes,
56                 OPdivide,
57                 OPand,
58                 OPor,
59                 OPequal,
60                 OPunequal,
61                 OPgreater,
62                 OPless,
63                 OPgreaterequal,
64                 OPlessequal,
65                 OPnot
66         };              // all kinds of operators
67
68         enum consttype {
69                 booltype,
70                 inttype,
71                 floattype,
72                 stringtype
73         };              // all kinds of constants
74         
75         int sym,                                        // current symbol
76                 opkind,                                 // kind of operator, if symbol is an operator
77                 constkind;                              // kind of operator, if symbol is a constant
78         
79         char ch;                                        // current character
80         int chcount;                            // index to character in input string
81         CExpression *errmsg;            // contains a errormessage, if scanner error
82         
83         STR_String text,                                // contains a copy of the original text
84                 const_as_string;                // string representation of the symbol, if symbol is a constant
85         bool boolvalue;                         // value of the boolean, if symbol is a constant of type boolean
86         CValue* m_identifierContext;// context in which identifiers are looked up
87         
88         
89         void ScanError(const char *str);
90         CExpression* Error(const char *str);
91         void NextCh();
92         void TermChar(char c);
93         void DigRep();
94         void CharRep();
95         void GrabString(int start);
96         void NextSym();
97 #if 0   /* not used yet */
98         int MakeInt();
99 #endif
100         STR_String Symbol2Str(int s);
101         void Term(int s);
102         int Priority(int optor);
103         CExpression *Ex(int i);
104         CExpression *Expr();
105
106 };
107
108 #endif
109