Write a program in Erlang to translate terms from CCS0 (deadlock, prefix and non-deterministic choice) to the corresponding Labelled Transition System (LTS).
As the choice was to provide the AST in tuples, the terms are represented as such:
- Prefix: {prefix, a, b};
- Non-deterministic choice: {choice, a, b};
- And the deadlock is represented by the atom zero.
The term a.(b.0 + c.0) can be represented by the AST {prefix, a, {choice, {prefix, b, zero}, {prefix, c, zero}}}, which corresponds to the LTS shown on image 1.
After compiling the lexer, parser, and src files, the functions available are:
getLTSfromCCS0/2, which receives the Pid and the string describing a CCS0 term, and returns the corresponding LTS;
translateAST/2, which receives the Pid and the AST describing CCS0, and returns the LTS;
translateCCS0/2, which receives the Pid and a string corresponding to the CCS0 term, and returns the AST.
Image 2 shows a test run example for the program using all three functions.
Programa em Erlang para traduzir termos do CCS0 (deadlock, prefixo e escolha não determinística) para o Labelled Transition System (LTS) correspondente.
-
- (valorização: 2,5 valores) Escreva um tradutor que tem como input a Abstract Syntax Tree (AST) do termo CCS0. Por exemplo, o termo a.0 + b.0 pode ser representado pela AST {choice {prefix 'a' zero} {prefix 'b' zero}}.
-
- (valorização: 1 valor) Use a função anterior para implementar um server Erlang que recebe a AST de um termo CCS0 e envia de volta ao cliente o LTS correspondente ao termo.
-
- (valorização: 0,5 valores) Escreva um parser que converte a string correspondente ao termo CCS0 na sua AST, e nesse caso envie a string ao server. Pode implementar o parser diretamente em Erlang ou utilizar um gerador de parsers (ex: https://www.erlang.org/doc/man/yecc.html).
Como a escolha foi representar a AST em tuplos, os termos são representados da seguinte maneira:
- Prefixo: {prefix, a, b};
- Escolha não-determinística: {choice, a, b};
- E o deadlock é representado pelo átomo zero.
O termo a.(b.0 + c.0) pode ser representado pela AST {prefix, a, {choice, {prefix, b, zero}, {prefix, c, zero}}}, que é correspondente ao LTS da imagem 1.
Depois de compilar o lexer, o parser e o src, estão disponíveis as seguintes funções:
getLTSfromCCS0/2, que recebe como argumento o Pid e a string correspondente ao termo CCS0, e retorna o LTS correspondente;
translateAST/2, que recebe o Pid e a AST correspondente ao termo CCS0, e retorna o LTS;
translateCCS0/2, que recebe o Pid e uma string correspondente ao termo CCS0, e retorna a AST.
Na imagem 2, há um exemplo de teste do funcionamento do código para traduzir o termo CCS0 para um LTS, AST para LTS e CCS0 para ATS.

