Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LEX
- Zadanie 1.(średnie)
- --------------------------------------------------------------------------
- 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.
- Należy usunąć wszystkie spacje na liście zakupów, a po nazwisku umieścić dokładnie jeden dwukropek i trzy spacje.
- Nazwisko zaczyna sie z wielkiej litery, nazwa towaru jest pisana z małej litery.
- Na przykład:
- Iksinski chleb ( - ) ; mleko ( 3.5); ser (8.24) ;
- Ygrekowska mydlo ( 5.0 ); powidlo(-) ;
- powinniśmy uzyskać:
- Iksinski: chleb(-);mleko(3.5);ser(8.24);
- Ygrekowska: mydlo(5.0);powidlo(-);
- Zadanie 2.(trudne)
- -----------------------------------------------------------------------------
- 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.
- Poprawne ciągi zawierają wyłącznie zera i jedynki oraz znak nowej linii (bez spacji i tabulacji).
- Na przykład dla wejścia:
- 010101
- 000111
- 00 11
- 01 01
- powinniśmy uzyskać:
- 010101 Error
- 000111 OK
- 00 11 Error
- OK
- 01 01 Error
- Zadanie 3.(łatwe)
- ------------------------------------------------------------------------
- Napisz w język Lex program, który zamieni każdy znak oprócz litery i nowej linii znakiem minusa -.
- Dla wejścia:
- J.M. Kowal
- 60-965 Poznan, Poland
- tel.: 0616653724
- e-mail: kowal@put.poznan.pl
- powinniśmy uzyskać:
- J-M--Kowal
- -------Poznan--Poland
- tel-------------
- e-mail--kowal-put-poznan-pl
- Zadanie 4. (łatwe)
- --------------------------------------------
- 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.
- Dla wejścia:
- 12345 abc ;
- 345 abc ;
- :-) :-( ;-)
- :-) :-(
- Powinnismy uzyskać:
- 12345 abc ;
- 345 abc ;
- :-) :-( ;-)
- :-) :-(
- Zadanie 4a. (średnie)
- --------------------------------------------
- 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":
- :-) 1
- :-| 0
- :-( -1
- Dla wejścia:
- :-) :-) :-| ;
- :-( :-) ;
- :-) :-( :-| ;
- :-) :-) ;
- Powinniśmy uzyskać:
- :-) :-) :-| * :-)
- :-( :-) * :-|
- :-) :-( :-| * :-|
- :-) :-) * :-)
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement