Click here to Skip to main content
13,290,729 members (75,224 online)
Click here to Skip to main content

Tagged as


113 bookmarked
Posted 25 Jan 2010

Building a Programing Language – Part I (Creating BrainLess)

, 11 Oct 2013
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 <stdio.h>
#include <memory.h>

#ifndef DIM
#define DIM( a ) (sizeof(a)/sizeof(a[0]))
#define TAPE_SIZE 30//Currently the tape size is 30, just increase it to add more slots to the VM memory.

/*This is a virtual machine  for which we are writing the programing language.*/
class TapeMachine
    int m_iTapeStore[TAPE_SIZE];
    unsigned int m_iHeadPos;
    const unsigned int m_iTapeSize;

    TapeMachine(unsigned int tapeSize = TAPE_SIZE):m_iHeadPos(0),m_iTapeSize(tapeSize)
        memset(m_iTapeStore, 0x0, sizeof(int) * DIM(m_iTapeStore));

    void moveHead(unsigned int num = 1, bool foreward = true)
        if(false == foreward)
            m_iHeadPos -= num;
            m_iHeadPos += num;

    void moveHeadForeward(unsigned int num = 1)
    void moveHeadBackward(unsigned int num = 1)

    void addWithNext()
    {m_iTapeStore[m_iHeadPos] += m_iTapeStore[m_iHeadPos + 1];}
    void substractFromNext()
    {m_iTapeStore[m_iHeadPos] -= m_iTapeStore[m_iHeadPos + 1];}

    void getCharAndStore();
    void displayChar();
    void displayMultiChar(const int);

    void incrementContent()
    {m_iTapeStore[m_iHeadPos] += 1;}
    void decrementContent()
    {m_iTapeStore[m_iHeadPos] -= 1;}


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...

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