LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Implementing yacc/lex (https://www.linuxquestions.org/questions/programming-9/implementing-yacc-lex-490145/)

Millenniumman 10-06-2006 06:01 PM

Implementing yacc/lex
 
I have been working on making a parser for a file format. yacc/lex were what I was recommended to use. I have read several guides and I have a good beginning grasp of it. I have been able to make a program that does basic lexical analysis on strings and prints an analysis of command line input.

The problem I am having is that I cannot find a guide anywhere on how to implement the parser in a C++ program. I am planning a C++ class for the file format, such that a file object is initialized with a file path and it then uses the parser to gather information from the file and store it in objects.

How do I call the parser from another file, rather than compile it into an executable?

I am using the GNU tools.

taylor_venable 10-06-2006 10:44 PM

Quote:

Originally Posted by Millenniumman
How do I call the parser from another file, rather than compile it into an executable?

Any stuff you're using either has to be linked together at compile time (or more correctly, at link time; this is the easy way, with direct access) or has to talk to another process during runtime (this is harder, as it then has to deal with the protocol of its communication mechanism, and it's slower; I don't know of any compilers that work this way, with the lexer and parser separate processes). Trust me, you want your parser to be linked into the overall binary.

(That is, if I understand your question correctly. :))

Millenniumman 10-07-2006 10:49 AM

So, if I understand correctly, I just compile the y.tab.c and lex.yy.c together with my fileClass.cpp? In that case, does the yacc file need a main function?


All times are GMT -5. The time now is 03:23 PM.