ParseElement* BigQuantifiers::copy() const { BigQuantifiers* res = new BigQuantifiers(NULL, NULL, parens()); res->postOp((postOp()) ? postOp()->copy() : NULL); for (QuantifierList::const_iterator it = quantsBegin(); it != quantsEnd(); it++) { if ((*it)->second) res->addQuant(new Quantifier((*it)->first, (*it)->second->copy())); } return res; }
ParseElement* ObjectLikeElement::copy() const { ParseElementList params; for (ParseElementList::const_iterator it = paramsBegin(); it != paramsEnd(); it++) { params.push_back((*it)->copy()); } return new ObjectLikeElement(baseName(), (Object const*)ref(), ¶ms, parens()); }
/*----------* * parens | *----------* | Write the gene tree */ void parens(struct node *ptree, int *descl, int *descr, int noden) { double time=0.0; if(descl[noden]==-1) printf("%d:%5.3lf", noden+1, (ptree+((ptree+noden)->abv))->time); else { printf("("); parens(ptree, descl, descr, descl[noden]); printf(", "); parens(ptree, descl, descr, descr[noden]); if((ptree+noden)->abv==0) printf(");\n"); else { time=(ptree+(ptree+noden)->abv)->time-(ptree+noden)->time; printf("):%5.3lf", time); } } }
const char *parens(const char *text, char open) { int c; char close = '\0'; switch (open) { case '(': close = ')'; break; case '{': close = '}'; break; case '[': close = ']'; break; // default: ASSERT(false); return text; } while (true) { text = comment(text); c = *text++; if (c == '\'') { text = skip(text, '\''); continue; } if (c == '"') { text = skip(text, '"'); continue; } if (c == '#') { text = skip(text, '\n'); continue; } if (c == open) { text = parens(text, open); continue; } if (c == close) return text; if (c == '\0') return text - 1; } } /* parens */
/*----------* * prtree | *----------* | builts tree information for a segment */ void prtree(struct node *ptree, int nsam) { int i=0, *descl=NULL, *descr=NULL; void parens(struct node *ptree, int *descl, int *descr, int noden); descl=(int*)malloc((unsigned)(2*nsam-1)*sizeof(int)); descr=(int*)malloc((unsigned)(2*nsam-1)*sizeof(int)); for(i=0;i<2*nsam-1;i++) descl[i]=descr[i]=-1; for(i=0;i<2*nsam-2;i++) { if(descl[(ptree+i)->abv]==-1) descl[(ptree+i)->abv]=i; else descr[(ptree+i)->abv]=i; } parens(ptree, descl, descr, 2*nsam-2); // Write the characteristic of the tree free(descl); free(descr); }
void ScanForFunctions(CLanguageProxy& proxy) { const char* text = proxy.Text(), *max = text + proxy.Size(); char* scope = (char*)"file"; if (*max != 0) return; while (text < max) { text = comment(text, false); switch (*text) { case 0: return; case '\'': text = skip(text + 1, '\''); break; case '"': text = skip(text + 1, '"'); break; case '(': case '{': case '[': text = parens(text + 1, *text); break; case '#': text = preprocessor(text + 1, proxy); break; default: if (isidentf(*text)) text = ident(text, proxy, scope); else text++; break; } } } /* ScanForFunctions */
NODE *runparse_node(NODE *nd, NODE **ndsptr) { NODE *outline = NIL, *tnode = NIL, *lastnode = NIL, *snd; char *wptr, *tptr; struct string_block *whead; int wlen, wcnt, tcnt, isnumb, gotdot; NODETYPES wtyp; BOOLEAN monadic_minus = FALSE; if (nd == Minus_Tight) return cons(nd, NIL); snd = cnv_node_to_strnode(nd); wptr = getstrptr(snd); wlen = getstrlen(snd); wtyp = nodetype(snd); wcnt = 0; whead = getstrhead(snd); while (wcnt < wlen) { if (*wptr == ';') { *ndsptr = NIL; break; } if (*wptr == '"') { tcnt = 0; tptr = ++wptr; wcnt++; while (wcnt < wlen && !parens(*wptr)) { if (wtyp == BACKSLASH_STRING && getparity(*wptr)) wtyp = PUNBOUND; /* flag for "\( case */ wptr++, wcnt++, tcnt++; } if (wtyp == PUNBOUND) { wtyp = BACKSLASH_STRING; tnode = cons(make_quote(intern(make_strnode(tptr, NULL, tcnt, wtyp, noparity_strnzcpy))), NIL); } else tnode = cons(make_quote(intern(make_strnode(tptr, whead, tcnt, wtyp, strnzcpy))), NIL); } else if (*wptr == ':') { tcnt = 0; tptr = ++wptr; wcnt++; while (wcnt < wlen && !parens(*wptr) && !infixs(*wptr)) wptr++, wcnt++, tcnt++; tnode = cons(make_colon(intern(make_strnode(tptr, whead, tcnt, wtyp, strnzcpy))), NIL); } else if (wcnt == 0 && *wptr == '-' && monadic_minus == FALSE && wcnt+1 < wlen && !white_space(*(wptr+1))) { /* minus sign with space before and no space after is unary */ tnode = cons(make_intnode((FIXNUM)0), NIL); monadic_minus = TRUE; } else if (parens(*wptr) || infixs(*wptr)) { if (monadic_minus) tnode = cons(Minus_Tight, NIL); else if (wcnt+1 < wlen && ((*wptr == '<' && (*(wptr+1) == '=' || *(wptr+1) == '>')) || (*wptr == '>' && *(wptr+1) == '='))) { tnode = cons(intern(make_strnode(wptr, whead, 2, STRING, strnzcpy)), NIL); wptr++, wcnt++; } else tnode = cons(intern(make_strnode(wptr, whead, 1, STRING, strnzcpy)), NIL); monadic_minus = FALSE; wptr++, wcnt++; } else { tcnt = 0; tptr = wptr; /* isnumb 4 means nothing yet; * 0 means digits so far, 1 means just saw * 'e' so minus can be next, 2 means no longer * eligible even if an 'e' comes along */ isnumb = 4; gotdot = 0; if (*wptr == '?') { isnumb = 3; /* turn ?5 to (? 5) */ wptr++, wcnt++, tcnt++; } while (wcnt < wlen && !parens(*wptr) && (!infixs(*wptr) || (isnumb == 1 && (*wptr == '-' || *wptr == '+')))) { if (isnumb == 4 && isdigit(*wptr)) isnumb = 0; if (isnumb == 0 && tcnt > 0 && (*wptr == 'e' || *wptr == 'E')) isnumb = 1; else if (!(isdigit(*wptr) || (!gotdot && *wptr == '.')) || isnumb == 1) isnumb = 2; if (*wptr == '.') gotdot++; wptr++, wcnt++, tcnt++; } if (isnumb == 3 && tcnt > 1) { /* ?5 syntax */ NODE *qmtnode; qmtnode = cons_list(0, Left_Paren, Query, cnv_node_to_numnode (make_strnode(tptr+1, whead, tcnt-1, wtyp, strnzcpy)), END_OF_LIST); if (outline == NIL) { outline = qmtnode; } else { setcdr(lastnode, qmtnode); } lastnode = cddr(qmtnode); tnode = cons(Right_Paren, NIL); } else if (isnumb < 2 && tcnt > 0) { tnode = cons(cnv_node_to_numnode(make_strnode(tptr, whead, tcnt, wtyp, strnzcpy)), NIL); } else tnode = cons(intern(make_strnode(tptr, whead, tcnt, wtyp, strnzcpy)), NIL); } if (outline == NIL) outline = tnode; else setcdr(lastnode, tnode); lastnode = tnode; } return(outline); }
const char *ident(const char *text, CLanguageProxy& proxy, char *&scope) { const char *start = text, *id = start; char nameBuf[kMaxNameSize], *name = nameBuf; int size = 0, offset = start - proxy.Text(); bool destructor = false; while (isident(*text)) name_append(text, name, size); *name = 0; text = comment(text); if (strcmp(nameBuf, "extern") == 0) return i_extern(text); else if (strcmp(nameBuf, "header") == 0) { // first add "header" while (!isspace(*text)) { name_append(text, name, size); } // then a space *name++ = ' '; // skip past the double quote text = skip(text, '"'); // save the identifier location start = text; // put in the identifier [up to next quote] while (*text != '"') name_append(text, name, size); // terminate *name = 0; // add it char match[256]; long l = std::min((long)255, text - start); strncpy(match, start, l); match[l] = 0; if (proxy.Types()) proxy.AddFunction(nameBuf, match, offset, false); // walk past the double quote text++; // eat the code text = parens(text + 1, '{'); return text; } else if (strcmp(nameBuf, "options") == 0) { // first add the scope label for (char * c = scope ; (size < kMaxNameSize) ; size++) { if (*c == '\0') break; *name++ = *c++; } // then a space *name++ = ' '; // save the "options" location start = text; // then add "options" while (!isspace(*text)) { name_append(text, name, size); } // terminate *name = 0; // add it char match[256]; long l = std::min((long)255, text - start); strncpy(match, start, l); match[l] = 0; if (proxy.Types()) proxy.AddFunction(nameBuf, match, offset, false); // walk past the double quote text++; // eat the code text = parens(text + 1, '{'); return text; } else if (strcmp(nameBuf, "class") == 0 || strcmp(nameBuf, "struct") == 0 || strcmp(nameBuf, "union") == 0) { *name++ = ' '; if (isidentf(*text)) { while (isident(*text)) name_append(text, name, size); *name = 0; text = comment(text); if (*text == ':') { text = comment(text + 1); while (isident(*text)) text++; text = comment(text); while (isident(*text)) text++; text = comment(text); } if (*text == '{' && proxy.Types()) { char match[256]; long l = std::min((long)255, text - start); strncpy(match, start, l); match[l] = 0; proxy.AddFunction(nameBuf, match, offset, false); } } if (*text == '{') text = parens(text + 1, '{'); text = comment(text); while (isidentf(*text)) { char match[kMaxNameSize]; name = strchr(nameBuf, ' ') + 1; strncpy(match, nameBuf, name - nameBuf - 1); match[name - nameBuf - 1] = 0; while (isident(*text)) name_append(text, name, size); *name = 0; if (proxy.Types()) proxy.AddFunction(nameBuf, match, offset, false); text = comment(text); while (*text == ',' || *text == '*') text = comment(text + 1); } return text; } if (is_template(text)) { name_append(text, name, size); text = comment(text); while (isident(*text)) { while (isident(*text)) name_append(text, name, size); text = comment(text); if (*text == ',') { name_append(text, name, size); text = comment(text); } } if (*text == '>') { name_append(text, name, size); text = comment(text); } } while (*text == ':' && text[1] == ':') { name_append(text, name, size); name_append(text, name, size); text = comment(text); id = name; if (*text == '~') { name_append(text, name, size); text = comment(text); destructor = true; } if (isidentf(*text)) while (isident(*text)) name_append(text, name, size); text = comment(text); if (is_template(text)) { name_append(text, name, size); text = comment(text); while (isident(*text)) { while (isident(*text)) name_append(text, name, size); text = comment(text); if (*text == ',') { name_append(text, name, size); text = comment(text); } } if (*text == '>') { name_append(text, name, size); text = comment(text); } } } if (!destructor && strcmp(id, "operator") == 0) { if (*text == '(') name_append(text, name, size); text = comment(text); while (*text != '(' && size < kMaxNameSize) { if (isidentf(*text)) { while (isident(*text)) name_append(text, name, size); } else if (! isspace(*text)) { while (! isspace(*text) && ! isidentf(*text) && *text != '(' && ! (*text == '/' && (text[1] == '*' || text[1] == '/'))) name_append(text, name, size); } text = comment(text); } } *name = 0; if (*text == '(') { char match[256]; long l = std::min((long)255, text - start); strncpy(match, start, l); match[l] = 0; text = parens(text + 1, '('); text = comment(text); if (*text == ':') { while (*text != '{' && *text != ';') text++; if (*text == '{') { text = parens(text + 1, '{'); proxy.AddFunction(nameBuf, match, offset, false); } else { text++; if (proxy.Prototypes()) proxy.AddFunction(nameBuf, match, offset, true); } if (*text == '\n') text++; return text; } if (*text == ';') { if (proxy.Prototypes()) proxy.AddFunction(nameBuf, match, offset, true); return text + 1; } if (isidentf(*text) || *text == '{') { proxy.AddFunction(nameBuf, match, offset, false); text = skip_ne(text, '{'); text = parens(text, '{'); if (*text == '\n') text ++; return text; } } return text; } /* ident */