forked from CO18301/HackotberFest2021
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathLALR parser.cpp
70 lines (70 loc) · 1.19 KB
/
LALR parser.cpp
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
#include<bits/stdc++.h>
using namespace std;
int main()
{
ifstream input;
string file;
cout<<"Enter file name"<<endl;
cin>>file;
input.open(file.c_str(), std::ifstream::in);
char ch;
int multi = 0;
int single = 0;
vector<string> comments;
string line;
while(getline(input,line))
{
for(int i = 0; i< line.length(); i++)
{
if(line[i]== '/' && line[i+1] == '/')
{
string s;
single ++;
i= i + 2;
while(i!=line.length())
{
s += line[i];
i++;
}
comments.push_back(s);
break;
}
if(line[i] == '/' && line[i+1]=='*')
{
i = i + 2;
multi++;
string s,
temp;
while(i!=line.length())
{
s += line[i];
i++;
}
int flag = 0;
while(getline(input,temp))
{
for (int j= 0; j< temp.length(); j++)
{
if (temp [j]== '*' && temp [j+1]== '/')
{
comments.push_back(s);
flag= 1;
break;
}
s += temp[j];
}
if(flag)
{
break;
}
}
}
}
}
cout<<"Multiline comments "<<multi<<endl<<"Singleline comments "<<single<<endl;
for(int i = 0; i < comments.size(); i ++)
{
cout<<i+1<<" "<<comments[i]<<endl;
}
return 0;
}