本文整理汇总了C++中LexGetToken函数的典型用法代码示例。如果您正苦于以下问题:C++ LexGetToken函数的具体用法?C++ LexGetToken怎么用?C++ LexGetToken使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LexGetToken函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParserCopy
/* parse a type - the part at the end after the identifier. eg. array specifications etc. */
struct ValueType *TypeParseBack(struct ParseState *Parser, struct ValueType *FromType)
{
enum LexToken Token;
struct ParseState Before;
ParserCopy(&Before, Parser);
Token = LexGetToken(Parser, NULL, TRUE);
if (Token == TokenLeftSquareBracket)
{
/* add another array bound */
enum RunMode OldMode = Parser->Mode;
int ArraySize;
Parser->Mode = RunModeRun;
ArraySize = ExpressionParseInt(Parser);
Parser->Mode = OldMode;
if (LexGetToken(Parser, NULL, TRUE) != TokenRightSquareBracket)
ProgramFail(Parser, "']' expected");
return TypeGetMatching(Parser, TypeParseBack(Parser, FromType), TypeArray, ArraySize, StrEmpty, TRUE);
}
else
{
/* the type specification has finished */
ParserCopy(Parser, &Before);
return FromType;
}
}
示例2: TypeParseFront
/* parse a type - just the basic type */
int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ, int *IsStatic){
struct ParseState Before;
struct Value *LexerValue;
enum LexToken Token;
int Unsigned = FALSE;
struct Value *VarValue;
int StaticQualifier = FALSE;
Picoc *pc = Parser->pc;
*Typ = NULL;
/* ignore leading type qualifiers */
ParserCopy(&Before, Parser);
Token = LexGetToken(Parser, &LexerValue, TRUE);
while (Token == TokenStaticType || Token == TokenAutoType || Token == TokenRegisterType || Token == TokenExternType){
if (Token == TokenStaticType) StaticQualifier = TRUE;
Token = LexGetToken(Parser, &LexerValue, TRUE);
}
if (IsStatic != NULL) *IsStatic = StaticQualifier;
/* handle signed/unsigned with no trailing type */
if (Token == TokenSignedType || Token == TokenUnsignedType || Token == TokenLongType){
enum LexToken FollowToken = LexGetToken(Parser, &LexerValue, FALSE);
Unsigned = (Token == TokenUnsignedType);
if (FollowToken != TokenIntType && FollowToken != TokenLongType && FollowToken != TokenShortType && FollowToken != TokenCharType){
if (Token == TokenUnsignedType) *Typ = &pc->UnsignedIntType;
else if (Token == TokenLongType){
if ( FollowToken == TokenDoubleType) *Typ = &pc->FP128Type;
else *Typ = &pc->LongType;
}
else *Typ = &pc->IntType;
return TRUE;
}
Token = LexGetToken(Parser, &LexerValue, TRUE);
}
switch (Token){
case TokenIntType: *Typ = Unsigned ? &pc->UnsignedIntType : &pc->IntType; break;
case TokenShortType: *Typ = Unsigned ? &pc->UnsignedShortType : &pc->ShortType; break;
case TokenCharType: *Typ = Unsigned ? &pc->UnsignedCharType : &pc->CharType; break;
case TokenLongType: *Typ = Unsigned ? &pc->UnsignedLongType : &pc->LongType; break;
#ifndef NO_FP
case TokenFloatType: *Typ = &pc->FP32Type;break;
case TokenDoubleType: *Typ = &pc->FP64Type; break;
case TokenLongDoubleType: *Typ = &pc->FP128Type;break;
#endif
case TokenVoidType: *Typ = &pc->VoidType; break;
case TokenStructType: case TokenUnionType:
if (*Typ != NULL) ProgramFail(Parser, "bad type declaration");
TypeParseStruct(Parser, Typ, Token == TokenStructType);
break;
case TokenEnumType:
if (*Typ != NULL) ProgramFail(Parser, "bad type declaration");
TypeParseEnum(Parser, Typ);
break;
case TokenIdentifier:
/* we already know it's a typedef-defined type because we got here */
VariableGet(pc, Parser, LexerValue->Val->Identifier, &VarValue);
*Typ = VarValue->Val->Typ;
break;
default: ParserCopy(Parser, &Before); return FALSE;
}
return TRUE;
}
示例3: ParseBlock
/* parse a block of code and return what mode it returned in */
enum RunMode ParseBlock(struct ParseState *Parser, int AbsorbOpenBrace, int Condition)
{
int PrevScopeID = 0, ScopeID = VariableScopeBegin(Parser, &PrevScopeID);
if (AbsorbOpenBrace && LexGetToken(Parser, NULL, TRUE) != TokenLeftBrace)
ProgramFail(Parser, "'{' expected");
if (Parser->Mode == RunModeSkip || !Condition)
{
/* condition failed - skip this block instead */
enum RunMode OldMode = Parser->Mode;
Parser->Mode = RunModeSkip;
while (ParseStatement(Parser, TRUE) == ParseResultOk)
{}
Parser->Mode = OldMode;
}
else
{
/* just run it in its current mode */
while (ParseStatement(Parser, TRUE) == ParseResultOk)
{}
}
if (LexGetToken(Parser, NULL, TRUE) != TokenRightBrace)
ProgramFail(Parser, "'}' expected");
VariableScopeEnd(Parser, ScopeID, PrevScopeID);
return Parser->Mode;
}
示例4: ParseDeclarationAssignment
/* assign an initial value to a variable */
void ParseDeclarationAssignment(struct ParseState *Parser, struct Value *NewVariable, int DoAssignment)
{
struct Value *CValue;
int ArrayIndex;
enum LexToken Token = TokenComma;
if (LexGetToken(Parser, NULL, FALSE) == TokenLeftBrace)
{
/* this is an array initialiser */
LexGetToken(Parser, NULL, TRUE);
for (ArrayIndex = 0; (Parser->Mode != RunModeRun && Token == TokenComma) || (Parser->Mode == RunModeRun && ArrayIndex < NewVariable->Typ->ArraySize); ArrayIndex++)
{
struct Value *ArrayElement = NULL;
if (Token != TokenComma)
ProgramFail(Parser, "comma expected");
if (Parser->Mode == RunModeRun)
ArrayElement = VariableAllocValueFromExistingData(Parser, NewVariable->Typ->FromType, (union AnyValue *)(&NewVariable->Val->ArrayMem[0] + TypeSize(NewVariable->Typ->FromType, 0, TRUE) * ArrayIndex), TRUE, NewVariable);
if (!ExpressionParse(Parser, &CValue))
ProgramFail(Parser, "expression expected");
if (Parser->Mode == RunModeRun && DoAssignment)
{
ExpressionAssign(Parser, ArrayElement, CValue, FALSE, NULL, 0, FALSE);
VariableStackPop(Parser, CValue);
VariableStackPop(Parser, ArrayElement);
}
Token = LexGetToken(Parser, NULL, TRUE);
}
if (Token == TokenComma)
Token = LexGetToken(Parser, NULL, TRUE);
if (Token != TokenRightBrace)
ProgramFail(Parser, "'}' expected");
}
else
{
/* this is a normal expression initialiser */
if (!ExpressionParse(Parser, &CValue))
ProgramFail(Parser, "expression expected");
if (Parser->Mode == RunModeRun && DoAssignment)
{
ExpressionAssign(Parser, NewVariable, CValue, FALSE, NULL, 0, FALSE);
VariableStackPop(Parser, CValue);
}
}
}
示例5: TypeParseIdentPart
/* parse a type - the part which is repeated with each identifier in a declaration list */
void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, struct ValueType **Typ, char **Identifier)
{
struct ParseState Before;
enum LexToken Token;
struct Value *LexValue;
int Done = FALSE;
*Typ = BasicTyp;
*Identifier = StrEmpty;
while (!Done)
{
ParserCopy(&Before, Parser);
Token = LexGetToken(Parser, &LexValue, TRUE);
switch (Token)
{
case TokenOpenBracket:
if (*Typ != NULL)
ProgramFail(Parser, "bad type declaration");
TypeParse(Parser, Typ, Identifier, NULL);
if (LexGetToken(Parser, NULL, TRUE) != TokenCloseBracket)
ProgramFail(Parser, "')' expected");
break;
case TokenAsterisk:
if (*Typ == NULL)
ProgramFail(Parser, "bad type declaration");
*Typ = TypeGetMatching(Parser, *Typ, TypePointer, 0, StrEmpty, TRUE);
break;
case TokenIdentifier:
if (*Typ == NULL || *Identifier != StrEmpty)
ProgramFail(Parser, "bad type declaration");
*Identifier = LexValue->Val->Identifier;
Done = TRUE;
break;
default: ParserCopy(Parser, &Before); Done = TRUE; break;
}
}
if (*Typ == NULL)
ProgramFail(Parser, "bad type declaration");
if (*Identifier != StrEmpty)
{
/* parse stuff after the identifier */
*Typ = TypeParseBack(Parser, *Typ);
}
}
示例6: ParseDeclaration
/* declare a variable or function */
int ParseDeclaration(struct ParseState *Parser, enum LexToken Token)
{
char *Identifier;
struct ValueType *BasicType;
struct ValueType *Typ;
struct Value *NewVariable = NULL;
int IsStatic = FALSE;
int FirstVisit = FALSE;
Picoc *pc = Parser->pc;
TypeParseFront(Parser, &BasicType, &IsStatic);
do
{
TypeParseIdentPart(Parser, BasicType, &Typ, &Identifier);
if ((Token != TokenVoidType && Token != TokenStructType && Token != TokenUnionType && Token != TokenEnumType) && Identifier == pc->StrEmpty)
ProgramFail(Parser, "identifier expected");
if (Identifier != pc->StrEmpty)
{
/* handle function definitions */
if (LexGetToken(Parser, NULL, FALSE) == TokenOpenBracket)
{
ParseFunctionDefinition(Parser, Typ, Identifier);
return FALSE;
}
else
{
if (Typ == &pc->VoidType && Identifier != pc->StrEmpty)
ProgramFail(Parser, "can't define a void variable");
if (Parser->Mode == RunModeRun || Parser->Mode == RunModeGoto)
NewVariable = VariableDefineButIgnoreIdentical(Parser, Identifier, Typ, IsStatic, &FirstVisit);
if (LexGetToken(Parser, NULL, FALSE) == TokenAssign)
{
/* we're assigning an initial value */
LexGetToken(Parser, NULL, TRUE);
ParseDeclarationAssignment(Parser, NewVariable, !IsStatic || FirstVisit);
}
}
}
Token = LexGetToken(Parser, NULL, FALSE);
if (Token == TokenComma)
LexGetToken(Parser, NULL, TRUE);
} while (Token == TokenComma);
return TRUE;
}
示例7: ReadMacro
static OBJECT ReadMacro(OBJECT *token, OBJECT curr_encl, OBJECT encl)
{ OBJECT t, res;
/* find macro name and insert into symbol table */
SuppressScope();
Dispose(*token); t = LexGetToken();
if( !is_word(type(t)) )
{ Error(5, 24, "%s ignored (name is missing)", WARN, &fpos(t), KW_MACRO);
debug1(ANY, D, "offending type is %s", Image(type(t)));
UnSuppressScope();
*token = t;
return nilobj;
}
res = InsertSym(string(t), MACRO, &fpos(t), 0, FALSE,TRUE,0,curr_encl,nilobj);
if( curr_encl != encl ) visible(res) = TRUE;
UnSuppressScope();
/* find alternative names for this symbol */
Dispose(t); t = LexGetToken();
while( is_word(type(t)) )
{
InsertAlternativeName(string(t), res, &fpos(t));
Dispose(t); t = LexGetToken();
}
/* find opening left brace */
if( type(t) != LBR )
{ Error(5, 25, "%s ignored (opening %s is missing)",
WARN, &fpos(t), KW_MACRO, KW_LBR);
*token = t;
return nilobj;
}
/* read macro body */
ReadTokenList(t, res);
Dispose(t);
/* clean up (kill final RBR, dispose macro name) and exit */
t = pred(sym_body(res), PARENT);
sym_body(res) = Delete(t, PARENT);
Dispose(t);
recursive(res) = FALSE;
*token = nilobj;
return res;
} /* end ReadMacro */
示例8: ParseCountParams
/* count the number of parameters to a function or macro */
int ParseCountParams(struct ParseState *Parser)
{
int ParamCount = 0;
enum LexToken Token = LexGetToken(Parser, NULL, TRUE);
if (Token != TokenCloseBracket && Token != TokenEOF)
{
/* count the number of parameters */
ParamCount++;
while ((Token = LexGetToken(Parser, NULL, TRUE)) != TokenCloseBracket && Token != TokenEOF)
{
if (Token == TokenComma)
ParamCount++;
}
}
return ParamCount;
}
示例9: ReadLangDef
static void ReadLangDef(OBJECT encl)
{ OBJECT t, names, inside;
New(names, ACAT);
t = LexGetToken();
while( is_word(type(t)) )
{ Link(names, t);
t = LexGetToken();
}
if( type(t) != LBR )
{ Error(5, 4, "expected opening %s of langdef here", WARN, &fpos(t), KW_LBR);
Dispose(t);
return;
}
inside = Parse(&t, encl, FALSE, FALSE);
inside = ReplaceWithTidy(inside, ACAT_TIDY);
LanguageDefine(names, inside);
return;
} /* end ReadLangDef */
示例10: ReadDatabaseDef
void ReadDatabaseDef(unsigned typ, OBJECT encl)
{ OBJECT symbs, t, fname;
New(symbs, ACAT);
t = LexGetToken();
while( type(t)==CLOSURE || (type(t)==WORD && string(t)[0]==CH_SYMSTART) )
{ if( type(t) == CLOSURE )
{ Link(symbs, t);
}
else
{ Error(5, 7, "unknown or misspelt symbol %s", WARN, &fpos(t), string(t));
Dispose(t);
}
t = LexGetToken();
}
if( type(t) != LBR )
{ Error(5, 8, "symbol name or %s expected here (%s declaration)",
WARN, &fpos(t), KW_LBR, KW_DATABASE);
Dispose(t);
return;
}
if( Down(symbs) == symbs )
{ Error(5, 9, "symbol names missing in %s declaration",
WARN, &fpos(t), KW_DATABASE);
}
fname = Parse(&t, encl, FALSE, FALSE);
fname = ReplaceWithTidy(fname, ACAT_TIDY);
if( !is_word(type(fname)) )
{ Error(5, 10, "name of %s file expected here", WARN, &fpos(fname),
KW_DATABASE);
DisposeObject(fname);
return;
}
if( StringEndsWith(string(fname), DATA_SUFFIX) )
{ Error(5, 47, "%s suffix should be omitted in %s clause", WARN,
&fpos(fname), DATA_SUFFIX, KW_DATABASE);
DisposeObject(fname);
return;
}
if( Down(symbs) != symbs )
(void) DbLoad(fname, typ == DATABASE ? DATABASE_PATH : SYSDATABASE_PATH,
TRUE, symbs, InMemoryDbIndexes);
} /* end ReadDatabaseDef */
示例11: ParseDeclarationAssignment
/* assign an initial value to a variable */
void ParseDeclarationAssignment(struct ParseState *Parser, struct Value *NewVariable, int DoAssignment)
{
struct Value *CValue;
if (LexGetToken(Parser, NULL, FALSE) == TokenLeftBrace)
{
/* this is an array initialiser */
LexGetToken(Parser, NULL, TRUE);
ParseArrayInitialiser(Parser, NewVariable, DoAssignment);
}
else
{
/* this is a normal expression initialiser */
if (!ExpressionParse(Parser, &CValue))
ProgramFail(Parser, "expression expected");
if (Parser->Mode == RunModeRun && DoAssignment)
{
ExpressionAssign(Parser, NewVariable, CValue, FALSE, NULL, 0, FALSE);
VariableStackPop(Parser, CValue);
}
}
}
示例12: TypeParseEnum
/* parse an enum declaration */
void TypeParseEnum(struct ParseState *Parser, struct ValueType **Typ){
struct Value *LexValue;
struct Value InitValue;
enum LexToken Token;
int EnumValue = 0;
char *EnumIdentifier;
Picoc *pc = Parser->pc;
Token = LexGetToken(Parser, &LexValue, FALSE);
if (Token == TokenIdentifier){
LexGetToken(Parser, &LexValue, TRUE);
EnumIdentifier = LexValue->Val->Identifier;
Token = LexGetToken(Parser, NULL, FALSE);
}
else{
static char TempNameBuf[7] = "^e0000";
EnumIdentifier = PlatformMakeTempName(pc, TempNameBuf);
}
TypeGetMatching(pc, Parser, &pc->UberType, TypeEnum, 0, EnumIdentifier, Token != TokenLeftBrace);
*Typ = &pc->IntType;
if (Token != TokenLeftBrace){
/* use the already defined enum */
if ((*Typ)->Members == NULL)
ProgramFail(Parser, "enum '%s' isn't defined", EnumIdentifier);
return;
}
if (pc->TopStackFrame != NULL) ProgramFail(Parser, "enum definitions can only be globals");
LexGetToken(Parser, NULL, TRUE);
(*Typ)->Members = &pc->GlobalTable;
memset((void *)&InitValue, '\0', sizeof(struct Value));
InitValue.Typ = &pc->IntType;
InitValue.Val = (union AnyValue *)&EnumValue;
do {
if (LexGetToken(Parser, &LexValue, TRUE) != TokenIdentifier)
ProgramFail(Parser, "identifier expected");
EnumIdentifier = LexValue->Val->Identifier;
if (LexGetToken(Parser, NULL, FALSE) == TokenAssign){
LexGetToken(Parser, NULL, TRUE);
EnumValue = ExpressionParseInt(Parser);
}
VariableDefine(pc, Parser, EnumIdentifier, &InitValue, NULL, FALSE);
Token = LexGetToken(Parser, NULL, TRUE);
if (Token != TokenComma && Token != TokenRightBrace)
ProgramFail(Parser, "comma expected");
EnumValue++;
} while (Token == TokenComma);
}
示例13: ReadIncGRepeatedDef
void ReadIncGRepeatedDef(unsigned typ, OBJECT encl)
{ OBJECT t, fname;
t = LexGetToken();
if( type(t) != LBR )
{ Error(5, 5, "left brace expected here in %s declaration",
WARN, &fpos(t), KW_INCG_REPEATED);
Dispose(t);
return;
}
fname = Parse(&t, encl, FALSE, FALSE);
fname = ReplaceWithTidy(fname, ACAT_TIDY);
if( !is_word(type(fname)) )
{ Error(5, 6, "name of %s file expected here", WARN, &fpos(fname),
KW_INCG_REPEATED);
DisposeObject(fname);
return;
}
debug0(DFS, D, " calling PS_IncGRepeated from ReadPrependDef");
incg_type(fname) = (typ == INCG_REPEATED ? INCGRAPHIC : SINCGRAPHIC);
PS_IncGRepeated(fname);
} /* end ReadPrependDef */
示例14: ReadPrependDef
void ReadPrependDef(unsigned typ, OBJECT encl)
{ OBJECT t, fname;
FILE_NUM fnum;
t = LexGetToken();
if( type(t) != LBR )
{ Error(5, 5, "left brace expected here in %s declaration",
WARN, &fpos(t), KW_PREPEND);
Dispose(t);
return;
}
fname = Parse(&t, encl, FALSE, FALSE);
fname = ReplaceWithTidy(fname, ACAT_TIDY);
if( !is_word(type(fname)) )
{ Error(5, 6, "name of %s file expected here", WARN, &fpos(fname),KW_PREPEND);
DisposeObject(fname);
return;
}
debug0(DFS, D, " calling DefineFile from ReadPrependDef");
fnum = FileNum(string(fname), STR_EMPTY);
if( fnum == NO_FILE || FileType(fnum) != PREPEND_FILE )
DefineFile(string(fname), STR_EMPTY, &fpos(fname), PREPEND_FILE,
typ == PREPEND ? INCLUDE_PATH : SYSINCLUDE_PATH);
} /* end ReadPrependDef */
示例15: ParseFor
/* parse a "for" statement */
void ParseFor(struct ParseState *Parser)
{
int Condition;
struct ParseState PreConditional;
struct ParseState PreIncrement;
struct ParseState PreStatement;
struct ParseState After;
if (LexGetToken(Parser, NULL, TRUE) != TokenOpenBracket)
ProgramFail(Parser, "'(' expected");
if (ParseStatement(Parser, TRUE) != ParseResultOk)
ProgramFail(Parser, "statement expected");
ParserCopyPos(&PreConditional, Parser);
if (LexGetToken(Parser, NULL, FALSE) == TokenSemicolon)
Condition = TRUE;
else
Condition = ExpressionParseInt(Parser);
if (LexGetToken(Parser, NULL, TRUE) != TokenSemicolon)
ProgramFail(Parser, "';' expected");
ParserCopyPos(&PreIncrement, Parser);
ParseStatementMaybeRun(Parser, FALSE, FALSE);
if (LexGetToken(Parser, NULL, TRUE) != TokenCloseBracket)
ProgramFail(Parser, "')' expected");
ParserCopyPos(&PreStatement, Parser);
if (ParseStatementMaybeRun(Parser, Condition, TRUE) != ParseResultOk)
ProgramFail(Parser, "statement expected");
if (Parser->Mode == RunModeContinue)
Parser->Mode = RunModeRun;
ParserCopyPos(&After, Parser);
while (Condition && Parser->Mode == RunModeRun)
{
ParserCopyPos(Parser, &PreIncrement);
ParseStatement(Parser, FALSE);
ParserCopyPos(Parser, &PreConditional);
if (LexGetToken(Parser, NULL, FALSE) == TokenSemicolon)
Condition = TRUE;
else
Condition = ExpressionParseInt(Parser);
if (Condition)
{
ParserCopyPos(Parser, &PreStatement);
trace_state_print(Parser);
ParseStatement(Parser, TRUE);
if (Parser->Mode == RunModeContinue)
Parser->Mode = RunModeRun;
}
}
if (Parser->Mode == RunModeBreak)
Parser->Mode = RunModeRun;
ParserCopyPos(Parser, &After);
}