Exemple #1
0
/*
 * Parse file, calling action specific functions for:
 * 1) Lines containing !E
 * 2) Lines containing !I
 * 3) Lines containing !D
 * 4) Lines containing !F
 * 5) Lines containing !P
 * 6) Lines containing !C
 * 7) Default lines - lines not matching the above
 */
static void parse_file(FILE *infile)
{
	char line[MAXLINESZ];
	char * s;
	while (fgets(line, MAXLINESZ, infile)) {
		if (line[0] == '!') {
			s = line + 2;
			switch (line[1]) {
				case 'E':
					while (*s && !isspace(*s)) s++;
					*s = '\0';
					externalfunctions(line+2);
					break;
				case 'I':
					while (*s && !isspace(*s)) s++;
					*s = '\0';
					internalfunctions(line+2);
					break;
				case 'D':
					while (*s && !isspace(*s)) s++;
                                        *s = '\0';
                                        symbolsonly(line+2);
                                        break;
				case 'F':
					/* filename */
					while (*s && !isspace(*s)) s++;
					*s++ = '\0';
                                        /* function names */
					while (isspace(*s))
						s++;
					singlefunctions(line +2, s);
					break;
				case 'P':
					/* filename */
					while (*s && !isspace(*s)) s++;
					*s++ = '\0';
					/* DOC: section name */
					while (isspace(*s))
						s++;
					docsection(line + 2, s);
					break;
				case 'C':
					while (*s && !isspace(*s)) s++;
					*s = '\0';
					if (findall)
						findall(line+2);
					break;
				default:
					defaultline(line);
			}
		}
		else {
			defaultline(line);
		}
	}
	fflush(stdout);
}
 void findall(TreeNode* root, string &a)
 {
     int val=root->val;
     string ha=to_string(val);
     if(a.size()!=0)
         a=a+"->"+ha;
     else
         a=ha;
     if(root->left==NULL&&root->right==NULL)
     {
         result.push_back(a);
         return;
     }
     string b=a;
     if(root->left!=NULL)
         findall(root->left,a);
     if(root->right!=NULL)
         findall(root->right,b);
 }
Exemple #3
0
/*
 * Parse file, calling action specific functions for:
 * 1) Lines containing !E
 * 2) Lines containing !I
 * 3) Lines containing !D
 * 4) Lines containing !F
 * 5) Lines containing !P
 * 6) Lines containing !C
 * 7) Default lines - lines not matching the above
 */
