Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

Lex.H

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // File: Lex.H                                                
00020 // Last Modified On Fri Aug  6 11:59:17 EDT 2004 by ken@xorian.net 
00021 //      Modified On Mon Feb  2 15:38:44 PST 1998 by yuanyu    
00022 //      Modified On Fri Oct 31 10:02:42 PST 1997 by heydon    
00023 //      Modified On Fri Jan 26 18:11:09 PST 1996 by horning   
00024 //      Modified On Tue Dec  7 16:10:29 PST 1993 by hanna     
00025 
00026 #ifndef Lex_H
00027 #define Lex_H
00028 
00029 #include "Location.H"
00030 #include "ValExpr.H"
00031 #include <VestaSource.H>
00032 #include <iostream>
00033 
00034 // Where we are currently lexing (position of the current token):
00035 extern Text fileName;
00036 extern ShortId shortId;
00037 extern int lineNumber;
00038 extern int charNumber;
00039 
00040 // NB: When this enumeration is modified, it is essential to make
00041 // corresponding modifications to the table initializations of TokenNames,
00042 // CharMap, and ReservedWords in the function LexInit in Lex.C.
00043 enum TokenClass
00044   { TkBinding, TkBool, TkDo, TkElse, TkErr, TkFalse, TkFiles,
00045     TkForeach, TkFrom, TkFunction, TkIf, TkIn, TkImport, TkInt,
00046     TkList, TkReturn, TkText, TkThen, TkTrue, TkType, TkValue,
00047 
00048     TkId, TkNumber, TkString,
00049 
00050     TkAnd, TkEqEq, TkNotEq, TkGreaterEq, TkImplies, TkLessEq, TkOr,
00051     TkPlusPlus,
00052 
00053     TkBackSlash, TkBang, TkColon, TkComma, TkDollar, TkEqual, TkGreater,
00054     TkLess, TkMinus, TkPercent, TkPlus, TkQuery, TkSemicolon, TkSlash,
00055     TkStar, TkUnderscore,
00056 
00057     TkLBrace, TkRBrace, TkLBracket, TkRBracket, TkLParen, TkRParen,
00058 
00059     TkPragma,
00060 
00061     TkEOF, TkIllegal };
00062 
00063 // For printout:
00064 extern Text TokenNames[];
00065 
00066 class Token {
00067 public:
00068   Token();
00069 
00070   TokenClass tclass;
00071   Expr expr;
00072   SrcLoc *loc;
00073 
00074   void Init(const Text& model, ShortId sid);
00075   void Next();
00076   void LexFlush();
00077 
00078   void StartBytes() { length = 0; bytes[0] = 0; };
00079   void AppendChar(char c);
00080   void UnAppendChar() { length--; };
00081 
00082   void EndBytes() { bytes[length] = 0; };
00083   char *Bytes() { return bytes; };
00084   Text AsText() { return Text(bytes); }; 
00085   int Length() { return length; };
00086 
00087   void TokenAssign(Token& tk);
00088 
00089 private:
00090   char *bytes;
00091   int bytesLength;
00092   int length;
00093 
00094   void ScanIdNumber(char c);
00095   void ScanText();
00096   bool ScanPragma();
00097   void ScanComment(char c);
00098 
00099   Token(const Token&);
00100   Token &operator=(const Token&);
00101 };
00102 
00103 void LexInit();
00104 
00105 #endif // Lex_H

Generated on Mon May 8 00:48:38 2006 for Vesta by  doxygen 1.4.2