-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGarden.cpp
57 lines (49 loc) · 1.27 KB
/
Garden.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "Garden.h"
#include <iostream>
#include <fstream>
#include <string>
#include <map>
Garden::~Garden(){
for(auto& x:garden)
delete x;
garden.clear();
}
void Garden::loadFromFile(std::string path){
Tokens tokens;
tokens.loadFromFile(path);
loadFromTokens(&tokens);
}
void Garden::loadFromString(std::string code){
Tokens tokens;
tokens.loadFromString(code);
loadFromTokens(&tokens);
}
Symbol x(std::map<std::string,Symbol*>& ){
}
void Garden::loadFromTokens(Tokens* tokens){
size_t pos = 0;
std::map<std::string,Symbol*> globalnames;
while(tokens->children.size()>pos)
{
if(tokens->isChildType(pos,Tokens::LETTER)
&&tokens->getChildValue(pos)=="Symbol"){
do{
pos++;
//symbolname
Symbol* symbol = new Symbol;
globalnames[tokens->getChildValue(pos)]=symbol;
garden.push_back(symbol);
if(!tokens->isChildType(pos,Tokens::LETTER) )
std::cerr << "Symbolname expected: Line "<<tokens->children[pos]->line<<std::endl;
else pos++;
}while(tokens->isChildType(pos,Tokens::SPECIAL)
&&tokens->getChildValue(pos)==",");
if(tokens->isChildType(pos,Tokens::SPECIAL)
&&tokens->getChildValue(pos)==";")
pos++;
else std::cerr << "Semicolon expected: Line "<<tokens->children[pos]->line<<std::endl;
}else{
// a:b>c;
}
}
}