static void parse_file(FILE *infile)
{
	char line[MAXLINESZ];
	char *p, *s;
	while (fgets(line, MAXLINESZ, infile)) {
		p = is_directive(line);
		if (!p) {
			defaultline(line);
			continue;
		}

		switch (*p++) {
		case 'E':
			chomp(p);
			externalfunctions(p);
			break;
		case 'I':
			chomp(p);
			internalfunctions(p);
			break;
		case 'D':
			chomp(p);
			symbolsonly(p);
			break;
		case 'F':
			/* filename */
			s = chomp(p);
			/* function names */
			while (isspace(*s))
				s++;
			singlefunctions(p, s);
			break;
		case 'P':
			/* filename */
			s = chomp(p);
			/* DOC: section name */
			while (isspace(*s))
				s++;
			docsection(p, s);
			break;
		case 'C':
			chomp(p);
			if (findall)
				findall(p);
			break;
		default:
			defaultline(line);
		}
	}
	fflush(stdout);
}
Exemple #4
0
void View::extract_regex(string regex,
                         vector<int> groups,
                         vector<string> column_names,
                         string text) {
    vector<vector<int> > result = findall(regex.c_str(), text.c_str());
    columns.clear();
    for (int col = 0; col < groups.size(); col++) {
        columns.push_back(Column(column_names[col]));
        for (int i = 0; i < result.size(); i++) {
            int from = result[i][groups[col]*2]
            ,to = result[i][groups[col]*2+1];
            columns[col].spans.push_back(Span(text.substr(from, to-from), from, to));
        }
    }
}
Exemple #5
0
int main(void)
{
      int i;
      node **L;

      if (sizeof(int) < 4)
      {
            puts("This code must be compiled with 32-bit ints!");
            return EXIT_FAILURE;
      }

      L=newlist();

      puts(" DOWN");

      for(i = 100; i >= 0; i -=2)
            insertnode(L, i, i);

      puts(" UP");
      for(i = 1; i < 100; i += 2)
            insertnode(L, i, i);

      deletenode(L, 40);

      puts(" FIND");
      for(i = -2; i <= 100; ++i)
            findnode(L, i);

      puts(" FAST");
      findall(L);

      puts("SAMPLES");
      printf(" %d", findnode(L, -10));

      printf(" %d,", findnode(L, 0));
      printf(" %d", findnode(L, 1));
      printf(" %d", findnode(L, 2));
      printf(" %d", findnode(L, 39));
      printf(" %d", findnode(L, 40));
      printf(" %d", findnode(L, 41));
      printf(" %d", findnode(L, 42));

      puts(" DONE");

      return EXIT_SUCCESS;
}
std::vector<col> Parser::extract_stmt() {
    this->match("extract");
    std::vector<token> extract_spec_v = this->extract_spec();
    this->match("from");
    std::vector<token> from_list_v = this->from_list();
    std::map<std::string, std::string> temp_to_origin_view_name;
    for (int i = 0; (size_t)i < from_list_v.size(); i += 2)
        temp_to_origin_view_name[from_list_v[i + 1].value] = from_list_v[i].value;
    if (extract_spec_v[0].type == EMPTY) {
        /*
         * back-end extract regex logic.
         */
        if (extract_spec_v.size() > 6)
            this->error("semantic error.");
        std::string reg = extract_spec_v[1].value.substr(1, extract_spec_v[1].value.length() - 2);
        col col_to_exec = this->get_col(this->get_view(temp_to_origin_view_name[extract_spec_v[2].value]), extract_spec_v[3].value);
        std::string col_name = (extract_spec_v.size() == 5) ? extract_spec_v[4].value : extract_spec_v[5].value;
        std::string document = col_to_exec.spans[0].value;
        std::vector< std::vector<int> > result = findall(reg.c_str(), document.c_str());
        std::vector<col> regex_spec_col_v;
        col regex_exec_result = col(col_name);
        for (int i = 0; (size_t)i < result.size(); i++) {
            std::string match;
            for (int j = result[i][0]; j < result[i][1]; j++)
                match += document[j];
            regex_exec_result.spans.push_back(span(match, result[i][0], result[i][1]));
        }
        regex_spec_col_v.push_back(regex_exec_result);
        return regex_spec_col_v;
    } else {
        /*
         * back-end extract pattern logic.
         */
        int look = 0;
        std::vector<col> cols_to_exec;
        while (extract_spec_v[look].type != EMPTY) {
            if (extract_spec_v[look].type == ID) {
                col c = this->get_col(this->get_view(temp_to_origin_view_name[extract_spec_v[look].value]), extract_spec_v[look + 1].value);
                if (extract_spec_v[look].is_grouped)
                    c.is_grouped = true;
                cols_to_exec.push_back(c);
                look += 2;
            } else if (extract_spec_v[look].type == TOKEN) {
                int min = atoi(extract_spec_v[look + 1].value.c_str()), max = atoi(extract_spec_v[look + 2].value.c_str());
                std::string document = this->get_col(this->get_view("Document"), "text").spans[0].value;
                col token_col = col("token");
                for (int i = min; i <= max; i++)
                    for (int j = 0; (size_t)j + i <= this->document_tokens.size(); j++)
                        token_col.spans.push_back(span("token", this->document_tokens[j].from, this->document_tokens[j + i - 1].to));
                cols_to_exec.push_back(token_col);
                look += 3;
            } else if (extract_spec_v[look].type == REG) {
                std::string reg = extract_spec_v[look].value.substr(1, extract_spec_v[look].value.length() - 2);
                std::string document = this->get_col(this->get_view("Document"), "text").spans[0].value;
                std::vector< std::vector<int> > result = findall(reg.c_str(), document.c_str());
                col regex_exec_result = col("regex");
                for (int i = 0; (size_t)i < result.size(); i++) {
                    std::string match;
                    for (int j = result[i][0]; j < result[i][1]; j++)
                        match += document[j];
                    regex_exec_result.spans.push_back(span(match, result[i][0], result[i][1]));
                }
                if (extract_spec_v[look].is_grouped)
                    regex_exec_result.is_grouped = true;
                cols_to_exec.push_back(regex_exec_result);
                look++;
            } else
                this->error("pattern match failed.");
        }
        std::vector<record> r;
        std::string document = this->get_col(this->get_view("Document"), "text").spans[0].value;
        for (int j = 0; (size_t)j < cols_to_exec[0].spans.size(); j++) {
            int temp = cols_to_exec[0].spans[j].to;
            while (document[temp] == ' ')
                temp++;
            record re = record(temp);
            re.pos.push_back(j);
            r.push_back(re);
        }
        for (int i = 0; (size_t)i < cols_to_exec.size() - 1; i++) {
            std::vector<record> temp_record;
            for (int j = 0; (size_t)j < cols_to_exec[i + 1].spans.size(); j++)
                for (int k = 0; (size_t)k < r.size(); k++)
                    if (cols_to_exec[i + 1].spans[j].from == r[k].to) {
                        int temp = cols_to_exec[i + 1].spans[j].to;
                        while (document[temp] == ' ')
                            temp++;
                        record re = record(temp);
                        for (int t = 0; (size_t)t < r[k].pos.size(); t++)
                            re.pos.push_back(r[k].pos[t]);
                        re.pos.push_back(j);
                        temp_record.push_back(re);
                    }
            r.clear();
            r.insert(r.end(), temp_record.begin(), temp_record.end());
        }
        look++;
        std::vector<col> group;
        if (extract_spec_v[look].type == ID)
            group.push_back(col(extract_spec_v[look].value));
        else
            while ((size_t)look < extract_spec_v.size())
                group.push_back(col(extract_spec_v[look + 1].value)), look += 2;
        for (int i = 0; (size_t)i < r.size(); i++) {
            int group_count = 1;
            std::string span_value;
            int last_to = -1;
            for (int j = 0; (size_t)j < r[i].pos.size(); j++) {
                span s = cols_to_exec[j].spans[r[i].pos[j]];
                if (last_to != -1)
                    while (last_to != s.from)
                        span_value += ' ', last_to++;
                span_value += (s.value == "token") ? document.substr(s.from, s.to - s.from) : s.value, last_to = s.to;
                if (cols_to_exec[j].is_grouped)
                    group[group_count++].spans.push_back(s);
            }
            group[0].spans.push_back(span(span_value, cols_to_exec[0].spans[r[i].pos[0]].from, cols_to_exec[cols_to_exec.size() - 1].spans[r[i].pos[cols_to_exec.size() - 1]].to));
        }
        return group;
    }
}
 vector<string> binaryTreePaths(TreeNode* root) {
     string ha;
     if(root==NULL) return result;
     findall(root,ha);
     return result;
 }