Coder Social home page Coder Social logo

lex-samples's Introduction

Lex Samples

This repository contains sample problems solved using lex/flex utility.

Prerequisites

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 :-

  1. 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.
  2. 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.
  3. yytext: a buffer that holds the input characters that actually match the pattern (i.e lexeme) or say a pointer to the matched string.
  4. yyleng: the length of the lexeme.
  5. yylval: contains the token value.
  6. yyval: a local variable.
  7. 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.
  8. yywrap(): it is called by lex when input is exhausted (or at EOF). default yywrap always return 1.
  9. yymore(): returns the next token.
  10. yyless(k): returns the first k characters in yytext.
  11. yyparse(): it parses (i.e builds the parse tree) of lexeme.

Problem Statements

  1. print "GOODBYE!" in place of "hello world" in a given string
  2. count number of spaces in a given string
  3. count number of words in a given string
  4. count the number of vowels and consonents in a given string
  5. count words that are less than 10 and greater than 5 in a given string
  6. count the frequency of the given word in a file
  7. find the length of the longest word in a given string
  8. find the length of a given string
  9. accept string starting with vowel
  10. accept a valid integer and float value
  11. find the number of valid 'printf' statements alongwith variables used in it

Facing a Issue

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.

Want to Contribute

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 ๐Ÿ˜Ž.

lex-samples's People

Contributors

ub1302 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.