Click here to Skip to main content
12,406,687 members (56,872 online)
Click here to Skip to main content

Stats

32.1K views
1.5K downloads
65 bookmarked
Posted

Building a Programming Language: Part II (Adding Conditions, Loop and Blocks to BrainLess)

, 11 Oct 2013 LGPL3
In this article, we will discuss implementing conditional statements, loops and blocks.
#include <cstdio>
#include <time.h>
using namespace std;

#include "TimeLogger.h"
const double CTimer::_frequency = getFrequency();
LARGE_INTEGER CTimer::_start = {0};
LARGE_INTEGER CTimer::_end = {0};
double CTimer::_timeElapsedInSec = {0};
LARGE_INTEGER TimeLogger::_start;
LARGE_INTEGER TimeLogger::_end;

ofstream TimeLogger::_file;

void TimeLogger::init(const string& fileName)
{
	_file.open(fileName.c_str());
	if(!_file.is_open() || !_file.good())
		cerr<<"Cannot open file"<<endl;
}

void TimeLogger::functionStart(const std::string& funName)
{
	time_t rawtime;
	string timeS;
	getTime(timeS);

	ST(_start);
	char str[1024] = {0};
	sprintf(str, "%s:%I64d %s Start{",  timeS.c_str(), _start.QuadPart, funName.c_str());
	_file<<str<<endl;
}

void TimeLogger::functionEnd(const std::string& funName)
{
	string timeS;
	getTime(timeS);
	ET(_end);
	float diff = DIFF(_start, _end);
	char str[1024] = {0};
	sprintf(str, "%s:%I64d %s End}",  timeS.c_str(), _end.QuadPart, funName.c_str());
	_file<<str<<endl;
	sprintf(str, "============%s execution time = %f seconds============%",  funName.c_str(), diff);
	_file<<str<<endl;
}


void TimeLogger::getTime(string& timeS)
{
	time_t rawtime;
	struct tm * timeinfo;

	time ( &rawtime );
	timeinfo = localtime ( &rawtime );
	timeS = asctime (timeinfo);
	timeS[timeS.length()-2] = '\0';
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

Share

About the Author

BrainlessLabs.com
Engineer
India India
I like to explore different aspects of technology. Try new things, and get delighted. My interests are programming language, and Imaging. But its not hard to work on other things also. Algorithms delight me over a coffee break.

I basically code in C++, but JAVA is not so alien for me. I know few scripting languages also. Basically I feel that knowing a programing language is just a matter of getting introduced to it.

For my other articles check my blog on homepage:

http://brainlesslabs.com/

https://github.com/BrainlessLabsInc
https://github.com/sp-mishra

http://www.luxrender.net/en_GB/authors_contributors - SMISRA

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160730.1 | Last Updated 11 Oct 2013
Article Copyright 2010 by BrainlessLabs.com
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid