diff --git a/version0.3/ebnf.cpp b/version0.3/ebnf.cpp index 1ca076d..8febdca 100644 --- a/version0.3/ebnf.cpp +++ b/version0.3/ebnf.cpp @@ -9,38 +9,38 @@ ::= STRING //scalar - ::= || - ::= ||||| + ::= || + ::= <,> + ::= <,> + ::= |||| ::= <,> ::= <,> //array - ::= <[> <]> - ::= <[> | <]> + ::= <[> <]> + ::= <[> ||| <]> //hash - ::= <.> | - ::= <:> | + ::= <.> | + ::= <:> || ::= <,> ::= <,> ::= <{> | <}> //function - ::= - ::= - ::= <(> | <)> <{> | <}> - ::= <(> | <)> + ::= <(> | <)> <{> | <}> + ::= <(> ||| <)> //definition & assignment - ::= <=> | <;> - ::= <=>|<+=>|<-=>|<*=>||<~=> <;> + ::= <=> || <;> + ::= <=>|<+=>|<-=>|<*=>||<~=> | <;> //calculation - ::= <+> - ::= <-> - ::= <*> -
::= - ::= <~> + ::= | <+> | + ::= | <-> | + ::= | <*> | +
::= | | + ::= | <~> | ::= |||
::= <(> | <)> ::= <+>|<->|<*>||<~> @@ -55,8 +55,8 @@ //if else ::= || ::= <==>|<>>|<<>|<<=>|<>=>|| - ::= - ::= + ::= | + ::= | | ::= <(> <)> <(> <)> ::= <(> <)> <(> <)> ::= <(> <)> <(> <)> @@ -82,7 +82,7 @@ ::= <_if> <_else> //statement - ::= + ::= | ::= ::= ::= ||||||| <;> diff --git a/version0.3/nasal_parse.h b/version0.3/nasal_parse.h index 999e72e..9b2cfa9 100644 --- a/version0.3/nasal_parse.h +++ b/version0.3/nasal_parse.h @@ -5,8 +5,18 @@ enum token_type { - __stack_end,__identifier,__use_identifier, - __scalar,__function,__var,__equal,__semi,__definition + __stack_end, + __equal,// = + __add_operator,__sub_operator,__mul_operator,__div_operator,__link_operator,// + - * / ~ + __add_equal,__sub_equal,__mul_equal,__div_equal,__link_equal,// += -= *= /= ~= + __left_brace,__right_brace,// {} + __left_bracket,__right_bracket,// [] + __left_curve,__right_curve,// () + __semi,// ; + __var,// var + __identifier,__scalar,__function, + __definition,__assignment, + }; token_type token_type_tbl; @@ -22,6 +32,7 @@ class parse std::stack parser; public: void definition_reduction(); + void assignment_reduction(); void parse_work(token_list&); }; @@ -37,7 +48,7 @@ void parse::definition_reduction() tbl[i]=temp.top().type; parser.pop(); } - if(tbl[0]==__var && tbl[1]==__identifier && tbl[2]==__equal && tbl[3]==__scalar && tbl[4]==__semi) + if(tbl[0]==__var && tbl[1]==__identifier && tbl[2]==__equal && (tbl[3]==__scalar || tbl[3]==__identifier || tbl[3]==__function) && tbl[4]==__semi) { parse_unit temp_parse_unit; temp_parse_unit.type=__definition; @@ -54,6 +65,35 @@ void parse::definition_reduction() } return; } +void parse::assignment_reduction() +{ + int tbl[4]; + std::stack temp; + for(int i=3;i>=0;--i) + { + if(parser.empty()) + break; + temp.push(parser.top()); + tbl[i]=temp.top().type; + parser.pop(); + } + if(tbl[0]==__identifier && tbl[1]==__equal && (tbl[2]==__scalar || tbl[2]==__identifier) && tbl[3]==__semi) + { + parse_unit temp_parse_unit; + temp_parse_unit.type=__assignment; + temp_parse_unit.line=temp.top().line; + parser.push(temp_parse_unit); + } + else + for(int i=0;i<4;++i) + { + if(temp.empty()) + break; + parser.push(temp.top()); + temp.pop(); + } + return; +} void parse::parse_work(token_list& lexer) { @@ -88,10 +128,41 @@ void parse::parse_work(token_list& lexer) token_type_tbl=__scalar; temp_parse.type=token_type_tbl; } + else if(temp->content=="+" || temp->content=="-" || temp->content=="*" || temp->content=="/" || temp->content=="~") + { + if(temp->content=="+") + token_type_tbl=__add_operator; + else if(temp->content=="-") + token_type_tbl=__sub_operator; + else if(temp->content=="*") + token_type_tbl=__mul_operator; + else if(temp->content=="/") + token_type_tbl=__div_operator; + else if(temp->content=="~") + token_type_tbl=__link_operator; + temp_parse.type=token_type_tbl; + } + else if(temp->content=="+=" || temp->content=="-=" || temp->content=="*=" || temp->content=="/=" || temp->content=="~=") + { + if(temp->content=="+=") + token_type_tbl=__add_equal; + else if(temp->content=="-=") + token_type_tbl=__sub_equal; + else if(temp->content=="*=") + token_type_tbl=__mul_equal; + else if(temp->content=="/=") + token_type_tbl=__div_equal; + else if(temp->content=="~=") + token_type_tbl=__link_equal; + temp_parse.type=token_type_tbl; + } parser.push(temp_parse); definition_reduction(); + assignment_reduction(); if(parser.top().type==__definition) - std::cout<<"Definition in "<