本文整理汇总了C++中LexGetToken函数的典型用法代码示例。如果您正苦于以下问题:C++ LexGetToken函数的具体用法?C++ LexGetToken怎么用?C++ LexGetToken使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LexGetToken函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
}
开发者ID:josegomezr,项目名称:PicoCi,代码行数:29,代码来源:type.c
示例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;
}
开发者ID:gdkar,项目名称:picoc,代码行数:61,代码来源:type.c
示例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;
}
开发者ID:galacticstudios,项目名称:picoc,代码行数:31,代码来源:parse.c
示例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);
}
}
}
开发者ID:nehatj,项目名称:pointers.io,代码行数:54,代码来源:parse.c
示例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);
}
}
开发者ID:josegomezr,项目名称:PicoCi,代码行数:53,代码来源:type.c
示例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;
}
开发者ID:galacticstudios,项目名称:picoc,代码行数:51,代码来源:parse.c
示例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 */
开发者ID:thektulu,项目名称:lout,代码行数:45,代码来源:z05.c
示例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;
}
开发者ID:galacticstudios,项目名称:picoc,代码行数:19,代码来源:parse.c
示例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 */
开发者ID:thektulu,项目名称:lout,代码行数:19,代码来源:z05.c
示例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 */
开发者ID:thektulu,项目名称:lout,代码行数:42,代码来源:z05.c
示例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);
}
}
}
开发者ID:galacticstudios,项目名称:picoc,代码行数:24,代码来源:parse.c
示例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);
}
开发者ID:gdkar,项目名称:picoc,代码行数:47,代码来源:type.c
示例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 */
开发者ID:thektulu,项目名称:lout,代码行数:21,代码来源:z05.c
示例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 */
开发者ID:thektulu,项目名称:lout,代码行数:24,代码来源:z05.c
示例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);
}
开发者ID:nehatj,项目名称:pointers.io,代码行数:66,代码来源:parse.c
示例16: ParseFor
/* parse a "for" statement */
void ParseFor(struct ParseState *Parser)
{
int Condition;
struct ParseState PreConditional;
struct ParseState PreIncrement;
struct ParseState PreStatement;
struct ParseState After;
enum RunMode OldMode = Parser->Mode;
int PrevScopeID = 0, ScopeID = VariableScopeBegin(Parser, &PrevScopeID);
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) != 0;
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 && OldMode == RunModeRun)
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) != 0;
if (Condition)
{
ParserCopyPos(Parser, &PreStatement);
ParseStatement(Parser, TRUE);
if (Parser->Mode == RunModeContinue)
Parser->Mode = RunModeRun;
}
}
if (Parser->Mode == RunModeBreak && OldMode == RunModeRun)
Parser->Mode = RunModeRun;
VariableScopeEnd(Parser, ScopeID, PrevScopeID);
ParserCopyPos(Parser, &After);
}
开发者ID:galacticstudios,项目名称:picoc,代码行数:71,代码来源:parse.c
示例17: ReadDefinitions
void ReadDefinitions(OBJECT *token, OBJECT encl, unsigned char res_type)
{ OBJECT t, res, res_target, export_list, import_list, link, y, z;
OBJECT curr_encl; BOOLEAN compulsory_par, has_import_encl;
t = *token;
while( res_type==LOCAL || is_string(t, KW_NAMED) || is_string(t, KW_IMPORT) )
{
curr_encl = encl;
if( is_string(t, KW_LANGDEF) )
{ ReadLangDef(encl);
t = LexGetToken();
continue; /* next definition */
}
else if( type(t) == PREPEND || type(t) == SYS_PREPEND )
{ ReadPrependDef(type(t), encl);
Dispose(t);
t = LexGetToken();
continue; /* next definition */
}
else if( type(t) == INCG_REPEATED || type(t) == SINCG_REPEATED )
{ ReadIncGRepeatedDef(type(t), encl);
Dispose(t);
t = LexGetToken();
continue; /* next definition */
}
else if( type(t) == DATABASE || type(t) == SYS_DATABASE )
{ ReadDatabaseDef(type(t), encl);
Dispose(t);
t = LexGetToken();
continue; /* next definition */
}
if( !is_string(t, KW_DEF) && !is_string(t, KW_MACRO) &&
!is_string(t, KW_NAMED) && !is_string(t, KW_IMPORT) &&
!is_string(t, KW_EXTEND) && !is_string(t, KW_EXPORT) )
break;
/* get import or extend list and change scope appropriately */
BodyParNotAllowed();
New(import_list, ACAT);
has_import_encl = FALSE;
if( is_string(t, KW_IMPORT) )
{ Dispose(t);
t = LexGetToken();
while( type(t) == CLOSURE ||
(type(t)==WORD && !is_string(t,KW_EXPORT) && !is_string(t,KW_DEF)
&& !is_string(t, KW_MACRO) && !is_string(t, KW_NAMED)) )
{ if( type(t) == CLOSURE )
{ if( type(actual(t)) == LOCAL )
{
/* *** letting this through now
if( res_type == NPAR && has_par(actual(t)) )
{
Error(5, 46, "named parameter import %s has parameters",
WARN, &fpos(t), SymName(actual(t)));
}
else
{
*** */
PushScope(actual(t), FALSE, TRUE);
if( actual(t) == encl ) has_import_encl = TRUE;
Link(import_list, t);
/* ***
}
*** */
}
else
{ Error(5, 26, "import name expected here", WARN, &fpos(t));
Dispose(t);
}
}
else
{ Error(5, 27, "import %s not in scope", WARN, &fpos(t), string(t));
Dispose(t);
}
t = LexGetToken();
}
}
else if( is_string(t, KW_EXTEND) )
{ Dispose(t);
t = LexGetToken();
while( type(t) == CLOSURE ||
(type(t)==WORD && !is_string(t,KW_EXPORT) && !is_string(t,KW_DEF)
&& !is_string(t, KW_MACRO)) )
{ if( type(t) == CLOSURE )
{ if( imports(actual(t)) != nilobj )
{ Error(5, 48, "%s has %s clause, so cannot be extended",
WARN, &fpos(t), SymName(actual(t)), KW_IMPORT);
}
else if( type(actual(t)) == LOCAL )
{ PushScope(actual(t), FALSE, FALSE);
curr_encl = actual(t);
debug1(DRD, D, " curr_encl = %s", SymName(curr_encl));
Link(import_list, t);
}
else
{ Error(5, 28, "%s symbol name expected here",
WARN, &fpos(t), KW_EXTEND);
Dispose(t);
//.........这里部分代码省略.........
开发者ID:thektulu,项目名称:lout,代码行数:101,代码来源:z05.c
示例18: ParseMacroDefinition
/* parse a #define macro definition and store it for later */
void ParseMacroDefinition(struct ParseState *Parser)
{
struct Value *MacroName;
char *MacroNameStr;
struct Value *ParamName;
struct Value *MacroValue;
if (LexGetToken(Parser, &MacroName, TRUE) != TokenIdentifier)
ProgramFail(Parser, "identifier expected");
MacroNameStr = MacroName->Val->Identifier;
if (LexRawPeekToken(Parser) == TokenOpenMacroBracket)
{
/* it's a parameterised macro, read the parameters */
enum LexToken Token = LexGetToken(Parser, NULL, TRUE);
struct ParseState ParamParser;
int NumParams;
int ParamCount = 0;
ParserCopy(&ParamParser, Parser);
NumParams = ParseCountParams(&ParamParser);
MacroValue = VariableAllocValueAndData(Parser->pc, Parser, sizeof(struct MacroDef) + sizeof(const char *) * NumParams, FALSE, NULL, TRUE);
MacroValue->Val->MacroDef.NumParams = NumParams;
MacroValue->Val->MacroDef.ParamName = (char **)((char *)MacroValue->Val + sizeof(struct MacroDef));
Token = LexGetToken(Parser, &ParamName, TRUE);
while (Token == TokenIdentifier)
{
/* store a parameter name */
MacroValue->Val->MacroDef.ParamName[ParamCount++] = ParamName->Val->Identifier;
/* get the trailing comma */
Token = LexGetToken(Parser, NULL, TRUE);
if (Token == TokenComma)
Token = LexGetToken(Parser, &ParamName, TRUE);
else if (Token != TokenCloseBracket)
ProgramFail(Parser, "comma expected");
}
if (Token != TokenCloseBracket)
ProgramFail(Parser, "close bracket expected");
}
else
{
/* allocate a simple unparameterised macro */
MacroValue = VariableAllocValueAndData(Parser->pc, Parser, sizeof(struct MacroDef), FALSE, NULL, TRUE);
MacroValue->Val->MacroDef.NumParams = 0;
}
/* copy the body of the macro to execute later */
ParserCopy(&MacroValue->Val->MacroDef.Body, Parser);
MacroValue->Typ = &Parser->pc->MacroType;
LexToEndOfLine(Parser);
MacroValue->Val->MacroDef.Body.Pos = (unsigned char *) LexCopyTokens(&MacroValue->Val->MacroDef.Body, Parser);
if (!TableSet(Parser->pc, &Parser->pc->GlobalTable, MacroNameStr, MacroValue, (char *)Parser->FileName, Parser->Line, Parser->CharacterPos))
ProgramFail(Parser, "'%s' is already defined", MacroNameStr);
}
开发者ID:galacticstudios,项目名称:picoc,代码行数:62,代码来源:parse.c
示例19: ParseKey
/* Parses a key, checks whether or not it is legal.
* Returns
* 1 if the key is illegal (a nested error message is printed)
* , 0 if succesfull.
*/
static int ParseKey(
LOOK_UP_KEY *k, /* write-only key, if k->t == TEST_NOKEY
* then the end of file is reached
*/
CSF_VS vs) /* value scale */
{
typedef enum STATE { STATE_START, STATE_LOWNUM, STATE_COMMA,
STATE_HIGHNUM, STATE_HIGHTOKEN } STATE;
STATE state = STATE_START;
int t; /* token */
long startLineNr = LexGetLineNr();
while(1)
{
t = LexGetToken();
if (t >= 0 && LexGetLineNr() != startLineNr)
{
if (state == STATE_START) /* parsed empty line */
startLineNr = LexGetLineNr();
else
t = LEX_EOL;
}
switch(state)
{
case STATE_START: switch(t) {
case LEX_NUMBER:
k->t = TEST_ONE;
if (SetNumber(k, TRUE, vs))
return 1;
return 0;
case '[' :
k->t = TEST_GE_INF;
state = STATE_LOWNUM;
break;
case '<' :
k->t = TEST_GT_INF;
state = STATE_LOWNUM;
break;
case 0 :
k->t = TEST_NOKEY;
return 0;
default : return IllegalState(k,t,"$[<");
} break;
case STATE_LOWNUM:
PRECOND(k->t == TEST_GE_INF || k->t == TEST_GT_INF);
switch(t) {
case LEX_NUMBER:
if (SetNumber(k, TRUE, vs))
return 1;
state = STATE_COMMA;
break;
case ',':
k->t = TEST_INF_INF;
state = STATE_HIGHNUM;
break;
default : return IllegalState(k,t,"$,");
} break;
case STATE_COMMA:
if (t != ',')
return IllegalState(k,t,",");
state = STATE_HIGHNUM;
break;
case STATE_HIGHNUM:
POSTCOND(k->t==TEST_GE_INF||k->t==TEST_GT_INF ||k->t==TEST_INF_INF);
switch(t) {
case LEX_NUMBER:
if (SetNumber(k, FALSE, vs))
return 1;
state = STATE_HIGHTOKEN;
if (k->t != TEST_INF_INF && (k->l > k->h) )
{
k->t = TEST_ERROR; // pcrcalc/test69
return RetErrorNested(1,"low value ('%g') of range larger than high value ('%g')", k->l,k->h);
}
break;
case ']':
case '>':
/* already set, by choosing
* intermediate states of k->t
*/
return 0;
default : return IllegalState(k,t,"$]>");
}break;
case STATE_HIGHTOKEN:
POSTCOND(k->t==TEST_GE_INF||k->t==TEST_GT_INF ||k->t==TEST_INF_INF);
switch(t) {
/* inc over enums, that's why particular order */
case ']':
k->t += 3;
return 0;
case '>':
k->t += 6;
return 0;
default : return IllegalState(k,t,"]>");
} break;
} /* eoswitch state */
//.........这里部分代码省略.........
开发者ID:gaoshuai,项目名称:pcraster,代码行数:101,代码来源:readltab.c
示例20: ParseArrayInitialiser
/* parse an array initialiser and assign to a variable */
int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable, int DoAssignment)
{
int ArrayIndex = 0;
enum LexToken Token;
struct Value *CValue;
/* count the number of elements in the array */
if (DoAssignment && Parser->Mode == RunModeRun)
{
struct ParseState CountParser;
int NumElements;
ParserCopy(&CountParser, Parser);
NumElements = ParseArrayInitialiser(&CountParser, NewVariable, FALSE);
if (NewVariable->Typ->Base != TypeArray)
AssignFail(Parser, "%t from array initializer", NewVariable->Typ, NULL, 0, 0, NULL, 0);
if (NewVariable->Typ->ArraySize == 0)
{
NewVariable->Typ = TypeGetMatching(Parser->pc, Parser, NewVariable->Typ->FromType, NewVariable->Typ->Base, NumElements, NewVariable->Typ->Identifier, TRUE);
VariableRealloc(Parser, NewVariable, TypeSizeValue(NewVariable, FALSE));
}
#ifdef DEBUG_ARRAY_INITIALIZER
PRINT_SOURCE_POS;
printf("array size: %d \n", NewVariable->Typ->ArraySize);
#endif
}
/* parse the array initialiser */
Token = LexGetToken(Parser, NULL, FALSE);
while (Token != TokenRightBrace)
{
if (LexGetToken(Parser, NULL, FALSE) == TokenLeftBrace)
{
/* this is a sub-array initialiser */
int SubArraySize = 0;
struct Value *SubArray = NewVariable;
if (Parser->Mode == RunModeRun && DoAssignment)
{
SubArraySize = TypeSize(NewVariable->Typ->FromType, NewVariable->Typ->FromType->ArraySize, TRUE);
SubArray = VariableAllocValueFromExistingData(Parser, NewVariable->Typ->FromType, (union AnyValue *)(&NewVariable->Val->ArrayMem[0] + SubArraySize * ArrayIndex), TRUE, NewVariable);
#ifdef DEBUG_ARRAY_INITIALIZER
int FullArraySize = TypeSize(NewVariable->Typ, NewVariable->Typ->ArraySize, TRUE);
PRINT_SOURCE_POS;
PRINT_TYPE(NewVariable->Typ)
printf("[%d] subarray size: %d (full: %d,%d) \n", ArrayIndex, SubArraySize, FullArraySize, NewVariable->Typ->ArraySize);
#endif
if (ArrayIndex >= NewVariable->Typ->ArraySize)
ProgramFail(Parser, "too many array elements");
}
LexGetToken(Parser, NULL, TRUE);
ParseArrayInitialiser(Parser, SubArray, DoAssignment);
}
else
{
struct Value *ArrayElement = NULL;
if (Parser->Mode == RunModeRun && DoAssignment)
{
struct ValueType * ElementType = NewVariable->Typ;
int TotalSize = 1;
int ElementSize = 0;
/* int x[3][3] = {1,2,3,4} => handle it just like int x[9] = {1,2,3,4} */
while (ElementType->Base == TypeArray)
{
TotalSize *= ElementType->ArraySize;
ElementType = ElementType->FromType;
/* char x[10][10] = {"abc", "def"} => assign "abc" to x[0], "def" to x[1] etc */
if (LexGetToken(Parser, NULL, FALSE) == TokenStringConstant && ElementType->FromType->Base == TypeChar)
break;
|
请发表评论