Example #1
0
/* main ()
**
** Scan the command line arguments, then enter into the command loop.
*/
int main (int argc, char ** argv) {
  checkHostCompatibility ();
  checkArithmetic ();
  processCommandLine (argc, argv);

  /* If the "write" option (-w) was given, write a file to the DISK. */
  if (commandOptionW) {
    writeCommand ();
  } else if (commandOptionI) {
    initializeCommand ();
  } else if (commandOptionL) {
    listCommand ();
  } else if (commandOptionC) {
    createCommand ();
  } else if (commandOptionR) {
    removeCommand ();
  } else if (commandOptionA) {
    addCommand ();
  } else if (commandOptionE) {
    extractCommand ();
  } else {
    fatalError ("No commands given; Use -h for help display");
    return -1;
  }

  return 0;
}
Example #2
0
void semCheckTypes(AST_NODE *node) {
    static int returnType = DTYPE_UNDEF;
    int i;

    if(!node) return;

    if(node->type == AST_FUNDEC)
        returnType = node->datatype;

    for(i = 0; i < node->size; i++)
        semCheckTypes(node->children[i]);

    switch (node->type) {
    case AST_VAR:
    case AST_LIT:
        node->datatype = node->symbol->datatype;
        break;

    case AST_NOT:
        if(node->children[0]->datatype != DTYPE_BOOL)
            semError(SEM_TYPE_EXPECTED_BOOL, node->lineNumber, NULL);
        node->datatype = DTYPE_BOOL;
        break;

    case AST_AND:
    case AST_OR:
        if(node->children[0]->datatype != DTYPE_BOOL ||
                node->children[1]->datatype != DTYPE_BOOL)
            semError(SEM_TYPE_EXPECTED_BOOL, node->lineNumber, NULL);
        node->datatype = DTYPE_BOOL;
        break;

    case AST_EQ:
    case AST_NE:
        if((node->children[0]->datatype == DTYPE_BOOL &&
                node->children[1]->datatype != DTYPE_BOOL) || 
                (node->children[0]->datatype != DTYPE_BOOL &&
                node->children[1]->datatype == DTYPE_BOOL))
            semError(SEM_TYPE_INCOMPATIBLE_OPS, node->lineNumber, NULL);
        node->datatype = DTYPE_BOOL;
        break;

    case AST_LE:
    case AST_GE:
    case AST_LESS:
    case AST_GREATER:
        if(node->children[0]->datatype == DTYPE_BOOL ||
                node->children[1]->datatype == DTYPE_BOOL)
            semError(SEM_TYPE_EXPECTED_NUMBER, node->lineNumber, NULL);

        node->datatype = DTYPE_BOOL;
        break;

    case AST_ADD:
    case AST_SUB:
    case AST_MUL:
        node->datatype = checkArithmetic(node->children[0]->datatype,
                                         node->children[1]->datatype,
                                         node->lineNumber);
        break;

    case AST_DIV:
        if(node->children[0]->datatype == DTYPE_BOOL ||
                node->children[1]->datatype == DTYPE_BOOL)
            semError(SEM_TYPE_EXPECTED_NUMBER, node->lineNumber, NULL);
        node->datatype = DTYPE_REAL;
        break;

    case AST_PAR:
        node->datatype = node->children[0]->datatype;
        break;	

	case AST_FUNCALL:
	    node->datatype = node->symbol->declaration->datatype;
	    checkParameters(node);
	    break;
	
	case AST_ARRACCESS:
	    node->datatype = node->symbol->datatype;
	    if(node->children[0]->datatype != DTYPE_INT && 
			    node->children[0]->datatype != DTYPE_CHAR) 
                semError(SEM_TYPE_INDEX, node->lineNumber, node->symbol->text);
	    break;
	
	case AST_ATTR:
	    if(numAndBool(node->symbol->datatype, node->children[0]->datatype)) 
		semError(SEM_TYPE_ATTR_TYPE, node->lineNumber, NULL);
	    break;

	case AST_ATTRARR:
	    if(numAndBool(node->symbol->datatype, node->children[1]->datatype)) 
		semError(SEM_TYPE_ATTR_TYPE, node->lineNumber, NULL);

	    if(node->children[0]->datatype != DTYPE_INT && 
			    node->children[0]->datatype != DTYPE_CHAR) 
                semError(SEM_TYPE_INDEX, node->lineNumber, node->symbol->text);
	    break;
	
	case AST_IF:
	case AST_IFTE:
	case AST_WHILE:
	    if(node->children[0]->datatype != DTYPE_BOOL)
		semError(SEM_TYPE_EXPECTED_BOOL, node->lineNumber, NULL);
	    break;

	case AST_INPUT:
	    checkInput(node->children[0]);
	    break;

	case AST_OUTPUT:
	    checkOutput(node->children[0]);
	    break;

	case AST_RETURN:
        if(numAndBool(node->children[0]->datatype, returnType))
		    semError(SEM_TYPE_INCOMPATIBLE_RETURN, node->lineNumber, NULL);
	    break;
    }
}