you will use the lexical analyser generator lex or its variant flex, initially by itself, and…

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.

Order a Similar Paper HERE Order a Different Paper HERE

INTRODUCTION: Lex, Yacc and the CHAIN language
In this part of the Assignment, you will use the lexical analyser generator lex or its variant flex,
initially by itself, and then with the parser generator yacc.
Some useful references on Lex and Yacc:
• T. Niemann, Lex & Yacc Tutorial,
• Doug Brown, John Levine, and Tony Mason, lex and yacc (2nd edn.), O’Reilly, 2012.
• the lex and yacc manpages
We will illustrate the use of these programs with a language CHAIN based on certain expressions
involving strings. Then you will use lex and yacc on a language CRYPT of expressions based on
cryptographic operations.
The language CHAIN consists of expressions of the following type. An expression consists of a
number of terms, with # between each pair of consecutive terms, where each term is either a string
of lower-case letters or an application of the Reverse function to such a string. Examples of such
expressions include
mala # y # Reverse(mala)
block # drive # cut # pull # hook # sweep # Reverse(sweep)
Reverse(side) # Reverse(direction) # Reverse(gear)
For lexical analysis, we wish to treat every lower-case alphabetical string as a lexeme for the token
STRING, and the word Reverse as a lexeme for the token REVERSE.
An input file to lex is, by convention, given a name ending in .l. Such a file has three parts:
• definitions,
• rules,
• C code.
These are separated by double-percent, %%. Comments begin with /* and end with */. Any
comments are ignored when lex is run on the file.
You will find an input file, chain.l, among the files for this Assignment. Study its structure
now, identifying the three sections and noticing that various pieces of code have been commented
out. Those pieces of code are not needed yet, but some will be needed later.