Blender  V2.59
InputParser.h
Go to the documentation of this file.
00001 /*
00002  * Parser.h: interface for the CParser class.
00003  * Eindhoven University of Technology 1997
00004  * OOPS team (Serge vd Boom, Erwin Coumans, Tom Geelen, Wynke Stuylemeier)
00005  * $Id: InputParser.h 35063 2011-02-22 10:33:14Z jesterking $
00006  * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
00007  *
00008  * Permission to use, copy, modify, distribute and sell this software
00009  * and its documentation for any purpose is hereby granted without fee,
00010  * provided that the above copyright notice appear in all copies and
00011  * that both that copyright notice and this permission notice appear
00012  * in supporting documentation.  Erwin Coumans makes no
00013  * representations about the suitability of this software for any
00014  * purpose.  It is provided "as is" without express or implied warranty.
00015  *
00016  */
00017 
00022 #ifndef __INPUTPARSER_H__
00023 #define __INPUTPARSER_H__
00024 
00025 class CParser;
00026 #include "Expression.h"
00027 
00028 
00029 class CParser
00030 {
00031 public:
00032         CParser();
00033         virtual                         ~CParser();
00034 
00035         float                           GetFloat(STR_String& txt);
00036         CValue*                         GetValue(STR_String& txt, bool bFallbackToText=false);
00037         CExpression*            ProcessText(const char *intext);
00038         void                            SetContext(CValue* context);
00039 
00040 private:
00041         enum symbols {
00042                 errorsym,
00043                 lbracksym,
00044                 rbracksym,
00045                 cellsym,
00046                 commasym,
00047                 opsym,
00048                 constsym,
00049                 sumsym,
00050                 ifsym,
00051                 whocodedsym,
00052                 eolsym,
00053                 idsym
00054         };                      // all kinds of symbols
00055 
00056         enum optype {
00057                 OPmodulus,
00058                 OPplus,
00059                 OPminus,
00060                 OPtimes,
00061                 OPdivide,
00062                 OPand,
00063                 OPor,
00064                 OPequal,
00065                 OPunequal,
00066                 OPgreater,
00067                 OPless,
00068                 OPgreaterequal,
00069                 OPlessequal,
00070                 OPnot
00071         };              // all kinds of operators
00072 
00073         enum consttype {
00074                 booltype,
00075                 inttype,
00076                 floattype,
00077                 stringtype
00078         };              // all kinds of constants
00079         
00080         int sym,                                        // current symbol
00081                 opkind,                                 // kind of operator, if symbol is an operator
00082                 constkind;                              // kind of operator, if symbol is a constant
00083         
00084         char ch;                                        // current character
00085         int chcount;                            // index to character in input string
00086         CExpression *errmsg;            // contains a errormessage, if scanner error
00087         
00088         STR_String text,                                // contains a copy of the original text
00089                 const_as_string;                // string representation of the symbol, if symbol is a constant
00090         bool boolvalue;                         // value of the boolean, if symbol is a constant of type boolean
00091         CValue* m_identifierContext;// context in which identifiers are looked up
00092         
00093         
00094         void ScanError(const char *str);
00095         CExpression* Error(const char *str);
00096         void NextCh();
00097         void TermChar(char c);
00098         void DigRep();
00099         void CharRep();
00100         void GrabString(int start);
00101         void GrabRealString(int start);
00102         void NextSym();
00103 #if 0   /* not used yet */
00104         int MakeInt();
00105 #endif
00106         STR_String Symbol2Str(int s);
00107         void Term(int s);
00108         int Priority(int optor);
00109         CExpression *Ex(int i);
00110         CExpression *Expr();
00111         
00112         
00113 #ifdef WITH_CXX_GUARDEDALLOC
00114 public:
00115         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:CParser"); }
00116         void operator delete( void *mem ) { MEM_freeN(mem); }
00117 #endif
00118 };
00119 
00120 #endif
00121