Click here to Skip to main content
12,253,908 members (61,303 online)
Click here to Skip to main content

Tagged as

Stats

37.9K views
531 downloads
114 bookmarked
Posted

Building a Programing Language – Part I (Creating BrainLess)

, 11 Oct 2013 LGPL3
This is the first of a series of articles where we will explore about writing compilers.
#ifndef __BRAINLESS_HELPER__
#define __BRAINLESS_HELPER__
/*
Author : Shakti Misra
All are welcome to use these files, distribute, modify and release. But This notice should be included.
*/
#include <stdio.h>
#include <string>
using namespace std;

#define DIM( a ) (sizeof(a)/sizeof(a[0]))

class FileRead
{
private:
    int m_iCount;
    int m_iIndex;
    char m_szBuffer[101];
    const string m_sFileName;
    FILE* m_pFile;
    char m_cCurChar;
    bool m_bEOFReached;

private:
    char getNextCharInternal();

public:
    FileRead(string sFileName):
          m_sFileName(sFileName),
          m_iCount(0),
          m_iIndex(-1),
          m_cCurChar(0x0),
          m_bEOFReached(false)
    {
        if(false == m_sFileName.empty())
        {
            m_pFile = fopen(m_sFileName.c_str(), "rb");
        }

        memset(m_szBuffer, 0x0, DIM(m_szBuffer));
    }

    ~FileRead()
    {
        if(NULL != m_pFile)
        {
            fclose(m_pFile);
            m_pFile = NULL;
        }
    }

    char getNextChar()
    {
        return getNextCharInternal();
    }

    char getCurrentChar(){return m_cCurChar;}

    int getNextNumber();
    bool unreadChar(const char);

    bool isEOF(){return m_bEOFReached;}
};

#endif //__BRAINLESS_HELPER__

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
Web02 | 2.8.160426.1 | Last Updated 11 Oct 2013
Article Copyright 2010 by BrainlessLabs.com
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid