ot_resrv.cpp

来自「在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己」· C++ 代码 · 共 797 行 · 第 1/4 页

CPP
797
字号
	{_S("NDA"),KOplAllTargets,TUint8(TOplToken::EEndA&0xff),TUint8(TOplToken::EEndA>>8),0},
	{_S("NDIF"),KOplAllTargets,TUint8(TOplToken::EEndIf&0xff),TUint8(TOplToken::EEndIf>>8),0},
	{_S("NDP"),KOplAllTargets,TUint8(TOplToken::EEndP&0xff),TUint8(TOplToken::EEndP>>8),0},
	{_S("NDV"),KOplAllTargets,TUint8(TOplToken::EEndV&0xff),TUint8(TOplToken::EEndV>>8),0},
	{_S("NDWH"),KOplAllTargets,TUint8(TOplToken::EEndWh&0xff),TUint8(TOplToken::EEndWh>>8),0},
	{_S("XT"),KOplOpl1993Only,TUint8(TOplToken::EExt&0xff),TUint8(TOplToken::EExt>>8),0},
	{_S("XTERNAL"),KOplNotOpl1993,TUint8(TOplToken::EExternal&0xff),TUint8(TOplToken::EExternal>>8),0}
	};
static const TReservedLookup reservedFTable[]=
	{
	{_S("LAGS"),KOplNotOpl1993,TUint8(TOplToken::EFlags&0xff),TUint8(TOplToken::EFlags>>8),0}
	};
static const TReservedLookup reservedGTable[]=
	{
	{_S("LOBAL"),KOplAllTargets,TUint8(TOplToken::EGlobal&0xff),TUint8(TOplToken::EGlobal>>8),0}
	};
static const TReservedLookup reservedITable[]=
	{
	{_S("CON"),KOplAllTargets,TUint8(TOplToken::EIcon&0xff),TUint8(TOplToken::EIcon>>8),0},
	{_S("F"),KOplAllTargets,TUint8(TOplToken::EIf&0xff),TUint8(TOplToken::EIf>>8),0},
	{_S("NCLUDE"),KOplNotOpl1993,TUint8(TOplToken::EInclude&0xff),TUint8(TOplToken::EInclude>>8),0}
	};
static const TReservedLookup reservedLTable[]=
	{
	{_S("OCAL"),KOplAllTargets,TUint8(TOplToken::ELocal&0xff),TUint8(TOplToken::ELocal>>8),0}
	};
static const TReservedLookup reservedMTable[]=
	{
	{_S("IME"),KOplNotOpl1993,TUint8(TOplToken::EMime&0xff),TUint8(TOplToken::EMime>>8),0}
	};
static const TReservedLookup reservedNTable[]=
	{
	{_S("OT"),KOplAllTargets,TUint8(TOplToken::ENot&0xff),TUint8(TOplToken::ENot>>8),0}
	};
static const TReservedLookup reservedOTable[]=
	{
	{_S("R"),KOplAllTargets,TUint8(TOplToken::EOr&0xff),TUint8(TOplToken::EOr>>8),0},
	{_S("N"),KOplAllTargets,TUint8(TOplToken::EOn&0xff),TUint8(TOplToken::EOn>>8),0},
	{_S("PX"),KOplNotOpl1993,TUint8(TOplToken::EOpx&0xff),TUint8(TOplToken::EOpx>>8),0}
	};
static const TReservedLookup reservedPTable[]=
	{
	{_S("ATH"),KOplOpl1993Only,TUint8(TOplToken::EPath&0xff),TUint8(TOplToken::EPath>>8),0},
	{_S("ROC"),KOplAllTargets,TUint8(TOplToken::EProc&0xff),TUint8(TOplToken::EProc>>8),0}
	};
static const TReservedLookup reservedRTable[]=
	{
	{_S("EM"),KOplAllTargets,TUint8(TOplToken::EEos&0xff),TUint8(TOplToken::EEos>>8),0}
	};
static const TReservedLookup reservedTTable[]=
	{
	{_S("YPE"),KOplOpl1993Only,TUint8(TOplToken::EType&0xff),TUint8(TOplToken::EType>>8),0}
	};
static const TReservedLookup reservedUTable[]=
	{
	{_S("NTIL"),KOplAllTargets,TUint8(TOplToken::EUntil&0xff),TUint8(TOplToken::EUntil>>8),0}
	};
static const TReservedLookup reservedVTable[]=
	{
	{_S("ECTOR"),KOplAllTargets,TUint8(TOplToken::EVector&0xff),TUint8(TOplToken::EVector>>8),0}
	};
static const TReservedLookup reservedWTable[]=
	{
	{_S("HILE"),KOplAllTargets,TUint8(TOplToken::EWhile&0xff),TUint8(TOplToken::EWhile>>8),0}
	};
/////////////////////////////////////////////////////////////////////////
//
// The root table. One entry per latter of the latin alphabet.
//
/////////////////////////////////////////////////////////////////////////
struct TInitialLetterTableEntry
	{
	const TFunctionLookup *iFunctions;
	TInt iFunctionsCount;
	const TKeywordLookup *iKeywords;
	TInt iKeywordsCount;
	const TReservedLookup *iReserved;
	TInt iReservedCount;
	};

const TInt KAlphabetTableSize=25; // One for each letter of the latin alphabet, except Z for there are no Z's
static const TInitialLetterTableEntry reservedLookupTable[KAlphabetTableSize]=
	{
	{functionATable, sizeof(functionATable)/sizeof(TFunctionLookup),keywordATable, sizeof(keywordATable)/sizeof(TKeywordLookup),reservedATable, sizeof(reservedATable)/sizeof(TReservedLookup)},
	{functionBTable, sizeof(functionBTable)/sizeof(TFunctionLookup),keywordBTable, sizeof(keywordBTable)/sizeof(TKeywordLookup),reservedBTable, sizeof(reservedBTable)/sizeof(TReservedLookup)},
	{functionCTable, sizeof(functionCTable)/sizeof(TFunctionLookup),keywordCTable, sizeof(keywordCTable)/sizeof(TKeywordLookup),reservedCTable, sizeof(reservedCTable)/sizeof(TReservedLookup)},
	{functionDTable, sizeof(functionDTable)/sizeof(TFunctionLookup),keywordDTable, sizeof(keywordDTable)/sizeof(TKeywordLookup),reservedDTable, sizeof(reservedDTable)/sizeof(TReservedLookup)},
	{functionETable, sizeof(functionETable)/sizeof(TFunctionLookup),keywordETable, sizeof(keywordETable)/sizeof(TKeywordLookup),reservedETable, sizeof(reservedETable)/sizeof(TReservedLookup)},
	{functionFTable, sizeof(functionFTable)/sizeof(TFunctionLookup),keywordFTable, sizeof(keywordFTable)/sizeof(TKeywordLookup),reservedFTable, sizeof(reservedFTable)/sizeof(TReservedLookup)},
	{functionGTable, sizeof(functionGTable)/sizeof(TFunctionLookup),keywordGTable, sizeof(keywordGTable)/sizeof(TKeywordLookup),reservedGTable, sizeof(reservedGTable)/sizeof(TReservedLookup)},
	{functionHTable, sizeof(functionHTable)/sizeof(TFunctionLookup),         NULL,                                            0,          NULL,                                              0},
	{functionITable, sizeof(functionITable)/sizeof(TFunctionLookup),keywordITable, sizeof(keywordITable)/sizeof(TKeywordLookup),reservedITable, sizeof(reservedITable)/sizeof(TReservedLookup)},
	{          NULL,                                              0,         NULL,                                            0,          NULL,                                              0},
	{functionKTable, sizeof(functionKTable)/sizeof(TFunctionLookup),keywordKTable, sizeof(keywordKTable)/sizeof(TKeywordLookup),          NULL,                                              0},
	{functionLTable, sizeof(functionLTable)/sizeof(TFunctionLookup),keywordLTable, sizeof(keywordLTable)/sizeof(TKeywordLookup),reservedLTable, sizeof(reservedLTable)/sizeof(TReservedLookup)},
	{functionMTable, sizeof(functionMTable)/sizeof(TFunctionLookup),keywordMTable, sizeof(keywordMTable)/sizeof(TKeywordLookup),reservedMTable, sizeof(reservedMTable)/sizeof(TReservedLookup)},
	{functionNTable, sizeof(functionNTable)/sizeof(TFunctionLookup),keywordNTable, sizeof(keywordNTable)/sizeof(TKeywordLookup),reservedNTable, sizeof(reservedNTable)/sizeof(TReservedLookup)},
	{functionOTable, sizeof(functionOTable)/sizeof(TFunctionLookup),keywordOTable, sizeof(keywordOTable)/sizeof(TKeywordLookup),reservedOTable, sizeof(reservedOTable)/sizeof(TReservedLookup)},
	{functionPTable, sizeof(functionPTable)/sizeof(TFunctionLookup),keywordPTable, sizeof(keywordPTable)/sizeof(TKeywordLookup),reservedPTable, sizeof(reservedPTable)/sizeof(TReservedLookup)},
	{          NULL,                                              0,         NULL,                                            0,          NULL,                                              0},
	{functionRTable, sizeof(functionRTable)/sizeof(TFunctionLookup),keywordRTable, sizeof(keywordRTable)/sizeof(TKeywordLookup),reservedRTable, sizeof(reservedRTable)/sizeof(TReservedLookup)},
	{functionSTable, sizeof(functionSTable)/sizeof(TFunctionLookup),keywordSTable, sizeof(keywordSTable)/sizeof(TKeywordLookup),          NULL,                                              0},
	{functionTTable, sizeof(functionTTable)/sizeof(TFunctionLookup),keywordTTable, sizeof(keywordTTable)/sizeof(TKeywordLookup),reservedTTable, sizeof(reservedTTable)/sizeof(TReservedLookup)},
	{functionUTable, sizeof(functionUTable)/sizeof(TFunctionLookup),keywordUTable, sizeof(keywordUTable)/sizeof(TKeywordLookup),reservedUTable, sizeof(reservedUTable)/sizeof(TReservedLookup)},
	{functionVTable, sizeof(functionVTable)/sizeof(TFunctionLookup),         NULL,                                            0,reservedVTable, sizeof(reservedVTable)/sizeof(TReservedLookup)},
	{functionWTable, sizeof(functionWTable)/sizeof(TFunctionLookup),         NULL,                                            0,reservedWTable, sizeof(reservedWTable)/sizeof(TReservedLookup)},
	{          NULL,                                              0,         NULL,                                            0,          NULL,                                              0},
	{functionYTable, sizeof(functionYTable)/sizeof(TFunctionLookup),         NULL,                                            0,          NULL,                                              0}
    };


