Initial
This commit is contained in:
50
http/HOLD/EMIT.CPP
Normal file
50
http/HOLD/EMIT.CPP
Normal file
@@ -0,0 +1,50 @@
|
||||
#if 0
|
||||
#include <string.h>
|
||||
#include <http/emit.hpp>
|
||||
|
||||
Emit::Emit(PureViewOfFile &inputView,PureViewOfFile &outputView)
|
||||
: mIsEmitting(TRUE), mInputView(inputView), mOutputView(outputView)
|
||||
{
|
||||
}
|
||||
|
||||
Emit::~Emit()
|
||||
{
|
||||
}
|
||||
|
||||
void Emit::emit(int code,int type,int identifier)const
|
||||
{
|
||||
if(!mIsEmitting)return;
|
||||
mOutputView.write(code);
|
||||
mOutputView.write(type);
|
||||
mOutputView.write(identifier);
|
||||
}
|
||||
|
||||
void Emit::emit(int code,double value)const
|
||||
{
|
||||
if(!mIsEmitting)return;
|
||||
mOutputView.write(code);
|
||||
mOutputView.write(value);
|
||||
}
|
||||
|
||||
void Emit::emit(int code,int op)const
|
||||
{
|
||||
if(!mIsEmitting)return;
|
||||
mOutputView.write(code);
|
||||
mOutputView.write(op);
|
||||
}
|
||||
|
||||
void Emit::emit(const char *lpLiteralValue)const
|
||||
{
|
||||
if(!mIsEmitting||!lpLiteralValue)return;
|
||||
mOutputView.write(String(lpLiteralValue));
|
||||
}
|
||||
|
||||
void Emit::emit(const String &literalValue)const
|
||||
{
|
||||
if(!mIsEmitting||literalValue.isNull())return;
|
||||
int stringLength(literalValue.length());
|
||||
mOutputView.write(stringLength);
|
||||
mOutputView.write(literalValue);
|
||||
}
|
||||
|
||||
#endif
|
||||
67
http/HOLD/EMIT.HPP
Normal file
67
http/HOLD/EMIT.HPP
Normal file
@@ -0,0 +1,67 @@
|
||||
#ifndef _HTTP_EMIT_HPP_
|
||||
#define _HTTP_EMIT_HPP_
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_PUREVIEWOFFILE_HPP_
|
||||
#include <common/pview.hpp>
|
||||
#endif
|
||||
|
||||
class Emit
|
||||
{
|
||||
friend class Scan;
|
||||
friend class Parse;
|
||||
public:
|
||||
void emit(const char *lpLiteralValue)const;
|
||||
void emit(const String &literalValue)const;
|
||||
void emit(int code,int type,int identifier)const;
|
||||
void emit(int code)const;
|
||||
void emit(int code,double value)const;
|
||||
void emit(int code,int op)const;
|
||||
int read(void);
|
||||
int read(void *variable,size_t size);
|
||||
void emitting(int);
|
||||
int emitting(void)const;
|
||||
private:
|
||||
Emit(PureViewOfFile &inputView,PureViewOfFile &outputView);
|
||||
virtual ~Emit();
|
||||
|
||||
int mIsEmitting;
|
||||
char mLastSymbol;
|
||||
PureViewOfFile &mInputView;
|
||||
PureViewOfFile &mOutputView;
|
||||
};
|
||||
|
||||
inline
|
||||
void Emit::emitting(int isEmitting)
|
||||
{
|
||||
mIsEmitting=isEmitting;
|
||||
}
|
||||
|
||||
inline
|
||||
int Emit::emitting(void)const
|
||||
{
|
||||
return mIsEmitting;
|
||||
}
|
||||
|
||||
inline
|
||||
void Emit::emit(int code)const
|
||||
{
|
||||
if(!mIsEmitting)return;
|
||||
mOutputView.write(code);
|
||||
}
|
||||
|
||||
inline
|
||||
int Emit::read(void)
|
||||
{
|
||||
if(!mInputView.read((unsigned char&)mLastSymbol))return 0xFFFF;
|
||||
return mLastSymbol;
|
||||
}
|
||||
|
||||
inline
|
||||
int Emit::read(void *variable,size_t size)
|
||||
{
|
||||
if(!mInputView.read((char*)variable,size))return 0xFFFF;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
28
http/HOLD/PRESCAN.CPP
Normal file
28
http/HOLD/PRESCAN.CPP
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <http/prescan.hpp>
|
||||
#include <common/string.hpp>
|
||||
#include <common/openfile.hpp>
|
||||
#include <common/pview.hpp>
|
||||
#include <common/filemap.hpp>
|
||||
#include <bsptree/btree.hpp>
|
||||
|
||||
void PreScan::preScan(const String &pathFileName)
|
||||
{
|
||||
BTree<PureBYTE> mapToken;
|
||||
String formatString;
|
||||
BYTE readByte;
|
||||
|
||||
FileHandle writeFile("tokens.txt",FileHandle::Write,FileHandle::ShareRead,FileHandle::Overwrite);
|
||||
FileHandle scanFile(pathFileName,FileHandle::Read,FileHandle::ShareRead,FileHandle::Open);
|
||||
if(!scanFile.isOkay())return;
|
||||
FileMap scanMap(scanFile);
|
||||
PureViewOfFile scanView(scanMap);
|
||||
|
||||
PureVector<PureBYTE> scanBytes;
|
||||
while(scanView.read(readByte))mapToken.insert(PureBYTE(readByte));
|
||||
mapToken.treeItems(scanBytes);
|
||||
for(int itemIndex=0;itemIndex<scanBytes.size();itemIndex++)
|
||||
{
|
||||
::sprintf(formatString,"'%c'",(BYTE)scanBytes[itemIndex]);
|
||||
writeFile.writeLine(formatString);
|
||||
}
|
||||
}
|
||||
27
http/HOLD/PRESCAN.HPP
Normal file
27
http/HOLD/PRESCAN.HPP
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef _HTTP_PRESCAN_HPP_
|
||||
#define _HTTP_PRESCAN_HPP_
|
||||
#ifndef _COMMON_PUREBYTE_HPP_
|
||||
#include <common/purebyte.hpp>
|
||||
#endif
|
||||
|
||||
class String;
|
||||
|
||||
class PreScan
|
||||
{
|
||||
public:
|
||||
PreScan(void);
|
||||
virtual ~PreScan();
|
||||
void preScan(const String &pathFileName);
|
||||
private:
|
||||
};
|
||||
|
||||
inline
|
||||
PreScan::PreScan(void)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
PreScan::~PreScan()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
197
http/HOLD/READER.CPP
Normal file
197
http/HOLD/READER.CPP
Normal file
@@ -0,0 +1,197 @@
|
||||
#include <http/reader.hpp>
|
||||
#include <http/scan.hpp>
|
||||
|
||||
Reader::Reader(void)
|
||||
{
|
||||
}
|
||||
|
||||
Reader::~Reader()
|
||||
{
|
||||
}
|
||||
|
||||
void Reader::read(PureViewOfFile &inView)
|
||||
{
|
||||
Scan::ScanSymbols scanSymbol;
|
||||
String workString;
|
||||
double workDouble;
|
||||
int strLength;
|
||||
|
||||
inView.rewind();
|
||||
while(TRUE)
|
||||
{
|
||||
if(!inView.read((int&)scanSymbol))break;
|
||||
switch(scanSymbol)
|
||||
{
|
||||
case Scan::leftangle1 :
|
||||
leftangle();
|
||||
break;
|
||||
case Scan::rightangle1 :
|
||||
rightangle();
|
||||
break;
|
||||
case Scan::forwardslash1 :
|
||||
forwardslash();
|
||||
break;
|
||||
case Scan::ampersand1 :
|
||||
ampersand();
|
||||
break;
|
||||
case Scan::semicolon1 :
|
||||
semicolon();
|
||||
break;
|
||||
case Scan::space1 :
|
||||
space();
|
||||
break;
|
||||
case Scan::colon1 :
|
||||
colon();
|
||||
break;
|
||||
case Scan::leftparen1 :
|
||||
leftparen();
|
||||
break;
|
||||
case Scan::rightparen1 :
|
||||
rightparen();
|
||||
break;
|
||||
case Scan::exclamation1 :
|
||||
exclamation();
|
||||
break;
|
||||
case Scan::minus1 :
|
||||
minus();
|
||||
break;
|
||||
case Scan::pound1 :
|
||||
pound();
|
||||
break;
|
||||
case Scan::equal1 :
|
||||
equal();
|
||||
break;
|
||||
case Scan::newline1 :
|
||||
newline();
|
||||
break;
|
||||
case Scan::endtext1 :
|
||||
endtext();
|
||||
break;
|
||||
case Scan::unknown1 :
|
||||
unknown();
|
||||
break;
|
||||
case Scan::literal1 :
|
||||
inView.read(strLength);
|
||||
workString.reserve(strLength+1);
|
||||
inView.read((LPSTR)workString,strLength);
|
||||
literal(workString);
|
||||
break;
|
||||
case Scan::name1 :
|
||||
inView.read(strLength);
|
||||
workString.reserve(strLength+1);
|
||||
inView.read((LPSTR)workString,strLength);
|
||||
name(workString);
|
||||
break;
|
||||
case Scan::numeral1 :
|
||||
inView.read(workDouble);
|
||||
numeral(workDouble);
|
||||
break;
|
||||
case Scan::stop1 :
|
||||
stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// virtuals
|
||||
|
||||
void Reader::leftangle(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::rightangle(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::forwardslash(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::ampersand(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::semicolon(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::space(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::colon(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::leftparen(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::rightparen(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::exclamation(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::minus(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::pound(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::equal(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::newline(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::endtext(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::unknown(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::numeral(double /*value*/)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::literal(const String &/*literal*/)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::name(const String &/*name*/)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void Reader::stop(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
38
http/HOLD/READER.HPP
Normal file
38
http/HOLD/READER.HPP
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef _HTTP_READER_HPP_
|
||||
#define _HTTP_READER_HPP_
|
||||
#ifndef _HTTP_SCAN_HPP_
|
||||
#include <http/scan.hpp>
|
||||
#endif
|
||||
|
||||
class String;
|
||||
|
||||
class Reader
|
||||
{
|
||||
public:
|
||||
Reader(void);
|
||||
virtual ~Reader();
|
||||
void read(PureViewOfFile &inView);
|
||||
protected:
|
||||
virtual void leftangle(void);
|
||||
virtual void rightangle(void);
|
||||
virtual void forwardslash(void);
|
||||
virtual void ampersand(void);
|
||||
virtual void semicolon(void);
|
||||
virtual void space(void);
|
||||
virtual void colon(void);
|
||||
virtual void leftparen(void);
|
||||
virtual void rightparen(void);
|
||||
virtual void exclamation(void);
|
||||
virtual void minus(void);
|
||||
virtual void pound(void);
|
||||
virtual void equal(void);
|
||||
virtual void newline(void);
|
||||
virtual void endtext(void);
|
||||
virtual void unknown(void);
|
||||
virtual void literal(const String &literal);
|
||||
virtual void name(const String &name);
|
||||
virtual void numeral(double value);
|
||||
virtual void stop(void);
|
||||
private:
|
||||
};
|
||||
#endif
|
||||
265
http/HOLD/SCAN.CPP
Normal file
265
http/HOLD/SCAN.CPP
Normal file
@@ -0,0 +1,265 @@
|
||||
#if 0
|
||||
#include <http/table.hpp>
|
||||
#include <http/scan.hpp>
|
||||
|
||||
Scan::Scan(PureViewOfFile &srcView,PureViewOfFile &dstView,Table &symbolTable,WORD allowUserSymbols)
|
||||
: Emit(srcView,dstView), mSymbolTable(symbolTable), mUserSymbols(allowUserSymbols),
|
||||
mLogFile("scan.log",FileHandle::Write,FileHandle::ShareRead,FileHandle::Overwrite)
|
||||
{
|
||||
}
|
||||
|
||||
Scan::~Scan(void)
|
||||
{
|
||||
}
|
||||
|
||||
void Scan::analyze(void)
|
||||
{
|
||||
readch();
|
||||
while((int)mChar!=-1&&mChar!=0x001A)
|
||||
{
|
||||
skipSeparators();
|
||||
if(0xFFFF==mChar||0x001A==mChar)break;
|
||||
if(isdigit(mChar))scanNumeral();
|
||||
else if(isalpha(mChar))scanWord();
|
||||
else if(mChar=='\r')scanNewLine();
|
||||
else if(mChar=='"')scanLiteral();
|
||||
else if(mChar=='<')scanLeftAngle();
|
||||
else if(mChar=='>')scanRightAngle();
|
||||
else if(mChar=='/')scanForwardSlash();
|
||||
else if(mChar=='&')scanAmpersand();
|
||||
else if(mChar==';')scanSemicolon();
|
||||
else if(mChar=='#')scanPound();
|
||||
else if(mChar=='!')scanExclamation();
|
||||
else if(mChar=='-')scanMinus();
|
||||
else if(mChar=='=')scanEqual();
|
||||
else if(mChar==':')scanColon();
|
||||
else if(mChar=='(')scanRightParen();
|
||||
else if(mChar==')')scanLeftParen();
|
||||
else if(mChar==' ')scanSpace();
|
||||
else scanUnknown();
|
||||
}
|
||||
emit(endtext1);
|
||||
}
|
||||
|
||||
void Scan::scanNewLine(void)
|
||||
{
|
||||
mLogFile.writeLine("Scan::scanNewLine");
|
||||
readch();
|
||||
if(mChar=='\n')
|
||||
{
|
||||
emit(newline1);
|
||||
readch();
|
||||
}
|
||||
else emit(unknown1);
|
||||
}
|
||||
|
||||
void Scan::skipSeparators(void)
|
||||
{
|
||||
while(mChar==TabChar||mChar==LineFeed)readch(); // mChar==SpaceChar||
|
||||
}
|
||||
|
||||
void Scan::scanWord(void)
|
||||
{
|
||||
String wordString;
|
||||
int tableIndex(0);
|
||||
|
||||
if(mChar=='"')readch();
|
||||
while(0xFFFF!=mChar&&0x0D!=mChar&&mChar!='"'&&mChar!='>'&&mChar!='<'&&mChar!='='&&mChar!='"'&&mChar!='&'&&mChar!=';'&&mChar!=')'&&mChar!='#'&&!isspace(mChar)) // &&mChar!='/'
|
||||
{
|
||||
wordString+=String((char)mChar);
|
||||
readch();
|
||||
}
|
||||
if(mChar=='"')readch();
|
||||
if(wordString.isNull())return;
|
||||
mLogFile.writeLine(String("Scan::scanWord")+String(" '")+wordString+String("'"));
|
||||
if(mSymbolTable.locateSymbolString(wordString,tableIndex))
|
||||
{
|
||||
if(Symbol::UserSymbol==mSymbolTable[tableIndex].symbolType())
|
||||
emit(name1,mSymbolTable[tableIndex].symbolType(),tableIndex);
|
||||
else if(Symbol::AssignedSymbol==mSymbolTable[tableIndex].symbolType())
|
||||
emit(name1,mSymbolTable[tableIndex].symbolType(),mSymbolTable[tableIndex].identifier());
|
||||
else if(Symbol::ConstantSymbol==mSymbolTable[tableIndex].symbolType())
|
||||
emit(name1,mSymbolTable[tableIndex].symbolType(),mSymbolTable[tableIndex].identifier());
|
||||
else if(Symbol::SystemSymbol==mSymbolTable[tableIndex].symbolType())
|
||||
emit(name1,mSymbolTable[tableIndex].symbolType(),mSymbolTable[tableIndex].identifier());
|
||||
else if(Symbol::CommandSymbol==mSymbolTable[tableIndex].symbolType())
|
||||
emit(name1,mSymbolTable[tableIndex].symbolType(),mSymbolTable[tableIndex].identifier());
|
||||
else emit(unknown1);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit(literal1);
|
||||
emit(wordString.length());
|
||||
emit((char*)wordString);
|
||||
}
|
||||
}
|
||||
|
||||
void Scan::scanLiteral(void)
|
||||
{
|
||||
String wordString;
|
||||
int tableIndex(0);
|
||||
|
||||
readch();
|
||||
while(0xFFFF!=mChar&&'"'!=mChar)
|
||||
{
|
||||
wordString+=String((char)mChar);
|
||||
readch();
|
||||
}
|
||||
if(mChar=='"')readch();
|
||||
if(wordString.isNull())return;
|
||||
mLogFile.writeLine(String("Scan::scanLiteral")+String(" '")+wordString+String("'"));
|
||||
if(mSymbolTable.locateSymbolString(wordString,tableIndex))
|
||||
{
|
||||
if(Symbol::UserSymbol==mSymbolTable[tableIndex].symbolType())
|
||||
emit(name1,mSymbolTable[tableIndex].symbolType(),tableIndex);
|
||||
else if(Symbol::AssignedSymbol==mSymbolTable[tableIndex].symbolType())
|
||||
emit(name1,mSymbolTable[tableIndex].symbolType(),mSymbolTable[tableIndex].identifier());
|
||||
else if(Symbol::ConstantSymbol==mSymbolTable[tableIndex].symbolType())
|
||||
emit(name1,mSymbolTable[tableIndex].symbolType(),mSymbolTable[tableIndex].identifier());
|
||||
else if(Symbol::SystemSymbol==mSymbolTable[tableIndex].symbolType())
|
||||
emit(name1,mSymbolTable[tableIndex].symbolType(),mSymbolTable[tableIndex].identifier());
|
||||
else if(Symbol::CommandSymbol==mSymbolTable[tableIndex].symbolType())
|
||||
emit(name1,mSymbolTable[tableIndex].symbolType(),mSymbolTable[tableIndex].identifier());
|
||||
else emit(unknown1);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit(literal1);
|
||||
emit(wordString.length());
|
||||
emit((char*)wordString);
|
||||
}
|
||||
}
|
||||
|
||||
void Scan::scanNumeral(void)
|
||||
{
|
||||
int multiplier=10;
|
||||
double value=0;
|
||||
double digits;
|
||||
|
||||
while(0xFFFF!=mChar&&isdigit(mChar))
|
||||
{
|
||||
digits=atof((char *)&mChar);
|
||||
value=multiplier*value+digits;
|
||||
readch();
|
||||
}
|
||||
|
||||
String numberString;
|
||||
::sprintf(numberString,"%lf",value);
|
||||
mLogFile.writeLine(String("Scan::scanNumeral")+String(" '")+numberString+String("'"));
|
||||
|
||||
if(mChar=='.')
|
||||
{
|
||||
readch();
|
||||
while(isdigit(mChar))
|
||||
{
|
||||
digits=atof((char *)&mChar);
|
||||
value=(digits/multiplier)+value;
|
||||
multiplier*=10;
|
||||
readch();
|
||||
}
|
||||
}
|
||||
emit(numeral1,value);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
|
||||
void Scan::scanLeftAngle(void)
|
||||
{
|
||||
mLogFile.writeLine("Scan::scanLeftAngle");
|
||||
emit(leftangle1);
|
||||
readch();
|
||||
}
|
||||
|
||||
void Scan::scanRightAngle(void)
|
||||
{
|
||||
mLogFile.writeLine("Scan::scanRightAngle");
|
||||
emit(rightangle1);
|
||||
readch();
|
||||
}
|
||||
|
||||
void Scan::scanForwardSlash(void)
|
||||
{
|
||||
mLogFile.writeLine("Scan::scanForwardSlash");
|
||||
emit(forwardslash1);
|
||||
readch();
|
||||
}
|
||||
|
||||
void Scan::scanAmpersand(void)
|
||||
{
|
||||
mLogFile.writeLine("Scan::scanAmpersand");
|
||||
emit(ampersand1);
|
||||
readch();
|
||||
}
|
||||
|
||||
void Scan::scanSemicolon(void)
|
||||
{
|
||||
mLogFile.writeLine("Scan::scanSemicolon");
|
||||
emit(semicolon1);
|
||||
readch();
|
||||
}
|
||||
|
||||
void Scan::scanPound(void)
|
||||
{
|
||||
mLogFile.writeLine("Scan::scanPound");
|
||||
emit(pound1);
|
||||
readch();
|
||||
}
|
||||
|
||||
void Scan::scanExclamation(void)
|
||||
{
|
||||
mLogFile.writeLine("Scan::scanExclamation");
|
||||
emit(exclamation1);
|
||||
readch();
|
||||
}
|
||||
|
||||
void Scan::scanMinus(void)
|
||||
{
|
||||
mLogFile.writeLine("Scan::scanMinus");
|
||||
emit(minus1);
|
||||
readch();
|
||||
}
|
||||
|
||||
void Scan::scanEqual(void)
|
||||
{
|
||||
mLogFile.writeLine("Scan::scanEqual");
|
||||
emit(equal1);
|
||||
readch();
|
||||
}
|
||||
|
||||
void Scan::scanColon(void)
|
||||
{
|
||||
mLogFile.writeLine("Scan::scanColon");
|
||||
emit(colon1);
|
||||
readch();
|
||||
}
|
||||
|
||||
void Scan::scanRightParen(void)
|
||||
{
|
||||
mLogFile.writeLine("Scan::scanRightParen");
|
||||
emit(rightparen1);
|
||||
readch();
|
||||
}
|
||||
|
||||
void Scan::scanLeftParen(void)
|
||||
{
|
||||
mLogFile.writeLine("Scan::scanLeftParen");
|
||||
emit(leftparen1);
|
||||
readch();
|
||||
}
|
||||
|
||||
void Scan::scanSpace(void)
|
||||
{
|
||||
mLogFile.writeLine("Scan::scanSpace");
|
||||
emit(space1);
|
||||
readch();
|
||||
}
|
||||
|
||||
void Scan::scanUnknown(void)
|
||||
{
|
||||
String logString;
|
||||
::sprintf(logString,"Scan::unknown '0x%x' %d",(int)mChar,(int)mChar);
|
||||
mLogFile.writeLine(logString);
|
||||
emit(unknown1);
|
||||
readch();
|
||||
}
|
||||
#endif
|
||||
62
http/HOLD/SCAN.HPP
Normal file
62
http/HOLD/SCAN.HPP
Normal file
@@ -0,0 +1,62 @@
|
||||
#ifndef _HTTP_SCAN_HPP_
|
||||
#define _HTTP_SCAN_HPP_
|
||||
#ifndef _COMMON_BLOCK_HPP_
|
||||
#include <common/block.hpp>
|
||||
#endif
|
||||
#ifndef _HTTP_EMIT_HPP_
|
||||
#include <http/emit.hpp>
|
||||
#endif
|
||||
#ifndef _HTTP_SYMBOL_HPP_
|
||||
#include <http/symbol.hpp>
|
||||
#endif
|
||||
#ifndef _HTTP_TABLE_HPP_
|
||||
#include <http/table.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_OPENFILE_HPP_
|
||||
#include <common/openfile.hpp>
|
||||
#endif
|
||||
|
||||
class Scan : public Emit
|
||||
{
|
||||
public:
|
||||
enum ScanSymbols{leftangle1,rightangle1,forwardslash1,ampersand1,semicolon1,space1,
|
||||
colon1,leftparen1,rightparen1,exclamation1,minus1,pound1,literal1,name1,
|
||||
equal1,newline1,numeral1,endtext1,unknown1,stop1};
|
||||
Scan(PureViewOfFile &srcView,PureViewOfFile &dstView,Table &symbolTable,WORD allowUserSymbols=TRUE);
|
||||
virtual ~Scan();
|
||||
void analyze(void);
|
||||
private:
|
||||
enum {SpaceChar=32,TabChar=9,LineFeed=10};
|
||||
void readch(void);
|
||||
void skipSeparators(void);
|
||||
void scanNewLine(void);
|
||||
void scanNumeral(void);
|
||||
void scanWord(void);
|
||||
void scanLiteral(void);
|
||||
void scanLeftAngle(void);
|
||||
void scanRightAngle(void);
|
||||
void scanForwardSlash(void);
|
||||
void scanAmpersand(void);
|
||||
void scanSemicolon(void);
|
||||
void scanPound(void);
|
||||
void scanExclamation(void);
|
||||
void scanMinus(void);
|
||||
void scanEqual(void);
|
||||
void scanColon(void);
|
||||
void scanSpace(void);
|
||||
void scanRightParen(void);
|
||||
void scanLeftParen(void);
|
||||
void scanUnknown(void);
|
||||
|
||||
WORD mUserSymbols;
|
||||
Table &mSymbolTable;
|
||||
FileHandle mLogFile;
|
||||
int mChar;
|
||||
};
|
||||
|
||||
inline
|
||||
void Scan::readch(void)
|
||||
{
|
||||
mChar=read();
|
||||
}
|
||||
#endif
|
||||
126
http/HOLD/SYMBOL.HPP
Normal file
126
http/HOLD/SYMBOL.HPP
Normal file
@@ -0,0 +1,126 @@
|
||||
#ifndef _HTTP_SYMBOL_HPP_
|
||||
#define _HTTP_SYMBOL_HPP_
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
|
||||
class Symbol
|
||||
{
|
||||
public:
|
||||
enum SymbolType{AssignedSymbol,ConstantSymbol,SystemSymbol,
|
||||
CommandSymbol,UserSymbol,UnknownSymbol};
|
||||
Symbol(void);
|
||||
Symbol(const Symbol &someSymbol);
|
||||
Symbol(const String &symbolString,int identifier,SymbolType symbolType);
|
||||
virtual ~Symbol();
|
||||
Symbol &operator=(const Symbol &someSymbol);
|
||||
int operator==(const Symbol &someSymbol)const;
|
||||
int operator==(const String &symbolString)const;
|
||||
String symbolName(void)const;
|
||||
void symbolName(const String &symbolName);
|
||||
int identifier(void)const;
|
||||
void identifier(int identifier);
|
||||
SymbolType symbolType(void)const;
|
||||
void symbolType(SymbolType symbolType);
|
||||
void symbolValue(double symbolValue);
|
||||
double symbolValue(void)const;
|
||||
private:
|
||||
String mSymbolName;
|
||||
int mIdentifier;
|
||||
SymbolType mSymbolType;
|
||||
double mSymbolValue;
|
||||
};
|
||||
|
||||
inline
|
||||
Symbol::Symbol(void)
|
||||
: mIdentifier(0), mSymbolType(UnknownSymbol), mSymbolValue(0.00)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
Symbol::Symbol(const Symbol &someSymbol)
|
||||
{
|
||||
*this=someSymbol;
|
||||
}
|
||||
|
||||
inline
|
||||
Symbol::Symbol(const String &symbolString,int identifier,SymbolType symbolType)
|
||||
: mSymbolName(symbolString), mSymbolType(symbolType), mIdentifier(identifier)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
Symbol::~Symbol()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
int Symbol::operator==(const Symbol &someSymbol)const
|
||||
{
|
||||
return (mSymbolName==someSymbol.mSymbolName);
|
||||
}
|
||||
|
||||
inline
|
||||
int Symbol::operator==(const String &symbolName)const
|
||||
{
|
||||
return (mSymbolName==symbolName);
|
||||
}
|
||||
|
||||
inline
|
||||
Symbol &Symbol::operator=(const Symbol &someSymbol)
|
||||
{
|
||||
symbolName(someSymbol.symbolName());
|
||||
identifier(someSymbol.identifier());
|
||||
symbolType(someSymbol.symbolType());
|
||||
symbolValue(someSymbol.symbolValue());
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
String Symbol::symbolName(void)const
|
||||
{
|
||||
return mSymbolName;
|
||||
}
|
||||
|
||||
inline
|
||||
void Symbol::symbolName(const String &symbolName)
|
||||
{
|
||||
mSymbolName=symbolName;
|
||||
}
|
||||
|
||||
inline
|
||||
Symbol::SymbolType Symbol::symbolType(void)const
|
||||
{
|
||||
return mSymbolType;
|
||||
}
|
||||
|
||||
inline
|
||||
void Symbol::symbolType(SymbolType symbolType)
|
||||
{
|
||||
mSymbolType=symbolType;
|
||||
}
|
||||
|
||||
inline
|
||||
int Symbol::identifier(void)const
|
||||
{
|
||||
return mIdentifier;
|
||||
}
|
||||
|
||||
inline
|
||||
void Symbol::identifier(int identifier)
|
||||
{
|
||||
mIdentifier=identifier;
|
||||
}
|
||||
|
||||
inline
|
||||
void Symbol::symbolValue(double symbolValue)
|
||||
{
|
||||
mSymbolValue=symbolValue;
|
||||
}
|
||||
|
||||
inline
|
||||
double Symbol::symbolValue(void)const
|
||||
{
|
||||
return mSymbolValue;
|
||||
}
|
||||
#endif
|
||||
32
http/HOLD/TABLE.CPP
Normal file
32
http/HOLD/TABLE.CPP
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <http/table.hpp>
|
||||
|
||||
WORD Table::locateSymbolString(String &symbolString,int &tableIndex)
|
||||
{
|
||||
size_t numSymbols((size_t)size());
|
||||
|
||||
for(int index=0;index<numSymbols;index++)
|
||||
{
|
||||
if(operator[](index)==symbolString)
|
||||
{
|
||||
tableIndex=index;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
WORD Table::locateSymbolIdentifier(int symbolIdentifier,int &tableIndex)
|
||||
{
|
||||
size_t numSymbols((size_t)size());
|
||||
|
||||
for(int index=0;index<numSymbols;index++)
|
||||
{
|
||||
if(operator[](index).identifier()==symbolIdentifier)
|
||||
{
|
||||
tableIndex=index;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
29
http/HOLD/TABLE.HPP
Normal file
29
http/HOLD/TABLE.HPP
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef _HTTP_TABLE_HPP_
|
||||
#define _HTTP_TABLE_HPP_
|
||||
#ifndef _COMMON_BLOCK_HPP_
|
||||
#include <common/block.hpp>
|
||||
#endif
|
||||
#ifndef _HTTP_SYMBOL_HPP_
|
||||
#include <http/symbol.hpp>
|
||||
#endif
|
||||
|
||||
class Table : public Block<Symbol>
|
||||
{
|
||||
public:
|
||||
Table(void);
|
||||
virtual ~Table();
|
||||
WORD locateSymbolString(String &symbolString,int &tableIndex);
|
||||
WORD locateSymbolIdentifier(int identifier,int &tableIndex);
|
||||
private:
|
||||
};
|
||||
|
||||
inline
|
||||
Table::Table(void)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
Table::~Table()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user