DAG Program For Compiler Lab
DAG Program For Compiler Lab
JP COLLEGE OF ENGINEERING
sendhil28@gmail.com
CS6612-Compiler Laboratory
JP COLLEGE OF ENGINEERING
getch();
}
char* type(char x[],int m)
{
int i;
char mes[20];
for(i=0;i<m;i++)
{
if(isalpha(x[i]))
{
strcpy(mes,"AlphaNumeric");
goto X;
}
else if (x[i]=='.')
{
strcpy(mes,"float");
goto X;
}
}
strcpy(mes,"int");
X:
return mes;
}
sendhil28@gmail.com
CS6612-Compiler Laboratory
JP COLLEGE OF ENGINEERING
DAG Program:
#include <stdio.h>
#define N 8
typedef struct node node;
struct node
{
int count;
node *next;
};
node graph[N];
void buildGraph( int a[][2], int edges )
{
int i;
for( i=0; i<N; ++i ) {
graph[i].count = 0;
graph[i].next = NULL;
}
for( i=0; i<edges; ++i )
{
node *ptr = (node *)malloc( sizeof(node) );
ptr->count = a[i][1];
ptr->next = graph[ a[i][0] ].next;
graph[ a[i][0] ].next = ptr;
graph[ a[i][1] ].count++;
}
}
void printGraph()
{
int i;
node *ptr;
sendhil28@gmail.com
CS6612-Compiler Laboratory
JP COLLEGE OF ENGINEERING
sendhil28@gmail.com