Ejemplo n.º 1
0
main()
{
    symtabADT table;
    scannerADT scanner;
    string line, name, value;

    table = NewSymbolTable();
    scanner = NewScanner();
    SetScannerSpaceOption(scanner, IgnoreSpaces);
    while (TRUE) {
        printf("-> ");
        line = GetLine();
        if (StringEqual(line, "quit")) break;
        SetScannerString(scanner, line);
        name = ReadToken(scanner);
        if (MoreTokensExist(scanner)) {
            if (!StringEqual(ReadToken(scanner), "=")) {
                Error("Missing equal sign in assignment");
            }
            value = ReadToken(scanner);
            if (MoreTokensExist(scanner)) {
                Error("Statement contains additional data");
            }
            Enter(table, name, value);
        } else {
            value = Lookup(table, name);
            if (value == UNDEFINED) {
                printf("'%s' is undefined.\n", name);
            } else {
                printf("%s\n", value);
            }
        }
    }
    FreeSymbolTable(table);
}
Ejemplo n.º 2
0
main()
{
    cmdScannerADT cs;

    printf("Test program for the symbol table package\n");
    cs = NewCommandScanner();
    SetCommandData(cs, NewSymbolTable());
    InitCommandTable(cs);
    CommandLoop(cs, "-> ");
    FreeSymbolTable(GetCommandData(cs));
    FreeCommandScanner(cs);
}
Ejemplo n.º 3
0
bool WantToContinue(creatureADT *creatureP,int num,double *time)
{
	int i;
	int *k;
	string str;
	symtabADT symtab=NewSymbolTable();

	
	for (i=0;i<=num-1;i++)
	{
		if ( Lookup ( symtab  ,SpeciesName ( GetSpecies (creatureP[i]) ) )==UNDEFINED )
		{
			k=GetBlock(sizeof (int) );
			*k=1;
			Enter( symtab , SpeciesName ( GetSpecies (creatureP[i]) ) , k);
		}
		else 
		{
			k=(int*)Lookup(symtab,SpeciesName ( GetSpecies (creatureP[i]) ));
			*k=*k+1;
		}
	}
	printf("\nInventory:\n");
	MapSymbolTable(PrintInventory,symtab,NULL);
	FreeSymbolTable(symtab);

	ChangeTimeInterval(time);
	
	while(TRUE)
	{
		printf("\npress s+Enter to stop and c+Enter to continue :");
		str=GetLine();
		if (StringEqual(str,"s"))  {return FALSE;}
		if (StringEqual(str,"c")) 
		{
			printf("\nTo pause,click mouse on the graph.\n");
			return TRUE;
		}
	}
}
Ejemplo n.º 4
0
static void ClearCmdFn(cmdScannerADT cs)
{
    CheckForExtraTokens(cs);
    FreeSymbolTable(GetCommandData(cs));
    SetCommandData(cs, NewSymbolTable());
}
Ejemplo n.º 5
0
void FreeCommandScanner(cmdScannerADT cs)
{
    FreeSymbolTable(cs->cmdTable);
    FreeScanner(cs->scanner);
    FreeBlock(cs);
}