Changeset 620

Show
Ignore:
Timestamp:
08/02/08 11:10:49 (4 months ago)
Author:
weyrick
Message:

try to plug the parser in. currently it appears to create and traverse a random parse tree

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/rphp/compiler/pDriver.cpp

    r616 r620  
    2525#include <unicode/ustream.h> 
    2626 
     27#include "parser/rphp_debug_visitor.h" 
    2728#include "parser/phplexer.h" 
    2829#include "parser/rphp_parser.h" 
     
    369370    } 
    370371 
     372    void pDriver::dumpAST(string fileName) { 
     373 
     374        ifstream inFile; 
     375 
     376        inFile.open(fileName.c_str(), ifstream::in); 
     377        if (!inFile) { 
     378            cout << "Unable to open file: " << endl; 
     379            exit(1); // terminate with error 
     380        } 
     381 
     382        UnicodeString contents; 
     383        char buf[512]; 
     384        while (inFile) { 
     385            inFile.getline(buf, 512); 
     386            //cout << "read: " << buf << endl; 
     387            contents += buf; 
     388        } 
     389 
     390        inFile.close(); 
     391 
     392        parser p; 
     393        p.set_token_stream( new parser::token_stream_type() ); 
     394        p.set_memory_pool( new parser::memory_pool_type() ); 
     395        p.setDebug( true ); 
     396 
     397        p.tokenize(contents); 
     398        start_ast* phpAst; 
     399        bool matched = p.parse_start(&phpAst); 
     400        if( matched ) 
     401        { 
     402            std::cout << "Successfully parsed" << std::endl; 
     403            debug_visitor dv; 
     404            dv.visit_start(phpAst); 
     405        }else 
     406        { 
     407            //*ast = 0; 
     408            //std::cout << p.expected_symbol(ast_node::Kind_start, "start"); 
     409            std::cout << "Couldn't parse content" << std::endl; 
     410        } 
     411 
     412    } 
     413 
     414 
    371415} 
    372416 
  • trunk/rphp/compiler/pDriver.h

    r614 r620  
    3030        public: 
    3131            void dumpTokens(std::string fileName); 
     32            void dumpAST(std::string fileName); 
    3233 
    3334    }; 
  • trunk/rphp/frontend/cli/main.cpp

    r618 r620  
    1919    desc.add_options() 
    2020        ("help", "produce help message") 
     21        ("dump-toks", "dump tokens from lexer") 
     22        ("dump-ast", "dump AST") 
    2123//        ("optimization", po::value<int>(&opt)->default_value(10), "optimization level") 
    2224        ("input-file", po::value< std::vector<std::string> >(), "input file") 
     
    3234 
    3335    if (vm.count("help") || !vm.count("input-file")) { 
     36        std::cout << "Roadsend PHP" << std::endl; 
    3437        std::cout << desc << "\n"; 
    3538        return 1; 
    3639    } 
    3740 
    38     //std::cout << "Roadsend PHP" << std::endl; 
    3941 
    40     std::vector<std::string> infiles = vm["input-file"].as< std::vector<std::string> >(); 
    41     for (std::vector<std::string>::iterator it = infiles.begin(); it!=infiles.end(); ++it) { 
    42         driver.dumpTokens(*it); 
     42    if (vm.count("dump-toks")) { 
     43        std::vector<std::string> infiles = vm["input-file"].as< std::vector<std::string> >(); 
     44        for (std::vector<std::string>::iterator it = infiles.begin(); it!=infiles.end(); ++it) { 
     45            driver.dumpTokens(*it); 
     46        } 
     47    } 
     48    else if (vm.count("dump-ast")) { 
     49        std::vector<std::string> infiles = vm["input-file"].as< std::vector<std::string> >(); 
     50        for (std::vector<std::string>::iterator it = infiles.begin(); it!=infiles.end(); ++it) { 
     51            driver.dumpAST(*it); 
     52        } 
     53    } 
     54    else { 
     55        std::cout << "Roadsend PHP" << std::endl; 
     56        std::cout << desc << "\n"; 
     57        return 1; 
    4358    } 
    4459 
    45     //std::cout << "Optimization level is " << opt << "\n"
     60    return 0
    4661 
    4762} 
  • trunk/rphp/runtime/pFunctionManager.cpp

    r619 r620  
    2424void pFunctionManager::registerBuiltin(const pExtBase* sourceExt, const pUString& funName, const pFunPointer1& f) { 
    2525 
    26     std::cout << "registering " << funName << std::endl; 
    2726    functionRegistry.insert(functionEntry(funName, new pFunctionSig(sourceExt, funName, f))); 
    2827 
  • trunk/rphp/runtime/standard/pStandardExt.cpp

    r618 r620  
    2424void pStandardExt::extensionStartup() { 
    2525 
    26     std::cout << "initializing standard extension" << std::endl; 
     26    //std::cout << "initializing standard extension" << std::endl; 
    2727 
    2828    registerBuiltin("strlen", boost::bind(&pStandardExt::strlen, this, _1)); 
     
    3232void pStandardExt::extensionShutdown() { 
    3333 
    34     std::cout << "deinitializing standard extension" << std::endl; 
     34    //std::cout << "deinitializing standard extension" << std::endl; 
    3535 
    3636}