From 541ec80f6d0aecc2e720b285358a3adf5c6641b2 Mon Sep 17 00:00:00 2001 From: XimenaCantera <95453390+XimenaCantera@users.noreply.github.com> Date: Mon, 29 Jan 2024 18:11:57 -0600 Subject: [PATCH 1/3] Create lexer.l Definir reglas en Lex --- labs/03/lexer.l | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 labs/03/lexer.l diff --git a/labs/03/lexer.l b/labs/03/lexer.l new file mode 100644 index 0000000..26a4eb7 --- /dev/null +++ b/labs/03/lexer.l @@ -0,0 +1,16 @@ +%{ +#include "y.tab.h" +%} + +%% +"the"|"a" {return ARTICLE; } +"boy"|"girl"|"flower" {return NOUN; } +"touches"|"likes"|"sees" {return VERB; } +"with" {return PREPOS; } +\n {return ENDLINE; } +[ \t] ; /*Sin espacios vacios*/ +%% + +int yywrap(void) { + return 1; +} From beaba17efd58c92d9c7ba26177208890d74d6343 Mon Sep 17 00:00:00 2001 From: XimenaCantera <95453390+XimenaCantera@users.noreply.github.com> Date: Mon, 29 Jan 2024 18:21:35 -0600 Subject: [PATCH 2/3] Yacc Rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Definición de reglas en Yacc --- labs/03/parser.y | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 labs/03/parser.y diff --git a/labs/03/parser.y b/labs/03/parser.y new file mode 100644 index 0000000..c6d8783 --- /dev/null +++ b/labs/03/parser.y @@ -0,0 +1,29 @@ +%{ +#include +%} + +%token ARTICLE NOUN VERB PREPOS ENDLINE + +%% +sentence : noun_phrase verb_phrase ENDLINE {printf("PASS\n");} + | noun_phrase verb_phrase prep_phrase ENDLINE {printf("PASS\n");} + ; + +noun_phrase : cmplx_noun { } + | cmplx_noun prep_phrase { } + ; + +verb_phrase : cmplx_verb { } + | cmplx_verb prep_phrase { } + ; + +prep_phrase : PREPOS cmplx_noun { } + ; + +cmplx_noun : ARTICLE NOUN { } + ; + +cmplx_verb : VERB { } + | VERB noun_phrase { } + ; +%% From 754b77059a5bb5d8e1bff336957a9d8586475df8 Mon Sep 17 00:00:00 2001 From: XimenaCantera <95453390+XimenaCantera@users.noreply.github.com> Date: Mon, 29 Jan 2024 18:34:56 -0600 Subject: [PATCH 3/3] Create test.txt Archivo de prueba --- labs/03/test.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 labs/03/test.txt diff --git a/labs/03/test.txt b/labs/03/test.txt new file mode 100644 index 0000000..b464089 --- /dev/null +++ b/labs/03/test.txt @@ -0,0 +1,4 @@ +a boy sees +the boy sees a flower +a girl with a flower likes the boy +a flower sees a flower