Posts

JDBC Connectivity using Eclipse

 import java.io.BufferedReader; import java.io.InputStreamReader; import java.sql.*;   public class mysqlconn { public static void main(String args[]){   try{   Class.forName("com.mysql.cj.jdbc.Driver");   Connection con=DriverManager.getConnection(   "jdbc:mysql://localhost:3306/demo","root","root");   Statement stmt=con.createStatement();   ResultSet rs=stmt.executeQuery("select * from emp");   while(rs.next())   System.out.println(rs.getInt(1)+"  "+rs.getString(2));  int i=17; String name1="smita"; int did=4; int credit =2000; InputStreamReader r1=new InputStreamReader(System.in);     BufferedReader br1=new BufferedReader(r1);             System.out.println("Enter your id");     try { name1=br1.readLine();  }catch(Exception E) {} i=Integer.parseInt(name1); InputStreamReader r=new InputStreamReader(System.in);     BufferedReader

Unit Test questions

Unit I 1)Explain Role of Lexical Analyzer in Compiler 2)  Explain use of yyleng, yytext, yylval, yywrap in yacc.. Unit II 1)Construct LR(0) item-set for following grammar. E E + E | E * E | id where + , * , id are terminals. 2) Explain left factoring with example. Unit III 1)Generate Quadruple for a = b + (c * d) / f 2) Explain  Intermediate code generation of declaration statement. Unit IV 1)Explain Parameter passing methods along with suitable example [8] b) Explain Function Call and Return with suitable example Unit V 1)Explain Simple Code Generator Algorithms along with suitable example. [8] 2) What is DAG? Explain the role of DAG in Code Generation Unit VI 1)What is loop transformations? What are its types 2)Explain Following Data Flow Properties Available Expressions, Reaching Definitions

Unit Wise Assignments

Unit Wise Assignments  Unit I 1)Explain  LEX features and specification. 2)Write regular expression for comment,operators,datatype,identifier ,keywords. Unit II 1) Expalin automatic construction of parsers using YACC. (Explain for calculator with lex and yacc specifications) 2) Explain Need of semantic analysis. Unit III 1)Explain with exampleThree-Address codes: Quadruples, Triples and Indirect Triples 2)Explain S and L attributed grammar Unit iv 1)Explain Activation Record, 2)Explain display mechanism Unit V 1)Explain Issues in code generation. 2)Explain Register allocation and Assignment, Unit VI 1) Explain common sub-expression elimination, variable propagation, code movement, strength reduction, dead code elimination. 2)Explain Data flow equations and iterative data flow analysis.

instruction scheduling with topological sorting of a DAG

// A C++ program to print topological sorting of a DAG #include<iostream> #include <list> #include <stack> using namespace std; // Class to represent a graph class Graph { int V; // No. of vertices' // Pointer to an array containing adjacency listsList list<int> *adj; // A function used by topologicalSort void topologicalSortUtil(int v, bool visited[], stack<int> &Stack); public: Graph(int V); // Constructor // function to add an edge to graph void addEdge(int v, int w); // prints a Topological Sort of the complete graph void topologicalSort(); }; Graph::Graph(int V) { this->V = V; adj = new list<int>[V]; } void Graph::addEdge(int v, int w) { adj[v].push_back(w); // Add w to vĂ¢€™s list. } // A recursive function used by topologicalSort void Graph::topologicalSortUtil(int v, bool visited[], stack<int> &Stack) { // Mark the current node as visited. visited[v] = true;

A Register Allocation algorithm that translates the given code into one with a fixed number of registers.

//C code for  A Register Allocation algorithm that translates the given code into one with a fixed number of registers. #include<stdlib.h> #include<stdio.h> /* We will implement DAG as Strictly Binary Tree where each node has zero or two children */ struct bin_tree { char data; int label; struct bin_tree *right, *left; }; typedef struct bin_tree node; /* R is stack for storing registers */ int R[10]; int top; /* op will be used for opcode name w.r.t. arithmetic operator e.g. ADD for + */ char *op; /* insertnode() and insert() functions are for adding nodes to tree(DAG) */void insertnode(node **tree,char val) { node *temp = NULL; if(!(*tree)) { temp = (node *)malloc(sizeof(node)); temp->left = temp->right = NULL; temp->data = val; temp->label=-1; *tree = temp; } } void insert(node **tree,char val) { char l,r; int numofchildren; insertnode(tree, val); printf("\nEnter number of children of %c:",val); scanf("%d&quo

Implementation of Code optimization

//c code for illustrating Code optimization #include<stdio.h> #include<stdlib.h> #include<string.h> #include<ctype.h> struct TAC { char res[5]; char op[2]; char arg1[5]; char arg2[5]; }quad[10]; struct ref { char * id; int label; struct node *ptr; }ref[10]; int cnt=0; int n; typedef struct node { struct node *left; struct node *right; char * val; char arg1[10]; char arg2[10]; char lable1; char label2; }node; struct node *nptr; struct node *ptr; void printtree(); node * mknode(node *left,node *right,char *val,char *arg1,char *arg2,char l1,char l2); int search(char*); void main() { int i,sres; printf("Enter how many TAC"); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter res"); scanf("%s",quad[i].res); printf("Enter op"); scanf("%s",quad[i].op); printf("Enter arg1"); scanf("%s",quad[i].arg1); printf("Enter arg2"

Implementation of Three address code generation

Contents of tac.l file  %{ #include "y.tab.h" #include <string.h> char * split(char* s,char* delimeter); %} relop >=|<=|>|<|==|!= number [0-9]+ %% [\n\t ]+ {;} "if" {return IF;} "while" {return WHILE;} "for" {return FOR;} "else" {return ELSE;} "int"|"string"|"char"|"double" { return TYPE;} [a-z]([a-z]|[0-9])* { yylval.tuple.result = strdup(yytext); return identifier; } [0-9]+  {yylval.tuple.num= atoi(yytext); return number;} {relop} { yylval.tuple.arg1 =strdup(yytext); return RELOP;}  [-+*=/;] {return yytext[0];} [(){}]               {return yytext[0];} %% int yywrap(void) { return 1; } Contents of tac.y file  %{     int yylex();     void yyerror(char* s);     #include <stdio.h>     #include <stdlib.h>     #include <string.h>     char* symbols[1000];     int symbolValues[1000];     int symbolCounter =