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; +} 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 { } + ; +%% 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