Lex program to check whether the input is digit or not Last Updated : 30 Apr, 2019 Improve Improve Like Article Like Save Share Report Lex is a computer program that generates lexical analyzers. Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lexer in the C programming language. Prerequisite: Flex (Fast lexical Analyzer Generator). Given an input, the task is to check if the input is digit or not. Examples: Input: 28 Output: digit Input: a Output: not a digit. Input: 21ab Output: not a digit. Below is the implementation: /* Lex program to check whether input is digit or not. */ %{ #include<stdio.h> #include<stdlib.h> %} /* Rule Section */ %% ^[0-9]* printf("digit"); ^[^0-9]|[0-9]*[a-zA-Z] printf("not a digit"); . ; %% int main() { // The function that starts the analysis yylex(); return 0; } Output: Like Article Suggest improvement Next Lex program to check whether input number is odd or even Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads Lex program to check whether input number is odd or even Lex program to check whether an year is a leap year or not Lex Program to check whether a number is Prime or Not Lex program to check whether given string is Palindrome or Not Lex program to check whether given number is armstrong number or not Lex program to check whether a given number is even or odd Lex program to check if a Date is valid or not Lex Program to print the total characters, white spaces, tabs in the given input file LEX Code that accepts string having even number's of 'a' over input alphabet {a,b} Lex Program to check valid email Like K kanugargng Follow Article Tags : Lex program Compiler Design