Compiler( Sam)

Download Compiler( Sam)

Post on 10-Apr-2015

221 views

Category:

Documents

2 download

Embed Size (px)

TRANSCRIPT

<p>EX.NO: 1 DATE:</p> <p>IMPLEMENTAION OF LEXICAL ANALYSER-TOKEN SEPARATION</p> <p>AIM: To write a c program to implement the lexical analyzer performing token separation.</p> <p>ALGORITHM: INPUT : OUTPUT : Source program Identified tokens</p> <p>1. Create list of keywords, operators, and separators. 2. Split a given input into lexemes. 3. To check whether given input is a keyword comparing it with the list of keywords if so then set token for current input as keyword. 4. To check whether given input is a operator comparing it with the list of operator if so then set token for current input as operator. 5. To check whether given input is a separator comparing it with the list of separator if so then set token for current input as separator.</p> <p>6. To check whether given input is a alphabets if so then set token as identifier.</p> <p>TOKEN SEPARATION #include #include #include void main() { FILE *in,*out; char a[80],m[80]; char b[10][10]={"void","main","if","FILE","lnt","char"}; int t=0,h=0,p=0,y=0,ch=0,i; clrscr(); in=fopen("a.txt","r"); out=fopen("nn1.txt","w"); while(!feof(in)) { a[p]=getc(in); p++;} for(i=0;i'a'&amp;&amp;a[i]</p>