Thank you so much...

This is a discussion on Thank you so much... within the C++ Programming forums, part of the General Programming Boards category; Long time ago i posted this message: http://www.cprogramming.com/cboard/s...?threadid=2092 I want to thank everybody. I worked on the program myself and ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    5

    Thank you so much...

    Long time ago i posted this message:
    http://www.cprogramming.com/cboard/s...?threadid=2092

    I want to thank everybody. I worked on the program myself and it is running. I have asked my professor to let me submit the program on Monday, and he agreed.

    Now i only need small help,, which is I have the program but it is not running in the way my professor wants it. If someone can look at it and help me on it please...
    this is the program:
    #include<iostream>
    #include<stdio.h>
    #include<string>
    #include<cstring>
    #include "d_stack.h"
    using namespace std;
    bool Operator(char* str,int i)
    {
    bool check = false;
    if(str[i] == '*')
    check = true;
    else if (str[i] == '/')
    check = true;
    else if (str[i] == '+')
    check = true;
    else if (str[i] == '-')
    check = true;
    return check;

    }

    bool Specialchar(char* str,int i)
    {
    bool check = false;
    if(str[i] == '*')
    check = true;
    else if (str[i] == '/')
    check = true;
    else if (str[i] == '+')
    check = true;
    else if (str[i] == '-')
    check = true;
    else if (str[i] == ' ')
    check = true;
    else if (str[i] == ';')
    check = true;
    return check;
    }

    bool Signnumber(char* str,int i)
    {
    bool check = false;
    int j ;
    int dot = 0;
    j = i;
    if ((str[j] == '-') || (str[j] == '+'))
    {
    j++;

    while (((str[j]>= '0') && (str[j] <= '9')) || (str[j] == '.'))
    {
    if (str[j] == '.')
    dot ++;
    j++;

    }

    if (dot > 1)
    {
    cout << "<Error> Invalid Number" << endl;
    exit(1);
    }
    else
    check = true;

    }
    return check;

    }

    bool Number(char* str,int i)
    {
    bool check = false;
    int j;
    int dot = 0;
    j = i;

    if ((str[j] >= '0') && (str[j] <= '9'))
    {
    while (((str[j]>= '0') && (str[j] <= '9')) || (str[j] == '.'))
    {
    if (str[j] == '.')
    dot ++;
    j++;

    }

    if (dot > 1)
    {
    cout << endl;
    cout << "<Error> Invalid Number" << endl;
    exit(1);
    }

    else
    check = true;
    }

    return check;
    }

    bool Number09(char* str, int i)
    {
    if ((str[i] >= '0') && (str[i] <= '9'))
    return true;
    else
    return false;
    }


    bool Character(char* str,int i)
    {

    if ((str[i]>= 'A' && str[i] <= 'Z') || (str[i]>= 'a' && str[i] <= 'z'))
    return true;
    else
    return false;
    }

    bool Whitespace(char* str, int i)
    {
    if (str[i] == ' ')
    return true;
    else
    return false;

    }

    int Getridwhitespace(char* str, int i)
    {

    while (str[i] == ' ' )
    i++;
    return i;

    }
    bool Isprintword(char* str,int i)
    {
    bool check = false;
    int j;
    j = i;
    if((str[j]=='p') || (str[j]== 'P'))
    if((str[j+1]=='r') || (str[j+1]== 'R'))
    if((str[j+2]=='i') || (str[j+2]== 'I'))
    if((str[j+3]=='n') || (str[j+3]== 'N'))
    if((str[j+4]=='t') || (str[j+4]== 'T'))
    if(str[j+5]==' ')
    check = true;
    return check;
    }

    bool Printstate(char* str, int i)
    {
    bool check = false;
    int j;
    j = i;
    if(Isprintword(str,j))
    {
    j = j +5;
    j = Getridwhitespace(str,j);
    if (str[j] != '=')
    check = true;
    }
    return check;
    }

    bool Name(char* str, int i)
    {
    int j = i;
    bool check = false;


    if (!Isprintword(str,j))
    if (Character(str,j))
    {
    i++;
    while ((Character(str,j)) || (Number09(str,j)) || (str[j] == '_'))
    j++;
    if (Whitespace(str,j))
    j = Getridwhitespace(str,j);
    if ((Operator(str,j)) || (str[j] == ';'))
    check = true;
    }
    return check;
    }

    bool Assignmentstate(char* str, int i )
    {
    int j = i;
    bool check = false;

    if (!Isprintword(str,j))
    if (Character(str,j))
    {
    i++;
    while ((Character(str,j)) || (Number09(str,j)) || (str[j] == '_'))
    j++;
    if (Whitespace(str,j))
    j = Getridwhitespace(str,j);
    if (str[j] == '=')
    check = true;
    }
    return check;
    }



    string Gettoken(char* str, int& i)
    {
    char s [20];
    int j= i;
    int k=0;
    cout << i << " befor token" << endl;
    if(Whitespace(str,i))
    i = Getridwhitespace(str,i);

    cout << i <<" token i" << endl;
    if (Name(str,i))
    { while(Name(str,i))
    {
    s[k] = str[i];
    k++;
    i++;
    }
    }
    else if ((Signnumber(str,i)) ||(Number(str,i)))
    {
    cout << "number";
    }
    s[k] = NULL;
    return s;
    }
    int main()
    {
    string token[20];
    int index = 0;
    char line[81];
    int Newlinepos=0;
    cout << ">";
    cin.getline(line, 81, '\n');
    if (line[strlen(line)-1] != ';')
    {
    cout << endl;
    cout << "<Error> Instruction should end with ';'" << endl;
    exit(1);
    }

    if (Whitespace(line,0))
    Newlinepos = Getridwhitespace(line,0);

    if (Printstate(line,Newlinepos))
    {
    cout << endl;
    cout <<" Print" << endl;
    }
    else if (Assignmentstate(line,Newlinepos))
    { cout << endl;
    cout <<" Assignment" << endl;
    cout << endl;
    cout <<" ";
    while((line[Newlinepos] != '=') && (line[Newlinepos] != ' '))
    {
    cout <<line[Newlinepos];
    Newlinepos++;
    }
    cout << endl;
    if(Whitespace(line,Newlinepos))
    Newlinepos = Getridwhitespace(line,Newlinepos);
    cout <<" " << line[Newlinepos] << endl;
    Newlinepos++;

    // Expression(line,Newlineposm,token,index);



    }
    else
    { cout << endl;
    cout << "<Error> The statement is not Assign or Print statement" << endl;
    cout << endl;
    }
    cout << endl;
    cout << endl;
    return 0;
    }
    This is how the final run should look like: x=x*2+y;
    Assignment
    ...............X
    ...............=
    ......Operation
    ............... Operation
    ................. X
    ................. *
    ................. 2
    ..........+
    ..........Y
    i made up the dots to make the run looks like a tree.
    Last edited by ta1samail; 10-10-2001 at 08:57 PM.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21