Lex Program to accept string starting with vowel
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.
The commands for executing the lex program are:
lex abc.l (abc is the file name) cc lex.yy.c -efl ./a.out
Let’s see lex program to accept string starting with vowel.
Examples:
Input: animal Output: Accepted Input: zebra Output: Not Accepted
Below is the implementation:
/* Lex Program to accept string starting with vowel */% { int flag = 0; % } %% [aeiouAEIOU].[a-zA-Z0-9.]+ flag=1; [a-zA-Z0-9]+ %% main() { yylex(); if (flag == 1) printf("Accepted"); else printf("Not Accepted"); } |
chevron_right
filter_none
Output:

Recommended Posts:
- Lex Program to accept a valid integer and float value
- YACC program which accept strings that starts and ends with 0 or 1
- C program to find the length of a string
- C Program to print all permutations of a given string
- Lex program to find the Length of a String
- Lex program to check whether given string is Palindrome or Not
- C program to check if a given string is Keyword or not
- YACC program to recognize string with grammar { anbn | n≥0 }
- YAAC program to check whether given string is Palindrome or not
- LEX program to count the number of vowels and consonants in a given string
- TCP Client-Server Program to Check if a Given String is Palindrome
- C Program for Program to find area of a circle
- Lex Program to remove comments from C program
- C Program for Program for array rotation
- C program to detect tokens in a C program
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



