亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? chsh.cpp

?? 一個類c++語言解釋器
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
#include <iostream>
#include <fstream>
#include <new>
#include <stack>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include "chsh.h"

using namespace std;

char *prog;  // current execution point in source code
char *p_buf; // points to start of program buffer

// This structure encapsulates the info
// associated with variables.
struct var_type {
  char var_name[MAX_ID_LEN+1]; // name
  token_ireps v_type; // data type
  int value; // value
};

// This vector holds info for global variables.
vector<var_type> global_vars;

// This vector holds info for local variables
// and parameters.
vector<var_type> local_var_stack;

// This structure encapsulates function info.
struct func_type {
  char func_name[MAX_ID_LEN+1]; // name
  token_ireps ret_type; // return type
  char *loc; // location of entry point in program
};

// This vector holds info about functions.
vector<func_type> func_table;

// Stack for managing function scope.
stack<int> func_call_stack;

// Stack for managing nested scopes.
stack<int> nest_scope_stack;

char token[MAX_T_LEN+1]; // current token
tok_types token_type; // token type
token_ireps tok; // internal representation

int ret_value; // function return value

bool breakfound = false; // true if break encountered

int main(int argc, char *argv[])
{
  if(argc != 2) {
    cout << "Usage: minicpp <filename>\n";
    return 1;
  }

  // Allocate memory for the program.
  try {
    p_buf = new char[PROG_SIZE];
  } catch (bad_alloc exc) {
    cout << "Could Not Allocate Program Buffer\n";
    return 1;
  }

  // Load the program to execute.
  if(!load_program(p_buf, argv[1])) return 1;

  // Set program pointer to start of program buffer.
  prog = p_buf;

  try {
    // Find the location of all functions
    // and global variables in the program.
    prescan();

    // Next, set up the call to main().

    // Find program starting point.
    prog = find_func("main");

    // Check for incorrect or missing main() function.
    if(!prog) {
      cout << "main() Not Found\n";
      return 1;
    }

    // Back up to opening (.
    prog--;

    // Set the first token to main
    strcpy(token, "main");

    // Call main() to start interpreting.
    call();
  }
  catch(InterpExc exc) {
    sntx_err(exc.get_err());
    return 1;
  }
  catch(bad_alloc exc) {
    cout << "Out Of Memory\n";
    return 1;
  }

  return ret_value;
}

// Load a program.
bool load_program(char *p, char *fname)
{
  int i=0;

  ifstream in(fname, ios::in | ios::binary);
  if(!in) {
    cout << "Cannot Open file.\n";
    return false;
  }

  do {
    *p = in.get();
    p++; i++;
  } while(!in.eof() && i < PROG_SIZE);

  if(i == PROG_SIZE) {
    cout << "Program Too Big\n";
    return false;
  }

  // Null terminate the program. Skip any EOF
  // mark if present in the file.
  if(*(p-2) == 0x1a) *(p-2) = '\0';
  else *(p-1) = '\0';

  in.close();

  return true;
}

// Find the location of all functions in the program
// and store global variables.
void prescan()
{
  char *p, *tp;
  char temp[MAX_ID_LEN+1];
  token_ireps datatype;
  func_type ft;

  // When brace is 0, the current source position
  // is outside of any function.
  int brace = 0;

  p = prog;

  do {
    // Bypass code inside functions
    while(brace) {
      get_token();
      if(tok == END) throw InterpExc(UNBAL_BRACES);
      if(*token == '{') brace++;
      if(*token == '}') brace--;
    }

    tp = prog; // save current position
    get_token();

    // See if global var type or function return type.
    if(tok==CHAR || tok==INT) {
      datatype = tok; // save data type
      get_token();

      if(token_type == IDENTIFIER) {
        strcpy(temp, token);
        get_token();

        if(*token != '(') { // must be global var
          prog = tp; // return to start of declaration
          decl_global();
        }
        else if(*token == '(') { // must be a function

          // See if function already defined.
          for(unsigned i=0; i < func_table.size(); i++)
            if(!strcmp(func_table[i].func_name, temp))
              throw InterpExc(DUP_FUNC);

          ft.loc = prog;
          ft.ret_type = datatype;
          strcpy(ft.func_name, temp);
          func_table.push_back(ft);

          do {
            get_token();
          } while(*token != ')');
          // Next token will now be opening curly
          // brace of function.
        }
        else putback();
      }
    }
    else {
      if(*token == '{') brace++;
      if(*token == '}') brace--;
    }
  } while(tok != END);
  if(brace) throw InterpExc(UNBAL_BRACES);
  prog = p;
}

