Thursday, 2 April 2015

Write an application to parse input text file concurrently and compare the result of concurrent parsing with serial parsing ( Use concurrent YACC parser)

Write an application to parse input text file concurrently and compare the result of concurrent parsing with serial parsing ( Use concurrent YACC parser).

 

file1

 ((a+b)*c)

file2

((a+b)*c

file3

((a+b)*c)()

 lex.l

 %option reentrant
%option bison-bridge
%option noyywrap
%option bison-locations
%{
  #include "parser.h"

%}

%%


"(" { return (LPAREN); }
")" { return (RPAREN); }
\n {return(N);}
.|[ \t]+   { }
%%


main.c

 #include "parser.h"
#include "lexer.h"
//to read filenames for parsing
struct fname
{
  char fn[10];
};

//to store temp. result of scanner
 struct pwc {
   char op[20];
 };


int main(int argc, char **argv) {
  int result,n,i;
  struct fname file[10];
  struct pwc mypwc;
  yyscan_t scanner; 
  FILE *f;
  yylex_init(&scanner);
  printf("\n enter no. of files:");
  scanf("%d",&n);
  printf("\n enter file names:");
  for(i=0;i<n;i++)
  {
    scanf("%s",file[i].fn);
  }

  for(i=0;i<n;i++)
  {
    printf("fname=%s ",file[i].fn);
  }


pars.y

%define api.pure true
%locations
%token-table
%glr-parser
%lex-param {void *scanner}
%parse-param {void *scanner}

%{
/* your top code here */
#include<omp.h>
int t;
%}

%token LPAREN
%token RPAREN
%token N

%%

document  :
         | document exprs N {printf("\n successful parsing by thread ID=%d\n",omp_get_thread_num()); }
;
exprs
    :
    | expr exprs
;
expr
    : parens
;
parens
    : LPAREN exprs RPAREN
;

%%

int yyerror() {
    printf("\nparse error: thread ID=%d\n",omp_get_thread_num());

}


Execution Steps


[student@localhost conYacc]$ lex --header-file=lexer.h lex.l
[student@localhost conYacc]$ bison --defines=parser.h pars.y
[student@localhost conYacc]$ gcc -fopenmp main.c lex.yy.c pars.tab.c
[student@localhost conYacc]$ ./a.out

 enter no. of files:3

 enter file names:file1 file2 file3
fname=file1 fname=file2 fname=file3
 in parallel=0

 in parallel=1

parse error: thread ID=1

 successful parsing by thread ID=0

 in parallel=2

 successful parsing by thread ID=2













No comments:

Post a Comment