started work on the scope (not really sure what I'm doing)

This commit is contained in:
fsan 2021-10-07 23:54:23 -03:00
parent 3991cb9895
commit a08402f795
2 changed files with 38 additions and 3 deletions

View File

@ -82,17 +82,21 @@ class parser {
class scope {
public:
scope();
scope(scope const &father);
enum symbol_type{
NOT_FOUND,
VALUE,
};
scope();
void add(std::string key, symbol_type type);
symbol_type look(std::string key);
// scope(scope const &father);
private:
struct node {
std::string key;
symbol_type type;
struct node *next = nullptr;
};
struct node head;
struct node *head;
};
class translate {

View File

@ -0,0 +1,31 @@
#include "orga-comp.h"
#include <string>
scope::scope(){
head = nullptr;
}
void
scope::add(std::string key, symbol_type type){
if (head == nullptr){
head = new node;
head->key = key;
head->type = type;
}else{
struct node *tmp = head;
head = new node;
head->key = key;
head->type = type;
head->next = tmp;
}
}
scope::symbol_type
scope::look(std::string key){
struct node *tmp = head;
while(tmp != nullptr){
if(tmp->key == key) return tmp->type;
tmp = tmp->next;
}
return NOT_FOUND;
}