Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions labs/03/lexer.l
Original file line number Diff line number Diff line change
@@ -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;
}
29 changes: 29 additions & 0 deletions labs/03/parser.y
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
%{
#include <stdio.h>
%}

%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 { }
;
%%
4 changes: 4 additions & 0 deletions labs/03/test.txt
Original file line number Diff line number Diff line change
@@ -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