This repository contains sample problems solved using lex/flex utility.
Lex
is a lexical analyser tool mostly used with Yacc
parse generator. It lexically analyses (i.e. matches) the patterns (regular expressions) given as input string or as a file.
Following are the Lex
predefined functions and variables :-
yyin
: the input stream pointer (i.e it points to an input file which is to be scanned or tokenised), however the default input of default main() is stdin.yylex()
: implies the main entry point for lex, reads the input stream generates tokens, returns zero at the end of input stream. It is called to invoke the lexer (or scanner) and each time yylex() is called, the scanner continues processing the input from where it last left off.yytext
: a buffer that holds the input characters that actually match the pattern (i.e lexeme) or say a pointer to the matched string.yyleng
: the length of the lexeme.yylval
: contains the token value.yyval
: a local variable.yyout
: the output stream pointer (i.e it points to a file where it has to keep the output), however the default output of default main() is stdout.yywrap()
: it is called by lex when input is exhausted (or at EOF). default yywrap always return 1.yymore()
: returns the next token.yyless(k)
: returns the first k characters in yytext.yyparse()
: it parses (i.e builds the parse tree) of lexeme.
- print "GOODBYE!" in place of "hello world" in a given string
- count number of spaces in a given string
- count number of words in a given string
- count the number of vowels and consonents in a given string
- count words that are less than 10 and greater than 5 in a given string
- count the frequency of the given word in a file
- find the length of the longest word in a given string
- find the length of a given string
- accept string starting with vowel
- accept a valid integer and float value
- find the number of valid 'printf' statements alongwith variables used in it
If you are in this situation first and foremost Don't panic 😢 I'm here to help you get over it. Simply click this and properly state your issue (be as verbose as you can be), After that sit tight and watch 🎥 the movie you have been postponing for so long while I 👷 fix the issue.
I will be glad 😃 to work with you on a new idea or fixing a invisible bug 🐛 or if you have already done the work 🔨 just create a pull request and I will merge it asap.
Well that's all for now but before you close this browser tab hit the star ⭐ button (it motivates me to make new stuff).
Have a great day 😎.