Hello,
I am trying to make a compiler. Don't ask me why because I am making it for fun and experience. I have made a lexical analyser in c++ (I didn't use flex). I now want to make the parser for which I want to use Bison. But I am having problems.

1) how do you specify which function is the lex analyser (I saw the manual, made a yylex function and made it return the numeric value for each token (it is enumerated).

2) Can you please give me some kind of base code on which I can build upon, like putting new rules etc.

Hello,
I am trying to make a compiler. Don't ask me why because I am making it for fun and experience. I have made a lexical analyser in c++ (I didn't use flex). I now want to make the parser for which I want to use Bison. But I am having problems.

1) how do you specify which function is the lex analyser (I saw the manual, made a yylex function and made it return the numeric value for each token (it is enumerated).

2) Can you please give me some kind of base code on which I can build upon, like putting new rules etc.

if u want to use your yylex() in there add it as
extern int yylex(); in the .y file (.y for yacc).

U have to specify your grammer in the .y file.

What should the yylex return, an int value? Does it need to correspond to the %token 's that we declare?
Thanks

What should the yylex return, an int value? Does it need to correspond to the %token 's that we declare?
Thanks

yes.
yylex() returns the token value as integer.
The token gets stored in a char * called yytext. U have to access that variable to get the actual text token.

u will have to declare this variavle also as "extern char *yytext;" in the file where u want to use it.

Read about flex and yacc tool. Read more on developing parser.
I hope U have your grammer ready for building your parser.

hope that helps..............

how does the token get stored in yytext? I am not using flex, I have made my own lexical analyser, I have defined a function called yylex, that does the lexical analysing. I have my grammar ready, which is something like c++ (I am only, doing this for fun, so I don't mind it not being unique).

Thanks

how i can make compiler

google "compiler design"

how i can make compiler

With a computer. Click.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.