// Interpret a single statement or block of code. When
// interp() returns from its initial call, the final
// brace (or a return) in main() has been encountered.
void interp()
{
  int value;
  int block = 0;

  do {
    // Don't interpret until break is handled.
    if(breakfound) return;

    token_type = get_token();

    // See what kind of token is up.
    if(token_type == IDENTIFIER ||
       *token == INC || *token == DEC)
    {
      // Not a keyword, so process expression.
      putback();  // restore token to input stream for
                  // further processing by eval_exp()
      eval_exp(value); // process the expression
      if(*token != ';') throw InterpExc(SEMI_EXPECTED);
    }
    else if(token_type==BLOCK) { // block delimiter?
      if(*token == '{') { // is a block
        block = 1; // interpreting block, not statement
        // Record nested scope.
        nest_scope_stack.push(local_var_stack.size());
      }
      else { // is a }, so reset scope and return
        // Reset nested scope.
        local_var_stack.resize(nest_scope_stack.top());
        nest_scope_stack.pop();
        return;
      }
    }
    else // is keyword
      switch(tok) {
        case CHAR:
        case INT:     // declare local variables
          putback();
          decl_local();
          break;
        case RETURN:  // return from function call
          func_ret();
          return;
        case IF:      // process an if statement
          exec_if();
          break;
        case ELSE:    // process an else statement
          find_eob(); // find end of else block
                      // and continue execution
          break;
        case WHILE:   // process a while loop
          exec_while();
          break;
        case DO:      // process a do-while loop
          exec_do();
          break;
        case FOR:     // process a for loop
          exec_for();
          break;
        case BREAK:   // handle break
          breakfound = true;

          // Reset nested scope.
          local_var_stack.resize(nest_scope_stack.top());
          nest_scope_stack.pop();
          return;
        case SWITCH:  // handle a switch statement
          exec_switch();
          break;
        case COUT:    // handle console output
          exec_cout();
          break;
        case CIN:     // handle console input
          exec_cin();
          break;
        case END:
          exit(0);
      }
  } while (tok != END && block);
  return;
}

// Return the entry point of the specified function.
// Return NULL if not found.
char *find_func(char *name)
{
  unsigned i;

  for(i=0; i < func_table.size(); i++)
    if(!strcmp(name, func_table[i].func_name))
      return func_table[i].loc;

  return NULL;
}

// Declare a global variable.
void decl_global()
{
  token_ireps vartype;
  var_type vt;

  get_token(); // get type

  vartype = tok; // save var type

  // Process comma-separated list.
  do {
    vt.v_type = vartype;
    vt.value = 0; // init to 0
    get_token(); // get name

    // See if variable is a duplicate.
    for(unsigned i=0; i < global_vars.size(); i++)
      if(!strcmp(global_vars[i].var_name, token))
        throw InterpExc(DUP_VAR);

    strcpy(vt.var_name, token);
    global_vars.push_back(vt);

    get_token();
  } while(*token == ',');

  if(*token != ';') throw InterpExc(SEMI_EXPECTED);
}

// Declare a local variable.
void decl_local()
{
  var_type vt;

  get_token(); // get var type
  vt.v_type = tok; // store type

  vt.value = 0; // init var to 0

  // Process comma-separated list.
  do {
    get_token(); // get var name

    // See if variable is already the name
    // of a local variable in this scope.
    if(!local_var_stack.empty())
    for(int i=local_var_stack.size()-1;
        i >= nest_scope_stack.top(); i--)
    {
      if(!strcmp(local_var_stack[i].var_name, token))
        throw InterpExc(DUP_VAR);
    }

    strcpy(vt.var_name, token);
    local_var_stack.push_back(vt);
    get_token();
  } while(*token == ',');

  if(*token != ';') throw InterpExc(SEMI_EXPECTED);
}

