Re: yacc samples?

"Janaki. S" <>
15 May 1998 22:37:07 -0400

          From comp.compilers

Related articles
yacc samples? dgh2@Ra.MsState.Edu (Daniel G. Hyams) (1998-05-04)
Re: yacc samples? (Janaki. S) (1998-05-15)
| List of all articles for this month |

From: "Janaki. S" <>
Newsgroups: comp.compilers
Date: 15 May 1998 22:37:07 -0400
Organization: Compilers Central
References: 98-05-009
Keywords: yacc


First of all, i don't whether anybody else has already replied to
this. I might have missed the mail as our mail server was down for
sometime in between.

I don't know how much this will help you in your requirement. But
still thought may be this way if the point i am giving is wrong, i will be
corrected by someone who knows it better.

> Specifically, I need to
> 1) allow for an if/endif and if/else/endif construct.
> 2) allow lists in a declaration, i.e, instead of allowing
> only a declaration like
> double a;
> also allow
> double a,b,c,d;

The first part can be done with a rule of form :

if_statement : IF cond statement ENDIF
| IF cond statement ELSE statement ENDIF

where the capital lettered words like IF, ELSE and ENDIF stand for the
corresponding terminal symbol returned by lex as a token.

This won't be having any shift-reduce or reduce-reduce conflicts i
presume, as there is an end marker to the if statement in the form if

For the second one, you can give a rule of form :

decl_statement : type var_list ';'

var_list : variable
                  | var_list ',' variable


I hope this will serve your purpose.

> If anyone knows of some good yacc samples, I would really
> appreciate any pointers!

As such i don't know any site or any such source. It will be
useful for me also if anyone can give me a pointer.


Janaki S
Research Student
Indian Institute of Science
India - 560 012

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.