Jump to content

Writing A Simple Interpreter

- - - - -

  • Please log in to reply
1 reply to this topic

#1
titan_550

titan_550

    Newbie

  • Members
  • Pip
  • 1 posts
Hello,

My university professor has given me this project "Simple C++ interpreter". Here are some challenges with pointers that I solved them all. But now, my major problem is with understanding the written code and calling appropriate functions. For example:
int *p=new int;

*p = *p+1;

I'm now trying to do so by using nested ifs. But my feelings say, it's not the right way. Can anyone tell me the other ways?

I write here the sample code:
int *p=new int;

int *q=Null;

int *r=q;

*p=5+3;

*p=*p+1;

r=new int;

cout<<*p;

r=p;

*r=*r+*p;

cout<<*p;

cout<<5;

r=Null;

int *s=q;

s=new int;

*s=7+*p;

cout<<*s;

*s=*p;

cout<<*s;
This message most be displayed on the console:
9

18

5

25

18

Programming language was arbitrary and I chose C#.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Before you can do interpretting, you need to parse statements. That means you must first be able to tokenize symbols. You might use regular expressions to grab chunks of text that are valid literals and look for keywords, or perhaps something else. Without seeing any of your source code, however, it's very hard to suggest where you might be going right or wrong.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users