// Call a function.
void call()
{
  char *loc, *temp;
  int lvartemp;

  // First, find entry point of function.
  loc = find_func(token);

  if(loc == NULL)
    throw InterpExc(FUNC_UNDEF); // function not defined
  else {
    // Save local var stack index.
    lvartemp = local_var_stack.size();

    get_args(); // get function arguments
    temp = prog; // save return location

    func_call_stack.push(lvartemp); // push local var index

    prog = loc; // reset prog to start of function
    get_params(); // load the function's parameters with
                  // the values of the arguments

    interp(); // interpret the function

    prog = temp; // reset the program pointer

    if(func_call_stack.empty()) throw InterpExc(RET_NOCALL);

    // Reset local_var_stack to its previous state.
    local_var_stack.resize(func_call_stack.top());
    func_call_stack.pop();
  }
}

// Push the arguments to a function onto the local
// variable stack.
void get_args()
{
  int value, count, temp[NUM_PARAMS];
  var_type vt;

  count = 0;
  get_token();
  if(*token != '(') throw InterpExc(PAREN_EXPECTED);

  // Process a comma-separated list of values.
  do {
    eval_exp(value);
    temp[count] = value; // save temporarily
    get_token();
    count++;
  } while(*token == ',');
  count--;

  // Now, push on local_var_stack in reverse order.
  for(; count>=0; count--) {
    vt.value = temp[count];
    vt.v_type = ARG;
    local_var_stack.push_back(vt);
  }
}

