Skip to content

Commit c9bff4d

Browse files
authored
Added: cin and cout tokens to grammar.g (#22)
1 parent b76c27f commit c9bff4d

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
else float if int void
88
( ) { } * + - / % ,
99
<< >> < > <= >= = == != ;
10-
identifier integer_constant float_constant main
10+
identifier integer_constant float_constant
11+
main cin cout
1112
%
1213

1314
## Non Terminals
@@ -48,6 +49,8 @@ identifier integer_constant float_constant main
4849
<additive_expression> : <additive_expression> + <multiplicative_expression>
4950
<additive_expression> : <additive_expression> - <multiplicative_expression>
5051
<shift_expression> : <additive_expression>
52+
<shift_expression> : cin >> <additive_expression>
53+
<shift_expression> : cout << <additive_expression>
5154
<shift_expression> : <shift_expression> << <additive_expression>
5255
<shift_expression> : <shift_expression> >> <additive_expression>
5356
<relational_expression> : <shift_expression>

src/grammar/grammar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ bool Parser::Parse() {
240240
}
241241
prod.SetParent(production.first);
242242

243-
std::vector<Rule> rules;
243+
Rules rules;
244244
for (const auto &rule : production.second) {
245245
Rule prod_rule;
246246
for (const auto &entity : rule) {

src/include/grammar/grammar.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ class Production {
4646
* rules = { Rule1, Rule2 }
4747
*/
4848
std::string parent_;
49-
std::vector<Rule> rules_;
49+
Rules rules_;
5050

5151
public:
5252
Production() = default;
53-
Production(std::string parent, std::vector<Rule> rules) : parent_(std::move(parent)), rules_(std::move(rules)) {}
53+
Production(std::string parent, Rules rules) : parent_(std::move(parent)), rules_(std::move(rules)) {}
5454

5555
[[nodiscard]] const std::string &GetParent() const { return parent_; }
56-
[[nodiscard]] const std::vector<Rule> &GetRules() const { return rules_; }
56+
[[nodiscard]] const Rules &GetRules() const { return rules_; }
5757
void SetParent(const std::string &parent) { Production::parent_ = parent; }
58-
void SetRules(const std::vector<Rule> &rules) { Production::rules_ = rules; }
58+
void SetRules(const Rules &rules) { Production::rules_ = rules; }
5959
};
6060

6161
using Productions = std::vector<Production>;

0 commit comments

Comments
 (0)