Ejemplo n.º 1
0
//---------------------------------------------------------------------
//subprogram_head->PROCEDURE ID subprogram_parameters SEMICOLON
//1.  Traverse the list of variable symbols to create list of parameters
//2.  Create a procedure symbol using the list of parameters created in step 1.
//3.  Insert the procedure symbol into the symbol table.
//4.  Create a new locality.
//5.  Insert the variable symbols into the symbol table.
//---------------------------------------------------------------------
SubprogramSymbol* subprogram_head(string id,List<VariableSymbol*>* VL)
{  Subprogram* PL=ParameterList(VL,ST.TVoid());
   ProcedureSymbol* P=new ProcedureSymbol(id,PL,ST.LexicalLevel());
   ST.Insert(P);
   ST.NewLocality();
   InsertVariables(VL);
   return P;
}
Ejemplo n.º 2
0
//---------------------------------------------------------------------
//subprogram_head->FUNCTION ID subprogram_parameters COLON standard_type SEMICOLON
//1.  Traverse the list of variable symbols to create list of parameters
//2.  Create a function symbol using the list of parameters created in step 1.
//3.  Insert the function symbol into the symbol table.
//4.  Create a new locality.
//5.  Insert the variable symbols into the symbol table.
//---------------------------------------------------------------------
SubprogramSymbol* subprogram_head(string id,List<VariableSymbol*>* VL,Typ* RT)
{  Subprogram* PL=ParameterList(VL,RT);
   FunctionSymbol* F=new FunctionSymbol(id,PL,ST.LexicalLevel());
   ST.Insert(F);
   ST.NewLocality();
   InsertVariables(VL);
   return F;
}
Ejemplo n.º 3
0
//---------------------------------------------------------------------
//---------------------------------------------------------------------
SubprogramSymbol* program_head(string id)
{  List<VariableSymbol*>* VL=new List<VariableSymbol*>;
   Subprogram* PL=ParameterList(VL,ST.TVoid());
   ProcedureSymbol* P=new ProcedureSymbol(id,PL,0);

   ST.Insert(P);
   ST.NewLocality();
   return P;
}
Ejemplo n.º 4
0
			void RunFileTest::TestLogic(void) {
				ASTNode* root;
				ParserAPI test;
				test.ParseFile(FILE_PATH);
				if (test.HasError()) {
					logger->Notice("Parsing errors for file " FILE_PATH);
					__list_parsing_errors(test);
					// Try another file
					logger->Notice("trying \"./sin_tun_test.sin\"");
					ParserAPI test0;
					test0.ParseFile("sin_run_test.sin");
					if (test0.HasError()) {
						logger->Notice("Parsing errors for file ./sin_run_test.sin");
						__list_parsing_errors(test0);
						ASSERT(!test0.HasError()); // certain failure here, to stop the test
					}
					else {
						logger->Notice("fallback sin_run_test.sin passed");
						root = test0.GetAST();
					}
				}
				else
					root = test.GetAST();
				ASSERT(root != 0x00);
				
				FileOutputStream _foutxml("RunTreeVisualisation.xml", FileOutputStream::Mode::Truncate());
				FileOutputStream _fouttxt("RunTreeVisualisation.txt", FileOutputStream::Mode::Truncate());
				FileOutputStream _ctrltxt("RunTreeCtrlVisualisation.txt", FileOutputStream::Mode::Truncate());
				FileOutputStream _metatxt("ShiftToMetaEvaluatorASTVisitor.txt", FileOutputStream::Mode::Truncate());

				BufferedOutputStream foutxml(_foutxml);
				BufferedOutputStream fouttxt(_fouttxt);
				BufferedOutputStream ctrltxt(_ctrltxt); 
				BufferedOutputStream metatxt(_metatxt); 
				

				ASTTreeCtrlVisitor						ctrlvis(ctrltxt);
				ASTTreeVisualisationVisitor				visitor(fouttxt);
				//ASTTreeVisualisationVisitor				metaVisualVisitor(metatxt);
				//ASTMITTreeVisualizerXMLProducerVisitor	mitvis(foutxml);
				//ASTCloneVisitor							cloneVisitor;
				//ASTUnparseTreeVisitor					uparseVisitor;
				//
				root->Accept(&visitor);
				root->Accept(&ctrlvis);
				//root->Accept(&mitvis);
				//root->Accept(&uparseVisitor);
				//root->Accept(&cloneVisitor);

				//String unpasedString1 = uparseVisitor.UnparsedString();
				//uparseVisitor.CleanUnparsedString();

				//cloneVisitor.Root()->Accept(&uparseVisitor);
				//String unpasedString2 = uparseVisitor.UnparsedString();
				//
				//SINASSERT(unpasedString1 == unpasedString2);

				//

				//static_cast<OutputStream&>(STDOUT) << "\n\n" << unpasedString2 << "\n\n\n";

				foutxml.flush();
				fouttxt.flush();
				ctrltxt.flush();


				//ASTNode & lastKid = static_cast<ASTNode &>(*root->rbegin());
				//cloneVisitor.Resset();
				//lastKid.Accept(&cloneVisitor);
				//uparseVisitor.CleanUnparsedString();
				//ASTNode * cloneRoot = cloneVisitor.Root();
				//cloneRoot->Accept(&uparseVisitor);
				//static_cast<OutputStream&>(STDOUT) << "\n\n" << uparseVisitor.UnparsedString() << "\n\n\n";
				//cloneVisitor.DeleteListAndAST();


				VM::VirtualState vs;
				vs.SetPrintHandler(&__print_handler);

				Library::Library lib;

				Library::Functions::print			print;
				Library::Functions::println			println;
				Library::Functions::arguments		arguments;
				Library::Functions::totalarguments	totalarguments;
				Library::Functions::tostring		tostring;
				Library::Functions::strtonum		strtonum;
				Library::Functions::typeof			typeof;
				Library::Functions::fileopen        fileopen;
				Library::Functions::fileread        fileread;
				
				lib.InstallFunction(&print			);
				lib.InstallFunction(&println		);
				lib.InstallFunction(&arguments		);
				lib.InstallFunction(&totalarguments	);
				lib.InstallFunction(&tostring		);
				lib.InstallFunction(&strtonum		);
				lib.InstallFunction(&typeof			);
				lib.InstallFunction(&fileopen       );
				lib.InstallFunction(&fileread       );

				// TODO remove the reference here and watch it burn 
				SymbolTable *globalSymTable = &vs.CurrentStable();
				globalSymTable->Insert("print",          SINEWCLASS(MemoryCellLibFunction, (&print)));
				globalSymTable->Insert("println",        SINEWCLASS(MemoryCellLibFunction, (&println)));
				globalSymTable->Insert("arguments",      SINEWCLASS(MemoryCellLibFunction, (&arguments)));
				globalSymTable->Insert("totalarguments", SINEWCLASS(MemoryCellLibFunction, (&totalarguments)));
				globalSymTable->Insert("tostring",       SINEWCLASS(MemoryCellLibFunction, (&tostring)));
				globalSymTable->Insert("strtonum",       SINEWCLASS(MemoryCellLibFunction, (&strtonum)));
				globalSymTable->Insert("typeof",         SINEWCLASS(MemoryCellLibFunction, (&typeof)));
				globalSymTable->Insert("fileopen",       SINEWCLASS(MemoryCellLibFunction, (&fileopen)));
				globalSymTable->Insert("fileread",       SINEWCLASS(MemoryCellLibFunction, (&fileread)));

				
				TreeEvaluationVisitor eval(&lib, &vs);
				
				try {
					root->Accept(&eval);
				} catch(SIN::RunTimeError rte) {
					static_cast<OutputStream&>(STDOUT) << rte.CompleteMessage() << "\n";
					exit(-1);
				} catch(...) {
					static_cast<OutputStream&>(STDOUT) << "Unexpected exception" << "\n";
					exit(-1);
				}
				//ShiftToMetaEvaluatorASTVisitor shifter(eval);
				//root->Accept(&shifter);
				//shifter.Root()->Accept(&metaVisualVisitor);
				
				

				metatxt.flush();
				test.DeleteListAndAST();
//				shifter.DeleteListAndAST();
			}
Ejemplo n.º 5
0
//---------------------------------------------------------------------
//Function InsertVariables inserts variables into the symbol table
//---------------------------------------------------------------------
static void InsertVariables(List<VariableSymbol*>* VL)
{   for (VL->First();!VL->IsEol();VL->Next()) {
        VariableSymbol* S=VL->Member();
        ST.Insert(S);
    }
}