/*******************************************************************************
 ***  FUNCTION DECL()
 *******************************************************************************
 ***  DESCRIPTION  :  Processes DECL grammar rule.
 ***
 ***  DECL ->  TYPE IDLIST |
 ***           const idt = num ; DECL |
 ***           e
 ******************************************************************************/
void RecursiveParser::DECL(int & offset)
{
   EntryPtr ptr;
   VarType type;

   if (global->Token == Global::intt || global->Token == Global::floatt || global->Token == Global::chart)
   {
      TYPE(type);
      IDLIST(type, offset);
   }
   else if (global->Token == Global::constt)
   {
      match(Global::constt);

      checkduplicate(global->Lexeme, depth);
      symtab->insert(global->Lexeme, global->Token, depth);
      ptr = symtab->lookup(global->Lexeme);
      ptr->TypeOfEntry = constEntry;

      match(Global::idt);
      match(Global::assignopt);

      if (lex->isFloat)
      {
         ptr->constant.TypeOfConstant = floatType;
         ptr->constant.ValueR = global->ValueR;
      }
      else
      {
         ptr->constant.TypeOfConstant = intType;
         ptr->constant.Value = global->Value;
      }
      match(Global::numt);
      match(Global::semicolont);
      DECL(offset);
   }
   else
      return;
}
Beispiel #2
0
void FUNCTIONDEFINITION(void){
	/*functiondefinition = type ID ( idlist ) defstartsymbol statementlist defendsymbol*/
	switch (l){
	case KW_BOOLEAN: case KW_FLOAT: case KW_INT: case KW_VOID:						TYPE(); eat(ID); eat('('); IDLIST(); eat(')'); DEFSTARTSYMBOL(); STATEMENTLIST(); DEFENDSYMBOL(); return;
	default:																		StdError(__func__);
	}
}