New update
This commit is contained in:
parent
a0171462c0
commit
f1de7b3a09
|
@ -4,6 +4,7 @@ int main()
|
|||
resource_programme_process prog;
|
||||
nasal_lexer lex;
|
||||
nasal_parser pas;
|
||||
generator gen;
|
||||
std::string command;
|
||||
std::cout<<">> Nasal interpreter by ValKmjolnir"<<std::endl;
|
||||
std::cout<<">> Input [help] to find help."<<std::endl;
|
||||
|
@ -61,7 +62,12 @@ int main()
|
|||
lex.token_list_type_detail_edit();
|
||||
pas.parse_process(lex.return_list());
|
||||
pas.parse_main_work();
|
||||
pas.print_ast();
|
||||
if(!pas.get_error_num())
|
||||
{
|
||||
gen.gen_process(lex.return_list());
|
||||
gen.gen_main_work();
|
||||
gen.print_ast();
|
||||
}
|
||||
}
|
||||
else if(command=="run")
|
||||
{
|
||||
|
@ -69,7 +75,10 @@ int main()
|
|||
lex.token_list_type_detail_edit();
|
||||
pas.parse_process(lex.return_list());
|
||||
pas.parse_main_work();
|
||||
pas.run();
|
||||
if(!pas.get_error_num())
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
else
|
||||
prog.input_file(command);
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
#include <list>
|
||||
|
||||
#include "nasal_token_type.h"
|
||||
#include "abstract_syntax_tree.h"
|
||||
#include "ast.h"
|
||||
#include "nasal_var.h"
|
||||
#include "nasal_var_inrun_list.h"
|
||||
|
||||
#include "nasal_lexer.h"
|
||||
#include "nasal_parser.h"
|
||||
#include "ast_generator.h"
|
||||
|
||||
#include "nasal_var.cpp"
|
||||
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
#ifndef __NASAL_PARSER_H__
|
||||
#define __NASAL_PARSER_H__
|
||||
|
||||
#include "nasal_token_type.h"
|
||||
|
||||
class nasal_parser
|
||||
{
|
||||
private:
|
||||
ast_tree_node root;
|
||||
std::stack<token> parse;
|
||||
std::stack<ast_tree_node> node_cache;
|
||||
token this_token;
|
||||
int error;
|
||||
int warning;
|
||||
|
@ -30,6 +26,10 @@ class nasal_parser
|
|||
parse.pop();
|
||||
return;
|
||||
}
|
||||
int get_error_num()
|
||||
{
|
||||
return error;
|
||||
}
|
||||
void print_parser_stack()
|
||||
{
|
||||
if(parse.empty())
|
||||
|
@ -84,7 +84,7 @@ class nasal_parser
|
|||
}
|
||||
if(temp.empty())
|
||||
{
|
||||
std::cout<<">>[Parse] [-Warning] Empty lexer list."<<std::endl;
|
||||
std::cout<<">>[Parse] warning: empty lexer list."<<std::endl;
|
||||
return;
|
||||
}
|
||||
while(!temp.empty())
|
||||
|
@ -94,20 +94,6 @@ class nasal_parser
|
|||
}
|
||||
return;
|
||||
}
|
||||
void print_ast()
|
||||
{
|
||||
std::cout<<">>[Abstract-syntax-tree]"<<std::endl;
|
||||
root.print(0);
|
||||
return;
|
||||
}
|
||||
void run()
|
||||
{
|
||||
if(!error)
|
||||
root.run();
|
||||
else
|
||||
std::cout<<">>[Parse] "<<error<<" error(s) occurred,stop."<<std::endl;
|
||||
return;
|
||||
}
|
||||
void parse_main_work();
|
||||
void in_curve_calc_expr();
|
||||
void number_begin_expr();
|
||||
|
|
|
@ -30,6 +30,8 @@ enum token_type
|
|||
//basic elements
|
||||
|
||||
__root,
|
||||
__list,__hash,
|
||||
__call_function,__list_search,__hash_search,
|
||||
__block,
|
||||
__definition,__assignment,
|
||||
__function,__loop,__ifelse
|
||||
|
@ -91,6 +93,11 @@ void print_token(int type)
|
|||
case __string: context="str";break;
|
||||
|
||||
case __root: context="root";break;
|
||||
case __list: context="list";break;
|
||||
case __hash: context="hash";break;
|
||||
case __call_function: context="call_func";break;
|
||||
case __list_search: context="call_list";break;
|
||||
case __hash_search: context="call_hash";break;
|
||||
case __block: context="block";break;
|
||||
case __definition: context="definition";break;
|
||||
case __assignment: context="assignment";break;
|
||||
|
|
|
@ -51,7 +51,7 @@ class nasal_hash
|
|||
class nasal_function
|
||||
{
|
||||
private:
|
||||
std::list<ast_tree_node> root;
|
||||
std::list<abstract_syntax_tree> root;
|
||||
public:
|
||||
nasal_function();
|
||||
nasal_function(const nasal_function&);
|
||||
|
|
Loading…
Reference in New Issue