Lp Lab Manual

August 7, 2017 | Author: computerstudent | Category: Parsing, C (Programming Language), Array Data Structure, Software Engineering, Notation
Share Embed Donate


Short Description

Download Lp Lab Manual...

Description

NARAYANA ENGINEERING COLLEGE::NELLORE CSE DEPARTMENT III-B.TECH II-SEM

LANGUAGE PROCESSORS LAB

NARAYANA ENGINEERING COLLEGE::NELLORE DEPARTMENT : CSE

LANGUAGE PROCESSORS LAB III-B.TECH II-SEM (2007-08) 1. Develop a lexical analyzer to recognize a few patterns in PASCL, C and FORTRAN (EX: identifiers, Constants, comments, operators, etc) 2. Write a program to parse using brute force technique of top down parsing 3. Develop on LL(1) parser (construct parse table also). 4. Develop an operator precedence parsed (construct parse table also) 5. Develop a recursive descent parser 6. Write a program for generating for various intermediate code forms i) Three address code

ii) Polish notation

7. Write a program to simulate heap storage allocation strategy 8. Generate Lexical analyzer using LEX. 9.Generate YACC specification for a few syntactic categories. 10.Given any intermediate code form implement code optimization techniques.

PROGRAM ---1

/ ************************************************************** ********

C-program to implement Lexical Analyzer to recognize keywords, Data types, identifiers, numbers, parenthesis, symbols, and operators.... ************************************************************** ********/

Algorithm: 1.start. 2.Intialize the symbol table with keywords. 3.Read token by token from the input string. 4.Using finite automation check for keywords, identifiers, constants & then Operators successively. 5.If nothing matches print an error message. 6.Until all tokens are over, repeat above three steps. 7.Print token information. 8.Stop.

Aim:- C-program to implement Lexical Analyzer to recognize keywords, Data types, identifiers, numbers, parenthesis, symbols, and operators....

#include #include #include #include #include void main() { char ipstr[300],temp,tmp[15],fname[50]; char parn[6]={'(',')','{','}','[',']'}; char symb[10]={'.',',',':',';','','?','$','#'}; char ops[6]={'+','-','=','/','*','^'}; char keywd[8][10]={"main","if","else","switch","void","do","while","for"}; char daty[6][10]={"int","char","float","double","string","longint"}; int pos=0,i,j,k,flagi,ip; FILE *fid; clrscr(); /* Input is taken from fname file*/ printf("enter filename which is to be parsed\n"); scanf("%s",fname); fid=fopen(fname,"r"); while((ip=getc(fid))!=EOF) ipstr[pos++]=ip; ipstr[pos]='\0'; printf("%s",ipstr); printf("\t\tlexicanalysis\n________________________________________\n"); for(i=0;ipstr[i]!='\0';i++) { if((ipstr[i]!=' ')&&(ipstr[i]!='\0')&&(ipstr[i]!='@')&&(ipstr[i]!='\n')) { temp=ipstr[i]; /* Check for parenthesis*/ for(j=0;j
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF