#ifndef __NASAL_PARSE_H__ #define __NASAL_PARSE_H__ class nasal_parse { private: std::stack parse_token_stream; std::stack checked_tokens; token this_token; int error; int warning; abstract_syntax_tree root; public: // basic void print_detail_token(); void get_token_list(std::list&); void get_token(); void push_token(); int get_error(); abstract_syntax_tree& get_root(); // abstract_syntax_tree generation void main_generate(); abstract_syntax_tree number_expr(); abstract_syntax_tree string_expr(); abstract_syntax_tree nil_expr(); abstract_syntax_tree var_outside_definition(); }; void nasal_parse::print_detail_token() { std::stack tmp=parse_token_stream; std::string space=""; int line=1; std::cout<& detail_token_stream) { while(!parse_token_stream.empty()) parse_token_stream.pop(); while(!checked_tokens.empty()) checked_tokens.pop(); // clear stack std::stack backward_tmp; for(std::list::iterator i=detail_token_stream.begin();i!=detail_token_stream.end();++i) backward_tmp.push(*i); while(!backward_tmp.empty()) { parse_token_stream.push(backward_tmp.top()); backward_tmp.pop(); } return; } void nasal_parse::get_token() { if(!parse_token_stream.empty()) { this_token=parse_token_stream.top(); parse_token_stream.pop(); checked_tokens.push(this_token); } else { this_token.type=__stack_end; this_token.str="__stack_end"; std::cout<<">>[Parse-error] empty token stack."<>[Parse-error] empty checked token stack."<get_token(); switch(this_token.type) { case __var:this->push_token();root.get_children().push_back(var_outside_definition());break; case __nor_operator: case __sub_operator: case __number: case __string: case __nil: case __id:break; case __left_curve:break; case __left_bracket:break; case __left_brace:break; case __func:break; case __if:break; case __while: case __for: case __foreach: case __forindex:break; case __semi:break; default:++error;print_parse_error(error_token_in_main,this_token.line,this_token.type); } } std::cout<<">>[Parse] complete generation. "<get_token(); node.set_line(this_token.line); node.set_type(__number); node.set_number(this_token.str); return node; } abstract_syntax_tree nasal_parse::string_expr() { abstract_syntax_tree node; this->get_token(); node.set_line(this_token.line); node.set_type(__string); node.set_string(this_token.str); return node; } abstract_syntax_tree nasal_parse::nil_expr() { abstract_syntax_tree node; this->get_token(); node.set_line(this_token.line); node.set_type(__nil); return node; } abstract_syntax_tree nasal_parse::var_outside_definition() { abstract_syntax_tree definition_node; this->get_token(); if(this_token.type!=__var) { ++error; print_parse_error(definition_lack_var,this_token.line); } this->get_token(); if(this_token.type==__id) { } else if(this_token.type==__left_curve) { } else { ++error; print_parse_error(definition_lack_id,this_token.line); } return definition_node; } #endif