/Users/ericb/Desktop/SRC680_m247/starmath/inc/parse.hxx

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  OpenOffice.org - a multi-platform office productivity suite
00004  *
00005  *  $RCSfile: parse.hxx,v $
00006  *
00007  *  $Revision: 1.9 $
00008  *
00009  *  last change: $Author: vg $ $Date: 2007/05/25 12:09:50 $
00010  *
00011  *  The Contents of this file are made available subject to
00012  *  the terms of GNU Lesser General Public License Version 2.1.
00013  *
00014  *
00015  *    GNU Lesser General Public License Version 2.1
00016  *    =============================================
00017  *    Copyright 2005 by Sun Microsystems, Inc.
00018  *    901 San Antonio Road, Palo Alto, CA 94303, USA
00019  *
00020  *    This library is free software; you can redistribute it and/or
00021  *    modify it under the terms of the GNU Lesser General Public
00022  *    License version 2.1, as published by the Free Software Foundation.
00023  *
00024  *    This library is distributed in the hope that it will be useful,
00025  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00026  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027  *    Lesser General Public License for more details.
00028  *
00029  *    You should have received a copy of the GNU Lesser General Public
00030  *    License along with this library; if not, write to the Free Software
00031  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00032  *    MA  02111-1307  USA
00033  *
00034  ************************************************************************/
00035 #ifndef PARSE_HXX
00036 #define PARSE_HXX
00037 
00038 
00039 #ifndef _SV_SVAPP_HXX
00040 #include <vcl/svapp.hxx>
00041 #endif
00042 #ifndef _STACK_HXX //autogen
00043 #include <tools/stack.hxx>
00044 #endif
00045 #ifndef _LIST_HXX //autogen
00046 #include <tools/list.hxx>
00047 #endif
00048 #ifndef _STRING_HXX //autogen
00049 #include <tools/string.hxx>
00050 #endif
00051 
00052 #include "types.hxx"
00053 
00054 class SmNode;
00055 class SmDocShell;
00056 
00057 
00058 // TokenGroups
00059 #define TGOPER                  0x00000001
00060 #define TGRELATION              0x00000002
00061 #define TGSUM                   0x00000004
00062 #define TGPRODUCT               0x00000008
00063 #define TGUNOPER                0x00000010
00064 #define TGPOWER                 0x00000020
00065 #define TGATTRIBUT              0x00000040
00066 #define TGALIGN                 0x00000080
00067 #define TGFUNCTION              0x00000100
00068 #define TGBLANK                 0x00000200
00069 #define TGLBRACES               0x00000400
00070 #define TGRBRACES               0x00000800
00071 #define TGCOLOR                 0x00001000
00072 #define TGFONT                  0x00002000
00073 #define TGSTANDALONE    0x00004000
00074 #define TGDISCARDED             0x00008000
00075 #define TGLIMIT                 0x00010000
00076 #define TGFONTATTR              0x00020000
00077 
00078 
00079 enum SmTokenType
00080 {
00081         TEND,                   TLGROUP,                TRGROUP,                TLPARENT,               TRPARENT,
00082         TLBRACKET,              TRBRACKET,              TPLUS,                  TMINUS,                 TMULTIPLY,
00083         TDIVIDEBY,              TASSIGN,                TPOUND,                 TSPECIAL,               TSLASH,
00084         TBACKSLASH,             TBLANK,                 TSBLANK,                TRSUB,                  TRSUP,
00085         TCSUB,                  TCSUP,                  TLSUB,                  TLSUP,                  TGT,
00086         TLT,                    TAND,                   TOR,                    TINTERSECT,             TUNION,
00087         TNEWLINE,               TBINOM,                 TFROM,                  TTO,                    TINT,
00088         TSUM,                   TOPER,                  TABS,                   TSQRT,                  TFACT,
00089         TNROOT,                 TOVER,                  TTIMES,                 TGE,                    TLE,
00090         TGG,                    TLL,                    TDOTSAXIS,              TDOTSLOW,               TDOTSVERT,
00091         TDOTSDIAG,              TDOTSUP,                TDOTSDOWN,              TACUTE,                 TBAR,
00092         TBREVE,                 TCHECK,                 TCIRCLE,                TDOT,                   TDDOT,
00093         TDDDOT,                 TGRAVE,                 THAT,                   TTILDE,                 TVEC,
00094         TUNDERLINE,             TOVERLINE,              TOVERSTRIKE,    TITALIC,                TNITALIC,
00095         TBOLD,                  TNBOLD,                 TPHANTOM,               TFONT,                  TSIZE,
00096         TCOLOR,                 TALIGNL,                TALIGNC,                TALIGNR,                TLEFT,
00097         TRIGHT,                 TLANGLE,                TLBRACE,                TLLINE,                 TLDLINE,
00098         TLCEIL,                 TLFLOOR,                TNONE,                  TMLINE,                 TRANGLE,
00099         TRBRACE,                TRLINE,                 TRDLINE,                TRCEIL,                 TRFLOOR,
00100         TSIN,                   TCOS,                   TTAN,                   TCOT,                   TFUNC,
00101         TSTACK,                 TMATRIX,                TMATFORM,               TDPOUND,                TPLACE,
00102         TTEXT,                  TNUMBER,                TCHARACTER,             TIDENT,                 TNEQ,
00103         TEQUIV,                 TDEF,                   TPROP,                  TSIM,                   TSIMEQ,
00104         TAPPROX,                TPARALLEL,              TORTHO,                 TIN,                    TNOTIN,
00105         TSUBSET,                TSUBSETEQ,              TSUPSET,                TSUPSETEQ,              TPLUSMINUS,
00106         TMINUSPLUS,             TOPLUS,                 TOMINUS,                TDIV,                   TOTIMES,
00107         TODIVIDE,               TTRANSL,                TTRANSR,                TIINT,                  TIIINT,
00108         TLINT,                  TLLINT,                 TLLLINT,                TPROD,                  TCOPROD,
00109         TFORALL,                TEXISTS,                TLIM,                   TNABLA,                 TTOWARD,
00110         TSINH,                  TCOSH,                  TTANH,                  TCOTH,                  TASIN,
00111         TACOS,                  TATAN,                  TLN,                    TLOG,                   TUOPER,
00112         TBOPER,                 TBLACK,                 TWHITE,                 TRED,                   TGREEN,
00113         TBLUE,                  TCYAN,                  TMAGENTA,               TYELLOW,                TFIXED,
00114         TSANS,                  TSERIF,                 TPOINT,                 TASINH,                 TACOSH,
00115         TATANH,                 TACOTH,                 TACOT,                  TEXP,                   TCDOT,
00116         TODOT,                  TLESLANT,               TGESLANT,               TNSUBSET,               TNSUPSET,
00117         TNSUBSETEQ,             TNSUPSETEQ,             TPARTIAL,               TNEG,                   TNI,
00118         TBACKEPSILON,   TALEPH,                 TIM,                    TRE,                    TWP,
00119         TEMPTYSET,              TINFINITY,              TESCAPE,                TLIMSUP,                TLIMINF,
00120         TNDIVIDES,              TDRARROW,               TDLARROW,               TDLRARROW,              TUNDERBRACE,
00121         TOVERBRACE,             TCIRC,                  TTOP,                   THBAR,                  TLAMBDABAR,
00122         TLEFTARROW,             TRIGHTARROW,    TUPARROW,               TDOWNARROW,             TDIVIDES,
00123         TNDIBVIDES,             TSETN,                  TSETZ,                  TSETQ,                  TSETR,
00124         TSETC,                  TWIDEVEC,               TWIDETILDE,             TWIDEHAT,               TWIDESLASH,
00125         TWIDEBACKSLASH, TLDBRACKET,             TRDBRACKET,
00126         TUNKNOWN,               TDEBUG
00127 };
00128 
00129 
00130 struct SmToken
00131 {
00132         // token text
00133         String  aText;
00134         // token info
00135         SmTokenType eType;
00136         sal_Unicode             cMathChar;
00137         // parse-help info
00138         ULONG           nGroup;
00139         USHORT          nLevel;
00140         // token position
00141     USHORT      nRow;
00142     xub_StrLen  nCol;
00143 
00144         SmToken();
00145 };
00146 
00147 
00148 enum SmParseError
00149 {
00150         PE_NONE,                                        PE_UNEXPECTED_END_OF_INPUT,
00151         PE_UNEXPECTED_CHAR,                     PE_UNEXPECTED_TOKEN,
00152         PE_FUNC_EXPECTED,                       PE_UNOPER_EXPECTED,
00153         PE_BINOPER_EXPECTED,            PE_SYMBOL_EXPECTED,
00154         PE_IDENTIFIER_EXPECTED,         PE_POUND_EXPECTED,
00155         PE_COLOR_EXPECTED,                      PE_LGROUP_EXPECTED,
00156         PE_RGROUP_EXPECTED,                     PE_LBRACE_EXPECTED,
00157         PE_RBRACE_EXPECTED,                     PE_PARENT_MISMATCH,
00158         PE_RIGHT_EXPECTED,                      PE_FONT_EXPECTED,
00159         PE_SIZE_EXPECTED,                       PE_DOUBLE_ALIGN,
00160         PE_DOUBLE_SUBSUPSCRIPT
00161 };
00162 
00163 
00164 struct SmErrorDesc
00165 {
00166         SmParseError  Type;
00167         SmNode           *pNode;
00168         String            Text;
00169 };
00170 
00171 DECLARE_STACK(SmNodeStack,  SmNode *)
00172 DECLARE_LIST(SmErrDescList, SmErrorDesc *)
00173 
00174 /**************************************************************************/
00175 
00176 // defines possible conversions of the formula text from the format of
00177 // one release to the one of another.
00178 enum SmConvert
00179 {
00180     CONVERT_NONE,
00181     CONVERT_40_TO_50,
00182     CONVERT_50_TO_60,
00183     CONVERT_60_TO_50
00184 };
00185 
00186 
00187 class SmParser
00188 {
00189     String          BufferString;
00190     SmToken         CurToken;
00191     SmNodeStack     NodeStack;
00192     SmErrDescList   ErrDescList;
00193     int             CurError;
00194     LanguageType    nLang;
00195     xub_StrLen      BufferIndex,
00196                     nTokenIndex;
00197     USHORT          Row,
00198                     ColOff;
00199     SmConvert       eConversion;
00200     BOOL            bImportSymNames,
00201                     bExportSymNames;
00202 
00203         // declare copy-constructor and assignment-operator private
00204         SmParser(const SmParser &);
00205         SmParser & operator = (const SmParser &);
00206 
00207 protected:
00208 #if OSL_DEBUG_LEVEL
00209         BOOL                    IsDelimiter( const String &rTxt, xub_StrLen nPos );
00210 #endif
00211         void                    NextToken();
00212         xub_StrLen              GetTokenIndex() const   { return nTokenIndex; }
00213         void                    Insert(const String &rText, USHORT nPos);
00214     void            Replace( USHORT nPos, USHORT nLen, const String &rText );
00215 
00216         inline BOOL             TokenInGroup(ULONG nGroup);
00217 
00218         // grammar
00219         void    Table();
00220         void    Line();
00221         void    Expression();
00222         void    Relation();
00223         void    Sum();
00224         void    Product();
00225         void    SubSup(ULONG nActiveGroup);
00226         void    OpSubSup();
00227         void    Power();
00228         void    Blank();
00229         void    Term();
00230         void    Escape();
00231         void    Operator();
00232         void    Oper();
00233         void    UnOper();
00234         void    Align();
00235         void    FontAttribut();
00236         void    Attribut();
00237         void    Font();
00238         void    FontSize();
00239         void    Color();
00240         void    Brace();
00241         void    Bracebody(BOOL bIsLeftRight);
00242         void    Function();
00243         void    Binom();
00244         void    Stack();
00245         void    Matrix();
00246         void    Special();
00247         void    GlyphSpecial();
00248         // end of grammar
00249     
00250     LanguageType    GetLanguage() const { return nLang; }
00251     void            SetLanguage( LanguageType nNewLang ) { nLang = nNewLang; }
00252 
00253         void    Error(SmParseError Error);
00254 
00255 public:
00256                  SmParser();
00257 
00258         SmNode          *Parse(const String &rBuffer);
00259 
00260         const String & GetText() const { return BufferString; };
00261 
00262     SmConvert    GetConversion() const              { return eConversion; }
00263     void         SetConversion(SmConvert eConv)     { eConversion = eConv; }
00264 
00265     BOOL         IsImportSymbolNames() const        { return bImportSymNames; }
00266     void         SetImportSymbolNames(BOOL bVal)    { bImportSymNames = bVal; }
00267     BOOL         IsExportSymbolNames() const        { return bExportSymNames; }
00268     void         SetExportSymbolNames(BOOL bVal)    { bExportSymNames = bVal; }
00269 
00270         USHORT           AddError(SmParseError Type, SmNode *pNode);
00271 
00272         const SmErrorDesc *     NextError();
00273         const SmErrorDesc *     PrevError();
00274         const SmErrorDesc *     GetError(USHORT i = 0xFFFF);
00275 };
00276 
00277 
00278 inline BOOL SmParser::TokenInGroup(ULONG nGroup)
00279 {
00280         return (CurToken.nGroup & nGroup) ? TRUE : FALSE;
00281 }
00282 
00283 
00284 #endif
00285 

Generated on Wed Feb 20 17:21:56 2008 for maths by  doxygen 1.5.1