Friday, October 29, 2010

SYMBOL BALANCING/ SYNTAX PARSING -APPLICATIONS OF STACK



In computer science and linguistics, parsing, or, more formally, syntactic analysis, is the process of analyzing a text, made of a sequence of tokens (for example, words), to determine its grammatical structure with respect to a given (more or less) formal grammar. Parsing can also be used as a linguistic term, especially in reference to how phrases are divided up in garden path sentences.

Parsing is also an earlier term for the diagramming of sentences of natural languages, and is still used for the diagramming of inflected languages, such as the Romance languages or Latin. The term parsing comes from Latin pars (ōrātiōnis), meaning part (of speech).

Parsing is a common term used in psycholinguistics when describing language comprehension. In this context, parsing refers to the way that human beings, rather than computers, analyze a sentence or phrase (in spoken language or text) "in terms of grammatical constituents, identifying the parts of speech, syntactic relations, etc." This term is especially common when discussing what linguistic cues help speakers to parse garden-path sentences.

----------------------------------------------------------------------------------------------

A C PROGRAM TO IMPLEMENT SYMBOL BALANCING-STACK APPLICATION

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :2 kb

EXE FILE SIZE :22 kb

NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE

---------------------------------------------------------------------------------------------

C PROGRAM SOURCE & EXE DOWNLOAD:

Click download button to download

DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.

----------------------------------------------------------------------------------------------

CODE:

#include
#include
#define VALID 1
#define INVALID 0
#define SIZE 30
char stack[SIZE];
int top=-1;
int check(char[]);
void push(char);
int pop();
int main()
{
char expr[30];
int status;
printf("\n BALANCING OF SYMBOLS-IMPLEMENTATION OF STACK");
printf("\n\n\n ENTER EXPRESSION:");
scanf("%s",expr);
status=check(expr);
printf("\n\n\n %s",(status)?" EXPRESSION IS VALID":"ERROR!!!! EXPRESSION IS INVALID");
printf("\n\n");
system("pause");
return 0;
}
int check(char expr[])
{
char open[]={'(','{','['};
char close[]={')','}',']'};
int i,j,len,item,nop=3;
len=strlen(expr);
for(i=0;i
{
for(j=0;j
{
if(expr[i]==open[j])
{
push(expr[i]);
}
if(expr[i]==close[j])
{
item=pop();
if(item==-1||item!=open[j])
return INVALID;
}
}
}
if(top!=-1)
return INVALID;
else
return VALID;
}
void push(char val)
{
if(top>=SIZE-1)
{
printf("\nERROR!!!! STACK IS FULL....");
exit(0);
}
stack[++top]=val;
}
int pop()
{
int val;
if(top<=-1)
return -1;
val=stack[top--];
return val;
}



----------------------------------------------------------------------------------------------

Your's friendly,
[MOHANRAM.G],
ADMIN...

0 comments:

Post a Comment