void * consume_loop(void *vptr) { int i, val; printf("consume_loop thread, addr(stack) = %x\n", &i); for (i = 0; i < NLOOP; i++) { val = consume(&buf_t); } return(NULL); }
/* [<id> [, <formals>]] */ static Formals *formals() { Formals *p = 0; if (isId()) { p = NEW(Formals); p->first = getId(); consume(); p->n = 1; p->rest = 0; if (isComma()) { consume(); p->rest = formals(); if (p->rest) { p->n = p->rest->n + 1; } } } return p; }
/* * top-level compilation; break the document into * style, html, and source blocks with footnote links * weeded out. */ static Paragraph * compile_document(Line *ptr, MMIOT *f) { ParagraphRoot d = { 0, 0 }; ANCHOR(Line) source = { 0, 0 }; Paragraph *p = 0; struct kw *tag; int eaten, unclosed; while ( ptr ) { if ( !(f->flags & MKD_NOHTML) && (tag = isopentag(ptr)) ) { /* If we encounter a html/style block, compile and save all * of the cached source BEFORE processing the html/style. */ if ( T(source) ) { E(source)->next = 0; p = Pp(&d, 0, SOURCE); p->down = compile(T(source), 1, f); T(source) = E(source) = 0; } p = Pp(&d, ptr, strcmp(tag->id, "STYLE") == 0 ? STYLE : HTML); ptr = htmlblock(p, tag, &unclosed); if ( unclosed ) { p->typ = SOURCE; p->down = compile(p->text, 1, f); p->text = 0; } } else if ( isfootnote(ptr) ) { /* footnotes, like cats, sleep anywhere; pull them * out of the input stream and file them away for * later processing */ ptr = consume(addfootnote(ptr, f), &eaten); } else { /* source; cache it up to wait for eof or the * next html/style block */ ATTACH(source,ptr); ptr = ptr->next; } } if ( T(source) ) { /* if there's any cached source at EOF, compile * it now. */ E(source)->next = 0; p = Pp(&d, 0, SOURCE); p->down = compile(T(source), 1, f); } return T(d); }
int main(int argc, char ** argv) { unsigned char * payload = malloc(PAYLOAD_LEN); unsigned char tag = server(payload); // Now consume the tag and the payload. // This is not part of the model and in fact would violate secrecy if observable. consume(tag, payload); return 0; }
std::unique_ptr<Expr> FlowParser::interpolatedStr() { FNTRACE(); FlowLocation sloc(location()); std::unique_ptr<Expr> result = std::make_unique<StringExpr>(stringValue(), sloc.update(end())); nextToken(); // interpolation start std::unique_ptr<Expr> e(expr()); if (!e) return nullptr; result = asString(std::move(result)); if (!result) { reportError("Cast error in string interpolation."); return nullptr; } while (token() == FlowToken::InterpolatedStringFragment) { FlowLocation tloc = sloc.update(end()); result = std::make_unique<BinaryExpr>( Opcode::SADD, std::move(result), std::make_unique<StringExpr>(stringValue(), tloc) ); nextToken(); e = expr(); if (!e) return nullptr; e = asString(std::move(e)); if (!e) { reportError("Cast error in string interpolation."); return nullptr; } result = std::make_unique<BinaryExpr>(Opcode::SADD, std::move(result), std::move(e)); } if (!consume(FlowToken::InterpolatedStringEnd)) return nullptr; if (!stringValue().empty()) { result = std::make_unique<BinaryExpr>( Opcode::SADD, std::move(result), std::make_unique<StringExpr>(stringValue(), sloc.update(end())) ); } nextToken(); return result; }
void D() { //printf("\nEnter <D>"); if(!strcmp(token,"CONSTANT")) consume(); if(!(strcmp(token,"FLT_TYP") && strcmp(token,"BOOL_TYP") && strcmp(token,"INT_TYP") && strcmp(token,"STR_TYP"))) { consume(); V(); if(!strcmp(token,"STMNT_END")) consume(); else { //error("Unterminated Declaration statement. Expecting ;"); } } //printf("\nExit <D>"); }
int main (int argc, char **argv) { printf("pong started.\n"); unsigned int i; for (i = 0; i < 20; i++) { if (i % 2 == 0) consume(); } return 0; }
Generator::ParenthesesType Parser::consumeParenthesesType() { if (peek() != '?') return Generator::Capturing; consume(); switch (consume()) { case ':': return Generator::NonCapturing; case '=': return Generator::Assertion; case '!': return Generator::InvertedAssertion; default: setError(ParenthesesTypeInvalid); return Generator::Error; } }
void Parser::forStat() { consume(TK_for); syms->enterBlock(false); CERR(TOKEN != TK_NAME, E_FOR_NAME, VNIL); Value name = lexer->info.name; int slot = syms->localsTop(); advance(); consume(':'+TK_EQUAL); patchOrEmitMove(slot+2, slot+2, expr(slot+2)); consume(':'); patchOrEmitMove(slot+3, slot+1, expr(slot+3)); int pos1 = emitHole(); int pos2 = HERE; syms->set(name, slot); syms->addLocalsTop(2); insideBlock(); emitJump(HERE, LOOP, VAL_REG(slot), pos2); emitJump(pos1, FOR, VAL_REG(slot), HERE); syms->exitBlock(false); }
void consumer_loop(void *arg) { int rc = 0; event_buffer_t *buffer = (event_buffer_t *)arg; while (rc == 0 && exit_signal == 0) { rc = consume(buffer); } if (rc != 0) printf("consumer problem\n"); }
void dt() { //printf("\nEnter <dt>"); if(!strcmp(token,"ID")) { consume(); dt1(); } else error("Declaration syntax error. Expecting IDENTIFIER or TERMINATOR"); //printf("\nExit <dt>"); }
boost::tuple<boost::tribool, InputIterator> parse(request& req, InputIterator begin, InputIterator end) { while (begin != end) { boost::tribool result = consume(req, *begin++); if (result || !result) return boost::make_tuple(result, begin); } boost::tribool result = boost::indeterminate; return boost::make_tuple(result, begin); }
//===----------------------------------------------------------------------===// // HexagonGOTPLT //===----------------------------------------------------------------------===// HexagonGOTPLT::HexagonGOTPLT(LDSection& pSection) : HexagonGOT(pSection) { // Create GOT0 entries reserve(HexagonGOTPLT0Num); // Skip GOT0 entries for (size_t i = 0; i < HexagonGOTPLT0Num; ++i) { consume(); } pSection.setAlign(8); }
void forkSmokers() { printf("FORKING THREE SMOKERS!\n\n"); pid_t S1 = fork(); if (S1 == 0) { //forked properly printf("SMOKER S1:%d\n", getpid()); smoke(); fflush(stdout); exit(0); } else if (S1 < 0) { perror("Failed to fork"); } else { wait(); consume(); pid_t S2 = fork(); if (S2 == 0) { printf("SMOKER S2:%d\n", getpid()); smoke(); fflush(stdout); exit(0); } else if (S2 < 0) { perror("Failed to fork"); } else { wait(); consume(); pid_t S3 = fork(); if (S3 == 0) { printf("SMOKER S3:%d\n", getpid()); smoke(); fflush(stdout); exit(0); } else if (S3 < 0) { perror("Failed to fork"); } } } }
// Fill a direct offer. // @param offer the offer we are going to use. // @param amount the amount to flow through the offer. // @returns: tesSUCCESS if successful, or an error code otherwise. TER Taker::fill (Offer const& offer, Amounts const& amount) { consume (offer, amount); // Pay the taker, then the owner TER result = view ().accountSend (offer.account(), account(), amount.out); if (result == tesSUCCESS) result = view ().accountSend (account(), offer.account(), amount.in); return result; }
/**Make sure current lookahead symbol matches token type <tt>t</tt>. * Throw an exception upon mismatch, which is catch by either the * error handler or by the syntactic predicate. */ void Parser::match(int t) { if ( DEBUG_PARSER ) std::cout << "enter match(" << t << ") with LA(1)=" << LA(1) << std::endl; if ( LA(1)!=t ) { if ( DEBUG_PARSER ) std::cout << "token mismatch: " << LA(1) << "!=" << t << std::endl; throw MismatchedTokenException(tokenNames, LT(1), t, false); } else { // mark token as consumed -- fetch next token deferred until LA/LT consume(); } }
void ANTLRParser:: resynch(SetWordType *wd,SetWordType mask) { /* MR8 [email protected] */ /* MR8 Change file scope static "consumed" to instance var */ /* if you enter here without having consumed a token from last resynch * force a token consumption. */ /* MR8 */ if ( !resynchConsumed ) {consume(); resynchConsumed=1; return;} /* if current token is in resynch set, we've got what we wanted */ /* MR8 */ if ( wd[LA(1)]&mask || LA(1) == eofToken ) {resynchConsumed=0; return;} /* scan until we find something in the resynch set */ while ( !(wd[LA(1)]&mask) && LA(1) != eofToken ) {consume();} /* MR8 */ resynchConsumed=1; }
RegNodePtr _rangeCharset() { if (tryConsume('[')) { auto p = new RegNode_Charset(); RegNodePtr r(p); bool isInv = tryConsume('^'); _rangeCharSeq(p); if (isInv) p->inverse(); consume(']'); return r; } return RegNodePtr(); }
void DocumentBuilder::consumeComment(Node *root){ StringBuffer *sb = null; if (root != null && !isIgnoringComments()){ sb = new StringBuffer(); } consume("<!--", 4); while(peek(0) != '-' || peek(1) != '-' || peek(2) != '>'){ if (peek(0) == -1){ delete sb; get(); } if (root && !isIgnoringComments()){ sb->append(get()); }else{ get(); } } consume("-->", 3); if (root != null && !isIgnoringComments()){ root->appendChild(doc->createComment(sb)); } }
void Parser::match(Token::ID i) { if (i == curTok().Type) { consume(); } else { SourceLoc begin = curTok().Begin; SourceLoc end = curTok().getEnd(); ParseError err(begin,ParseError::match_fail); err << Token::getHumanTokenName(i) << Token::getHumanTokenName(lookahead(0).Type); err.setEnd(end); throw err; } }
static struct block *logical_or_expression(struct block *block) { struct block *right; block = logical_and_expression(block); if (peek().token == LOGICAL_OR) { consume(LOGICAL_OR); right = cfg_block_init(); block = eval_logical_or(block, right, logical_or_expression(right)); } return block; }
void Parser::parse_multi_line_statements( CmdList& commands ) { consume_eols(); while (next_is_statement()) { Cmd* statement = parse_statement(); if (statement) { commands.add( statement ); } while (consume_eols() || consume(TOKEN_SEMICOLON)) {} } }
bool Data::get(std::string text){ for (int i = 0; i < (int) text.size(); i++){ if (text[i] != this->charAt(currentPosition + i)){ return false; } } for (int i = 0; i < (int) text.size(); i++){ consume(); } return true; }
//----------------------------------------- int factor(void) { TOKEN *t; char temp[MAX]; char *sym = (char *)malloc(20); int index; // printf("%s ", currentToken -> image); switch(currentToken -> kind) { case UNSIGNED: t = currentToken; consume(UNSIGNED); sprintf(sym, "@%s", t -> image); index = enter(sym, t -> image, TRUE); return index; case PLUS: consume(PLUS); t = currentToken; consume(UNSIGNED); sprintf(sym, "@%s", t -> image); index = enter(sym, t -> image, TRUE); return index; case MINUS: consume(MINUS); t = currentToken; consume(UNSIGNED); sprintf(sym, "@_%s", t -> image); char *neg = (char *)malloc(20); sprintf(neg, "-%s", t -> image); index = enter(sym, neg, TRUE); return index; case ID: t = currentToken; consume(ID); index = enter(t -> image, "0", TRUE); return index; case LEFTPAREN: consume(LEFTPAREN); index = expr(); consume(RIGHTPAREN); return index; default: displayErrorLoc(); printf("Scanning %s, expecting factor\n", currentToken -> image); abend(); } }
static struct block *equality_expression(struct block *block) { struct var value; block = relational_expression(block); while (1) { value = block->expr; if (peek().token == EQ) { consume(EQ); block = relational_expression(block); block->expr = eval_expr(block, IR_OP_EQ, value, block->expr); } else if (peek().token == NEQ) { consume(NEQ); block = relational_expression(block); block->expr = eval_expr(block, IR_OP_EQ, var_int(0), eval_expr(block, IR_OP_EQ, value, block->expr)); } else break; } return block; }
void dt() { if(!strcmp("ID",token)) { consume(); dtp(); } else { error("Declaration syntax error. "); consumeStatement(); } }
static void DispatchEvent(KonohaContext *kctx, kbool_t (*consume)(KonohaContext *kctx, struct JsonBuf *, KTraceInfo *), KTraceInfo *trace) { struct EventContext *eventContext = EVENTAPI eventContext; pthread_mutex_lock(&eventContext->lock); RawEvent *rawEvent = dequeueRawEventFromLocalQueue(eventContext->queue); pthread_mutex_unlock(&eventContext->lock); while(rawEvent != NULL) { consume(kctx, (struct JsonBuf *)rawEvent, trace); pthread_mutex_lock(&eventContext->lock); rawEvent = dequeueRawEventFromLocalQueue(eventContext->queue); pthread_mutex_unlock(&eventContext->lock); } }
static void DispatchEvent(KonohaContext *kctx, kbool_t (*consume)(KonohaContext *kctx, struct JsonBuf *, KTraceInfo *), KTraceInfo *trace) { struct EventContext *eventContext = PLATAPI eventContext; if(eventContext->caughtSignal != 0) { eventContext->caughtSignal = 0; AddSignalEvent(kctx, eventContext, trace); } RawEvent *rawEvent = dequeueRawEventFromLocalQueue(eventContext->queue); while(rawEvent != NULL) { consume(kctx, (struct JsonBuf *)rawEvent, trace); rawEvent = dequeueRawEventFromLocalQueue(eventContext->queue); } }
static int number(lexparam l) { int token = INTEGER; int c = peek(l); int base = 10; int state = 0; double dval = 0; int fcnt = 0; int exp = 0; int expmult = 1; /* multi-digit numbers can't start with 0 in json, so parsing numbers * starting with 0 and 0x as octal and hex respectively does not * impede our ability to parse valid json. */ for(; c >= 0; c = consume(l)) { int v = digit(c); top: if(v < 0 || v >= base) switch(c) { // N.B. starting with a . is not legal JSON. case '.': if(state < 3) { if(state == 1) base = 10; state = 3; token = REAL; } else goto end; break; case 'e': case 'E': if(state < 4) { state = 4; token = REAL; } else goto end; break; case 'x': if(state == 1) { base = 16; state = 2; } else goto end; break; case '-': expmult = -1; /* fall through */ case '+': if(state == 4) { state = 5; } else goto end; break; default: goto end; } else switch(state) { case 0: if(v == 0) { state = 1; base = 8; break; } /* fall through */ case 1: state = 2; goto top; case 3: fcnt++; /* fall through */ case 2: dval = dval*base + v; break; case 4: state = 5; /* fall through */ case 5: exp = base*exp + v; break; } } end: switch(token) { case REAL: l.yylval->real = dval*pow(base, expmult*exp-fcnt); break; case INTEGER: // TODO range check l.yylval->integer = (int)dval; break; } return token; }
mu::io::character_result mu::io::lexer::hex_code (int size_a) { assert (size_a == 2 || size_a == 8); mu::io::character_result result ({'\0', nullptr}); auto size_l (size_a >> 1); for (int i (0); i < size_l && result.error == nullptr; ++i) { for (auto j (0); j < 2 && result.error == nullptr; ++j) { uint32_t code (source [0]); switch (code) { case U'a': case U'b': case U'c': case U'd': case U'e': case U'f': code -= 0x20; // Fall through case U'A': case U'B': case U'C': case U'D': case U'E': case U'F': code -= 0x7; // Fall through case U'0': case U'1': case U'2': case U'3': case U'4': case U'5': case U'6': case U'7': case U'8': case U'9': code -= 0x30; result.character <<= 4; result.character |= code; consume (1); break; default: result.error = new mu::core::error_string (U"Non-hex character", mu::core::error_type::non_hex_character, mu::core::region (position, position)); break; } } } return result; }