Advertisement
Guest User

JIFK

a guest
Nov 18th, 2017
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.14 KB | None | 0 0
  1. LEX
  2.  
  3.  
  4. Zadanie 1.(średnie)
  5. --------------------------------------------------------------------------
  6. Plik wejściowy zawiera ciąg wierszy, z których każdy składa się z: nazwiska osoby, niepustego ciągu spacji lub tabulacji i listy oddzielonych od siebie średnikiem ; nazw towarów, po których w nawiasie znajduje się ich cena (liczba rzeczywista), bądź znak -, jeśli cena nie jest znana. Spacje są swobodnie rozmieszczone na liście zakupów.
  7.  
  8. Należy usunąć wszystkie spacje na liście zakupów, a po nazwisku umieścić dokładnie jeden dwukropek i trzy spacje.
  9. Nazwisko zaczyna sie z wielkiej litery, nazwa towaru jest pisana z małej litery.
  10.  
  11. Na przykład:
  12. Iksinski chleb ( - ) ; mleko ( 3.5); ser (8.24) ;
  13. Ygrekowska mydlo ( 5.0 ); powidlo(-) ;
  14. powinniśmy uzyskać:
  15. Iksinski: chleb(-);mleko(3.5);ser(8.24);
  16. Ygrekowska: mydlo(5.0);powidlo(-);
  17.  
  18. Zadanie 2.(trudne)
  19. -----------------------------------------------------------------------------
  20. Napisz program w języku Lex służący do sprawdzenia, czy linia tekstu zawiera napis postaci 0n1n (0 do potęgi n i 1 do potęgi n),n >= 0. Jeśli tak, to należy dołączyć na końcu linii napis OK poprzedzony spacją, w przeciwnym wypadku - napis ERROR.
  21. Poprawne ciągi zawierają wyłącznie zera i jedynki oraz znak nowej linii (bez spacji i tabulacji).
  22. Na przykład dla wejścia:
  23. 010101
  24. 000111
  25. 00 11
  26.  
  27. 01 01
  28.  
  29. powinniśmy uzyskać:
  30.  
  31. 010101 Error
  32. 000111 OK
  33. 00 11 Error
  34. OK
  35. 01 01 Error
  36.  
  37.  
  38. Zadanie 3.(łatwe)
  39. ------------------------------------------------------------------------
  40. Napisz w język Lex program, który zamieni każdy znak oprócz litery i nowej linii znakiem minusa -.
  41.  
  42. Dla wejścia:
  43. J.M. Kowal
  44. 60-965 Poznan, Poland
  45. tel.: 0616653724
  46. e-mail: kowal@put.poznan.pl
  47.  
  48.  
  49. powinniśmy uzyskać:
  50. J-M--Kowal
  51. -------Poznan--Poland
  52. tel-------------
  53. e-mail--kowal-put-poznan-pl
  54.  
  55.  
  56. Zadanie 4. (łatwe)
  57. --------------------------------------------
  58. Napisz w języku Lex program, który wczyta wiersze wejściowe, usunie z nich początkowe spacje i w tej postaci przepisze je na wyjście.
  59.  
  60. Dla wejścia:
  61.  
  62. 12345 abc ;
  63. 345 abc ;
  64. :-) :-( ;-)
  65. :-) :-(
  66.  
  67. Powinnismy uzyskać:
  68. 12345 abc ;
  69. 345 abc ;
  70. :-) :-( ;-)
  71. :-) :-(
  72.  
  73.  
  74. Zadanie 4a. (średnie)
  75. --------------------------------------------
  76. Napisz w języku Lex program, który wczyta i przepisze wiersze wejściowe zawierające ciągi "faces" (oddzielonych od siebie dowolną liczbą spacji) zakończone średnikiem ;, a następnie ustali "średni humor" w każdej linii oraz zaznaczy go, po spacji, gwiazdce * i spacji, za pomocą symbolu "face". Należy przyjąć następujące "miary humoru":
  77. :-) 1
  78. :-| 0
  79. :-( -1
  80.  
  81. Dla wejścia:
  82.  
  83. :-) :-) :-| ;
  84. :-( :-) ;
  85. :-) :-( :-| ;
  86. :-) :-) ;
  87.  
  88. Powinniśmy uzyskać:
  89. :-) :-) :-| * :-)
  90. :-( :-) * :-|
  91. :-) :-( :-| * :-|
  92. :-) :-) * :-)
  93.  
  94.  
  95. Exercise 5.(medium)
  96. -------------------------------------------------------------------------
  97. An input file is a sequence of text lines. Write a LEX program which
  98. transforms the contents of an input file according to the following rules.
  99. If an input line contains exactly one number, possibly preceded and followed
  100. by spaces, check whether the number is divisible by 5. If so, write the
  101. line followed by a string "(+)" to the output file; if not, the output
  102. line should be followed by "(-)". Lines of any other form should be rewritten
  103. with no changes.
  104. Example:
  105. 15 12 20
  106. 12
  107. 15
  108. 20
  109. a= 20
  110.  
  111. Output should be:
  112. 15 12 20
  113. 12 (-)
  114. 15(+)
  115. 20(+)
  116. a= 20
  117.  
  118. Note: the end of the second line in the input file is preceded by
  119. three spaces.
  120.  
  121.  
  122. Exercise 6. (difficult)
  123. ----------------------------------------------------------------------------
  124. Use the LEX generator to create a program to convert a sequence of
  125. "Marseille-like" Prolog clauses to "Edinburgh-like" one.
  126. In the "Marseille-like" notation we use capital letters only. There are two
  127. kinds of clauses: assertion clauses and goal clauses. Let us assume that
  128. every clause is written in separate line. An assertion clause starts
  129. with '+' followed by the clause name and a parameter embraced in '[' and ']'
  130. (a parameter is a sequence of elements separated by a dot '.'; especially,
  131. a parameter may be an "empty" word; every parameter is either the 'NIL' atom
  132. or a name of the variable consisting of the asterisk '*' followed by name).
  133. After the brace ']' there is a sequence (maybe empty!) of calling-clauses
  134. (with parameters embraced in '(' and ')' ended by a dot '.'. The goal
  135. clause differs from the assertion clause in the beginning ('-') and
  136. ending signs ('!').
  137. The following example illustrates the "Marseille-like" notation:
  138.  
  139. +CLAUSE1[*FLAG.*X.*U]-CL1(*FLAG.*X.NIL)-CL1(NIL).
  140. -CLAUSE1[*X.NIL]-CL1(*C.*D)-CL1(NIL)!
  141. +CLAUSE2[]-CL2().
  142. -CLAUSE2[]!
  143. In the "Edinburgh-like" notation we use small letters to denote names of
  144. clauses and capital letters to represent variables (which are not preceded
  145. by '*'). We skip the beginning signs of clauses (i.e.'+', '-'). The braces'['
  146. and ']' in the clause head are replaced by parentheses '(' and ')', but the
  147. parameter itself is embraced in braces '[' and ']'. The dot '.' signs in a
  148. parameter are replaced by coma ','. The sequence of calling clauses in the
  149. clause body starts from ':-'. The other called clauses are separated by ','.
  150. The example "Edinburgh-like" clauses look like:
  151.  
  152. clause1([FLAG,X,U]):-cl1([FLAG,X,[]]),cl1([[]]).
  153. clause1([X,[]]),cl1([C,D]),cl1([[]])!
  154. clause2([]):-cl2([]).
  155. clause2([])!
  156. Note: You musn't use global variables !
  157.  
  158. Exercise 7.(medium)
  159. --------------------------------------------------------------------------
  160. Write a LEX program to check whether every line of an input text contains
  161. a string being the correct DOS file name (without an access paths).
  162. Correct names should be rewritten to the output with the "OK" annotation while
  163. incorrect ones should be omitted.
  164.  
  165. For example, given an input:
  166. idf.exe
  167. ?subj
  168. 12345678.123
  169. 123456789.aaa
  170. _a12??.*
  171. *.*
  172. ala.
  173. ala.*
  174. **a
  175. *.*bc
  176.  
  177. *.12
  178.  
  179. we should obtain:
  180. idf.exe OK
  181.  
  182. ?subj OK
  183.  
  184. 12345678.123 OK
  185.  
  186.  
  187. _a12??.* OK
  188.  
  189. *.* OK
  190.  
  191. ala. OK
  192.  
  193. ala.* OK
  194.  
  195.  
  196.  
  197.  
  198. *.12 OK
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement