Click here to Skip to main content
11,715,165 members (71,934 online)
Click here to Skip to main content
Add your own
alternative version

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

, 11 Oct 2013 LGPL3 30K 1.4K 64
In this article, we will discuss implementing conditional statements, loops and blocks.
Author : Shakti Misra
All are welcome to use these files, distribute, modify and release. But This notice should be included.
This software is given as is, for use and modification.
#include <stdio.h>
#include <string>
#include <map>
#include "constNDefs.h"

using namespace std;

class FileRead
    int m_iCount;
    int m_iIndex;
    char m_szBuffer[BUFFER_SIZE];
    const string m_sFileName;
    FILE* m_pFile;
    int m_cCurChar;
    bool m_bEOFReached;

    map<long, long int> m_restorePoints;
    long m_iNextNum;

    int getNextCharInternal();
    bool unreadCharInternal(const int);
    long getFileIndexInternal();
	void setFileIndexInternal(long index);
    long setRestorePointInternal();
    bool positionToRestorePointInternal(const long index, const bool remove = false);

    FileRead(string sFileName):
        if(false == m_sFileName.empty())
            m_pFile = fopen(m_sFileName.c_str(), "r+");
            if(NULL == m_pFile)
                puts("Cannot open file\n");

        memset(m_szBuffer, HEX_0, DIM(m_szBuffer));

        if(NULL != m_pFile)
            m_pFile = NULL;

    int getNextChar()
        int ch('\0');

            ch = getNextCharInternal();
        }while( isWhiteSpace(ch) );

        return ch;

    bool isWhiteSpace(const int ch)
        bool rcode = false;//false till its proved to be true

        case ' ':
        case '\t':
        case '\n':
        case '\v':
            rcode = true;

        return rcode;

    int getCurrentChar()
    {return m_cCurChar;}

    int getNextNumber();

    BOOL isEOF()
    {return m_bEOFReached;}

    bool unreadChar(const int ch)
    {return unreadCharInternal(ch);}

    void setFileIndex(const long index)
	long getFileIndex()
    {return getFileIndexInternal();}
    long setRestorePoint()
    {return setRestorePointInternal();}
    bool positionToRestorePoint(const long index, const bool remove)
    {return positionToRestorePointInternal(index, remove);}


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

You may also be interested in...

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