Beispiel #1
0
//all input instructions are assumed to be valid.
//i.e. sytactically correct and no illegal operations
//(e.g. division by zero)
//variables may not start with digits
//variables are assumed to be integers
int main(){
    char curr_var[MAX_VAR_IDENT_LENGTH];
    char curr_operator;
    char curr_operand[MAX_VAR_IDENT_LENGTH];

    /*Input from file for testing purposes
    FILE *fin;
    if( (fin = fopen("in.txt","r")) == NULL){
        printf("file not found\n");
        exit(1);
    }
    fscanf(fin,"%s",inst);
    */

    /*input from keyboard*/
    scanf("%s",inst);
    /**/

    instIndex = 0;
    int instLen = strlen(inst)-1;

    while(instIndex<instLen){
        readVariable(curr_var);
        readOperator(&curr_operator);
        readOperand(curr_operand);
        compute(curr_var, curr_operator, curr_operand);
    }

    printVars();

    return 0;
}
Beispiel #2
0
void
Message::print(XStr& str)
{
  if(external)
    str << "extern ";
  if(templat)
    templat->genSpec(str);
  str << "message ";
  type->print(str);
  printVars(str);
  str << ";\n";
}
Beispiel #3
0
 template <typename ... Values> void failedRequire(const char* whenName, const char* thenName, const char * line, const char * condition, const char *valueNames, const Values & ... values) {
   if ( lastErrdWhen != loopNumber ){
     printf("GIVEN %s: Failed when #%i \nWHEN %s: \n", testName , loopNumber, whenName);
     lastErrdWhen = loopNumber;
   }
   if (valueNames != 0 && valueNames[0] != 0){
     printf("THEN %s… FAILS line %s: %s. values: ", thenName, line, condition);
     printVars(valueNames, values...);
   } else {
     printf("THEN %s… FAILS line %s: %s\n", thenName, line, condition );
   }
 }
Beispiel #4
0
 template <typename T, typename ... More> void printVars (const char* names, const T& print, const More & ... more) const {
   const char * nextNames = strchr(names, ',');
   for (const char * printChar = names; printChar != nextNames && *printChar != 0 ; printChar++){
     if (*printChar == ' ') continue;
     std::cout << *printChar;
   }
   std::cout << " = " << print;
   if (nextNames != 0){
     std::cout << ", ";
     nextNames++;
   }
   printVars(nextNames, more...);
 }
Beispiel #5
0
    virtual void visitBlockNode(BlockNode *node)
    {
        bool topLevel = node->scope()->parent()->parent() == NULL;
        if (!topLevel) {
            out << "{" << endl;
        }

        printVars(node->scope());
        for (uint32_t i = 0; i < node->nodes(); i++) {
            AstNode *currentNode = node->nodeAt(i);
            currentNode->visit(this);
            if (currentNode->isLoadNode() || currentNode->isStoreNode() ||
                currentNode->isReturnNode() || currentNode->isCallNode() ||
                currentNode->isNativeCallNode() || currentNode->isPrintNode()) {
                out << ";" << endl;
            }
        }
        if (!topLevel) {
            out << "}" << endl;
        }
    }