Esempio n. 1
0
File: parse.cpp Progetto: shaurz/amp
Value
Parser::parse()
{
	switch (eats()) {
	case '(':
		read(); return list();
	case '\'':
		read(); return quoted(sym_quote);
	case '`':
		read(); return quoted(sym_quasiquote);
	case ',':
		read();
		if (c == '@') {
			read();
			return quoted(sym_unquote_splicing);
		}
		else
			return quoted(sym_unquote);
	case ')':
		parse_error("too many right-parens");
	case EOF:
		parse_error("unexpected end of file");
	}
	return atom();
}
Esempio n. 2
0
// The print out of info for each animal
// will either print the default message or custom one from a subclass
void Zoo::info(){
   printName();
   has4Legs();
   printName();
   eats(); 
   printName();
   hasFur();
}
Esempio n. 3
0
File: parse.cpp Progetto: shaurz/amp
Value
Parser::list()
{
	Value p = NIL, t = NIL, x;

	while (eats() != ')') {
		x = parse();
		p = cons(x, p);
		if (eats() == '.') {
			if (next() == ')')
				parse_error("nothing after dot");
			t = parse();
			if (eats() != ')')
				parse_error("after dot terminator");
		}
	}
	read();
	return reverse(p, t);
}
Esempio n. 4
0
static void		thinks(t_philo *philo,
			       pthread_mutex_t *mutex)
{
  printf(THINK_MSG);
  sleep(TIME_THINK);
  while (philo->hungry < MAX_HUNGRY)
    {
      if (pthread_mutex_trylock(mutex) == 0)
	{
	  eats(philo);
	  return ;
	}
      sleep(TIME_THINK);
      philo->hungry++;
    }
}
Esempio n. 5
0
File: parse.cpp Progetto: shaurz/amp
int
Parser::next()
{
	read();
	return eats();
}
Esempio n. 6
0
File: parse.cpp Progetto: shaurz/amp
bool
Parser::eof()
{
	eats();
	return c == EOF;
}
Esempio n. 7
0
/* A philosopher thread function, called out of CSdispatch */
STATUS
philosopher(
i4 mode,
MY_SCB *scb,
i4 *next_mode)
{
    i4 bites = 0;

#ifdef EX_DEBUG
    EX_CONTEXT context;

    if (EXdeclare(ex_handler, &context) != OK) {
	/* some exception was raised */
	Psem( &SIsem );
	SIfprintf( stderr,"Error: unexpected exception in philosopher()...");
	Vsem( &SIsem );

	EXdelete();
	return FAIL;
    }
#endif

    switch( mode )
    {
    case CS_INITIATE:	/* A new philsopher is born */

	scb->phil = Threads++;
	status[scb->phil] = mode;
	while( bites < NBITES )
	{
	    getsticks( scb->phil );
	    eats( scb->phil );
	    bites++;
	    freesticks( scb->phil );
	    thinks( scb->phil );
	}

	/* fall into: */

    default:
	*next_mode = CS_TERMINATE;
	break;

    case CS_TERMINATE:
	if( Noisy )
	{
# ifdef EX_SIG_DEBUG
	    signal(SIGUSR1, intfunc);
	    if (scb->phil == 1) {
		SIfprintf(stderr, "Send a signal #%d to process #%d\n",
			SIGUSR1, getpid());
		pause();
	    }
# endif /* EX_SIG_DEBUG */
	    Psem( &SIsem );
	    SIfprintf(stderr, "%d (%s) dies, RIP.\n",
			scb->phil, Names[ scb->phil ] );
	    if ( status[scb->phil]  == mode )
	    {
		SIfprintf(stderr, "Oops this philosopher is already dead?\n");
		SIfprintf(stderr, "\t\t CS code is non-functional\n");
	    }
	    Vsem( &SIsem );

	}

	*next_mode = CS_TERMINATE;

	/* If no more threads, shutdown */
	status[scb->phil] = mode;

	if( --Threads == 0 ) {
	    /* Everyone else should be dead, no semaphore needed. */
	    SIflush( stderr );

	    CSterminate( CS_KILL, (i4 *)NULL );
	}

	break;
    }

#ifdef EX_DEBUG
    EXdelete();
#endif
    return( OK );
}