/* There was going to be a nice fadeout effect using the allegro fade_out and fade_in functions, but for some reason these screwed up the palette. Oh well. */ void end_game(int fade_speed) { // fade_out(fade_speed); rest(1000 / fade_speed); clear_keybuf(); clear_bitmap(screen); // set_palette(palet); init_palette(); set_palette(palet); int challenge_winner = 0; if (arena[0].teams == 0) challenge_winner = score_table(); else challenge_winner = score_table_team(); if (arena[0].challenge_level != 0) { if (challenge_winner == 0) { switch(arena[0].challenge_level) { case 1: information_box("", "Norbert won?", "Hmm.", 0); break; case 2: information_box("", "Looks like you need some more practice.", "", 0); break; case 3: information_box("", "Sorry, you lose.", "", 0); break; case 4: information_box("", "Good, but not great.", "", 0); break; case 5: information_box("", "Oh well, better luck next time.", "", 0); break; case 6: information_box("", "Almost there. Try again.", "", 0); break; case 7: information_box("", "Very good, but not quite good enough.", "", 0); break; } end_challenge(); } } if (arena[0].qstart != QSTART_NONE) end_qstart(); //shutdown_network(); // fade_in(*palet, fade_speed); // set_palette(*palet); do { } while (keypressed() == 0); clear_keybuf(); //net_init(); }
void countdownEven(int n) { if (n == 0) { printf("0\n"); } else { if (n % 2 == 0) { printf("%d ", n); } countdownEven(rest(n)); } }
List *take(int n, List *xs) { double head = 0; if (null(xs) || n <= 0) { return init(); } else { head = first(ref(xs)); return cons(head, take(n-1, rest(xs))); } }
// (atan x) // (atan x y) Cell* op_atan(Scheme *sc) { Cell* x = first(sc->args); if (rest(sc->args) == &g_nil) { return s_return_helper(sc, make_real(sc, atan(double_value(x)))); } else { Cell* y = second(sc->args); return s_return_helper(sc, make_real(sc, atan2(double_value(x), double_value(y)))); } }
void SwapScreen::waitForKey(){ BITMAP* textBuf; textBuf = create_bitmap(150,50); clear_to_color(textBuf,makecol(255,0,255)); counter=255; flag=false; rest(20); clear_keybuf(); while (!keypressed()){ textprintf_ex(textBuf,font,5,5, makecol(counter,counter,counter), -1, "<Press Any Key>"); draw_sprite(screen,textBuf,160, SCREEN_H/2); setCounter(); } rest(20); destroy_bitmap(textBuf); }
List *map(double (*f)(double), List *xs) { double head = 0; if (null(xs)) { return init(); } else { head = first(ref(xs)); return cons((*f)(head), map(f, rest(xs))); } }
void controllNave(BITMAP * buffer,BITMAP * nave,SAMPLE * sound, int x,int y){ draw_sprite(buffer, nave,x,y); int color = 0,s; if(!key[KEY_SPACE] == 0){ it++; rest(100); shotGun(x+20,y-20); s = play_sample(sound, 100, 0, 2000, 0); } }
static bool bind_vars(obj* vars, obj lt, obj rt){ obj utype; switch(lt->type){ default: break; case tSymbol: if(macromode){ if(obj rr = search_assoc(car(macro_env), lt)){ //macromode = false; if(vars) add_assoc(vars, rr, rt); //macromode = true; return true; } } if(vars) add_assoc(vars, lt, rt); return true; case tRef: let(&(uref(lt)), rt); return true; case INT: return equal(lt, rt); case tOp: utype = search_assoc(curr_interp->types, ult(lt)); if(utype){ if(vrInt(utype) != rt->type) return false; return bind_vars(vars, urt(lt), uref(rt)); } if(rt->type!=tOp) return false; if(! bind_vars(vars, ult(lt), ult(rt))) return false; return bind_vars(vars, urt(lt), urt(rt)); case LIST: if(rt->type!=LIST) return false; list x=ul(lt), a=ul(rt); for(; (x && a); x=rest(x),a=rest(a)){ if(!bind_vars(vars, first(x), first(a))) return false; } if(x||a) return false; return true; } print(lt); assert(0); return nil; }
bool CLoginDialog::registration(){ CString phone, name, email; int country=((CComboBox*) GetDlgItem(IDC_COUNTRY))->GetCurSel(); GetDlgItemText(IDC_PHONE,phone); GetDlgItemText(IDC_NAME,name); GetDlgItemText(IDC_EMAIL,email); std::string header = "/oneworld/webreg?country="; header+=countries[country][2]; header+="&number="; header+=(CT2CA)phone; header+="&name="; header+=(CT2CA)name; header+="&email="; header+=(CT2CA)email; header+="&countrycode="; header+=countries[country][2]; CInternetSession session; CHttpConnection *pConnection = session.GetHttpConnection(_T("89.163.142.253")); char result[500]; CString request(header.c_str()); CHttpFile *pFile = pConnection->OpenRequest(1,request); if(!pFile->SendRequest()) return false; //pFile->QueryInfo(HTTP_QUERY_FLAG_REQUEST_HEADERS,result,(LPDWORD)500); #ifdef _DEBUG pFile->Read((void*)result,500); _cprintf("%s",result); #endif CString rest(result); int start=rest.Find(_T("success\":\"")); if(start<0) return false; start+=((CString)_T("success\":\"")).GetLength(); int end=rest.Find(_T("\""),start); if(end<0) return false; CString success=rest.Mid(start, end-start); #ifdef _DEBUG _cprintf("%s",(CT2CA)success); _cprintf("%s",result); #endif start=rest.Find(_T("msg\":\"")); start+=((CString)_T("msg\":\"")).GetLength(); end=rest.Find(_T("\""),start); CString msg=rest.Mid(start, end-start); SetDlgItemText(IDC_LOGTEXT,msg); Sleep(2000); return true; }
int main() { int koseler[8]; int kirmizi, yesil, mavi, renk; // Allegro'yu ilklendir allegro_init(); // klavyeyi ilklendir install_keyboard(); // rastgele sayı üretecini ilklendir srand(time(NULL)); // ekran kipini ayarla int donen = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); if (donen != 0) { allegro_message(allegro_error); return; } // ekran çözünürlüğünü göster textprintf(screen, font, 0, 0, 15, "Cokgen cizme programı - %dx%d - Cikmak icin ESC tusuna basiniz", SCREEN_W, SCREEN_H); // çıkış tusuna basılana kadar devam et while (!key[KEY_ESC]) { // rastgele bir nokta seç koseler[0] = 10 + rand() / (RAND_MAX / (SCREEN_W - 20)); koseler[1] = 10 + rand() / (RAND_MAX / (SCREEN_H - 20)); koseler[2] = koseler[0] + rand() / (RAND_MAX / 30) + 50; koseler[3] = koseler[1] + rand() / (RAND_MAX / 30) + 50; koseler[4] = koseler[2] + rand() / (RAND_MAX / 30) - 100; koseler[5] = koseler[3] + rand() / (RAND_MAX / 30) + 50; koseler[6] = koseler[4] + rand() / (RAND_MAX / 30); koseler[7] = koseler[5] + rand() / (RAND_MAX / 30) - 100; // rastgele bir renk seç kirmizi = rand() / (RAND_MAX / 255 + 1); yesil = rand() / (RAND_MAX / 255 + 1); mavi = rand() / (RAND_MAX / 255 + 1); renk = makecol(kirmizi, yesil, mavi); // çokgen çiz polygon(screen, 4, koseler, renk); rest(50); } // programı sonlandır allegro_exit(); }
int main() { allegro_init(); install_keyboard(); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED, width, height, 0, 0); bialy=makecol(200,200,200); czarny=makecol(0,0,0);//ustawienie kodow kolorow BITMAP *buffer = create_bitmap(width, height); clear_to_color(buffer, bialy); x=width/2; y=height/2;//ustawienie mrowki w centrum direction=0;//mrowka zwrocona poczatkowo w gore while (!keypressed()) { if(getpixel(buffer,x,y)==bialy)//jesli mrowka znajduje sie na polu bialym { //allegro_message("BIALY"); direction = (direction+3)%4;//obrot w lewo rectfill(buffer,x-0.5*a,y-0.5*a,x+0.5*a,y+0.5*a,czarny);//zamalowanie pola na czarno } else{ direction = (direction+5)%4;//obrot w prawo rectfill(buffer,x-0.5*a,y-0.5*a,x+0.5*a,y+0.5*a,bialy);//zamalowanie pola na bialo } x += a*moves[direction][0]; y += a*moves[direction][1];//przesuniecie mrowki w zadanym kierunku strcpy(napis,"X: "); strcat(napis,itoa(x,str,10)); strcat(napis," Y: "); strcat(napis,itoa(y,str,10)); strcat(napis," D: "); strcat(napis,itoa(direction,str,10)); textout_centre_ex(buffer, font, napis, SCREEN_W / 2, 0, makecol(255, 0, 0), makecol(0, 0, 0)); if(x<0.5*a || y<0.5*a || x>width-0.5*a || y>height-0.5*a)break; //ochrona przed wyjsciem mrowki poza ramy ekranu blit(buffer, screen, 0, 0, 0, 0, 640, 700);//wklejenie bufora na ekran rest(10);//odczekanie pomiêdzy kolejnym ruchem } readkey(); destroy_bitmap(buffer); return 0; }
static gint keyboard_event_handler(GtkWidget *mk, GdkEventKey *event, gpointer ignored) { int note; char *key; guint keyval; GdkKeymapKey kk; PianoKeyboard *pk = PIANO_KEYBOARD(mk); (void) ignored; /* We're not using event->keyval, because we need keyval with level set to 0. E.g. if user holds Shift and presses '7', we want to get a '7', not '&'. */ kk.keycode = event->hardware_keycode; kk.level = 0; kk.group = 0; keyval = gdk_keymap_lookup_key(NULL, &kk); key = gdk_keyval_name(gdk_keyval_to_lower(keyval)); if (key == NULL) { g_message("gtk_keyval_name() returned NULL; please report this."); return FALSE; } note = key_binding(pk, key); if (note < 0) { /* Key was not bound. Maybe it's one of the keys handled in jack-keyboard.c. */ return FALSE; } if (note == 128) { if (event->type == GDK_KEY_RELEASE) { rest (pk); } return TRUE; } note += pk->octave * 12; assert(note >= 0); assert(note < NNOTES); if (event->type == GDK_KEY_PRESS) { press_key(pk, note); } else if (event->type == GDK_KEY_RELEASE) { release_key(pk, note); } return TRUE; }
void menu() { int a=0; char s[50],version[]="1.0.8"; //play_sample(themes,255,128,1000,1); while(1) { textprintf_centre(screen,font,SREDINA,VISINA/3,15, " TANKS! v%s",version); if(a==0) { textprintf_centre(screen,font,SREDINA,VISINA/3+15, 15,"->Start game",version); textprintf_centre(screen,font,SREDINA,VISINA/3+30, 15," Exit",version); } else { textprintf_centre(screen,font,SREDINA,VISINA/3+15, 15," Start game",version); textprintf_centre(screen,font,SREDINA,VISINA/3+30, 15,"->Exit",version); } if(key[KEY_ESC]) exit(1); if(key[KEY_ENTER]) { if(a==0) break; else exit(1); } if(key[KEY_UP]||key[KEY_DOWN]) { a=!a; rest(100); } } //stop_sample(themes); rest(200); clear(screen); narisi(); }
int list_walk(LIST *list, list_walk_action action, gptr argument) { int error=0; while (list) { if ((error = (*action)(list->data,argument))) return error; list=rest(list); } return 0; }
void Abertura (void) { BITMAP *buffer; SAMPLE *som, *grito, *som2, *som3; buffer = create_bitmap(LARGURA, ALTURA); carregaSom_Abertura(&som3, "../audio/thunder.wav"); play_sample(som3, 255, 128, 1000, FALSE); rest (1000); carregaImg_Abertura(&buffer, "../grafics/img01.tga"); highcolor_fade_in_Abertura(buffer, 3); carregaSom_Abertura(&som, "../audio/00.wav"); play_sample(som, 255, 128, 1000, FALSE); carregaSom_Abertura(&som2, "../audio/a_thunder.wav"); play_sample(som2, 255, 128, 1000, FALSE); rest (2500); carregaImg_Abertura(&buffer, "../grafics/img02.tga"); play_sample(som, 255, 128, 1000, FALSE); carregaSom_Abertura(&som, "../audio/01.wav"); play_sample(som, 1000, 128, 1000, FALSE); carregaSom_Abertura(&grito, "../audio/scream05.wav"); play_sample(grito, 255, 128, 1000, FALSE); blit(buffer,screen,0,0,0,0,LARGURA,ALTURA); highcolor_fade_out_Abertura (5); rest(1000); destroy_sample(som); destroy_sample(som2); destroy_sample(som3); destroy_sample(grito); destroy_bitmap(buffer); }
void LMain::main_loop() { while (true) { undraw(); // Depending on the vsync option, I do either frameskipping or // a set number of logic cycle calculations. if (gloB->screen_vsync) { const unsigned loops = Help::get_timer_ticks_per_draw() + 1; rest(1); while (++tck % loops != 0) calc(); // To not have the program hang when the user changes the vsync // option, set tck here. The following "else" will start working // immediately in the next main_loop() call then. if (!gloB->screen_vsync) tck = Help::timer_ticks; } // If vsync is deactivated, do normal frameskipping: Calculate until // the logic is up to date, then draw. If the computer is slow, several // logic updates will be calcd before the draw. else { while (tck == Help::timer_ticks) { rest(1); // The mouse poll is something I've inserted here against // the Yassin bug. The Yassin bug is when clicks from the user // won't get registered by L++. I hope this helps. hardware.poll_mouse(); } while (tck < Help::timer_ticks) { ++tck; calc(); } } if (exit) break; draw(); } // This gets uncommented only whenever I want to test for exit crashes. // clear_to_color(screen, makecol(0, 0, 128)); // rest(400); }
/* Imprime el menu principal de la aplicacion */ void menu(){ clear_to_color(screen, 0x000000); textout_ex(screen, font, "ALGORITMOS PARA DIBUJAR PRIMITIVAS" , 200, 50, 0xFFFFFF, 0x000000); textout_ex(screen, font, "1.Linea DDA" , 150, 100, 0xFFFFFF, 0x000000); textout_ex(screen, font, "2.Linea Bresenham" , 150, 130, 0xFFFFFF, 0x000000); textout_ex(screen, font, "3.Circulo Polar" , 150, 160, 0xFFFFFF, 0x000000); textout_ex(screen, font, "4.Circulo Bresenham" , 150, 190, 0xFFFFFF, 0x000000); textout_ex(screen, font, "PRESIONE LA TECLA ESC PARA SALIR" , 200, 300, 0xFFFFFF, 0x000000); textout_ex(screen, font, "<< Computacion grafica Unimag 2014-I >>" , 15, 430, 0xFFFFFF, 0x000000); rest(200); }
void explosion2(BITMAP *bmp, int x,int y,int finalcolor) { int color,size; for (n=0; n<20; n++) { color = makecol(rand()%255,rand()%255,rand()%255); size = 20+rand()%20; circlefill(bmp, x, y, 350, color); rest(2); } circlefill(bmp, x, y, 350, finalcolor); }
void gameover() { BITMAP *fin = load_bitmap("media/gameover.bmp", NULL); if(fin == NULL) ERREUR("Echec chargement fin"); blit(fin, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); textprintf_centre_ex(screen, font, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0), makecol(255, 0, 0), " Score : %d ", score); while(keypressed()) readkey(); rest(2000); readkey(); }
//play intro movie etc void CGame::PlayIntro() { //play FLC from memory play_memory_fli(data[ZANIMATION].dat,screen, 0, NULL); // display flashing prompt text_mode(-1); //text with transparent background //crude by effective blinking text :) while (!keypressed()) { textout_centre(screen,font,"INSERT COIN(S)..",320,400,makecol(0,0,0)); rest(600); textout_centre(screen,font,"INSERT COIN(S)..",320,400,makecol(206,206,90)); rest(300); } clear_keybuf(); }
int spkrioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) { #ifdef SPKRDEBUG printf("spkrioctl: entering with dev = %"PRIx64", cmd = %lx\n", dev, cmd); #endif /* SPKRDEBUG */ if (minor(dev) != 0) return(ENXIO); else if (cmd == SPKRTONE) { tone_t *tp = (tone_t *)data; if (tp->frequency == 0) rest(tp->duration); else tone(tp->frequency, tp->duration); } else if (cmd == SPKRTUNE) { tone_t *tp = (tone_t *)(*(void **)data); tone_t ttp; int error; for (; ; tp++) { error = copyin(tp, &ttp, sizeof(tone_t)); if (error) return(error); if (ttp.duration == 0) break; if (ttp.frequency == 0) rest(ttp.duration); else tone(ttp.frequency, ttp.duration); } } else return(EINVAL); return(0); }
// -2 -> hole -1 -> all chances are over 0 -> ball lost 1 -> successful int ball::update_position(int value) { play_sample(swing, VOLUME, PANNING, PITCH, TRUE); rest(100); stop_sample(swing); currx = initx; curry = inity; for (int i=0; i<value-50; i+=5) { //without -50 level 3 was not working properly impossible to hit condition currx+=xspeed; curry+=yspeed; blit(buffer, screen, 0, 0, 0, 0, 640, 480); draw_sprite(screen, image, currx, curry); if(HOLE.is_inside(currx, curry, currx+width, curry+height)) { //birdie blit(buffer, screen, 0, 0, 0, 0, 640, 480); draw_sprite(screen, image, 60, 60); //draw ball inside hole blit(win, screen, 0, 0, 0, 0, 640, 480); rest(2500); return -2; } //check for ball in water for level 1 if (level == 1) { if (!(((curry > 15 && curry<156) && (currx >16 && currx<615)) || ((curry > 156 && curry<460) && (currx >475 && currx<615)))) { return(ball_lost()); } } //for level 2 else if (level == 2) { if (!((((curry>15&&curry<120)||(curry>360&&curry<465)) && (currx>23&&currx<617)) || ((curry>120&&curry<360)&&(currx>430&&currx<617)))) { return(ball_lost()); } } //for level 3 else if (level == 3) { if (!((((curry>15&&curry<110)||(curry>380&&curry<450)) && (currx>22&&currx<618)) || ((curry>110&&curry<380)&&(currx>498&&currx<618)) || ((curry>140&&curry<380)&&(currx>22&&currx<110)))) { return(ball_lost()); } } rest(260-value); //rest before repeating loop } initx = currx; inity = curry; if (ball_left < 0) { draw_sprite(screen, gameover, 0, 0); rest(2500); return -1;} //All chances are over return 1; //successful }
UnicodeString & FilteredNormalizer2::normalizeSecondAndAppend(UnicodeString &first, const UnicodeString &second, UBool doNormalize, UErrorCode &errorCode) const { uprv_checkCanGetBuffer(first, errorCode); uprv_checkCanGetBuffer(second, errorCode); if(U_FAILURE(errorCode)) { return first; } if(&first==&second) { errorCode=U_ILLEGAL_ARGUMENT_ERROR; return first; } if(first.isEmpty()) { if(doNormalize) { return normalize(second, first, errorCode); } else { return first=second; } } // merge the in-filter suffix of the first string with the in-filter prefix of the second int32_t prefixLimit=set.span(second, 0, USET_SPAN_SIMPLE); if(prefixLimit!=0) { UnicodeString prefix(second.tempSubString(0, prefixLimit)); int32_t suffixStart=set.spanBack(first, INT32_MAX, USET_SPAN_SIMPLE); if(suffixStart==0) { if(doNormalize) { norm2.normalizeSecondAndAppend(first, prefix, errorCode); } else { norm2.append(first, prefix, errorCode); } } else { UnicodeString middle(first, suffixStart, INT32_MAX); if(doNormalize) { norm2.normalizeSecondAndAppend(middle, prefix, errorCode); } else { norm2.append(middle, prefix, errorCode); } first.replace(suffixStart, INT32_MAX, middle); } } if(prefixLimit<second.length()) { UnicodeString rest(second.tempSubString(prefixLimit, INT32_MAX)); if(doNormalize) { normalize(rest, first, USET_SPAN_NOT_CONTAINED, errorCode); } else { first.append(rest); } } return first; }
// Function: execute stand up from chair gesture void GestureManager::standFromChair() { // Activate stiffness std_srvs::Empty empty; stiffness_enable_client.call(empty); // Execute stand chair motion //playGesture("stand", "gesture", "global", "stand chair"); playGesture(motion_state::body_state::STAND, motion_state::motion_type::GESTURE, gesture_names::gesture_subtype::GLOBAL, gesture_names::gesture_motion_names::GLOBAL_STAND_FROM_CHAIR); // Rest rest(); // Wakeup wakeUp(); }
static obj do_assign(obj lt, obj rt){ switch(type(lt)) { case tRef: return retain(*let(&(uref(lt)), rt)); case tSymbol: return retain(*let(lfind_var(lt),rt)); default: break; case tInd:{ obj *var; var = lfind_var(ult(lt)); if(!*var) error("the vector does not exist."); if((*var)->refcount > 1){ obj nv = copy(*var); release(*var); *var = nv; myPrintf("performance alert: copy"); } obj inds = eval(urt(lt)); doLInd(var, ul(inds), rt); release(inds); return retain(rt); } case LIST: return applyCC(do_assign, lt, rt); if(type(rt)!=LIST) error("list<-nonlist"); list s = ul(rt); for(list l = ul(lt); l; l=rest(l), s=rest(s)){ if(! s) error("number is not enough for rhs."); do_assign(first(l),first(s)); } if(s) error("too much for rhs."); return nil; } print(lt); assert(0); return nil; }
int main() { inicia_allegro(500,450); inicia_audio(70,70); BITMAP *nave = load_bitmap("nave.bmp",NULL); BITMAP *nube = load_tga("Galaxy2.tga",NULL); BITMAP *bala = load_bitmap("Bala2.bmp", NULL); // otra cosa BITMAP *buffer = create_bitmap(500,450); LOCK_VARIABLE(speed_counter); LOCK_FUNCTION(inc_speed_counter); install_int_ex(inc_speed_counter, BPS_TO_TIMER(30)); int i = 450 , dsw = 0 , cont = 0; while(!key[KEY_ESC]){ blit(nube,buffer,0,--i,0,0,500,450); if(i == 0) i=450; pintar_nave(nave,buffer,nav); if(key[KEY_UP]){ nav.dir = 1; nav.y -= 1; } else if(key[KEY_DOWN]) { nav.dir = 1; nav.y += 2; } if(key[KEY_RIGHT]){ nav.dir = 2; nav.x += 1; } else if(key[KEY_LEFT]){ nav.dir = 0; nav.x -= 1; } else nav.dir = 1; blit(buffer,screen,0,0,0,0,500,450); rest(5); } destroy_bitmap(buffer); destroy_bitmap(nave); destroy_bitmap(nube); return 0; }
void loop(char campo[V][H], int tam) { int muerto = 0; int tecla = 0; do { draw(campo); input(campo, &tam, &muerto); // comprobar la tecla que se pulsa if(muerto == 0) { if(keypressed()) { tecla = readkey() >> 8; if(tecla == KEY_DOWN && snake[0].ModY != -1) { snake[0].ModX = 0; snake[0].ModY = 1; } if(tecla == KEY_UP && snake[0].ModY != 1) { snake[0].ModX = 0; snake[0].ModY = -1; } if(tecla == KEY_LEFT && snake[0].ModX != 1) { snake[0].ModX = -1; snake[0].ModY = 0; } if(tecla == KEY_RIGHT && snake[0].ModX != -1) { snake[0].ModX = 1; snake[0].ModY = 0; } } } else { allegro_message("GAME OVER"); } update(campo, tam); if(PAUSA == 50) rest(50); else rest(PAUSA); } while (muerto == 0 && tecla != KEY_ESC);
static void intro_screen(void) { BITMAP *bmp; play_sample(data[INTRO_SPL].dat, 255, 128, 1000, FALSE); bmp = create_sub_bitmap(screen, SCREEN_W / 2 - 160, SCREEN_H / 2 - 100, 320, 200); play_memory_fli(data[INTRO_ANIM].dat, bmp, FALSE, NULL); destroy_bitmap(bmp); rest(1000); fade_out(1); }
/////////////////////////////////////////////////////////////////////////////// // Main program /////////////////////////////////////////////////////////////////////////////// int main() { std::cout << "/////////////////////////////////////////////////////////\n\n"; std::cout << "Expression parser...\n\n"; std::cout << "/////////////////////////////////////////////////////////\n\n"; std::cout << "Type an expression...or [q or Q] to quit\n\n"; typedef std::string::const_iterator iterator_type; typedef client::ast::program ast_program; typedef client::ast::printer ast_print; typedef client::ast::eval ast_eval; std::string str; while (std::getline(std::cin, str)) { if (str.empty() || str[0] == 'q' || str[0] == 'Q') break; auto& calc = client::calculator; // Our grammar ast_program program; // Our program (AST) ast_print print; // Prints the program ast_eval eval; // Evaluates the program iterator_type iter = str.begin(); iterator_type end = str.end(); boost::spirit::x3::ascii::space_type space; bool r = phrase_parse(iter, end, calc, space, program); if (r && iter == end) { std::cout << "-------------------------\n"; std::cout << "Parsing succeeded\n"; print(program); std::cout << "\nResult: " << eval(program) << std::endl; std::cout << "-------------------------\n"; } else { std::string rest(iter, end); std::cout << "-------------------------\n"; std::cout << "Parsing failed\n"; std::cout << "stopped at: \"" << rest << "\"\n"; std::cout << "-------------------------\n"; } } std::cout << "Bye... :-) \n\n"; return 0; }
/** * Recursive descent ABC parser */ void parse(abcToken tok) { switch (tok) { case T_NOTE: note(); break; case T_REST: rest(); break; case T_GCHORD: /*gchord();*/ break; } }