dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Flex fail on call second program

  1. #1
    Join Date
    Aug 2019
    Posts
    3

    Flex fail on call second program

    Greetings to all and thanks advances for paying attention to my mail


    I have a mistake just baffling

    I run my first program and next gets output correct

    Number : 1
    .
    Number : 1
    .
    Number : 0
    -
    Stage : snapshot
    Build : 20190729201751


    So y run a second program but i get a incorrect result
    Name :1

    Should be Number : 1 like in first ran program


    The program entry is the same, they differ in that one is the test
    program (cunit) and the second is the productive program, in both cases
    the complete scanner is called from a shared library generated in cmake
    and the scanner is generated in C ++

    the first rule in flex file is

    Code:
    {DIGIT}{1,11} {
        std::cout << "Number : " <<
        yytext << std::endl; 
        yylval->build< int >(atoi(yytext));
        return token::NUMBER;
    }
    when run the second program no call this rule it call final rule

    Code:
    {NAME} {
        std::cout << "Name: " << yytext << std::endl;
        yylval->build< std::string >( yytext );
        return token::NAME;
    }
    my question is why this differ is the same input, the same class scanner
    only different program.


    first program https://github.com/azaeldevel/toolkit.git commit
    8b4845dda686321fbaf0d9e6a5abc04992dd6f24
    second program https://github.com/azaeldevel/apidb.git commit
    c887addfdc0a7fbad80df3571a8214c5e0bb8d34


    I appreciate any comments
    Last edited by 2kaud; August 2nd, 2019 at 03:17 AM. Reason: Added code tags

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,764

    Re: Flex fail on call second program

    Well I can see in the first rule the cout << "Number" and in the second cout << "Name" - which is what you're seeing displayed. So why do you expect to see Number displayed from the second?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.2.2)

  3. #3
    Join Date
    Aug 2019
    Posts
    3

    Re: Flex fail on call second program

    2kaud I expect the same result in both programs bacause I use the same Analyzer with the same input

  4. #4
    Join Date
    Aug 2019
    Posts
    3

    Re: Flex fail on call second program

    this is the flex file


    Code:
    {DIGIT}{1,11}  	{
                                            std::cout << "Number : " << yytext << std::endl; 
                                            yylval->build< int >( atoi(yytext) );
                                            return token::NUMBER;
                                    }
    
    "."        	{
                                                            std::cout << yytext << std::endl;
                                                            return token&#58;&#58;DOT;
                                                    }
    "-"        	{
                                                                    std::cout <<yytext << std::endl;
                                                                    return token&#58;&#58;DASH;
                                                            }
    
    "snapshot"  {std::cout << "Stage : " << yytext << std::endl;yylval->build< std::string >( yytext );return token::SNAPSHOT;}
    "alpha"		{std::cout << "Stage : " << yytext << std::endl;yylval->build< std::string >( yytext );return token::ALPHA;}
    "beta"     	{std::cout << "Stage : " << yytext << std::endl;yylval->build< std::string >( yytext );return token::BETA;}
    "rc"       	{std::cout << "Stage : " << yytext << std::endl;yylval->build< std::string >( yytext );return token::RC;}
    "release"  	{std::cout << "Stage : " << yytext << std::endl;yylval->build< std::string >( yytext );return token::RELEASE;}
    			
    {DIGIT}{12,16}        {
                                                                            std::cout << "Build : " << yytext << std::endl;
                                                                            yylval->build< unsigned long >( std::stoul(yytext) );
                                                                            return token::BUILD;                                                                        
                                                                    }
    
    {NAME}  	{std::cout << "Name: " << yytext << std::endl; yylval->build< std::string >( yytext ); return token::NAME;}
    
    
    {SPACE}+	;
    
    [\n\0]		{return token::END;}
    .          	            {
                                            ECHO;
                                    }
    <<EOF>>    	yyterminate() ;

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)