Exemplo n.º 1
0
struct node *parse_statements(struct compiler *compiler)
{
    skip_seps(compiler);

    if(is_expression(compiler))
    {
        struct node *result = parse_statement(compiler);

        if (is_sep(compiler))
        {
            skip_seps(compiler);

            if(is_expression(compiler))
            {
                struct node *node = alloc_node(compiler, N_STATEMENTS);

                node->left = result;
                node->right = parse_statements(compiler);

                return node;
            }
        }

        return result;

    }
    else
        return &nil_node;
}
Exemplo n.º 2
0
Arquivo: reader.cpp Projeto: AmkG/hl
// read a sequence of bytecodes in a list left on the stack
void read_sequence(Process & proc, std::istream & in) {
  char c;
  proc.stack.push(Object::nil()); // head
  proc.stack.push(Object::nil()); // tail
  while (1) {
    skip_seps(in);
    c = in.peek();
    if (!in.eof() && c == bc_start) {
      read_bytecode(proc, in);
      Object::ref c2 = Object::to_ref(proc.create<Cons>());
      if (proc.stack.top(3)==Object::nil()) // test the head
        proc.stack.top(3) = c2; // new head
      else
        scdr(proc.stack.top(2), c2); // cdr of the tail
      scar(c2, proc.stack.top()); proc.stack.pop();
      proc.stack.top() = c2; // new tail
    }
    else 
      break;
  }
  proc.stack.pop(); // remove tail and leave head
}