-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.cpp
More file actions
44 lines (38 loc) · 819 Bytes
/
parser.cpp
File metadata and controls
44 lines (38 loc) · 819 Bytes
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
/*
* parser.cpp
* Daniel Jarka
* 10/12/24
*
* CS 15 Project 2: CalcYouLater
*
* Implementation of the parser class.
*/
#include <string>
#include <iostream>
#include <sstream>
#include "parser.h"
using namespace std;
/*
* name: parseRString
* purpose: This function returns the correctly formatted rstring
* after reading input.
* arguments: an istream object that represents input.
* returns: A correctly formatted rstring.
* effects: none
*/
string parseRString(istream &input) {
string s;
string parsed;
int isBalanced = 1;
while (isBalanced > 0) {
input >> s;
parsed += " " + s;
if (s == "{") {
++isBalanced;
}
else if(s == "}") {
--isBalanced;
}
}
return "{" + parsed;
}