void operator()(lambda const &value) const { Si::append(m_out, "("); for (auto p = begin(value.parameters); p != end(value.parameters); ++p) { auto const ¶meter = *p; print(m_out, parameter.type, m_indentation); Si::append(m_out, " "); Si::append(m_out, parameter.name.content); if (p != (end(value.parameters) - 1)) { Si::append(m_out, ", "); } } Si::append(m_out, ")\n"); for (auto &definition : value.body.elements) { print_indentation(m_out, m_indentation + 1); Si::append(m_out, definition.name.content); Si::append(m_out, " = "); print(m_out, definition.value, m_indentation + 1); Si::append(m_out, "\n"); } print_indentation(m_out, m_indentation + 1); Si::append(m_out, "return "); print(m_out, value.body.result, m_indentation + 1); Si::append(m_out, "\n"); }
//Print ID Nodes with correct identation void print_ID(ID_List* ids,int tabs, int n_type, int type) { while(ids != NULL) { print_indentation(tabs); printf("Id(%s)\n",ids->id); ids = ids->next; } }
/*Print Tree and Lower levels node*/ void print_TREE(AST_TREE* AST) { if(AST != NULL) { printf("%s\n", OP_TO_STRING[AST->n_type]); print_indentation(1); printf("Id(%s)\n", AST->id->id); } if(AST->next != NULL) print_lowerTreelevels(AST->next,1); }
//Print one AST AST_TREE depending on the type void printAST_Node( AST_TREE* currentNode, int tabs) { if(currentNode->n_type == NODE_DONTPRINT) return; else if(currentNode->n_type == NO_BOOLLIT || currentNode->n_type == NO_INTLIT || currentNode->n_type == NO_ID ) { print_indentation(tabs); printf("%s(%s)\n",OP_TO_STRING[currentNode->n_type], currentNode->value); } else { print_indentation(tabs); printf("%s\n", OP_TO_STRING[currentNode->n_type]); if(currentNode->n_type == NO_VARDECL || currentNode->n_type == NO_PARAMDECL || currentNode->n_type == NO_METHODDECL){ print_indentation(tabs + 1); printf("%s\n",NODE_TYPES[currentNode->type]); } print_ID(currentNode->id,tabs+1, currentNode->n_type, currentNode->type); } }
void Parser::print_newline(std::ostream& iStream, unsigned int iIndentation) { iStream << std::endl; print_indentation(iStream, iIndentation); }
void Parser::print_block(std::ostream& iStream, unsigned char* iBlock, unsigned int iSize) { unsigned char tIndentation = 1; print_indentation(iStream, tIndentation); unsigned int tLoc = 0; bool tPrevArgEnd = false; while (tLoc < iSize) { // Syntax if (mGrammar->isSyntax(iBlock[tLoc])) { switch (iBlock[tLoc]) { case ARG_OPEN: iStream << "("; break; case ARG_SEP: iStream << ", "; break; case ARG_CLOSE: iStream << ")"; tPrevArgEnd = true; break; case INSTR_OPEN: if (tPrevArgEnd) { iStream << " "; tPrevArgEnd = false; } iStream << "{"; tIndentation++; print_newline(iStream, tIndentation); break; case INSTR_SEP: iStream << ";"; print_newline(iStream, tIndentation); break; case INSTR_CLOSE: tIndentation--; if (tPrevArgEnd) { iStream << ";"; tPrevArgEnd = false; } print_newline(iStream, tIndentation); iStream << "}"; break; } } // Conditional else if (mGrammar->isConditional(iBlock[tLoc])) { switch (iBlock[tLoc]) { case COND_IF: iStream << "if"; break; case COND_UNLESS: iStream << "unless"; break; case COND_WHILE: iStream << "while"; break; } } // Function else if (mGrammar->isFunction(iBlock[tLoc])) { iStream << mGrammar->nameFunction(iBlock[tLoc]); } // Data else if (mGrammar->isData(iBlock[tLoc])) { unsigned char tDataType = iBlock[tLoc++]; switch (tDataType) { case DATA_VOID: iStream << Value(); break; case DATA_BOOL: iStream << toBool(iBlock[tLoc]); break; case DATA_INT: iStream << toInt(iBlock[tLoc]); break; } } tLoc++; } iStream << std::endl; }