开发者

How to put a final summary message in a yacc program?

开发者 https://www.devze.com 2022-12-13 13:09 出处:网络
When I redirect input to my yacc p开发者_StackOverflowrogram from an input file, after it finishes parsing the file I want the yacc parser to print a summary of what it did.I want it to do the same th

When I redirect input to my yacc p开发者_StackOverflowrogram from an input file, after it finishes parsing the file I want the yacc parser to print a summary of what it did. I want it to do the same thing if I am entering input through the keyboard and then I press Ctrl+D. Is there a way to do that?


on the grammar you can call a function the function should be on the third part

FIRST PART

%%
second PART

GRAMMAR {  CALL YOUR FUNCTION();}
GRAMMAR2 VAR1 VAR2 VAR3 {CALL YOUR FUNCTION2($1,$2,$3);}

%%
third PART

YOUR FUNCTION(){}
YOUR FUNCTION2(int c, char*y , int z){}

 int main (void) {
}
    void yyerror (char *s) {fprintf (stderr, "%s\n", s);} 

your function can print any thing you want also the grammar becouse you now from where it call the function by the parameter you give


I found out that the solution to my problem is to create a function yywrap() in the .y file. That function will run when yacc encounters an EOF, which is either the end of an input file or the user pressing Ctrl-D. This is the solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消