// Get function parameters.
void get_params()
{
  var_type *p;
  int i;

  i = local_var_stack.size()-1;

  // Process comma-separated list of parameters.
  do {
    get_token();
    p = &local_var_stack[i];
    if(*token != ')' ) {
      if(tok != INT && tok != CHAR)
        throw InterpExc(TYPE_EXPECTED);

      p->v_type = tok;
      get_token();

      // Link parameter name with argument already on
      // local var stack.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本精品免费观看高清观看| 欧美在线观看18| 99精品国产热久久91蜜凸| 91网站最新地址| 精品日韩在线观看| 一区二区三区四区精品在线视频| 蜜臀av在线播放一区二区三区| 成人激情文学综合网| 欧美丰满一区二区免费视频| 国产精品成人免费| 国精产品一区一区三区mba桃花| 一本大道久久a久久综合| 久久久久国色av免费看影院| 日本欧美大码aⅴ在线播放| 一本色道久久加勒比精品| 亚洲国产精品ⅴa在线观看| 麻豆视频观看网址久久| 欧美视频在线播放| 亚洲黄色免费电影| 97久久精品人人做人人爽| 国产亚洲制服色| 韩国女主播成人在线| 欧美猛男超大videosgay| 尤物在线观看一区| 91在线观看地址| 成人欧美一区二区三区1314| 成人一区二区三区中文字幕| 国产欧美在线观看一区| 国产一区不卡在线| 日韩亚洲欧美中文三级| 精品制服美女久久| 欧美成人性战久久| 久久99久久99| 久久麻豆一区二区| 韩国在线一区二区| 久久精品人人爽人人爽| 国产精品一区久久久久| 国产性天天综合网| 成人午夜大片免费观看| 国产精品夫妻自拍| 色综合天天天天做夜夜夜夜做| 亚洲欧洲精品天堂一级| 91啪亚洲精品| 亚洲永久免费视频| 555www色欧美视频| 久久99国产精品久久99 | 中文在线一区二区| 国产成人免费xxxxxxxx| 中文字幕在线观看一区二区| 91在线免费视频观看| 亚洲资源中文字幕| 日韩视频中午一区| 国内精品国产三级国产a久久| 2021国产精品久久精品| 成人a区在线观看| 亚洲欧美aⅴ...| 欧美日韩精品电影| 精品一区二区国语对白| 国产精品福利在线播放| 欧美年轻男男videosbes| 国内精品免费在线观看| 最新成人av在线| 欧美一级二级三级蜜桃| 国产**成人网毛片九色| 亚洲国产裸拍裸体视频在线观看乱了 | 日本欧美久久久久免费播放网| 26uuu色噜噜精品一区二区| 99久久国产综合精品色伊| 亚洲 欧美综合在线网络| 精品美女在线播放| 91色综合久久久久婷婷| 蜜乳av一区二区| 亚洲少妇中出一区| 欧美va亚洲va在线观看蝴蝶网| 99久免费精品视频在线观看| 三级一区在线视频先锋 | 欧美精品一区二区三区蜜臀| 91视视频在线观看入口直接观看www | 大尺度一区二区| 午夜精品久久久久久久久久久| 精品成人免费观看| 欧美老肥妇做.爰bbww| 波多野结衣视频一区| 美国一区二区三区在线播放| 亚洲欧美日韩国产成人精品影院| 日韩精品一区二区三区swag | 一区二区在线免费| 久久久久久97三级| 日韩美女视频在线| 在线日韩一区二区| 丰满白嫩尤物一区二区| 久久国产精品一区二区| 亚洲va天堂va国产va久| 亚洲欧美日韩国产综合在线| 久久香蕉国产线看观看99| 91精品久久久久久蜜臀| 欧洲在线/亚洲| 91农村精品一区二区在线| 精品中文字幕一区二区小辣椒| 日韩激情视频网站| 日产国产高清一区二区三区| 亚洲一区二区三区四区五区中文| 国产精品久久久久久户外露出| 欧美不卡在线视频| 欧美一区二区三区色| 欧美伊人久久大香线蕉综合69| 国产99久久久精品| 国产成人精品一区二| 韩国精品免费视频| 久久se这里有精品| 久久成人av少妇免费| 久久精品国产久精国产| 免费成人av资源网| 久久精品99国产精品日本| 久久99国产乱子伦精品免费| 极品瑜伽女神91| 精品亚洲成av人在线观看| 九一九一国产精品| 狠狠色丁香久久婷婷综| 国产a久久麻豆| 99久久er热在这里只有精品15 | 国产91精品在线观看| 国产精品资源在线观看| 国产精品456| www.欧美.com| 日本高清不卡aⅴ免费网站| 色素色在线综合| 欧美日韩免费不卡视频一区二区三区 | 欧美成人激情免费网| 精品少妇一区二区三区在线播放| 精品国产污污免费网站入口| 久久久久国产精品麻豆ai换脸| 国产欧美日韩精品a在线观看| 欧美国产1区2区| 亚洲精品午夜久久久| 天天色 色综合| 精品一区二区在线免费观看| 国产精品一二三四五| 成人免费电影视频| 欧美日韩中文国产| 日韩午夜三级在线| 国产欧美日韩在线| 亚洲午夜影视影院在线观看| 青青草国产精品亚洲专区无| 国产真实乱偷精品视频免| 成人爱爱电影网址| 欧美日韩免费观看一区三区| 精品久久久久久亚洲综合网 | 久久蜜桃av一区精品变态类天堂 | 亚洲品质自拍视频| 日本在线不卡视频| 国产福利精品一区二区| 在线视频欧美区| 精品日韩一区二区三区免费视频| 中文字幕制服丝袜成人av| 亚洲成av人影院在线观看网| 精品在线播放免费| 欧美性高清videossexo| 欧美精品一区二区三区蜜桃视频| 日韩伦理av电影| 狠狠色伊人亚洲综合成人| 欧美亚洲综合在线| 国产精品毛片大码女人| 日韩和欧美一区二区| 99精品1区2区| 国产日韩欧美a| 午夜精品国产更新| 波多野结衣在线aⅴ中文字幕不卡| 日韩一区二区三区观看| 亚洲高清视频在线| www.色精品| 久久久天堂av| 日韩精品免费专区| 日本高清不卡在线观看| 欧美国产激情二区三区| 久久电影网站中文字幕| 欧美精选在线播放| 亚洲欧美激情在线| 成人天堂资源www在线| 91精品国产综合久久香蕉麻豆| 中文字幕一区二区在线观看| 国产在线观看免费一区| 日韩亚洲欧美高清| 免费av成人在线| 欧美日韩一级片在线观看| 亚洲视频免费在线观看| 大白屁股一区二区视频| 国产欧美日韩在线看| 日本韩国视频一区二区| 综合色天天鬼久久鬼色| 粉嫩av一区二区三区在线播放| 日韩精品一区国产麻豆| 欧美a级理论片| 91精品久久久久久久久99蜜臂| 婷婷国产v国产偷v亚洲高清| 欧美性淫爽ww久久久久无| 亚洲激情六月丁香| 欧美性三三影院| 图片区小说区国产精品视频| 欧美日韩免费观看一区三区|