lib.cpp

来自「一个类c++语言解释器」· C++ 代码 · 共 69 行

CPP
69
字号
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include "chsh.h"

using namespace std;

// Read a character from the console.
// If your compiler supplies an unbuffered
// character intput function, feel free to
// substitute it for the call to cin.get().
int call_getchar()
{
  char ch;

  ch = getchar();

  // Advance past ()
  get_token();
  if(*token != '(')
    throw InterpExc(PAREN_EXPECTED);

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

  return ch;
}

// Write a character to the display.
int call_putchar()
{
  int value;

  eval_exp(value);

  putchar(value);

  return value;
}

// Return absolute value.
int call_abs()
{
  int val;

  eval_exp(val);

  val = abs(val);

  return val;
}

// Return a randome integer.
int call_rand()
{

  // Advance past ()
  get_token();
  if(*token != '(')
    throw InterpExc(PAREN_EXPECTED);

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

  return rand();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?