started work on the scope (not really sure what I'm doing)
This commit is contained in:
parent
3991cb9895
commit
a08402f795
10
orga-comp.h
10
orga-comp.h
|
@ -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 {
|
||||
|
|
31
scope.cpp
31
scope.cpp
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue