• R/O
  • SSH
  • HTTPS

eircompile: Commit


Commit MetaInfo

Revision56 (tree)
Time2021-11-22 01:45:43
Authorquiret

Log Message

- fixed bugs in COS (precedence, missing object generator)
- added unit tests for COS operations

Change Summary

Incremental Difference

--- eircompile/include/eircompile/lexing_compile.h (revision 55)
+++ eircompile/include/eircompile/lexing_compile.h (revision 56)
@@ -200,7 +200,7 @@
200200 }
201201 inline alts_dispatcher( const alts_dispatcher& right ) = default;
202202
203- inline ExecStep* CreateNode( ExecStep *first ) const
203+ inline CompiledAlternatives* CreateNode( ExecStep *first ) const
204204 {
205205 if ( auto *runtime_env = compiler->runtime_env )
206206 {
@@ -249,7 +249,7 @@
249249 }
250250 }
251251
252- inline ExecStep* CreateNode( ExecStep *first ) const
252+ inline CompiledSequence* CreateNode( ExecStep *first ) const
253253 {
254254 if ( auto *runtime_env = compiler->runtime_env )
255255 {
--- eircompile/include/eircompile/lexing_selectors.h (revision 55)
+++ eircompile/include/eircompile/lexing_selectors.h (revision 56)
@@ -425,7 +425,7 @@
425425 concept LexerStructHasAssignNodeToMethod =
426426 selector_utils::IsAssignNodeToMethod <decltype(structType::AssignNodeTo), charType, cNodeType, baseNodeType>;
427427
428-template <typename structType, typename charType, typename nodeType, typename subNodeType = nodeType>
428+template <typename structType, typename charType, typename nodeType, typename subNodeType>
429429 concept MintwoSelectorDispatcher =
430430 eir::constructible_from <structType, const structType&> &&
431431 eir::nothrow_constructible_from <structType, structType&&> &&
@@ -432,7 +432,7 @@
432432 std::is_nothrow_destructible <structType>::value &&
433433 LexerCompatibleNode <nodeType, charType> &&
434434 std::derived_from <subNodeType, nodeType> &&
435- std::is_invocable_r <nodeType*, decltype(&structType::CreateNode), structType&, nodeType* /* first_node */>::value &&
435+ std::is_invocable_r <subNodeType*, decltype(&structType::CreateNode), structType&, nodeType* /* first_node */>::value &&
436436 ( LexerStructHasAssignNode <nodeType, charType, nodeType> || LexerStructHasAssignNodeToMethod <structType, charType, subNodeType, nodeType> );
437437
438438 // Specialized selector that returns a node-concatenation only if at least two
--- testcompiler/src/cos_tests.cpp (revision 55)
+++ testcompiler/src/cos_tests.cpp (revision 56)
@@ -84,6 +84,10 @@
8484 {
8585 using UnaryOperation::UnaryOperation;
8686 };
87+struct PointerResolveOperation : public UnaryOperation
88+{
89+ using UnaryOperation::UnaryOperation;
90+};
8791
8892 struct BinaryOperation : public Operation
8993 {
@@ -533,6 +537,23 @@
533537 depMultiString numeric_string;
534538 };
535539
540+struct PointerTypeSpecifier : public COSNode
541+{
542+ inline PointerTypeSpecifier( COSNode *spec = nullptr ) noexcept : spec( spec )
543+ {
544+ return;
545+ }
546+ inline PointerTypeSpecifier( const PointerTypeSpecifier& ) = default;
547+ inline PointerTypeSpecifier( PointerTypeSpecifier&& right ) noexcept
548+ {
549+ this->spec = right.spec;
550+
551+ right.spec = nullptr;
552+ }
553+
554+ COSNode *spec;
555+};
556+
536557 struct CurlyPack : public COSNode
537558 {
538559 inline CurlyPack( depVector <COSNode*> params = {} ) noexcept : params( std::move( params ) )
@@ -640,7 +661,7 @@
640661 {
641662 struct program_dispatcher
642663 {
643- inline COSNode* CreateNode( COSNode *first )
664+ inline Program* CreateNode( COSNode *first )
644665 {
645666 Program *node = new Program();
646667 node->statements.AddToBack( first );
@@ -655,7 +676,7 @@
655676 };
656677 lexer.GetNamedProduction( "S" ).setSelector <mintwo_specialized_selector <char, Program, COSNode, program_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
657678 }
658- assert( lexer.CompileProduction( compiler, "statement", "function | takefirst declaration spaces ';' | takefirst operation spaces ';' | typedef | block | loop | if | except | objmod" ) == true );
679+ assert( lexer.CompileProduction( compiler, "statement", "function | typedef | block | loop | if | except | objmod | takefirst declaration spaces ';' | takefirst operation spaces ';'" ) == true );
659680 assert( lexer.CompileProduction( compiler, "function", "(type:spec spaces)^0:1 (\"func\" | \"operator\") spaces name:spec spaces '(' spaces param:paramlist spaces ')' spaces body:funcbody" ) == true );
660681 {
661682 struct function_dispatcher
@@ -722,6 +743,22 @@
722743 };
723744 lexer.GetNamedProduction( "spec" ).GetLastStep()->setSelector <direct_obj_build_selector <char, ResolveSpecifierOperation, COSNode, dynspec_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
724745 }
746+ assert( lexer.CompileProduction( compiler, "spec", "'*' spaces spec:spec" ) == true );
747+ {
748+ struct ptr_spec_dispatcher
749+ {
750+ static inline bool AssignNodeTo( PointerTypeSpecifier *assign_to, const eir::FixedString <char>& attrib, COSNode *node )
751+ {
752+ if ( attrib == "spec" )
753+ {
754+ assign_to->spec = node;
755+ return true;
756+ }
757+ return false;
758+ }
759+ };
760+ lexer.GetNamedProduction( "spec" ).GetLastStep()->setSelector <direct_obj_build_selector <char, PointerTypeSpecifier, COSNode, ptr_spec_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
761+ }
725762 assert( lexer.CompileProduction( compiler, "declaration", "(type:spec spaces)^0:1 name:spec ( spaces '=' spaces init:operation | spaces init:curlypack )^0:1" ) == true );
726763 {
727764 struct declaration_dispatcher
@@ -746,6 +783,7 @@
746783 return false;
747784 }
748785 };
786+ lexer.GetNamedProduction( "declaration" ).setSelector <direct_obj_build_selector <char, DeclarationStatement, COSNode, declaration_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
749787 }
750788 assert( lexer.CompileProduction( compiler, "dtypedef", "\"typedef\" spaces srctype:spec spaces dsttype:spec spaces ';'" ) == true );
751789 {
@@ -837,7 +875,7 @@
837875 };
838876 operation.GetLastStep()->setSelector <left_associative_selector <char, COSNode, logical_and_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
839877 }
840- assert( lexer.CompileInto( compiler, operation, "[opitem:operation, spaces optype:(\"==\" | \"!=\" | '<' | '>' | \"<=\" | \">=\") spaces]" ) == true );
878+ assert( lexer.CompileInto( compiler, operation, "[opitem:operation, spaces optype:(\"==\" | \"!=\" | \"<=\" | \">=\" | '<' | '>') spaces]" ) == true );
841879 {
842880 struct logical_comparison_dispatcher
843881 {
@@ -921,53 +959,53 @@
921959 };
922960 operation.GetLastStep()->setSelector <left_associative_selector <char, COSNode, logical_comparison_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
923961 }
924- assert( lexer.CompileInto( compiler, operation, "[opitem:operation, spaces optype:('^'|'&'|'|') spaces]" ) == true );
962+ assert( lexer.CompileInto( compiler, operation, "[opitem:operation, spaces optype:'|' spaces]" ) == true );
925963 {
926- struct summation_dispatcher
964+ struct bor_dispatcher
927965 {
928- enum class eOpType
966+ inline void AssignAttribute( const eir::FixedString <char>& attrib, const eir::FixedString <char>& value )
929967 {
930- UNDEFINED,
931- ADDITION,
932- SUBTRACTION
933- };
968+ return;
969+ }
934970
971+ inline COSNode* CreateOperation( COSNode *left, COSNode *right )
972+ {
973+ return new BitwiseOrOperation( left, right );
974+ }
975+ };
976+ operation.GetLastStep()->setSelector <left_associative_selector <char, COSNode, bor_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
977+ }
978+ assert( lexer.CompileInto( compiler, operation, "[opitem:operation, spaces optype:'^' spaces]" ) == true );
979+ {
980+ struct bxor_dispatcher
981+ {
935982 inline void AssignAttribute( const eir::FixedString <char>& attrib, const eir::FixedString <char>& value )
936983 {
937- if ( attrib == "optype" )
938- {
939- if ( value == "+" )
940- {
941- this->op_type = eOpType::ADDITION;
942- }
943- else if ( value == "-" )
944- {
945- this->op_type = eOpType::SUBTRACTION;
946- }
947- }
984+ return;
948985 }
949986
950987 inline COSNode* CreateOperation( COSNode *left, COSNode *right )
951988 {
952- eOpType op_type = this->op_type;
989+ return new BitwiseXorOperation( left, right );
990+ }
991+ };
992+ operation.GetLastStep()->setSelector <left_associative_selector <char, COSNode, bxor_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
993+ }
994+ assert( lexer.CompileInto( compiler, operation, "[opitem:operation, spaces optype:'&' spaces]" ) == true );
995+ {
996+ struct band_dispatcher
997+ {
998+ inline void AssignAttribute( const eir::FixedString <char>& attrib, const eir::FixedString <char>& value )
999+ {
1000+ return;
1001+ }
9531002
954- if ( op_type == eOpType::ADDITION )
955- {
956- return new AddOperation( left, right );
957- }
958- else if ( op_type == eOpType::SUBTRACTION )
959- {
960- return new SubOperation( left, right );
961- }
962- else
963- {
964- throw lexing_invalid_parameter_exception();
965- }
1003+ inline COSNode* CreateOperation( COSNode *left, COSNode *right )
1004+ {
1005+ return new BitwiseAndOperation( left, right );
9661006 }
967-
968- eOpType op_type = eOpType::UNDEFINED;
9691007 };
970- operation.GetLastStep()->setSelector <left_associative_selector <char, COSNode, summation_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
1008+ operation.GetLastStep()->setSelector <left_associative_selector <char, COSNode, band_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
9711009 }
9721010 assert( lexer.CompileInto( compiler, operation, "[opitem:operation, spaces optype:('-'|'+') spaces]" ) == true );
9731011 {
@@ -1070,34 +1108,42 @@
10701108 };
10711109 operation.GetLastStep()->setSelector <left_associative_selector <char, COSNode, muldiv_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
10721110 }
1073- assert( lexer.CompileInto( compiler, operation, "[<0,e>optype:'-~!', spaces] opitem:operation" ) == true );
1111+ assert( lexer.CompileInto( compiler, operation, "[<0,e>pre_optype:(\"++\" | \"--\"), spaces] opitem:operation [<0,e> spaces, post_optype:(\"++\" | \"--\")]" ) == true );
10741112 {
1075- struct unary_negation_dispatcher
1113+ struct quickunamod_dispatcher
10761114 {
10771115 enum class eOpType
10781116 {
10791117 UNDEFINED,
1080- NUMERIC_NEGATION,
1081- BITWISE_NEGATION,
1082- LOGICAL_NEGATION
1118+ PRE_INCREMENT,
1119+ PRE_DECREMENT,
1120+ POST_INCREMENT,
1121+ POST_DECREMENT
10831122 };
10841123
10851124 inline void AssignAttribute( const eir::FixedString <char>& attrib, const eir::FixedString <char>& value )
10861125 {
1087- if ( attrib == "optype" )
1126+ if ( attrib == "pre_optype" )
10881127 {
1089- if ( value == "-" )
1128+ if ( value == "++" )
10901129 {
1091- this->op_type = eOpType::NUMERIC_NEGATION;
1130+ this->op_type = eOpType::PRE_INCREMENT;
10921131 }
1093- else if ( value == "~" )
1132+ else if ( value == "--" )
10941133 {
1095- this->op_type = eOpType::BITWISE_NEGATION;
1134+ this->op_type = eOpType::PRE_DECREMENT;
10961135 }
1097- else if ( value == "!" )
1136+ }
1137+ else if ( attrib == "post_optype" )
1138+ {
1139+ if ( value == "++" )
10981140 {
1099- this->op_type = eOpType::LOGICAL_NEGATION;
1141+ this->op_type = eOpType::POST_INCREMENT;
11001142 }
1143+ else if ( value == "--" )
1144+ {
1145+ this->op_type = eOpType::POST_DECREMENT;
1146+ }
11011147 }
11021148 }
11031149
@@ -1105,18 +1151,22 @@
11051151 {
11061152 eOpType op_type = this->op_type;
11071153
1108- if ( op_type == eOpType::NUMERIC_NEGATION )
1154+ if ( op_type == eOpType::PRE_INCREMENT )
11091155 {
1110- return new NumericNegationOperation( op );
1156+ return new PreIncrementOperation( op );
11111157 }
1112- else if ( op_type == eOpType::BITWISE_NEGATION )
1158+ else if ( op_type == eOpType::PRE_DECREMENT )
11131159 {
1114- return new BitwiseNegationOperation( op );
1160+ return new PreDecrementOperation( op );
11151161 }
1116- else if ( op_type == eOpType::LOGICAL_NEGATION )
1162+ else if ( op_type == eOpType::POST_INCREMENT )
11171163 {
1118- return new LogicalNegationOperation( op );
1164+ return new PostIncrementOperation( op );
11191165 }
1166+ else if ( op_type == eOpType::POST_DECREMENT )
1167+ {
1168+ return new PostDecrementOperation( op );
1169+ }
11201170
11211171 throw lexing_invalid_parameter_exception();
11221172 }
@@ -1123,43 +1173,40 @@
11231173
11241174 eOpType op_type = eOpType::UNDEFINED;
11251175 };
1126- operation.GetLastStep()->setSelector <unary_operation_selector <char, COSNode, unary_negation_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
1176+ operation.GetLastStep()->setSelector <unary_operation_selector <char, COSNode, quickunamod_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
11271177 }
1128- assert( lexer.CompileInto( compiler, operation, "[<0,e>pre_optype:(\"++\" | \"--\"), spaces] opitem:operation [<0,e> spaces, post_optype:(\"++\" | \"--\")]" ) == true );
1178+ assert( lexer.CompileInto( compiler, operation, "[<0,e>optype:'-~!*', spaces] opitem:operation" ) == true );
11291179 {
1130- struct quickunamod_dispatcher
1180+ struct unary_negation_dispatcher
11311181 {
11321182 enum class eOpType
11331183 {
11341184 UNDEFINED,
1135- PRE_INCREMENT,
1136- PRE_DECREMENT,
1137- POST_INCREMENT,
1138- POST_DECREMENT
1185+ NUMERIC_NEGATION,
1186+ BITWISE_NEGATION,
1187+ LOGICAL_NEGATION,
1188+ PTR_RESOLVE
11391189 };
11401190
11411191 inline void AssignAttribute( const eir::FixedString <char>& attrib, const eir::FixedString <char>& value )
11421192 {
1143- if ( attrib == "pre_optype" )
1193+ if ( attrib == "optype" )
11441194 {
1145- if ( value == "++" )
1195+ if ( value == "-" )
11461196 {
1147- this->op_type = eOpType::PRE_INCREMENT;
1197+ this->op_type = eOpType::NUMERIC_NEGATION;
11481198 }
1149- else if ( value == "--" )
1199+ else if ( value == "~" )
11501200 {
1151- this->op_type = eOpType::PRE_DECREMENT;
1201+ this->op_type = eOpType::BITWISE_NEGATION;
11521202 }
1153- }
1154- else if ( attrib == "post_optype" )
1155- {
1156- if ( value == "++" )
1203+ else if ( value == "!" )
11571204 {
1158- this->op_type = eOpType::POST_INCREMENT;
1205+ this->op_type = eOpType::LOGICAL_NEGATION;
11591206 }
1160- else if ( value == "--" )
1207+ else if ( value == "*" )
11611208 {
1162- this->op_type = eOpType::POST_DECREMENT;
1209+ this->op_type = eOpType::PTR_RESOLVE;
11631210 }
11641211 }
11651212 }
@@ -1168,21 +1215,21 @@
11681215 {
11691216 eOpType op_type = this->op_type;
11701217
1171- if ( op_type == eOpType::PRE_INCREMENT )
1218+ if ( op_type == eOpType::NUMERIC_NEGATION )
11721219 {
1173- return new PreIncrementOperation( op );
1220+ return new NumericNegationOperation( op );
11741221 }
1175- else if ( op_type == eOpType::PRE_DECREMENT )
1222+ else if ( op_type == eOpType::BITWISE_NEGATION )
11761223 {
1177- return new PreDecrementOperation( op );
1224+ return new BitwiseNegationOperation( op );
11781225 }
1179- else if ( op_type == eOpType::POST_INCREMENT )
1226+ else if ( op_type == eOpType::LOGICAL_NEGATION )
11801227 {
1181- return new PostIncrementOperation( op );
1228+ return new LogicalNegationOperation( op );
11821229 }
1183- else if ( op_type == eOpType::POST_DECREMENT )
1230+ else if ( op_type == eOpType::PTR_RESOLVE )
11841231 {
1185- return new PostDecrementOperation( op );
1232+ return new PointerResolveOperation( op );
11861233 }
11871234
11881235 throw lexing_invalid_parameter_exception();
@@ -1190,7 +1237,7 @@
11901237
11911238 eOpType op_type = eOpType::UNDEFINED;
11921239 };
1193- operation.GetLastStep()->setSelector <unary_operation_selector <char, COSNode, quickunamod_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
1240+ operation.GetLastStep()->setSelector <unary_operation_selector <char, COSNode, unary_negation_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
11941241 }
11951242 assert( lexer.CompileInto( compiler, operation, "tocall:operation (spaces [begcall:'(' spaces [<0>param:procgate operation, spaces ',' spaces] spaces endcall:')', spaces])^0:1" ) == true );
11961243 {
@@ -1340,8 +1387,6 @@
13401387
13411388 auto tailop = lexer.MakeStep <decltype(lexer)::RuntimeEnv::StepAlternatives> ();
13421389
1343- assert( lexer.CompileInto( compiler, tailop, "name" ) == true );
1344- assert( lexer.CompileInto( compiler, tailop, "number" ) == true );
13451390 assert( lexer.CompileInto( compiler, tailop, "\"new\" spaces type:spec spaces ('(' spaces param:paramlist spaces ')')^0:1" ) == true );
13461391 {
13471392 struct new_dispatcher
@@ -1364,6 +1409,8 @@
13641409 };
13651410 tailop.GetLastStep()->setSelector <direct_obj_build_selector <char, NewOperation, COSNode, new_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
13661411 }
1412+ assert( lexer.CompileInto( compiler, tailop, "name" ) == true );
1413+ assert( lexer.CompileInto( compiler, tailop, "number" ) == true );
13671414 assert( lexer.CompileInto( compiler, tailop, "'{' spaces [item:procgate operation, spaces ',' spaces] spaces '}'" ) == true );
13681415 {
13691416 struct array_dispatcher
@@ -1466,16 +1513,6 @@
14661513
14671514 bool validchar = is_num( ucp );
14681515
1469- if ( first_char )
1470- {
1471- validchar = is_num_nonzero( ucp );
1472- first_char = false;
1473- }
1474- else
1475- {
1476- validchar = is_num( ucp );
1477- }
1478-
14791516 if ( validchar == false )
14801517 {
14811518 pt.SetOffset( oldoff );
@@ -1814,7 +1851,7 @@
18141851 lexer.GetNamedProduction( "curlypack" ).setSelector <direct_obj_build_selector <char, CurlyPack, COSNode, curlypack_dispatcher, decltype(lexer)::RuntimeEnv>> ( &lexer.GetRuntimeEnvironment() );
18151852 }
18161853
1817- printf( "testing COS operations..." );
1854+ printf( "testing COS operations (non-deep)..." );
18181855 {
18191856 assert( lexer.TestProduction( "1 + 1;" ) == true );
18201857 assert( lexer.TestProduction( "1 + 1 + 1;" ) == true );
@@ -1831,4 +1868,1209 @@
18311868 assert( lexer.TestProduction( "var() + var() + var();" ) == true );
18321869 }
18331870 printf( "ok.\n" );
1871+
1872+ printf( "testing COS operations..." );
1873+ {
1874+ // 1)
1875+ {
1876+ COSNode *_root = lexer.StartProduction( "1+1-1*1/1;" );
1877+
1878+ SubOperation *root = dynamic_cast <SubOperation*> ( _root );
1879+
1880+ assert( root != nullptr );
1881+
1882+ AddOperation *left_root = dynamic_cast <AddOperation*> ( root->left );
1883+
1884+ assert( left_root != nullptr );
1885+
1886+ NumberString *first = dynamic_cast <NumberString*> ( left_root->left );
1887+
1888+ assert( first != nullptr );
1889+ assert( first->numeric_string == "1" );
1890+
1891+ first->Delete();
1892+
1893+ NumberString *second = dynamic_cast <NumberString*> ( left_root->right );
1894+
1895+ assert( second != nullptr );
1896+ assert( second->numeric_string == "1" );
1897+
1898+ second->Delete();
1899+
1900+ left_root->Delete();
1901+
1902+ DivOperation *right_root = dynamic_cast <DivOperation*> ( root->right );
1903+
1904+ assert( right_root != nullptr );
1905+
1906+ MulOperation *left_right_root = dynamic_cast <MulOperation*> ( right_root->left );
1907+
1908+ assert( left_right_root != nullptr );
1909+
1910+ NumberString *third = dynamic_cast <NumberString*> ( left_right_root->left );
1911+
1912+ assert( third != nullptr );
1913+ assert( third->numeric_string == "1" );
1914+
1915+ third->Delete();
1916+
1917+ NumberString *fourth = dynamic_cast <NumberString*> ( left_right_root->right );
1918+
1919+ assert( fourth != nullptr );
1920+ assert( fourth->numeric_string == "1" );
1921+
1922+ fourth->Delete();
1923+
1924+ left_right_root->Delete();
1925+
1926+ NumberString *fifth = dynamic_cast <NumberString*> ( right_root->right );
1927+
1928+ assert( fifth != nullptr );
1929+ assert( fifth->numeric_string == "1" );
1930+
1931+ fifth->Delete();
1932+
1933+ right_root->Delete();
1934+ root->Delete();
1935+ }
1936+
1937+ // 2)
1938+ {
1939+ COSNode *_root = lexer.StartProduction( "1+1*1+1;" );
1940+
1941+ AddOperation *root = dynamic_cast <AddOperation*> ( _root );
1942+
1943+ assert( root != nullptr );
1944+
1945+ NumberString *first = dynamic_cast <NumberString*> ( root->right );
1946+
1947+ assert( first != nullptr );
1948+ assert( first->numeric_string == "1" );
1949+
1950+ first->Delete();
1951+
1952+ AddOperation *sub_root = dynamic_cast <AddOperation*> ( root->left );
1953+
1954+ assert( sub_root != nullptr );
1955+
1956+ NumberString *fourth = dynamic_cast <NumberString*> ( sub_root->left );
1957+
1958+ assert( fourth != nullptr );
1959+ assert( fourth->numeric_string == "1" );
1960+
1961+ fourth->Delete();
1962+
1963+ MulOperation *sub_sub_root = dynamic_cast <MulOperation*> ( sub_root->right );
1964+
1965+ assert( sub_sub_root != nullptr );
1966+
1967+ NumberString *second = dynamic_cast <NumberString*> ( sub_sub_root->left );
1968+ NumberString *third = dynamic_cast <NumberString*> ( sub_sub_root->right );
1969+
1970+ assert( second != nullptr );
1971+ assert( second->numeric_string == "1" );
1972+ assert( third != nullptr );
1973+ assert( third->numeric_string == "1" );
1974+
1975+ second->Delete();
1976+ third->Delete();
1977+
1978+ sub_sub_root->Delete();
1979+ sub_root->Delete();
1980+ root->Delete();
1981+ }
1982+
1983+ // 3)
1984+ {
1985+ COSNode *_root = lexer.StartProduction( "1*(1+1*1);" );
1986+
1987+ MulOperation *root = dynamic_cast <MulOperation*> ( _root );
1988+
1989+ assert( root != nullptr );
1990+
1991+ NumberString *first = dynamic_cast <NumberString*> ( root->left );
1992+
1993+ assert( first != nullptr );
1994+ assert( first->numeric_string == "1" );
1995+
1996+ first->Delete();
1997+
1998+ AddOperation *sub_root = dynamic_cast <AddOperation*>( root->right );
1999+
2000+ assert( sub_root != nullptr );
2001+
2002+ NumberString *second = dynamic_cast <NumberString*> ( sub_root->left );
2003+
2004+ assert( second != nullptr );
2005+ assert( second->numeric_string == "1" );
2006+
2007+ second->Delete();
2008+
2009+ MulOperation *sub_sub_root = dynamic_cast <MulOperation*> ( sub_root->right );
2010+
2011+ assert( sub_sub_root != nullptr );
2012+
2013+ NumberString *third = dynamic_cast <NumberString*> ( sub_sub_root->left );
2014+ NumberString *fourth = dynamic_cast <NumberString*> ( sub_sub_root->right );
2015+
2016+ assert( third != nullptr );
2017+ assert( third->numeric_string == "1" );
2018+ assert( fourth != nullptr );
2019+ assert( fourth->numeric_string == "1" );
2020+
2021+ third->Delete();
2022+ fourth->Delete();
2023+
2024+ sub_sub_root->Delete();
2025+ sub_root->Delete();
2026+ root->Delete();
2027+ }
2028+
2029+ // 4)
2030+ {
2031+ COSNode *_root = lexer.StartProduction( "a=1+1;" );
2032+
2033+ AssignmentOperation *root = dynamic_cast <AssignmentOperation*> ( _root );
2034+
2035+ assert( root != nullptr );
2036+
2037+ SpecifierString *first = dynamic_cast <SpecifierString*> ( root->left );
2038+
2039+ assert( first != nullptr );
2040+ assert( first->string == "a" );
2041+
2042+ first->Delete();
2043+
2044+ AddOperation *sub_root = dynamic_cast <AddOperation*> ( root->right );
2045+
2046+ assert( sub_root != nullptr );
2047+
2048+ NumberString *second = dynamic_cast <NumberString*> ( sub_root->left );
2049+ NumberString *third = dynamic_cast <NumberString*> ( sub_root->right );
2050+
2051+ assert( second != nullptr );
2052+ assert( second->numeric_string == "1" );
2053+ assert( third != nullptr );
2054+ assert( third->numeric_string == "1" );
2055+
2056+ second->Delete();
2057+ third->Delete();
2058+
2059+ sub_root->Delete();
2060+ root->Delete();
2061+ }
2062+
2063+ // 5)
2064+ {
2065+ COSNode *_root = lexer.StartProduction( "1==2;" );
2066+
2067+ CompareEqualityOperation *root = dynamic_cast <CompareEqualityOperation*> ( _root );
2068+
2069+ assert( root != nullptr );
2070+
2071+ NumberString *first = dynamic_cast <NumberString*> ( root->left );
2072+
2073+ assert( first != nullptr );
2074+ assert( first->numeric_string == "1" );
2075+
2076+ NumberString *second = dynamic_cast <NumberString*> ( root->right );
2077+
2078+ assert( second != nullptr );
2079+ assert( second->numeric_string == "2" );
2080+
2081+ first->Delete();
2082+ second->Delete();
2083+
2084+ root->Delete();
2085+ }
2086+
2087+ // 6)
2088+ {
2089+ COSNode *_root = lexer.StartProduction( "1+1==2-0;" );
2090+
2091+ CompareEqualityOperation *root = dynamic_cast <CompareEqualityOperation*> ( _root );
2092+
2093+ assert( root != nullptr );
2094+
2095+ AddOperation *left_root = dynamic_cast <AddOperation*> ( root->left );
2096+
2097+ assert( left_root != nullptr );
2098+
2099+ NumberString *first = dynamic_cast <NumberString*> ( left_root->left );
2100+ NumberString *second = dynamic_cast <NumberString*> ( left_root->right );
2101+
2102+ assert( first != nullptr );
2103+ assert( first->numeric_string == "1" );
2104+ assert( second != nullptr );
2105+ assert( second->numeric_string == "1" );
2106+
2107+ first->Delete();
2108+ second->Delete();
2109+
2110+ SubOperation *right_root = dynamic_cast <SubOperation*> ( root->right );
2111+
2112+ assert( right_root != nullptr );
2113+
2114+ NumberString *third = dynamic_cast <NumberString*> ( right_root->left );
2115+ NumberString *fourth = dynamic_cast <NumberString*> ( right_root->right );
2116+
2117+ assert( third != nullptr );
2118+ assert( third->numeric_string == "2" );
2119+ assert( fourth != nullptr );
2120+ assert( fourth->numeric_string == "0" );
2121+
2122+ third->Delete();
2123+ fourth->Delete();
2124+
2125+ left_root->Delete();
2126+ right_root->Delete();
2127+ root->Delete();
2128+ }
2129+
2130+ // 7)
2131+ {
2132+ COSNode *_root = lexer.StartProduction( "1==1<=1;" );
2133+
2134+ CompareLessThanEqualOperation *root = dynamic_cast <CompareLessThanEqualOperation*> ( _root );
2135+
2136+ assert( root != nullptr );
2137+
2138+ NumberString *first = dynamic_cast <NumberString*> ( root->right );
2139+
2140+ assert( first != nullptr );
2141+ assert( first->numeric_string == "1" );
2142+
2143+ first->Delete();
2144+
2145+ CompareEqualityOperation *sub_root = dynamic_cast <CompareEqualityOperation*> ( root->left );
2146+
2147+ assert( sub_root != nullptr );
2148+
2149+ NumberString *second = dynamic_cast <NumberString*> ( sub_root->left );
2150+ NumberString *third = dynamic_cast <NumberString*> ( sub_root->right );
2151+
2152+ assert( second != nullptr );
2153+ assert( second->numeric_string == "1" );
2154+ assert( third != nullptr );
2155+ assert( third->numeric_string == "1" );
2156+
2157+ second->Delete();
2158+ third->Delete();
2159+
2160+ sub_root->Delete();
2161+ root->Delete();
2162+ }
2163+
2164+ // 8)
2165+ {
2166+ COSNode *_root = lexer.StartProduction( "1<2;" );
2167+
2168+ CompareLessThanOperation *root = dynamic_cast <CompareLessThanOperation*> ( _root );
2169+
2170+ assert( root != nullptr );
2171+
2172+ NumberString *left = dynamic_cast <NumberString*> ( root->left );
2173+ NumberString *right = dynamic_cast <NumberString*> ( root->right );
2174+
2175+ assert( left != nullptr );
2176+ assert( left->numeric_string == "1" );
2177+ assert( right != nullptr );
2178+ assert( right->numeric_string == "2" );
2179+
2180+ left->Delete();
2181+ right->Delete();
2182+
2183+ root->Delete();
2184+ }
2185+
2186+ // 9)
2187+ {
2188+ COSNode *_root = lexer.StartProduction( "3>1;" );
2189+
2190+ CompareGreaterThanOperation *root = dynamic_cast <CompareGreaterThanOperation*> ( _root );
2191+
2192+ assert( root != nullptr );
2193+
2194+ NumberString *first = dynamic_cast <NumberString*> ( root->left );
2195+
2196+ assert( first != nullptr );
2197+ assert( first->numeric_string == "3" );
2198+
2199+ first->Delete();
2200+
2201+ NumberString *second = dynamic_cast <NumberString*> ( root->right );
2202+
2203+ assert( second != nullptr );
2204+ assert( second->numeric_string == "1" );
2205+
2206+ second->Delete();
2207+
2208+ root->Delete();
2209+ }
2210+
2211+ // 10)
2212+ {
2213+ COSNode *_root = lexer.StartProduction( "1>=0;" );
2214+
2215+ CompareGreaterThanEqualOperation *root = dynamic_cast <CompareGreaterThanEqualOperation*> ( _root );
2216+
2217+ assert( root != nullptr );
2218+
2219+ NumberString *first = dynamic_cast <NumberString*> ( root->left );
2220+ NumberString *second = dynamic_cast <NumberString*> ( root->right );
2221+
2222+ assert( first != nullptr );
2223+ assert( first->numeric_string == "1" );
2224+ assert( second != nullptr );
2225+ assert( second->numeric_string == "0" );
2226+
2227+ first->Delete();
2228+ second->Delete();
2229+
2230+ root->Delete();
2231+ }
2232+
2233+ // 11)
2234+ {
2235+ COSNode *_root = lexer.StartProduction( "20<11>19<=1>=2==3!=0;" );
2236+
2237+ CompareInequalityOperation *root = dynamic_cast <CompareInequalityOperation*> ( _root );
2238+
2239+ assert( root != nullptr );
2240+
2241+ NumberString *first = dynamic_cast <NumberString*> ( root->right );
2242+
2243+ assert( first != nullptr );
2244+ assert( first->numeric_string == "0" );
2245+
2246+ first->Delete();
2247+
2248+ CompareEqualityOperation *sub_root = dynamic_cast <CompareEqualityOperation*> ( root->left );
2249+
2250+ assert( sub_root != nullptr );
2251+
2252+ NumberString *second = dynamic_cast <NumberString*> ( sub_root->right );
2253+
2254+ assert( second != nullptr );
2255+ assert( second->numeric_string == "3" );
2256+
2257+ second->Delete();
2258+
2259+ CompareGreaterThanEqualOperation *sub_sub_root = dynamic_cast <CompareGreaterThanEqualOperation*> ( sub_root->left );
2260+
2261+ assert( sub_sub_root != nullptr );
2262+
2263+ NumberString *third = dynamic_cast <NumberString*> ( sub_sub_root->right );
2264+
2265+ assert( third != nullptr );
2266+ assert( third->numeric_string == "2" );
2267+
2268+ third->Delete();
2269+
2270+ CompareLessThanEqualOperation *sub_sub_sub_root = dynamic_cast <CompareLessThanEqualOperation*> ( sub_sub_root->left );
2271+
2272+ assert( sub_sub_sub_root != nullptr );
2273+
2274+ NumberString *fourth = dynamic_cast <NumberString*> ( sub_sub_sub_root->right );
2275+
2276+ assert( fourth != nullptr );
2277+ assert( fourth->numeric_string == "1" );
2278+
2279+ fourth->Delete();
2280+
2281+ CompareGreaterThanOperation *sub_sub_sub_sub_root = dynamic_cast <CompareGreaterThanOperation*> ( sub_sub_sub_root->left );
2282+
2283+ assert( sub_sub_sub_sub_root != nullptr );
2284+
2285+ NumberString *fifth = dynamic_cast <NumberString*> ( sub_sub_sub_sub_root->right );
2286+
2287+ assert( fifth != nullptr );
2288+ assert( fifth->numeric_string == "19" );
2289+
2290+ fifth->Delete();
2291+
2292+ CompareLessThanOperation *sub_sub_sub_sub_sub_root = dynamic_cast <CompareLessThanOperation*> ( sub_sub_sub_sub_root->left );
2293+
2294+ assert( sub_sub_sub_sub_sub_root != nullptr );
2295+
2296+ NumberString *sixth = dynamic_cast <NumberString*> ( sub_sub_sub_sub_sub_root->left );
2297+ NumberString *seventh = dynamic_cast <NumberString*> ( sub_sub_sub_sub_sub_root->right );
2298+
2299+ assert( sixth != nullptr );
2300+ assert( sixth->numeric_string == "20" );
2301+ assert( seventh != nullptr );
2302+ assert( seventh->numeric_string == "11" );
2303+
2304+ sixth->Delete();
2305+ seventh->Delete();
2306+
2307+ sub_sub_sub_sub_sub_root->Delete();
2308+ sub_sub_sub_sub_root->Delete();
2309+ sub_sub_sub_root->Delete();
2310+ sub_sub_root->Delete();
2311+ sub_root->Delete();
2312+ root->Delete();
2313+ }
2314+
2315+ // 12)
2316+ {
2317+ COSNode *_root = lexer.StartProduction( "a(1)+b(1)=3;" );
2318+
2319+ AssignmentOperation *root = dynamic_cast <AssignmentOperation*> ( _root );
2320+
2321+ assert( root != nullptr );
2322+
2323+ AddOperation *left_root = dynamic_cast <AddOperation*> ( root->left );
2324+
2325+ assert( left_root != nullptr );
2326+
2327+ FunctionCallOperation *left_left_root = dynamic_cast <FunctionCallOperation*> ( left_root->left );
2328+
2329+ assert( left_left_root != nullptr );
2330+ assert( left_left_root->params.GetCount() == 1 );
2331+
2332+ SpecifierString *a = dynamic_cast <SpecifierString*> ( left_left_root->what );
2333+
2334+ assert( a != nullptr );
2335+ assert( a->string == "a" );
2336+
2337+ a->Delete();
2338+
2339+ NumberString *second = dynamic_cast <NumberString*> ( left_left_root->params[0] );
2340+
2341+ assert( second != nullptr );
2342+ assert( second->numeric_string == "1" );
2343+
2344+ second->Delete();
2345+
2346+ left_left_root->Delete();
2347+
2348+ FunctionCallOperation *right_left_root = dynamic_cast <FunctionCallOperation*> ( left_root->right );
2349+
2350+ assert( right_left_root != nullptr );
2351+ assert( right_left_root->params.GetCount() == 1 );
2352+
2353+ SpecifierString *third = dynamic_cast <SpecifierString*> ( right_left_root->what );
2354+
2355+ assert( third != nullptr );
2356+ assert( third->string == "b" );
2357+
2358+ third->Delete();
2359+
2360+ NumberString *fourth = dynamic_cast <NumberString*> ( right_left_root->params[0] );
2361+
2362+ assert( fourth != nullptr );
2363+ assert( fourth->numeric_string == "1" );
2364+
2365+ fourth->Delete();
2366+
2367+ right_left_root->Delete();
2368+
2369+ NumberString *fifth = dynamic_cast <NumberString*> ( root->right );
2370+
2371+ assert( fifth != nullptr );
2372+ assert( fifth->numeric_string == "3" );
2373+
2374+ fifth->Delete();
2375+
2376+ root->Delete();
2377+ }
2378+
2379+ // 13)
2380+ {
2381+ COSNode *_root = lexer.StartProduction( "a(b(1)+1,c(1))+3==0;" );
2382+
2383+ CompareEqualityOperation *root = dynamic_cast <CompareEqualityOperation*> ( _root );
2384+
2385+ assert( root != nullptr );
2386+
2387+ AddOperation *left_root = dynamic_cast <AddOperation*> ( root->left );
2388+
2389+ assert( left_root != nullptr );
2390+
2391+ FunctionCallOperation *left_left_root = dynamic_cast <FunctionCallOperation*> ( left_root->left );
2392+
2393+ assert( left_left_root != nullptr );
2394+ assert( left_left_root->params.GetCount() == 2 );
2395+
2396+ SpecifierString *a = dynamic_cast <SpecifierString*> ( left_left_root->what );
2397+
2398+ assert( a != nullptr );
2399+ assert( a->string == "a" );
2400+
2401+ a->Delete();
2402+
2403+ AddOperation *left_left_left_root = dynamic_cast <AddOperation*> ( left_left_root->params[0] );
2404+
2405+ assert( left_left_left_root != nullptr );
2406+
2407+ FunctionCallOperation *left_left_left_left_root = dynamic_cast <FunctionCallOperation*> ( left_left_left_root->left );
2408+
2409+ assert( left_left_left_left_root != nullptr );
2410+ assert( left_left_left_left_root->params.GetCount() == 1 );
2411+
2412+ NumberString *first = dynamic_cast <NumberString*> ( left_left_left_left_root->params[0] );
2413+
2414+ assert( first != nullptr );
2415+ assert( first->numeric_string == "1" );
2416+
2417+ SpecifierString *second = dynamic_cast <SpecifierString*> ( left_left_left_left_root->what );
2418+
2419+ assert( second != nullptr );
2420+ assert( second->string == "b" );
2421+
2422+ second->Delete();
2423+
2424+ NumberString *third = dynamic_cast <NumberString*> ( left_left_left_root->right );
2425+
2426+ assert( third != nullptr );
2427+ assert( third->numeric_string == "1" );
2428+
2429+ third->Delete();
2430+
2431+ FunctionCallOperation *right_left_left_root = dynamic_cast <FunctionCallOperation*> ( left_left_root->params[1] );
2432+
2433+ assert( right_left_left_root != nullptr );
2434+ assert( right_left_left_root->params.GetCount() == 1 );
2435+
2436+ SpecifierString *fourth = dynamic_cast <SpecifierString*> ( right_left_left_root->what );
2437+
2438+ assert( fourth != nullptr );
2439+ assert( fourth->string == "c" );
2440+
2441+ fourth->Delete();
2442+
2443+ NumberString *fifth = dynamic_cast <NumberString*> ( right_left_left_root->params[0] );
2444+
2445+ assert( fifth != nullptr );
2446+ assert( fifth->numeric_string == "1" );
2447+
2448+ fifth->Delete();
2449+
2450+ NumberString *sixth = dynamic_cast <NumberString*> ( left_root->right );
2451+
2452+ assert( sixth != nullptr );
2453+ assert( sixth->numeric_string == "3" );
2454+
2455+ sixth->Delete();
2456+
2457+ NumberString *seventh = dynamic_cast <NumberString*> ( root->right );
2458+
2459+ assert( seventh != nullptr );
2460+ assert( seventh->numeric_string == "0" );
2461+
2462+ seventh->Delete();
2463+
2464+ left_left_left_left_root->Delete();
2465+ left_left_left_root->Delete();
2466+ left_left_root->Delete();
2467+ right_left_left_root->Delete();
2468+ left_root->Delete();
2469+ root->Delete();
2470+ }
2471+
2472+ // 14)
2473+ {
2474+ COSNode *_root = lexer.StartProduction( "-(1+1)*3;" );
2475+
2476+ MulOperation *root = dynamic_cast <MulOperation*> ( _root );
2477+
2478+ assert( root != nullptr );
2479+
2480+ NumericNegationOperation *left_root = dynamic_cast <NumericNegationOperation*> ( root->left );
2481+
2482+ assert( left_root != nullptr );
2483+
2484+ AddOperation *sub_left_root = dynamic_cast <AddOperation*> ( left_root->op );
2485+
2486+ assert( sub_left_root != nullptr );
2487+
2488+ NumberString *left_sub_left_root = dynamic_cast <NumberString*> ( sub_left_root->left );
2489+
2490+ assert( left_sub_left_root != nullptr );
2491+ assert( left_sub_left_root->numeric_string == "1" );
2492+
2493+ left_sub_left_root->Delete();
2494+
2495+ NumberString *right_sub_left_root = dynamic_cast <NumberString*> ( sub_left_root->right );
2496+
2497+ assert( right_sub_left_root != nullptr );
2498+ assert( right_sub_left_root->numeric_string == "1" );
2499+
2500+ right_sub_left_root->Delete();
2501+
2502+ sub_left_root->Delete();
2503+ left_root->Delete();
2504+
2505+ NumberString *third = dynamic_cast <NumberString*> ( root->right );
2506+
2507+ assert( third != nullptr );
2508+ assert( third->numeric_string == "3" );
2509+
2510+ third->Delete();
2511+
2512+ root->Delete();
2513+ }
2514+
2515+ // 15)
2516+ {
2517+ COSNode *_root = lexer.StartProduction( "-(-(1));" );
2518+
2519+ NumericNegationOperation *root = dynamic_cast <NumericNegationOperation*> ( _root );
2520+
2521+ assert( root != nullptr );
2522+
2523+ NumericNegationOperation *sub_root = dynamic_cast <NumericNegationOperation*> ( root->op );
2524+
2525+ assert( sub_root != nullptr );
2526+
2527+ NumberString *first = dynamic_cast <NumberString*> ( sub_root->op );
2528+
2529+ assert( first != nullptr );
2530+ assert( first->numeric_string == "1" );
2531+
2532+ first->Delete();
2533+
2534+ sub_root->Delete();
2535+ root->Delete();
2536+ }
2537+
2538+ // 16)
2539+ {
2540+ COSNode *_root = lexer.StartProduction( "--a;" );
2541+
2542+ PreDecrementOperation *root = dynamic_cast <PreDecrementOperation*> ( _root );
2543+
2544+ assert( root != nullptr );
2545+
2546+ SpecifierString *sub_root = dynamic_cast <SpecifierString*> ( root->op );
2547+
2548+ assert( sub_root != nullptr );
2549+ assert( sub_root->string == "a" );
2550+
2551+ sub_root->Delete();
2552+
2553+ root->Delete();
2554+ }
2555+
2556+ // 17)
2557+ {
2558+ COSNode *_root = lexer.StartProduction( "a--=1;" );
2559+
2560+ AssignmentOperation *root = dynamic_cast <AssignmentOperation*> ( _root );
2561+
2562+ assert( root != nullptr );
2563+
2564+ PostDecrementOperation *left_root = dynamic_cast <PostDecrementOperation*> ( root->left );
2565+
2566+ assert( left_root != nullptr );
2567+
2568+ SpecifierString *first = dynamic_cast <SpecifierString*> ( left_root->op );
2569+
2570+ assert( first != nullptr );
2571+ assert( first->string == "a" );
2572+
2573+ first->Delete();
2574+
2575+ left_root->Delete();
2576+
2577+ NumberString *second = dynamic_cast <NumberString*> ( root->right );
2578+
2579+ assert( second != nullptr );
2580+ assert( second->numeric_string == "1" );
2581+
2582+ second->Delete();
2583+
2584+ root->Delete();
2585+ }
2586+
2587+ // 18)
2588+ {
2589+ COSNode *_root = lexer.StartProduction( "a++;" );
2590+
2591+ PostIncrementOperation *root = dynamic_cast <PostIncrementOperation*> ( _root );
2592+
2593+ assert( root != nullptr );
2594+
2595+ SpecifierString *first = dynamic_cast <SpecifierString*> ( root->op );
2596+
2597+ assert( first != nullptr );
2598+ assert( first->string == "a" );
2599+
2600+ first->Delete();
2601+
2602+ root->Delete();
2603+ }
2604+
2605+ // 19)
2606+ {
2607+ COSNode *_root = lexer.StartProduction( "++a;" );
2608+
2609+ PreIncrementOperation *root = dynamic_cast <PreIncrementOperation*> ( _root );
2610+
2611+ assert( root != nullptr );
2612+
2613+ SpecifierString *first = dynamic_cast <SpecifierString*> ( root->op );
2614+
2615+ assert( first != nullptr );
2616+
2617+ first->Delete();
2618+
2619+ root->Delete();
2620+ }
2621+
2622+ // 20)
2623+ {
2624+ COSNode *_root = lexer.StartProduction( "2 | 1 & 0 == 2;" );
2625+
2626+ CompareEqualityOperation *root = dynamic_cast <CompareEqualityOperation*> ( _root );
2627+
2628+ assert( root != nullptr );
2629+
2630+ BitwiseOrOperation *left_root = dynamic_cast <BitwiseOrOperation*> ( root->left );
2631+
2632+ assert( left_root != nullptr );
2633+
2634+ NumberString *first = dynamic_cast <NumberString*> ( left_root->left );
2635+
2636+ assert( first != nullptr );
2637+ assert( first->numeric_string == "2" );
2638+
2639+ first->Delete();
2640+
2641+ BitwiseAndOperation *right_left_root = dynamic_cast <BitwiseAndOperation*> ( left_root->right );
2642+
2643+ assert( right_left_root != nullptr );
2644+
2645+ NumberString *second = dynamic_cast <NumberString*> ( right_left_root->left );
2646+ NumberString *third = dynamic_cast <NumberString*> ( right_left_root->right );
2647+
2648+ assert( second != nullptr );
2649+ assert( second->numeric_string == "1" );
2650+ assert( third != nullptr );
2651+ assert( third->numeric_string == "0" );
2652+
2653+ second->Delete();
2654+ third->Delete();
2655+
2656+ right_left_root->Delete();
2657+ left_root->Delete();
2658+
2659+ NumberString *fourth = dynamic_cast <NumberString*> ( root->right );
2660+
2661+ assert( fourth != nullptr );
2662+ assert( fourth->numeric_string == "2" );
2663+
2664+ fourth->Delete();
2665+
2666+ root->Delete();
2667+ }
2668+
2669+ // 21)
2670+ {
2671+ COSNode *_root = lexer.StartProduction( "10|~0==10;" );
2672+
2673+ CompareEqualityOperation *root = dynamic_cast <CompareEqualityOperation*> ( _root );
2674+
2675+ assert( root != nullptr );
2676+
2677+ BitwiseOrOperation *left_root = dynamic_cast <BitwiseOrOperation*> ( root->left );
2678+
2679+ assert( left_root != nullptr );
2680+
2681+ NumberString *first = dynamic_cast <NumberString*> ( left_root->left );
2682+
2683+ assert( first != nullptr );
2684+ assert( first->numeric_string == "10" );
2685+
2686+ first->Delete();
2687+
2688+ BitwiseNegationOperation *right_left_root = dynamic_cast <BitwiseNegationOperation*> ( left_root->right );
2689+
2690+ assert( right_left_root != nullptr );
2691+
2692+ NumberString *second = dynamic_cast <NumberString*> ( right_left_root->op );
2693+
2694+ assert( second != nullptr );
2695+ assert( second->numeric_string == "0" );
2696+
2697+ second->Delete();
2698+
2699+ right_left_root->Delete();
2700+ left_root->Delete();
2701+
2702+ NumberString *third = dynamic_cast <NumberString*> ( root->right );
2703+
2704+ assert( third != nullptr );
2705+ assert( third->numeric_string == "10" );
2706+
2707+ third->Delete();
2708+
2709+ root->Delete();
2710+ }
2711+
2712+ // 22)
2713+ {
2714+ COSNode *_root = lexer.StartProduction( "32==1&&false;" );
2715+
2716+ LogicalAndOperation *root = dynamic_cast <LogicalAndOperation*> ( _root );
2717+
2718+ assert( root != nullptr );
2719+
2720+ CompareEqualityOperation *left_root = dynamic_cast <CompareEqualityOperation*> ( root->left );
2721+
2722+ assert( left_root != nullptr );
2723+
2724+ NumberString *first = dynamic_cast <NumberString*> ( left_root->left );
2725+
2726+ assert( first != nullptr );
2727+ assert( first->numeric_string == "32" );
2728+
2729+ first->Delete();
2730+
2731+ NumberString *second = dynamic_cast <NumberString*> ( left_root->right );
2732+
2733+ assert( second != nullptr );
2734+ assert( second->numeric_string == "1" );
2735+
2736+ second->Delete();
2737+
2738+ left_root->Delete();
2739+
2740+ SpecifierString *third = dynamic_cast <SpecifierString*> ( root->right );
2741+
2742+ assert( third != nullptr );
2743+ assert( third->string == "false" );
2744+
2745+ third->Delete();
2746+
2747+ root->Delete();
2748+ }
2749+
2750+ // 23)
2751+ {
2752+ COSNode *_root = lexer.StartProduction( "2|1||7|8;" );
2753+
2754+ LogicalOrOperation *root = dynamic_cast <LogicalOrOperation*> ( _root );
2755+
2756+ assert( root != nullptr );
2757+
2758+ BitwiseOrOperation *left_root = dynamic_cast <BitwiseOrOperation*> ( root->left );
2759+
2760+ assert( left_root != nullptr );
2761+
2762+ NumberString *first = dynamic_cast <NumberString*> ( left_root->left );
2763+
2764+ assert( first != nullptr );
2765+ assert( first->numeric_string == "2" );
2766+
2767+ first->Delete();
2768+
2769+ NumberString *second = dynamic_cast <NumberString*> ( left_root->right );
2770+
2771+ assert( second != nullptr );
2772+ assert( second->numeric_string == "1" );
2773+
2774+ second->Delete();
2775+
2776+ left_root->Delete();
2777+
2778+ BitwiseOrOperation *right_root = dynamic_cast <BitwiseOrOperation*> ( root->right );
2779+
2780+ assert( right_root != nullptr );
2781+
2782+ NumberString *third = dynamic_cast <NumberString*> ( right_root->left );
2783+
2784+ assert( third != nullptr );
2785+ assert( third->numeric_string == "7" );
2786+
2787+ third->Delete();
2788+
2789+ NumberString *fourth = dynamic_cast <NumberString*> ( right_root->right );
2790+
2791+ assert( fourth != nullptr );
2792+ assert( fourth->numeric_string == "8" );
2793+
2794+ fourth->Delete();
2795+
2796+ right_root->Delete();
2797+
2798+ root->Delete();
2799+ }
2800+
2801+ // 24)
2802+ {
2803+ COSNode *_root = lexer.StartProduction( "isdata==true||number==0&&domain>=0;" );
2804+
2805+ LogicalOrOperation *root = dynamic_cast <LogicalOrOperation*> ( _root );
2806+
2807+ assert( root != nullptr );
2808+
2809+ CompareEqualityOperation *left_root = dynamic_cast <CompareEqualityOperation*> ( root->left );
2810+
2811+ assert( left_root != nullptr );
2812+
2813+ SpecifierString *first = dynamic_cast <SpecifierString*> ( left_root->left );
2814+
2815+ assert( first != nullptr );
2816+ assert( first->string == "isdata" );
2817+
2818+ first->Delete();
2819+
2820+ SpecifierString *second = dynamic_cast <SpecifierString*> ( left_root->right );
2821+
2822+ assert( second != nullptr );
2823+ assert( second->string == "true" );
2824+
2825+ second->Delete();
2826+
2827+ LogicalAndOperation *right_root = dynamic_cast <LogicalAndOperation*> ( root->right );
2828+
2829+ assert( right_root != nullptr );
2830+
2831+ CompareEqualityOperation *left_right_root = dynamic_cast <CompareEqualityOperation*> ( right_root->left );
2832+
2833+ assert( left_right_root != nullptr );
2834+
2835+ SpecifierString *third = dynamic_cast <SpecifierString*> ( left_right_root->left );
2836+
2837+ assert( third != nullptr );
2838+ assert( third->string == "number" );
2839+
2840+ third->Delete();
2841+
2842+ NumberString *fourth = dynamic_cast <NumberString*> ( left_right_root->right );
2843+
2844+ assert( fourth != nullptr );
2845+ assert( fourth->numeric_string == "0" );
2846+
2847+ fourth->Delete();
2848+
2849+ left_right_root->Delete();
2850+
2851+ CompareGreaterThanEqualOperation *right_right_root = dynamic_cast <CompareGreaterThanEqualOperation*> ( right_root->right );
2852+
2853+ assert( right_right_root != nullptr );
2854+
2855+ SpecifierString *fifth = dynamic_cast <SpecifierString*> ( right_right_root->left );
2856+
2857+ assert( fifth != nullptr );
2858+ assert( fifth->string == "domain" );
2859+
2860+ fifth->Delete();
2861+
2862+ NumberString *sixth = dynamic_cast <NumberString*> ( right_right_root->right );
2863+
2864+ assert( sixth != nullptr );
2865+ assert( sixth->numeric_string == "0" );
2866+
2867+ sixth->Delete();
2868+
2869+ right_right_root->Delete();
2870+ right_root->Delete();
2871+
2872+ root->Delete();
2873+ }
2874+
2875+ // 25)
2876+ {
2877+ COSNode *_root = lexer.StartProduction( "table.field.subfield=value;" );
2878+
2879+ AssignmentOperation *root = dynamic_cast <AssignmentOperation*> ( _root );
2880+
2881+ assert( root != nullptr );
2882+
2883+ DotOperation *left_root = dynamic_cast <DotOperation*> ( root->left );
2884+
2885+ assert( left_root != nullptr );
2886+
2887+ DotOperation *left_left_root = dynamic_cast <DotOperation*> ( left_root->left );
2888+
2889+ assert( left_left_root != nullptr );
2890+
2891+ SpecifierString *first = dynamic_cast <SpecifierString*> ( left_left_root->left );
2892+
2893+ assert( first != nullptr );
2894+ assert( first->string == "table" );
2895+
2896+ first->Delete();
2897+
2898+ SpecifierString *second = dynamic_cast <SpecifierString*> ( left_left_root->right );
2899+
2900+ assert( second != nullptr );
2901+ assert( second->string == "field" );
2902+
2903+ second->Delete();
2904+
2905+ left_left_root->Delete();
2906+
2907+ SpecifierString *third = dynamic_cast <SpecifierString*> ( left_root->right );
2908+
2909+ assert( third != nullptr );
2910+ assert( third->string == "subfield" );
2911+
2912+ third->Delete();
2913+
2914+ left_root->Delete();
2915+
2916+ SpecifierString *fourth = dynamic_cast <SpecifierString*> ( root->right );
2917+
2918+ assert( fourth != nullptr );
2919+ assert( fourth->string == "value" );
2920+
2921+ fourth->Delete();
2922+
2923+ root->Delete();
2924+ }
2925+
2926+ // 26)
2927+ {
2928+ COSNode *_root = lexer.StartProduction( "replace tvalue with 0;" );
2929+
2930+ ReplaceOperation *root = dynamic_cast <ReplaceOperation*> ( _root );
2931+
2932+ assert( root != nullptr );
2933+
2934+ SpecifierString *first = dynamic_cast <SpecifierString*> ( root->what );
2935+
2936+ assert( first != nullptr );
2937+ assert( first->string == "tvalue" );
2938+
2939+ first->Delete();
2940+
2941+ NumberString *second = dynamic_cast <NumberString*> ( root->with );
2942+
2943+ assert( second != nullptr );
2944+ assert( second->numeric_string == "0" );
2945+
2946+ second->Delete();
2947+
2948+ root->Delete();
2949+ }
2950+
2951+ // 27)
2952+ {
2953+ COSNode *_root = lexer.StartProduction( "value=*ptr+1;" );
2954+
2955+ AssignmentOperation *root = dynamic_cast <AssignmentOperation*> ( _root );
2956+
2957+ SpecifierString *left_root = dynamic_cast <SpecifierString*> ( root->left );
2958+
2959+ assert( left_root != nullptr );
2960+ assert( left_root->string == "value" );
2961+
2962+ left_root->Delete();
2963+
2964+ AddOperation *right_root = dynamic_cast <AddOperation*> ( root->right );
2965+
2966+ assert( right_root != nullptr );
2967+
2968+ PointerResolveOperation *left_right_root = dynamic_cast <PointerResolveOperation*> ( right_root->left );
2969+
2970+ assert( left_right_root != nullptr );
2971+
2972+ SpecifierString *sub_left_right_root = dynamic_cast <SpecifierString*> ( left_right_root->op );
2973+
2974+ assert( sub_left_right_root != nullptr );
2975+ assert( sub_left_right_root->string == "ptr" );
2976+
2977+ sub_left_right_root->Delete();
2978+ left_right_root->Delete();
2979+
2980+ NumberString *right_right_root = dynamic_cast <NumberString*> ( right_root->right );
2981+
2982+ assert( right_right_root != nullptr );
2983+ assert( right_right_root->numeric_string == "1" );
2984+
2985+ right_right_root->Delete();
2986+
2987+ right_root->Delete();
2988+ root->Delete();
2989+ }
2990+
2991+ // 28)
2992+ {
2993+ COSNode *_root = lexer.StartProduction( "delete object;" );
2994+
2995+ DeleteOperation *root = dynamic_cast <DeleteOperation*> ( _root );
2996+
2997+ assert( root != nullptr );
2998+
2999+ SpecifierString *sub_root = dynamic_cast <SpecifierString*> ( root->op );
3000+
3001+ assert( sub_root != nullptr );
3002+ assert( sub_root->string == "object" );
3003+
3004+ sub_root->Delete();
3005+ root->Delete();
3006+ }
3007+
3008+ // 29)
3009+ {
3010+ COSNode *_root = lexer.StartProduction( "mydata *obj = new mydata;" );
3011+
3012+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
3013+
3014+ assert( root != nullptr );
3015+
3016+ SpecifierString *type = dynamic_cast <SpecifierString*> ( root->type );
3017+
3018+ assert( type != nullptr );
3019+ assert( type->string == "mydata" );
3020+
3021+ type->Delete();
3022+
3023+ PointerTypeSpecifier *ptrspec = dynamic_cast <PointerTypeSpecifier*> ( root->name );
3024+
3025+ assert( ptrspec != nullptr );
3026+
3027+ SpecifierString *name = dynamic_cast <SpecifierString*> ( ptrspec->spec );
3028+
3029+ assert( name != nullptr );
3030+ assert( name->string == "obj" );
3031+
3032+ name->Delete();
3033+ ptrspec->Delete();
3034+
3035+ NewOperation *init = dynamic_cast <NewOperation*> ( root->initializer );
3036+
3037+ assert( init != nullptr );
3038+ assert( init->params.GetCount() == 0 );
3039+
3040+ SpecifierString *new_type = dynamic_cast <SpecifierString*> ( init->type );
3041+
3042+ assert( new_type != nullptr );
3043+ assert( new_type->string == "mydata" );
3044+
3045+ new_type->Delete();
3046+ init->Delete();
3047+
3048+ root->Delete();
3049+ }
3050+ }
3051+ printf( "ok.\n" );
3052+
3053+ printf( "testing COS control structures..." );
3054+ {
3055+ // TODO.
3056+ }
3057+ printf( "ok.\n" );
3058+
3059+ printf( "testing COS functions..." );
3060+ {
3061+ // TODO.
3062+ }
3063+ printf( "ok.\n" );
3064+
3065+ printf( "testing COS declarations..." );
3066+ {
3067+ // TODO.
3068+ }
3069+ printf( "ok.\n" );
3070+
3071+ printf( "testing COS type system..." );
3072+ {
3073+ // TODO.
3074+ }
3075+ printf( "ok.\n" );
18343076 }
\ No newline at end of file
--- testcompiler/src/lexingenv_tests.cpp (revision 55)
+++ testcompiler/src/lexingenv_tests.cpp (revision 56)
@@ -5608,7 +5608,7 @@
56085608
56095609 struct list_dispatcher
56105610 {
5611- inline Node* CreateNode( Node *n ) const
5611+ inline List* CreateNode( Node *n ) const
56125612 {
56135613 return new List( n );
56145614 }
Show on old repository browser