Skip to content

Commit

Permalink
before phase3
Browse files Browse the repository at this point in the history
  • Loading branch information
emiut97 committed Jul 15, 2021
1 parent 1b13aa4 commit a0b7fbc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
7 changes: 5 additions & 2 deletions driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ driver::driver () {
push_scope();
}

int driver::get_label () {
return label_counter++;
std::string driver::get_label () {
std::string label = label_prefix;
label_counter++;
label = label + std::to_string(label_counter);
return label;
}

void driver::push_scope () {
Expand Down
6 changes: 3 additions & 3 deletions driver.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# include <map>
# include <set>
# include <fstream>
# include "types.hh"
# include "types.hh"
# include "parser.hh"
#include "helpers/helpers.hh"

Expand All @@ -24,12 +24,12 @@ public:
// ====> LABEL
std::string label_prefix;
int label_counter;
int get_label();
std::string get_label();


// ====> SCOPE
int curr_scope;

void push_scope();
void pop_scope();

Expand Down
4 changes: 2 additions & 2 deletions scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ comment (($\*([^*]|[\r\n]|(\*+([^*$]|[\r\n])))*\*+$)|($$.*))
"default" token_to_file("DEFAULT"); return yy::parser::make_DEFAULT (loc);


"int" token_to_file("INT", std::string(yytext)); return yy::parser::make_INT (loc);
"int" token_to_file("INT"); return yy::parser::make_INT (loc);
"char" token_to_file("CHAR"); return yy::parser::make_CHAR (loc);
"void" token_to_file("VOID"); return yy::parser::make_VOID (loc);

Expand Down Expand Up @@ -99,7 +99,7 @@ comment (($\*([^*]|[\r\n]|(\*+([^*$]|[\r\n])))*\*+$)|($$.*))
"." token_to_file("DOT"); return yy::parser::make_DOT (loc);


{int} token_to_file("INT", std::string(yytext)); return make_INTCONST(yytext, constants, loc);
{int} token_to_file("INT"); return make_INTCONST(yytext, constants, loc);
{char} token_to_file("CHAR"); return make_CHARCONST(yytext, constants, loc);
{id} token_to_file("ID"); return yy::parser::make_ID(yytext, loc);

Expand Down
10 changes: 5 additions & 5 deletions types/Code.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
struct Code
{
std::string text;
// int continue_label;
// int break_label;
// int case_label;
int start_label;
int end_label;
// std::string continue_label;
// std::string break_label;
// std::string case_label;
std::string start_label;
std::string end_label;

/**
* start_label: LI $s0, 12
Expand Down
1 change: 0 additions & 1 deletion types/Var.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ struct Var
int offset;
std::string id;
int scope;
// TODO: "initial_value" --> "value"
int initial_value;

enum Type
Expand Down

0 comments on commit a0b7fbc

Please sign in to comment.