/*
Lexical Analyzer for 'C' Language
Author: Yasar Shaikh
Lexical Analyzer: http://en.wikipedia.org/wiki/Lexical_analysis
*/
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define MAX 1000
int main()
{
//FILE pointer for getting input file i for general index,
//flag for var identification
FILE *fp;
int keyIndex,preIndex,varIndex,oprIndex,i,flag;
char keyStore[MAX][10],preStore[MAX][10],varStore[MAX][10];
char oprStore[MAX],fname[80],ch,temp[80];
char keyword[32][20]={
"auto","break","case","continue",
"char","const","default","do",
"double","else","enum","extern",
"float","for","goto","if",
"int","long","register","return",
"short","signed","sizeof","static",
"struct","switch","typedef","union",
"unsigned","void","volatile","while"
};
char preprocessor[2][20]={"include","define"};
printf("\nEnter file name:");
scanf("%s",fname);
//opening a file in Read mode n checking for its availabilty
fp=fopen(fname,"r");
if(NULL == fp)
{
printf("\nFile not found.");
return 0;
}
keyIndex=varIndex=preIndex=oprIndex=0;
//Do operation until EOF is reached.
while(!feof(fp))
{
ch=fgetc(fp);
if(!isalnum(ch))
oprStore[oprIndex++]=ch;
else
{
//getting string
i=flag=0;
temp[i]=ch;
i++;
temp[i]=fgetc(fp);
while( isalnum(temp[i]) )
temp[++i]=fgetc(fp);
temp[i]='\0';
fseek(fp, SEEK_CUR-2 , SEEK_CUR);
//checking is it a keyword/var/preprocessor
for(i=0;i<32;i++)
{
//keyword checking n storing
if(strcmp(temp,keyword[i]) ==0)
{
strcpy(keyStore[keyIndex++],temp);
flag=1;
break;
}
//preprocessor checking n storing
else if(strcmp(temp,preprocessor[i])==0)
{
strcpy(preStore[preIndex++],temp);
flag=1;
break;
}
}
//checking for variables
if(!flag)
{
strcpy(varStore[varIndex++],temp);
strcpy(temp,"");
}
}
}
printf("\n******* OUTPUT *******");
printf("\n\nPreprocessor's List");
for(i=0;i<preIndex;i++)
printf("\n%s",preStore[i]);
printf("\n\nKeyword List");
for(i=0;i<keyIndex;i++)
printf("\n%s",keyStore[i]);
printf("\n\nVariable List");
for(i=0;i<varIndex;i++)
printf("\n%s",varStore[i]);
printf("\n\nOperators List");
for(i=0;i<oprIndex;i++)
printf("\n%c",oprStore[i]);
return 0;
}
/*
PS; You can even seperate standard header files,
predefined identifiers.
The above program mainly focus on important tokens.
*/
WHAT'S NEW?
Loading...
Showing posts with label program. Show all posts
Showing posts with label program. Show all posts
/*
Title : Program for demonstrating Layouts in Java
Author: Yasar Shaikh
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class LayoutDemo extends Frame implements ActionListener
{
Button b1,b2,b3,b4,b5,b6;
Button l1,l2,l3;
CheckboxGroup cbg;
Checkbox c1,c3,c2;
Panel p1,p2,main;
LayoutDemo l;
public LayoutDemo()
{
p1=new Panel();
p2=new Panel();
main=new Panel();
l=this;
p1.setLayout(new FlowLayout());
p2.setLayout(new GridLayout());
cbg=new CheckboxGroup();
c1=new Checkbox("Left",cbg,false);
c2=new Checkbox("Center",cbg,false);
c3=new Checkbox("Right",cbg,false);
l1=new Button("Flow");
l2=new Button("Grid");
l3=new Button("Border");
b1=new Button("Button 1");
b2=new Button("Button 2");
b3=new Button("Button 3");
b4=new Button("Button 4");
b5=new Button("Button 5");
b6=new Button("Button 6");
p1.add(b1); p1.add(b2);
p1.add(b3); p1.add(b4);
p1.add(b5); p1.add(b6);
p1.add(c1);p1.add(c2);p1.add(c3);
p2.add(l1);p2.add(l2);p2.add(l3);
l1.addActionListener(this);
l2.addActionListener(this);
l3.addActionListener(this);
main.setLayout(new BorderLayout());
main.add(p1,BorderLayout.NORTH);
main.add(p2,BorderLayout.SOUTH);
add(main);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==l2)
{
l.setSize(700,700);
repaint();
p1.setLayout(new GridLayout(3,3));
}
else if(ae.getSource()==l3)
{
l.setSize(800,800);
repaint();
main.add(p1,BorderLayout.WEST);
}
else
{
l.setSize(600,600);
repaint();
p1.setLayout(new FlowLayout());
}
}
public static void main(String ar[])
{
LayoutDemo l=new LayoutDemo();
l.setSize(600,600);
l.setVisible(true);
}
}
/*
PS: Save the above program with the name LayoutDemo.java (case-sensitive)
and then compile it with "javac LayoutDemo.java" command and execute
it with "java LayoutDemo" command in command prompt/terminal.
*/
/*
* Animation of Ballon Shooting
* Compiled on Turbo C++
* Written By: Yasar Shaikh
*/
* Animation of Ballon Shooting
* Compiled on Turbo C++
* Written By: Yasar Shaikh
*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void bg()
{
int xcord;
cleardevice();
setcolor(WHITE);
xcord=getmaxx()/2;
settextstyle(0, HORIZ_DIR,1);
outtextxy(xcord,10,"Created By:Yasar Shaikh");
outtextxy(xcord,20,"From: WIT,Solapur");
outtextxy(xcord,30,"Roll No.SE IT 55");
//First row of ballons
setfillstyle(SOLID_FILL,RED);
fillellipse(200,200,20,20);
setfillstyle(SOLID_FILL,YELLOW);
fillellipse(240,200,20,20);
setfillstyle(SOLID_FILL,GREEN);
fillellipse(280,200,20,20);
setfillstyle(SOLID_FILL,LIGHTGRAY);
fillellipse(320,200,20,20);
setfillstyle(SOLID_FILL,CYAN);
fillellipse(360,200,20,20);
//second row of ballon
setfillstyle(SOLID_FILL,MAGENTA);
fillellipse(220,240,20,20);
setfillstyle(SOLID_FILL,BLUE);
fillellipse(260,240,20,20);
setfillstyle(SOLID_FILL,LIGHTGREEN);
fillellipse(300,240,20,20);
setfillstyle(SOLID_FILL,LIGHTBLUE);
fillellipse(340,240,20,20);
//Third row of ballons
setfillstyle(SOLID_FILL,BROWN);
fillellipse(230,280,20,20);
setfillstyle(SOLID_FILL,LIGHTRED);
fillellipse(270,280,20,20);
setfillstyle(SOLID_FILL,LIGHTMAGENTA);
fillellipse(310,280,20,20);
}
void gun()
{
int a[8]={270,450,270,370,290,370,290,450};
setfillstyle(SOLID_FILL,BROWN);
fillpoly(4,a);
}
void main()
{
int gd=DETECT,gm,i;
initgraph(&gd,&gm,"d:\cpp");
bg();
gun();
setcolor(RED);
outtextxy(100,100,"Press Any Key to Start...");
getche();
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 5);
for(i=0;i<210;i+=2)
{
bg();
gun();
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 5);
setcolor(rand(i));
outtextxy(280,370-i,".");
outtextxy(280,370-i-2," ");
delay(100);
}
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillellipse(280,200,20,20);
setcolor(RED);
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 10);
outtextxy(100,200,"Bang...!!!");
getche();
getche();
closegraph();
}