Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
//program to find first of all nonterminals for given grammer

#include<stdio.h>
char NT[10],s[10][10],T[10];
main(){

 int a,i,j,b;


 printf("Specify no.of terminals u enter:");
 scanf("%d",&a);

 for(i=0;i<a;i++)
 {
 printf("Enter terminal symbols:");
 scanf("%s",&T[i]);
 }

 printf("Enter no.of nonterminals u enter:");
 scanf("%d",&b);

 printf("Enter nonterminal symbols:");
 for(i=0;i<b;i++)
 scanf("%s",&NT[i]);

 for(i=0;i<b;i++)
 {
  printf("Enter production %d : ",i+1);
  for(j=0;s[i][j-1]!='#';j++)
   scanf("%s",&s[i][j]);
 }
 for(i=0;i<b;i++)
   rec(a,b,s,T,s[i][0]);
  }

rec(int a,int b,char s[][],char T[],char x)
{  int m,l;
  for(m=0;m<a;m++)
  {
   if(x==T[m])
   {
      printf("FIRST of %s : %s\n",x,T[m]);
   }
  }
   for(l=0;l<b;l++)
  {
      if(x==NT[l])
      rec(a,b,s,T,s[l][0]);
   }
}
Posted

rec(int a,int b,char s[][],char T[],char x) undefine return value and undeclare this function before call.
 
Share this answer
 
Put the return type of rec as void. And the parameters of the calling function and called function should be same.

Error:
calling function: rec(a,b,s,T,s[i][0]);
called function: rec(int a,int b,char s[][],char T[],char x)
Checkout the parameters were not same. And the return type was not mentioned before the function name.

You should use void if you don't want to return any values.
 
Share this answer
 
v2
Your definition for main and rec are both missing the return type. Change them to:
C++
void main()

void rec(int a,int b,char s[][],char T[],char x)

Note that strictly speaking, main should use int as its return type.

[edit]
Note that there is also quite a bit wrong with your logic, particularly your methods of reading input data.
[/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900