/////////////////////////////////////////////////////////////////////////
//
// COplLexBase - Code to lookup reserved words.
//
/////////////////////////////////////////////////////////////////////////


TBool COplLexerBase::IsReserved()
//
// Checks to see if the parsed string is reserved
// FOR NOW 
	{

	TUint index=iText[0]-'A';
	if (index>=(TUint)KAlphabetTableSize)
		return EFalse;

	TPtrC end=iText.Mid(1); // Take the remains after the first letter
	const TInitialLetterTableEntry& tables=reservedLookupTable[index];

    TBool isReserved=EFalse;
	// Functions first
		{
		const TFunctionLookup *pF=tables.iFunctions;
		const TFunctionLookup *pFe=pF+tables.iFunctionsCount;
		while (pF<pFe)
			{
			if (((TLookupHeader *)pF)->Matches(iTarget,end)) // See comment by TFunctionHeader
				{
				isReserved=ETrue;
				iToken=TOplToken::EFunction;
				iType=pF->ReturnType();
				new(iFunction) TOplFunction(pF->Number());
				TOplSignature& signature=((TOplFunction *)iFunction)->Signature();
				signature.Initialize(iType);
				if (!pF->IsStatistical()) // Need to add the argument types
					{
					for (TInt argCount=0;;argCount++)
						{
						if (pF->IsAllowedCount(argCount))
							signature.AllowArgumentCount(argCount);

						TOplSignature::TArgType type=pF->Arg(argCount);
						if (type==TOplSignature::EArgBadType)
							break;
						signature.AddArgument(argCount,type);
						}
					}
				break;
				}
			pF++;
			}
		}
	if (!isReserved)
		{
		const TKeywordLookup *pK=tables.iKeywords;
		const TKeywordLookup *pKe=pK+tables.iKeywordsCount;
		while (pK<pKe)
			{
			if (((TLookupHeader *)pK)->Matches(iTarget,end))
				{
				isReserved=ETrue;
				iToken=TOplToken::EKeywordToken;
				new(iKeyword) TOplKeyword(pK->Trappable(),pK->Code());
				break;
				}
			pK++;
			}
		}
	if (!isReserved)
		{
		const TReservedLookup *pR=tables.iReserved;
		const TReservedLookup *pRe=pR+tables.iReservedCount;
		while (pR<pRe)
			{
			if (((TLookupHeader *)pR)->Matches(iTarget,end))
				{
				isReserved=ETrue;
				iToken=pR->Token();
				break;
				}
			pR++;
			}
		}
	return isReserved;
	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?