Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Tagged as

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.
Author : Shakti Misra
All are welcome to use these files, distribute, modify and release. But This notice should be included.
#include "Helper.h"
#include <ctype.h>
#include <stdlib.h>

char FileRead::getNextCharInternal()
    if(NULL == m_pFile)
        m_cCurChar = '\0';
        return m_cCurChar;

    if(0 == m_iCount && !m_bEOFReached)
        m_iCount = _fread_nolock(m_szBuffer, sizeof(char), DIM(m_szBuffer) - 1, m_pFile);
        m_iIndex = 0;
        if(m_iCount < DIM(m_szBuffer) - 1)
            m_bEOFReached = feof(m_pFile);

    if(0 < m_iCount)
        m_cCurChar = m_szBuffer[m_iIndex];
        m_szBuffer[--m_iCount, m_iIndex++] = '\0';
    else if(true == m_bEOFReached)
        m_cCurChar = '\0';
    return m_cCurChar;

int FileRead::getNextNumber()
    char numStr[20] = {0};
    int index = 0;

    while( isdigit( numStr[index++] = getNextCharInternal() ) )
        ;//Empty while loop to get numbers
    numStr[--index] = '\0';


    return atoi(numStr);

bool FileRead::unreadChar(const char ch)
    if(0 > --m_iIndex)
        return false;

    m_szBuffer[++m_iCount, m_iIndex] = ch;

    return true;

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.


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


About the Author
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: - SMISRA
Follow on   Twitter   LinkedIn

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150123.1 | Last Updated 11 Oct 2013
Article Copyright 2010 by
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid