lex/yacc with c++...... HELP!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deepusrp
    New Member
    • Jan 2007
    • 2

    lex/yacc with c++...... HELP!!!

    Helo everyone,

    i am doing a project on some graphic tool using qt as
    the front end. i am using lex and yacc as parser.
    now i am facing a problem since yacc generates only c
    code as i want to bring c++ features. so my request
    is " is there any way that we can create parser in qt
    itself or is there any method by which i can make a
    c++ (yacc) Parser... "

    please set me know how can i generate c++ parser using yacc

    please guide me its urgent...
    deepu
  • arvindkgs
    New Member
    • Oct 2008
    • 2

    #2
    Although Lex and YACC predate C++, it is possible to generate a C++ parser. While Flex includes an option to generate a C++ lexer, we won't be using that, as YACC doesn't know how to deal with it directly.
    It is possible to make the yacc generate a c++ file, but the lex outputs a c file. so in order for the yacc generated file to recoginize the c functions and variables,
    To do so, make a C header in YACC like this:

    extern "C"
    {
    int yyparse(void);
    int yylex(void);
    int yywrap()
    {
    return 1;
    }

    }
    if u want to declare or change yydebug then
    extern int yydebug;

    main()
    {
    yydebug=1;
    yyparse();
    }

    To compile, do something like this:

    lex bindconfig2.l
    yacc --verbose --debug -d bindconfig2.y -o bindconfig2.cc
    cc -c lex.yy.c -o lex.yy.o
    c++ lex.yy.o bindconfig2.cc -o bindconfig2

    Because of the -o statement, y.tab.h is now called bindconfig2.hh or
    bindconfig2.cc. h, so take that into account.

    Comment

    Working...