📄 statstak.cpp
字号:
// Copyright (c) 1996 Federal Highway Administration
//
// This software has been developed for the Federal Highway Administration
// by Viggen Corporation under contract with Oak Ridge National Lab.
//
// Permission to use, copy, and distribute this software for any purpose
// without fee is hereby granted, provided that the above copyright notice
// appears in all copies and that both the copyright and this permission notice
// appear in the supporting documentation.
//
// Permission to modify this software is granted provided that the above
// copyright and this permission notice appears in the modified software.
//
// This software is provided "as is" with no warranty expressed or implied.
//
// For additional information, please go to the Web site www.ntcip.org.
//
/*******************************************************************************
*
* Copyright (c) 1997 Viggen Corporation
*
* Permission to use, copy, and distribute this software for any purpose
* without fee is hereby granted, provided that this copyright notice
* appears in all copies and this permission notice appears in the
* supporting documentation.
*
* Permission to modify this software is granted provided that the above
* copyright and this permission notice appears in the modified software.
*
******************************************************************************/
/*********************************************
*
* statstak.cpp
*
* 9/29/97 Glenn Pruitt
*********************************************/
//Statement Stack source file
#include <string>
using namespace std;
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>
#include "api.h"
#include "symboltab.h"
#include "stattab.h"
#include "executor.h"
#include "lexical.h"
#include "statstak.h"
void push(struct STSTK **the_stack, int index, int eval)
{
STSTK *curr;
curr = (STSTK *)safe_alloc(1,sizeof(STSTK));
curr->index = index;
curr->evaluated = eval;
curr->next = *the_stack;
*the_stack = curr;
//printf("pushed %d\n",index);
//dump_stat_stak(*the_stack);
return;
}
void pop(struct STSTK **the_stack)
{
STSTK *curr;
curr = *the_stack;
*the_stack = curr->next;
safe_free(curr);
//printf("popped\n");
//dump_stat_stak(*the_stack);
}
int get_top_index(struct STSTK *the_stack)
{
return(the_stack->index);
}
int get_top_evaluated(struct STSTK *the_stack)
{
return(the_stack->evaluated);
}
int stack_empty(struct STSTK *the_stack)
{
if( the_stack == NULL)
return(1);
else
return(0);
}
void set_top_evaluated(struct STSTK *the_stack, int eval)
{
the_stack->evaluated = eval;
return;
}
void extract(struct STSTK **the_stack, int index)
{
struct STSTK *curr;
struct STSTK *prev;
curr = *the_stack;
prev = NULL;
//printf("Extracting %d\n",index);
if(*the_stack == NULL)
{
//stack is empty
return;
}
while(curr && curr->index != index)
{
prev = curr;
curr = curr->next;
}
if(curr == *the_stack)
{
//target is the head
*the_stack = curr->next;
safe_free(curr);
//printf("Extracted head\n");
//dump_stat_stak(*the_stack);
return;
}
if(!curr)
{
//target does not exist
return;
}
prev->next = curr->next;
safe_free(curr);
//printf("Extracted non-head node\n");
//dump_stat_stak(*the_stack);
return;
}
void dump_stat_stak(struct STSTK *the_stack)
{
struct STSTK *curr;
curr = the_stack;
while(curr)
{
printf("Statement %3d eval? %1d\n",curr->index,curr->evaluated);
curr = curr->next;
}
getch();
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -