本文整理汇总了C++中ReadToken函数的典型用法代码示例。如果您正苦于以下问题:C++ ReadToken函数的具体用法?C++ ReadToken怎么用?C++ ReadToken使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadToken函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
main()
{
symtabADT table;
scannerADT scanner;
string line, name, value;
table = NewSymbolTable();
scanner = NewScanner();
SetScannerSpaceOption(scanner, IgnoreSpaces);
while (TRUE) {
printf("-> ");
line = GetLine();
if (StringEqual(line, "quit")) break;
SetScannerString(scanner, line);
name = ReadToken(scanner);
if (MoreTokensExist(scanner)) {
if (!StringEqual(ReadToken(scanner), "=")) {
Error("Missing equal sign in assignment");
}
value = ReadToken(scanner);
if (MoreTokensExist(scanner)) {
Error("Statement contains additional data");
}
Enter(table, name, value);
} else {
value = Lookup(table, name);
if (value == UNDEFINED) {
printf("'%s' is undefined.\n", name);
} else {
printf("%s\n", value);
}
}
}
FreeSymbolTable(table);
}
示例2: main
main()
{
dataBlockT db;
string line, cmd, token, var;
int pos;
printf("List structure test program\n");
printf("Type \"help\" for help\n");
db = NewDataBlock();
while (TRUE) {
printf(">");
line = GetLine();
SetScannerString(db->scanner, line);
cmd = ConvertToLowerCase(ReadToken(db->scanner));
if (IsVariableName(cmd)) {
var = cmd;
token = ReadToken(db->scanner);
if (StringEqual(token, "")) {
DisplayStringList(GetValue(db, var));
} else if (StringEqual(token, "=")) {
ParseOperation(db, var);
} else {
Error("Unexpected token %s", token);
}
} else if (StringEqual(cmd, "help")) {
HelpCmd();
} else if (StringEqual(cmd, "quit")) {
break;
} else {
SaveToken(db->scanner, cmd);
ParseOperation(db, NULL);
}
}
}
示例3: DoKeyword
//===========================================================================
// DoKeyword
// The next token is expected to be a keyword.
//===========================================================================
int DoKeyword(void)
{
ReadToken();
if(ISTOKEN("syntax"))
{
ReadToken();
if(ISTOKEN("simple"))
{
syntax = STX_SIMPLE;
Message("Using simple syntax.");
}
else
{
Message("Unknown syntax '%s'.", token);
return false;
}
}
else if(ISTOKEN("group"))
{
ReadToken();
group = strtol(token, 0, 0);
if(group < 1 || group > NUM_GROUPS)
{
Message("Illegal group number %i (1..%i allowed).", group,
NUM_GROUPS);
return false;
}
Message("Switching to group %i.", group);
group--; // Make it an index number, though.
}
return true;
}
示例4: HandleCRAMMD5
int HandleCRAMMD5( int inSocket )
{
unsigned char pChallenge[255] = { 0, };
char pHostname[128] = { 0, };
char *pResponse = NULL;
char *pUsername = NULL;
struct timeval stCurrentTime;
int iResult = -1;
// we will be using ReadToken and WriteToken to send data back and forth for this
// example, though not necessarily the most efficient, it is simplistic for this
// demonstration.
// Since CRAM-MD5 was requested, let's generate a challenge and send it to the client
// using example method in RFC 1460, page 12.
gethostname( pHostname, 127 );
gettimeofday( &stCurrentTime, NULL ); // assume no error occurred
snprintf( pChallenge, 255, "<%ld.%[email protected]%s>", (long) getpid(), stCurrentTime.tv_sec, pHostname );
printf( "Sending challenge %s\n", pChallenge );
// send our challenge to the client
if( SendToken(inSocket, pChallenge, strlen(pChallenge)) > 0 ) {
// now wait for username and response to return
if( ReadToken(inSocket, &pUsername) > 0 ) {
if( ReadToken(inSocket, &pResponse) > 0 ) {
// here is where we authenticate the user using Open Directory
iResult = AuthCRAMMD5( pUsername, pChallenge, pResponse );
// send a response
if( iResult == eDSNoErr ) {
SendToken( inSocket, "Accepted", sizeof("Accepted") );
} else {
SendToken( inSocket, "Rejected", sizeof("Rejected") );
}
}
}
}
// free up any strings we allocated
if( pUsername != NULL ) {
free( pUsername );
pUsername = NULL;
}
if( pResponse != NULL ) {
free( pResponse );
pResponse = NULL;
}
return iResult;
}
示例5: SelectionOperation
static void SelectionOperation(dataBlockT db, string lhs)
{
string var;
int pos;
if (lhs != NULL) Error("NthElement result cannot be assigned");
CheckForToken(db->scanner, "(");
var = ConvertToLowerCase(ReadToken(db->scanner));
CheckForToken(db->scanner, ",");
pos = StringToInteger(ReadToken(db->scanner));
CheckForToken(db->scanner, ")");
printf("%s\n", NthElement(GetValue(db, var), pos));
}
示例6: HandleCleartext
int HandleCleartext( int inSocket )
{
char *pUsername = NULL;
char *pPassword = NULL;
char *pRecordname = NULL;
int iResult = -1;
// we will be using ReadToken and WriteToken to send data back and forth for this
// example, though not necessarily the most efficient, it is simplistic for this
// demonstration.
// we expect 2 tokens, username then password
// read the username from the network stream
if( ReadToken(inSocket, &pUsername) > 0 ) {
// read the password from the network stream
if( ReadToken(inSocket, &pPassword) > 0 ) {
iResult = AuthCleartext( pUsername, pPassword );
// send a response
if( iResult == eDSNoErr ) {
SendToken( inSocket, "Accepted", sizeof("Accepted") );
} else {
SendToken( inSocket, "Rejected", sizeof("Rejected") );
}
}
}
// free any allocated strings
if( pUsername != NULL ) {
free( pUsername );
pUsername = NULL;
}
if( pPassword != NULL ) {
free( pPassword );
pPassword = NULL;
}
if( pRecordname != NULL ) {
free( pRecordname );
pRecordname = NULL;
}
return iResult;
}
示例7: test
void test(void)
{
char buf[128];
xprintf(0x21, "Hello World!\r\n");
ReadToken(buf, TOKEN_PASSWORD, 8);
xprintf(0x21, "password = '%s'\r\n", buf);
}
示例8: SkipBracedSection
/*
=================
idLexer::SkipBracedSection
Skips until a matching close brace is found.
Internal brace depths are properly skipped.
=================
*/
int idLexer::SkipBracedSection( bool parseFirstBrace )
{
idToken token;
int depth;
depth = parseFirstBrace ? 0 : 1;
do
{
if( !ReadToken( &token ) )
{
return false;
}
if( token.type == TT_PUNCTUATION )
{
if( token == "{" )
{
depth++;
}
else if( token == "}" )
{
depth--;
}
}
}
while( depth );
return true;
}
示例9: Fail
void ParsedObject::MatchToken(const LispString* aToken)
{
if (aToken != iLookAhead)
Fail();
ReadToken();
}
示例10: ReadFloat
/*
================
Lexer::ReadFloat
================
*/
float Lexer::ReadFloat( void ) {
if ( !ReadToken() )
throw LexerError( LexerError::END_OF_FILE );
if ( !String::IsNumeric( token.GetString() ) )
throw LexerError( LexerError::BAD_TOKEN, token.line, "float", token.GetString() );
return String::ToFloat( token.GetString() );
}
示例11: RewindTokenStream
static TokenStream *PrescanMacroArg(TokenStream *a, yystypepp * yylvalpp)
{
int token;
TokenStream *n;
RewindTokenStream(a);
do {
token = ReadToken(a, yylvalpp);
if (token == CPP_IDENTIFIER && LookUpSymbol(macros, yylvalpp->sc_ident))
break;
} while (token > 0);
if (token <= 0)
return a;
n = NewTokenStream("macro arg", 0);
PushEofSrc();
ReadFromTokenStream(a, 0, 0);
while ((token = cpp->currentInput->scan(cpp->currentInput, yylvalpp)) > 0) {
if (token == CPP_IDENTIFIER
&& MacroExpand(yylvalpp->sc_ident, yylvalpp))
continue;
RecordToken(n, token, yylvalpp);
}
PopEofSrc();
DeleteTokenStream(a);
return n;
} /* PrescanMacroArg */
示例12: RewindTokenStream
TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream *a, TPpToken* ppToken)
{
int token;
TokenStream *n;
RewindTokenStream(a);
do {
token = ReadToken(a, ppToken);
if (token == CPP_IDENTIFIER && LookUpSymbol(ppToken->atom))
break;
} while (token != EOF);
if (token == EOF)
return a;
n = new TokenStream;
PushEofSrc();
ReadFromTokenStream(a, 0, 0);
while ((token = currentInput->scan(this, currentInput, ppToken)) > 0) {
if (token == CPP_IDENTIFIER && MacroExpand(ppToken->atom, ppToken, 0) == 1)
continue;
RecordToken(n, token, ppToken);
}
PopEofSrc();
delete a;
return n;
}
示例13: ParseCommand
bool FFeedbackContextMarkup::ParseCommand(const FString& Line, FFeedbackContext* Warn)
{
const TCHAR *Text = *Line;
if(ReadToken(Text, TEXT("@progress")))
{
FString Status;
bool bHaveStatus = ReadString(Text, Status);
int32 Numerator, Denominator;
bool bHaveProgress = ReadProgress(Text, Numerator, Denominator);
if(*Text == 0)
{
if(bHaveProgress && bHaveStatus)
{
Warn->StatusUpdate(Numerator, Denominator, FText::FromString(Status));
return true;
}
if(bHaveProgress)
{
Warn->UpdateProgress(Numerator, Denominator);
return true;
}
}
}
return false;
}
示例14: Invalidate
bool IACFile::Read(wxInputStream &stream) {
bool isok = false; // true if minimum one token was read from file
Invalidate();
wxString token;
m_tokensI = 0;
if (stream.IsOk()) {
for (;;) {
token = ReadToken(stream);
if (!token.IsEmpty()) {
m_tokens.Add(token);
m_tokensI++;
isok = true;
} else {
break;
}
}
}
m_tokensI = 0;
// for (std::vector<size_t>::iterator it = m_newlineTokens.begin(); it != m_newlineTokens.end(); ++it)
// {
// wxMessageBox( wxString::Format( _T("ID: %i :"), *it ) + m_tokens[*it] );
// }
if (isok) {
// decode tokens if some were found
isok = Decode();
}
m_isok = isok;
return isok;
}
示例15: PostFixEval
/*************************************************************
* Que 3. Post fix expression evaluation
*
* Comment : 1) prepare stack for holding operands only.
* 2) Push when numbers are read.
* 3) Pop two numbers when ever operand is encountered.
*
* Parameters : expression array
* Returns : int (eval result)
*************************************************************/
int PostFixEval(char A[])
{
LinkedListStack stack;
int tokenType = EMPTY,num,i=0;;
char token;
while((tokenType = ReadToken(A,i,token,num)) != EMPTY)
{
if(tokenType == OPERAND) //Numbers
{
stack.Push(token - '0');
}
else if(tokenType == OPERATOR) //Mathematical operator
{
int A = stack.Pop();
int B = stack.Pop();
stack.Push(Operate(A,B,token));
}
else
{
//Should not reach here
assert(1 == 0);
}
}
if(stack.IsEmpty())
return -1;
return stack.Pop();
}