//C style varaible actions for a Recursice Descent Parser CvarExample.c //written 3/10/08 by George Hamer /********************************************************************* Implements production rule DECL DECL -> TYPE IDLIST | empty_production **********************************************************************/ void DECL() { VarType TypVal; if(token==intt||token==floatt||token==chart){ TYPE(TypVal); //synthesizes the type IDLIST(TypVal); //now inherit the type } else return; //empty_production } /********************************************************************* Implements production rule TYPE TYPE -> int|float|char **********************************************************************/ void TYPE(VarTyp &TypVar) { TypVar=token; //Assume we have a correct type, if not we will //catch it with the following if statement! if(token==intt) Match(intt); else if(token==floatt) Match(floatt); else if(token==chart) Match(chart); else MatchError(14,token); //Expected: float, int, or char } /********************************************************************* Implements production rule IDLIST IDLIST -> idt IDTAIL;DECL **********************************************************************/ void IDLIST(VarTyp TypVal) { EntryPtr ptr; ptr=LookUp(lexeme); if(ptr && ptr->depth==depth){ cout<<"Error duplicate id- line"< , idt IDTAIL | empty_production **********************************************************************/ void IDTAIL(VarTyp TypVal) { EntryPtr ptr; if(token==commat){ Match(commat); ptr=LookUp(lexeme); if(ptr && ptr->depth==depth){ cout<<"Error duplicate id- line"<TypeOfEntry=varEntry; //because of the union ptr->var.TypeOfVariable = TypVal;; }