From 8bbefe95d25fa2981add4df35bdd9903c91a8e62 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Sun, 8 Nov 2026 08:13:29 +0300 Subject: publish --- README.org | 226 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 README.org (limited to 'README.org') diff --git a/README.org b/README.org new file mode 100644 index 0000000..805813f --- /dev/null +++ b/README.org @@ -0,0 +1,226 @@ +#+title: Lexical analysis +#+date: 2025H1 + +* Task +:PROPERTIES: +:CUSTOM_ID: task +:END: +Write a program that performs lexical analysis of the input text in +accordance with the task and generates a table of tokens with +indicating their types and values. Prepare several versions of the +program in the form of text in the input language. The program should +output messages indicating the presence of errors in the input text +that may be detected during the lexical analysis stage. The length of +identifiers and string constants is limited to 16 characters, using +only Latin letters. The program must allow for comments of unlimited +length in the input file (the format of the comments is selected +independently). Construct syntax diagrams. + +The input language contains loop statements ~for (...; ...; ...) do~, +separated by the ~|~ symbol (vertical bar). Loop statements contain +identifiers, comparison operators ~<~, ~>~, ~=~, string constants (a +sequence of characters in double quotes), and an assignment operator. +(~:=~). + +*Comment type:* +- ~// ...~ (until the end of the line) +- ~/* ... */~ (works with multiple lines and/or within a line) + +* Documentation +:PROPERTIES: +:CUSTOM_ID: documentation +:END: +The exported report can be found at [[https://git.michalec.dev/files/uni/term-06/math-logic/lab-01/report.pdf][this link]]. + +* Showcase +:PROPERTIES: +:CUSTOM_ID: showcase +:END: +#+caption: The result of an incorrect program launch +#+begin_src +$ ./build/lex +Usage: ./build/lex file +#+end_src + +#+caption: The result when specifying a non‑existent file +#+begin_src +$ ./build/lex no/such/file +error: No such file or directory: no/such/file +#+end_src + +#+caption: The result of analyzing a lexically correct text +#+begin_src +$ ./build/lex res/01-correct-input.txt +Исходный текст: +for (i :=-.1230; + i < 10; + i := 10) +do x := 11 "asdf" "asdf" "asdf" +| // I don't know to work with those pipes... +for (x := 11; x = 1;) /* INLINE COMMENT */ "123456789ABCDE" /* +323asdf +MULTILINE COMMENT + x=2 */ +do x := 10 + +| *Лексема* | *Тип лексемы* | *Значение* | +|------------------+-----------------------------+------------| +| for | Ключевое слово | K[0] | +| ( | Знак левой скобки | | +| i | Идентификатор | I[0] | +| := | Знак присваивания | | +| -.1230 | Вещественная константа | -0.123 | +| ; | Знак точки с запятой | | +| i | Идентификатор | I[0] | +| < | Знак операции сравнения | C[1] | +| 10 | Целочиселная константа | 10 | +| ; | Знак точки с запятой | | +| i | Идентификатор | I[0] | +| := | Знак присваивания | | +| 10 | Целочиселная константа | 10 | +| ) | Знак правой скобки | | +| do | Ключевое слово | K[1] | +| x | Идентификатор | I[1] | +| := | Знак присваивания | | +| 11 | Целочиселная константа | 11 | +| "asdf" | Строковая константа | S[0] | +| "asdf" | Строковая константа | S[0] | +| "asdf" | Строковая константа | S[0] | +| | | Символ вертикальной полосы | | +| for | Ключевое слово | K[0] | +| ( | Знак левой скобки | | +| x | Идентификатор | I[1] | +| := | Знак присваивания | | +| 11 | Целочиселная константа | 11 | +| ; | Знак точки с запятой | | +| x | Идентификатор | I[1] | +| = | Знак операции сравнения | C[0] | +| 1 | Целочиселная константа | 1 | +| ; | Знак точки с запятой | | +| ) | Знак правой скобки | | +| "123456789ABCDE" | Строковая константа | S[1] | +| do | Ключевое слово | K[1] | +| x | Идентификатор | I[1] | +| := | Знак присваивания | | +| 10 | Целочиселная константа | 10 | + +| *№* | *K* | +|-----+-----| +| 0 | for | +| 1 | do | + +| *№* | *C* | +|-----+-----| +| 0 | = | +| 1 | < | +| 2 | > | + +| *№* | *S* | +|-----+----------------| +| 0 | asdf | +| 1 | 123456789ABCDE | + +| *№* | *I* | +|-----+------------------| +| 0 | i | +| 1 | x | +#+end_src + +#+caption: The result of analyzing a text with various errors +#+begin_src +$ ./build/lex res/02-incorrect-input.txt +Исходный текст: +dofor (i :=-.1230; + i != 10; + i := 10) +fordo x := 11ebc123 "asdfasdfasdfasdfasdfasdf" +| // I don't know to work with those pipes... +for (x := 11; x = 1;) /* INLINE COMMENT */ "123456789ABCDE" /* +323asdf +MULTILINE COMMENT + x=2 */ +do _abcdefghijklmnop_1 := 10 + +/* + +some more text + +| *Лексема* | *Тип лексемы* | *Значение* | +|------------------+-----------------------------+------------| +| dofor | Идентификатор | I[0] | +| ( | Знак левой скобки | | +| i | Идентификатор | I[1] | +| := | Знак присваивания | | +| -.1230 | Вещественная константа | -0.123 | +| ; | Знак точки с запятой | | +| i | Идентификатор | I[1] | +| = | Знак операции сравнения | C[0] | +| 10 | Целочиселная константа | 10 | +| ; | Знак точки с запятой | | +| i | Идентификатор | I[1] | +| := | Знак присваивания | | +| 10 | Целочиселная константа | 10 | +| ) | Знак правой скобки | | +| fordo | Идентификатор | I[2] | +| x | Идентификатор | I[3] | +| := | Знак присваивания | | +| | | Символ вертикальной полосы | | +| for | Ключевое слово | K[0] | +| ( | Знак левой скобки | | +| x | Идентификатор | I[3] | +| := | Знак присваивания | | +| 11 | Целочиселная константа | 11 | +| ; | Знак точки с запятой | | +| x | Идентификатор | I[3] | +| = | Знак операции сравнения | C[0] | +| 1 | Целочиселная константа | 1 | +| ; | Знак точки с запятой | | +| ) | Знак правой скобки | | +| "123456789ABCDE" | Строковая константа | S[0] | +| do | Ключевое слово | K[1] | +| := | Знак присваивания | | +| 10 | Целочиселная константа | 10 | + +| *№* | *K* | +|-----+-----| +| 0 | for | +| 1 | do | + +| *№* | *C* | +|-----+-----| +| 0 | = | +| 1 | < | +| 2 | > | + +| *№* | *S* | +|-----+----------------| +| 0 | 123456789ABCDE | + +| *№* | *I* | +|-----+------------------| +| 0 | dofor | +| 1 | i | +| 2 | fordo | +| 3 | x | +res/02-incorrect-input.txt:2:7: error: invalid lexeme `!' + 2 | i != 10; + | ^ +res/02-incorrect-input.txt:4:11: error: invalid number constant `11ebc123' + 4 | fordo x := 11ebc123 "asdfasdfasdfasdfasdfasdf" + | ^~~~~~~~ +res/02-incorrect-input.txt:4:20: error: string constant longer than 16 symbols (26) + 4 | fordo x := 11ebc123 "asdfasdfasdfasdfasdfasdf" + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ +res/02-incorrect-input.txt:10:3: error: identifier longer than 16 symbols (19) + 10 | do _abcdefghijklmnop_1 := 10 + | ^~~~~~~~~~~~~~~~~~~ +res/02-incorrect-input.txt:12:0: error: unterminated comment + 12 | /* + | ^~ +#+end_src + +* Unlicense +:PROPERTIES: +:CUSTOM_ID: unlicense +:END: +#+include: UNLICENSE verse -- cgit v1.3.1