Exercise 5.(medium) ------------------------------------------------------------------------- An input file is a sequence of text lines. Write a LEX program which transforms the contents of an input file according to the following rules. If an input line contains exactly one number, possibly preceded and followed by spaces, check whether the number is divisible by 5. If so, write the line followed by a string "(+)" to the output file; if not, the output line should be followed by "(-)". Lines of any other form should be rewritten with no changes. Example: 15 12 20 12 15 20 a= 20 Output should be: 15 12 20 12 (-) 15(+) 20(+) a= 20 Note: the end of the second line in the input file is preceded by three spaces. Exercise 6. (difficult) ---------------------------------------------------------------------------- Use the LEX generator to create a program to convert a sequence of "Marseille-like" Prolog clauses to "Edinburgh-like" one. In the "Marseille-like" notation we use capital letters only. There are two kinds of clauses: assertion clauses and goal clauses. Let us assume that every clause is written in separate line. An assertion clause starts with '+' followed by the clause name and a parameter embraced in '[' and ']' (a parameter is a sequence of elements separated by a dot '.'; especially, a parameter may be an "empty" word; every parameter is either the 'NIL' atom or a name of the variable consisting of the asterisk '*' followed by name). After the brace ']' there is a sequence (maybe empty!) of calling-clauses (with parameters embraced in '(' and ')' ended by a dot '.'. The goal clause differs from the assertion clause in the beginning ('-') and ending signs ('!'). The following example illustrates the "Marseille-like" notation: +CLAUSE1[*FLAG.*X.*U]-CL1(*FLAG.*X.NIL)-CL1(NIL). -CLAUSE1[*X.NIL]-CL1(*C.*D)-CL1(NIL)! +CLAUSE2[]-CL2(). -CLAUSE2[]! In the "Edinburgh-like" notation we use small letters to denote names of clauses and capital letters to represent variables (which are not preceded by '*'). We skip the beginning signs of clauses (i.e.'+', '-'). The braces'[' and ']' in the clause head are replaced by parentheses '(' and ')', but the parameter itself is embraced in braces '[' and ']'. The dot '.' signs in a parameter are replaced by coma ','. The sequence of calling clauses in the clause body starts from ':-'. The other called clauses are separated by ','. The example "Edinburgh-like" clauses look like: clause1([FLAG,X,U]):-cl1([FLAG,X,[]]),cl1([[]]). clause1([X,[]]),cl1([C,D]),cl1([[]])! clause2([]):-cl2([]). clause2([])! Note: You musn't use global variables ! Exercise 7.(medium) -------------------------------------------------------------------------- Write a LEX program to check whether every line of an input text contains a string being the correct DOS file name (without an access paths). Correct names should be rewritten to the output with the "OK" annotation while incorrect ones should be omitted. For example, given an input: idf.exe ?subj 12345678.123 123456789.aaa _a12??.* *.* ala. ala.* **a *.*bc *.12 we should obtain: idf.exe OK ?subj OK 12345678.123 OK _a12??.* OK *.* OK ala. OK ala.* OK *.12 OK