Ejemplo n.º 1
0
/* EBNF: local-declarations -> 
 * var-declaration {var-declaration} | empty */
static TreeNode * local_declarations (void)
{ TreeNode * t = NULL;
  TreeNode * p = NULL;
  TreeNode * newNode = NULL;

  while (token == COMMENT) unexpectedTokenHandling();
  if ((token == INT) || (token == VOID))
  { t = var_declaration();
    p = t;
  }
  else /* empty */
    return NULL;

  while (token == COMMENT) unexpectedTokenHandling();
  /* {var-declarations} */
  while ((token == INT) || (token == VOID))
  { newNode = var_declaration();
    if ((p != NULL) && (newNode != NULL))
    { p->sibling = newNode;
      p = newNode;
    }
  }
  return t;
}
Ejemplo n.º 2
0
/* CARLOS */
void block(TokenBuffer *tokens, InstructionBuffer *code, SymbolTree *tree)
{
    const_declaration(tokens, code, tree);
    var_declaration(tokens, code, tree);

    int code_pos = getCodePosition(code);
    generateInstruction(code, INSTR_JMP, 0, 0);
    proc_declaration(tokens, code, tree);

    int new_code_pos = getCodePosition(code);

    // proc_declaration didn't generate any code, undo the jump instruction
    if (new_code_pos-code_pos == 1)
        popInstruction(code);
    else
        code->buf[code_pos].m = new_code_pos;

    statement(tokens, code, tree);
}