Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  dtob.l
Language: C/C++
Code:
/* Lex program for decimal to binary conversion */
  
%{ 
  /* Definition section */
  #include<stdio.h> 
  int num, r, b=0, p=1; 
%} 
  
DIGIT [0-9] 
/* Rule Section */
%% 
{DIGIT}+   { num=atoi(yytext); 
             while (num > 0) 
             { 
              r= num % 10; 
              b+= r*p; 
              p*= 2; 
              num/= 10; 
             } 
              printf("%d", b); 
            } 
.|n    ECHO; 
         
%% 
  
// driver code  
int main() 

    yylex(); 
    return 0; 
}       
          
Comments: