answersLogoWhite

0

Write a program to calculate follow in grammar in parsing?

Updated: 8/17/2019
User Avatar

Wiki User

11y ago

Best Answer

#include<iostream.h> #include<conio.h> #include<string.h> int out(char,int n,char []); static char p[10][20]; char c[10]; int k=0; char final[10][20]; void main() { clrscr(); int n,i,j,flag,u,t=4,d=0,l,v; char a[10],first[10][20]; cout<<"\nEnter the no of productions: "; cin>>n; for(i=0;i<n;i++) { cin>>p[i]; } for(j=0;j<n;j++) { k=0; u=0; if(p[j][3]>='A'&&p[j][3]<='Z') { for(i=3;i<strlen(p[j]);i++) { flag=0; k=0; k=out(p[j][i],n,a); for(int l=0;l<k;l++) { if(a[l]=='^') flag=1; else first[j][u++]=a[l]; } if(flag==1) { if(i!=strlen(p[j])-1) { if(p[j][t]>='A'&&p[j][t]<='Z') { t++; continue; } else { first[j][u++]=p[j][t]; break; } } else { first[j][u++]='^'; } } else { break; } } } else { first[j][0]=p[j][3]; first[j][1]='\0'; } } t=0; for(int e=0;e<n;e++) { int flag=1; for(int i=0;i<t;i++) { if(c[i]==p[e][0]) { flag=0; break; } else { flag=1; } } if(flag==1) { c[t]=p[e][0]; d=0; for(int f=0;f<n;f++) { if(p[e][0]==p[f][0]) { for(int o=0;o<strlen(first[f]);o++) { final[t][d++]=first[f][o]; } final[t][d]='\0'; } } t++; } } for(i=0;i<t;i++) cout<<"First of "<<c[i]<<"is : "<<final[i]<<"\n"; //Code to find follow cout<<"\n\nFOLLOW\n"; for(i=0;i<strlen(c);i++) { cout<<"\nFollow of "<<c[i]<<"is :"; if(i==0) cout<<'$'<<" "; for(j=0;j<n;j++) { for(k=3;k<strlen(p[j]);k++) { if(c[i]==p[j][k]) { if(k!=strlen(p[j])-1) { for(l=k+1;l<strlen(p[j]);l++) { flag=0; if(p[j][l]>='A'&&p[j][l]<='Z') { for(u=0;u<strlen(c);u++) { if(c[u]==p[j][l]) break; } for(v=0;v<strlen(c);v++) { if(final[u][v]=='^') flag=1; else cout<<final[u][v]<<" "; } if(flag==1) { if(l==strlen(p[j])-1) cout<<"Follow of "<<p[j][0]<<" "; else continue; } else { break; } } else { cout<<p[j][l]; break; } } } else { cout<<"Follow of "<<p[j][0]<<" "; } } } } } getch(); } int out(char c,int n,char a[]) { for(int i=0;i<n;i++) { if(p[i][0]==c) { if(p[i][3]>='A'&&p[i][3]<='Z') { out(p[i][3],n,a); } else a[k++]=p[i][3]; } } return k; }

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to calculate follow in grammar in parsing?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Grammar question Which of these is the most proper grammar Fred asked that I follow up with you Fred asked I follow up with you Fred asked me to follow up with you?

"Fred asked me to follow up with you"


Enlgish that follows the rules and standards found in grammar and composition books is called?

When you follow the rules and standards for proper grammar as outlined in composition and style books, you are said to be using proper English grammar.You are said to be using proper English grammar when you follow the composition and style rules.


What criteria does instructor follow when going over your paper?

Instructors look for correct facts, grammar, and spelling.


How do you write the grammar poem?

A poem without proper grammar would look ugly and inferior. No one will wish his or her poem to look ugly and inferior. Therefore it is better for a poem to follow grammatical rules. But skilled poets do break grammar rules without affecting the beauty of their poems.


What are the merits of arithmetic mean?

it is easy to follow and easy to calculate


In writing or speaking we follow agreed-upon rules called for spelling punctuation grammar capitalization and paraphrasing.?

Conventions


How you calculate deflection of a dial gauge of least count 01mm?

follow


What is syntax in computing?

If in the market research context, Syntax is normally the set of commands written while using database softwares like SPSS, Quantum Etc to generate tables In computer science, especially in the subfield of programming languages, the syntax of a computer language is the set of allowed reserved words and possible token order in a program. The syntax of a programming language is the set of rules that a sequence of characters in a source code file must follow to be considered a conforming program in that language. The rules specify how the character sequences are to be chunked into tokens (the lexical grammar), the permissible sequences of these tokens and some of the meaning to be attributed to these permissible token sequences (additional meaning is assigned by the semantics of the language). The syntactic analysis of source code usually entails the transformation of the linear sequence of tokens into a hierarchical syntax tree (abstract syntax trees are one convenient form of syntax tree). This process is called parsing, as it is in syntactic analysis in linguistics. Tools have been written that automatically generate parsers from a specification of a language grammar written in Backus-Naur form, e.g., Yacc (yet another compiler compiler). The syntax of computer languages is often at level-2 (ie, a context-free grammar) in the Chomsky hierarchy. As such the possible ordering of tokens is usually very restricted. The analysis of a program's syntax is usually performed using an automatically generated program known as a parser which often builds an abstract syntax tree.


Do poems always have to contain formal grammar?

No, poems do not always have to follow formal grammar rules. Poetry often plays with language, breaking grammar rules to create specific effects or convey emotions. Poets may use deliberate grammar &quot;mistakes&quot; for artistic purposes, such as to create a certain rhythm, to emphasize a particular word, or to evoke a specific mood.


Site the difference between finance and financial?

Finance is a noun. Financial is an adjective. Just remember that and follow the rules of English grammar.


In writing or speaking we follow agreed-upon rules called for spelling punctuation grammar capitalization and paraphrasing?

Conventions


What is the best weight management program to follow?

Yes, there are many safe programs available. As a former client of weight watchers, I highly recommend their program. It is safe and easy to follow if you are dedicated to losing weight.