#ifndef __NASAL_PARSER_H__ #define __NASAL_PARSER_H__ #include "nasal_token_type.h" class nasal_parser { private: std::stack parser; public: void print_parser_stack() { if(parser.empty()) return; int line=0; std::stack temp; while(!parser.empty()) { temp.push(parser.top()); if(line!=temp.top().line) { if(line+1==temp.top().line) { line=temp.top().line; if(line==1) std::cout<<"line "< "; parser.pop(); } while(!temp.empty()) { parser.push(temp.top()); temp.pop(); } std::cout<& return_stack() { return parser; } void parse_process(std::list& lexer) { while(!parser.empty()) parser.pop(); std::stack temp; for(std::list::iterator i=lexer.begin();i!=lexer.end();++i) { token temp_parse; temp_parse=*i; temp.push(temp_parse);//push this into stack } if(temp.empty()) { std::cout<<">>[Parse] [-Warning] Empty lexer list."< parse; std::stack node_cache; bool error; public: ast_generator() { error=false; } void input_token_stack(std::stack& temp) { parse=temp; return; } void number_gen() { number_expr t; t.set_line(parse.top().line); t.set_number(parse.top().content); if(node_cache.empty()) node_cache.push(t); else if((node_cache.top().return_type()==__add_operator || node_cache.top().return_type()==__sub_operator || node_cache.top().return_type()==__mul_operator || node_cache.top().return_type()==__div_operator) && (node_cache.top().child_num()==1)) node_cache.top().add_child(t); else { std::cout<<">>[Error] parse error in line "<>[Error] parse error in line "<>[Error] parse error in line "<>[Error] parse error in line "<>[Error] parse error in line "<>[Error] parse error in line "<>[Error] parse error in line "<>[Parse] Error(s) occurred."<>[Parse] Complete parsing."<>[Parse] 0 error."<>[Parse] Complete parsing."<>[Abstract-syntax-tree]"<>[Parse] Error(s) occurred,stop."<