예제 #1
0
파일: Parser.cpp 프로젝트: Arkm4n/Syntaxer
 sptr<Node> Parser::ParseBodyBlock()
 {
     ParseConstDecl();
     ParseTypeDecl();
     ParseVarDecl();
     return ParseBlock();
 }
예제 #2
0
void Parser::ParseDecl()
{
	while (true)
	{
		if (t.GetValue() == "var")
			ParseVarDecl();
		else
		if(t.GetValue() == "type")
			ParseTypeDecl();
		else
		if(t.GetValue() == "const")
			ParseConstDecl();
		else
		if(t.GetValue() == "procedure")
			ParseProc();
		else
		if(t.GetValue() == "function")
			ParseFunc();
		else
			break;
	}
}
예제 #3
0
파일: parser.cpp 프로젝트: 4aiman/HexEdit
int Parser::Parse()
{
	Tag *tagList;
	TypeDecl *typeDecl;
	Statement *stmt;


	// keep going until there are no more tokens!
	while(t)
	{
		TOKEN allowed[] = 
		{ 
			TOK_LENGTHIS, TOK_SIZEIS, TOK_IGNORE, TOK_STRING,
			TOK_OFFSET, TOK_ALIGN, TOK_BITFLAG, TOK_STYLE, TOK_DISPLAY,
			TOK_ENDIAN,	TOK_SWITCHIS, TOK_CASE, TOK_NAME, 
			TOK_ENUM, TOK_EXPORT, TOK_ASSOC,
			TOK_NULL 

		};

		// save any whitespace before the tags
		FILEREF fileRef;
		lex_fileref(&fileRef);

		if(!ParseTags(&tagList, allowed))
			return 0;
		
		//
		//	Decide what kind of statement/construct we need to parse 
		//
		switch(t)
		{
		case TOK_INCLUDE:
			
			// include-statement (not the same as #include which
			// is a C-preprocessor thing)
			if((stmt = ParseInclude()) == 0)
			{
				return 0;
			}

			curFile->stmtList.push_back(stmt);

			break;

		default:

			size_t s1 = globalFileHistory.size();

			// anything else must be a type-declaration
			if((typeDecl = ParseTypeDecl(tagList, globalIdentifierList, false, true)) == 0)
				return 0;

			size_t s2 = globalFileHistory.size();


			// store in the global list
			typeDecl->fileRef = fileRef;
			globalTypeDeclList.push_back(typeDecl);

			//curFile->typeDeclList.push_back(typeDecl);

			curFile->stmtList.push_back(new Statement(typeDecl));

			// every type-declaration must end with a ';'
			if(!Expected(';'))
				return 0;

			// record any whitespace that appears after the type-decl
			lex_fileref(&typeDecl->postRef);
			 
			break;
		}
	}

	ExportStructs();

	return (errcount == 0) ? 1 : 0;
}