a simple LL(1) parser code

I'm not too familiar with forums, so I'm not sure if I posted this in the right topic. I apologize in advance if I'm on the wrong topic, or if I'm not allowed questions like this.

Ok now, this is a long shot, but I figured I would try asking for help anyhow.

I'm currently studying the topic syntax analyzer, focusing on LL(1) parsers. I understand the theories, how it works, etc. Recently, I was given a small task of creating an LL(1) parser. But to be honest, I am very weak in coding. So I asked help from a friend and he gave me this code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>


int main()
     {
       char tmp[15];
       char str[15], csf[15]={"E"};
       int ssm=0, i, j, v, k, pos=0, a;
       clrscr();

       char pt[6][5][4]={"" , "i" , "+" , "*" , "/",
             "E", "TX", "n" , "n" , "n",
             "X", "n" , "TX", "n" , "" ,
             "T", "VY", "n" , "n" , "n",
             "Y", "n" , ""  , "VY", "" ,
             "V", "i" , "n" , "n" , "n"};
     cout<<"\n Enter An Expression: "<<endl;
     cin>>str;

     while(str[ssm]!='/')
    {
      pos=0;
      while(csf[pos]!='E' &&
        csf[pos]!='X' &&
        csf[pos]!='T' &&
        csf[pos]!='Y' &&
        csf[pos]!='V' && csf[pos]!='\0')
        pos++;
    if (csf[pos]=='\0')
       break;

    for(i=1; i<6; i++)
      {
        if(csf[pos]==pt[i][0][0])
           break;
      }
       for(j=1; j<5; j++)
      {
         if(str[ssm]==pt[0][j][0])
        break;
      }
       if(strcmp(pt[i][j], "n")==0)
       {
          cout<<"\n Null Value: "<<endl;
          cout<<pt[i][j];
          exit;
       }

       for(k=0; k<pos; k++)
       tmp[k]=csf[k];
       tmp[k]='\0';
       strcat(tmp, pt[i][j]);

       int l= strlen(tmp);
       k=l;

       for(a=pos+1; csf[a]!='\0'; a++, k++)
       tmp[k]=csf[a];
       strcpy(csf, tmp);
    }


       strcat(csf, "/");
     if(strcmp(csf, str)==0)
         {
         cout<<"\t csf"<<csf;

         cout<<"\tstr"<<str;

         cout<<"\n Valid Expression: "<<endl;


         }

     else
         {
          cout<<"\n Invalid Expression:"<<endl;

         }


      getch();
      return 0;
}


To explain, I was working on this code the past week with a smart friend. It's in c++ and I'm using Code::Blocks. He refused to explain everything to me line by line, and he often wrote things for me rather than teaching them. I am not trolling nor asking you to do my project for me. I will be honest when I say i am very weak at writing codes. I am asking for help on explanations, and possibly ideas/solutions.
For those who have the time and want to help a total code-illiterate person, could you explain each line of code and basically what it does? What the certain words/numbers do?
(yes, I will admit I did not create this code entirely, or nearly at all. I have mentioned that)
Last edited on
http://en.wikibooks.org/wiki/C%2B%2B_Programming

This forum is best used for when you have problems. If you come with nothing, you leave with nothing.
It isn't really reasonable to expect anyone to explain a piece of code entirely, line to line, if all the information you need is freely available on the internet and in books.

http://www.cplusplus.com/doc/tutorial/

That's one place out of many you can go.
Topic archived. No new replies allowed.