Repository for hometasks of the cource "Formal Languages"
Ninth hometask of the cource "Formal Languages"
Firstly, you must build this project:
# ./build
Now you can:
-
Check if some text is correct program on this query language:
-
# ./correct_prog
-
Enter you program. When you finish, press
Ctrl-D
. -
If
echo $?
prints0
, your program is correct.You also can check code in file through typing file name after
./correct_prog
.You also can check that some text isn't program through using
./incorrect_prog
instead.
-
-
Execute program:
# ./interpret.py
You also can check code in file through typing file name after
./interpret.py
.
Building docker-container:
# docker build -t task9 .
Running docker-container:
# docker run -it --rm task9 <command from chapter above>
query_lang.g4
is grammar of this query language.
examples/
is directory with examples of correct and incorrect programs.
data_bases/
is directory with examples of databases.
tests/query_lang
is directory with tests of query language interpreter.
Eighth hometask of the cource "Formal Languages"
Firstly, you must build docker-container:
# docker build -t task8 .
Now you can:
-
Check if some text is correct program on this query language:
-
# docker run -it --rm task8 ./correct_prog
-
Enter you program. When you finish, press
Ctrl-D
. -
If
echo $?
prints0
, your program is correct.You also can check code in file through typing file name after
./correct_prog
.You also can check that some text isn't program through using
./incorrect_prog
instead.
-
-
Get parse tree:
# docker run -it --rm -e DISPLAY=unix$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix task8 ./draw_tree
You also can check code in file through typing file name after
./draw_tree
.If new window doesn't open, enter
xhost +si:localuser:root
and try again.
query_lang.g4
is grammar of this query language.
examples/
is directory with examples of correct and incorrect programs.
Seventh hometask of the cource "Formal Languages"
You can run parser of query language through this command:
# docker build -t task7 .
# docker run --rm -i task7 ./main.py -g query_lang.txt
Now you can be typing your program. If you want to finish it, press Ctrl-D
.
There is CFG of query language in query_lang.txt
file.
main.py
program is parser which can say if your input is program on the query language.
Program is a set of comma-separated command followed by dot.
Every command is followed by comma/dot without any separators. You can add spaces and new lines before the first command, between commands, after final dot and into every command between words if you want.
Command is an action with data base.
There are only two types of command:
- Connect:
connect to
{database name} - Select:
select
{select expression}from
{graph expression}
Database name is just string.
Select expression is thing which you want to get from Select command.
There are only two types of select expression:
edges
count of edges
Graph expression is a graph.
There are three types of graph expression:
- Graph from database:
graph
{graph name} - Regular query:
query
{pattern} - Result of intersection: {graph expression}
intersect with
{graph expression}
Graph name is just string.
Pattern is just a regular expression.
There are six types of pattern:
- Terminal: {string}
- Kleene star: {pattern}
*
- Kleene plus: {pattern}
+
- Option: {pattern}
?
- Alternative: {pattern}
|
{pattern} or {pattern}or
{pattern} - Concatenation: {pattern}
.
{pattern} or {pattern} {pattern}
Of course, priority of operations Alternative and Concatenation are usual. You can also use parenthesises or square brackets.
String is a set of chars, concluded in double quoters.
But now you can use only lowercase letters, underscore and numbers.
connect to "/data_bases/abc.db".
connect to "/data_bases/abc.db",
select edges from graph "123".
connect to
"/data_bases/abc.db",
select
count of edges
from
graph "123" intersect with
query "123" or "456" or "789" intersect with
query [("1"* | "2"?) (["3" . "4"] | "5"+)].
Fifth hometask of the cource "Formal Languages"
Fourth hometask of the cource "Formal Languages"
I have united in this task previous tasks and add CYK and CFPQ. I have also updated old tests from previous tasks, so they can testing into updated program.
usage: main.py [-h] [-c file] [--rq file] [--cfq file] [-d file]
optional arguments:
-h, --help show this help message and exit
-c file, --config file
json configuration file
--rq file, --regular-query file
file with query as regular expression
--cfq file, --context-free-query file
file with query as context free grammar
-d file, --data-base file
file with description of data base
It is json file with such possible fields:
data_base_lists
- list ofV_from
s,S
s andV_to
s listsdata_base_file
- name of file with data base in the same directory as this configuration fileregular_query_regex
- string of regular expressionregular_query_file
- name of file with regular expression in the same directory as this configuration filecontext_free_query_text
- string of productions{head} -> {body}
, joined by '\n'context_free_query_file
- name of file with lines of productions{head} {body}
input_vertexes
- list of vertexes, from which will be start all paths in resulting set. In other words, all pairs in the resulting set will have first element frominput_vertexes
listoutput_vertexes
- the same asinput_vertexes
but all paths will be finished in vertexes fromoutput_vertexes
list
data_base_lists
ordata_base_file
in configuration file or data base file as argumentregular_query_regex
,regular_query_file
,context_free_query_text
orcontext_free_query_text
in configuration file or query file as argument--rq
or--cfq
Second hometask of the cource "Formal Languages"
For building a docker container run:
docker build -t task2 .
You can run the container in interactive mode:
docker run --rm -it task2
Now you can run:
-
tests through
pytest
:# pytest main_test.py
-
main.py
with file of data base and file of query in regular expression and/or configuration file:# ./main.py -q <file_of_query> -d <file_of_data_base>
or
# ./main.py -c <configuration_file>
or even
# ./main.py -c <configuration_file> -q <file_of_query> -d <file_of_data_base>
It is program which takes information about data base and request in regular expression and print on the screen a set of pair of data base vertexes, between which a path, which is allowed by regular expression, exist.
It is text file which contains a set of triple {V_from} {S} {V_to}
which define an edge in
data base from V_from
vertex to V_to
vertex by symbol S
. For example
0 a 1
0 b 2
1 c 2
2 a 0
It is text file with single line of regular expression, format of which is the same as
regular expressions in pyformlang
library.
It is json file with such possible fields:
data_base_lists
- list ofV_from
s,S
s andV_to
s listsdata_base_file
- name of file with data base in the same directory as this configuration filequery_regex
- string of regular expressionquery_file
- name of file with regular expression in the same directory as this configuration fileinput_vertexes
- list of vertexes, from which will be start all paths in resulting set. In other words, all pairs in the resulting set will have first element frominput_vertexes
listoutput_vertexes
- the same asinput_vertexes
but all paths will be finished in vertexes fromoutput_vertexes
list
data_base_lists
ordata_base_file
in configuration file or data base file as argumentquery_regex
orquery_file
in configuration file or query file as argument
First hometask of the cource "Formal Languages"
For building a docker container run:
docker build -t task1 .
Now you can run the container in interactive mode:
docker run --rm -it task1 ipython