diff --git a/labs/03/analyzer.l b/labs/03/analyzer.l new file mode 100644 index 0000000..337c69a --- /dev/null +++ b/labs/03/analyzer.l @@ -0,0 +1,21 @@ +%{ +#include "y.tab.h" +%} +%{ +int spacing = 1; +%} + +%% +a | the { return ARTICLE; } + +boy | girl | flower { return NOUN; } + +touches | likes | sees { return VERB; } + +with { return PREP; } + +\n { spacing++; return '\n'; } +[ \t]+ +^[ \t]*\n + +%% diff --git a/labs/03/analyzer.y b/labs/03/analyzer.y new file mode 100644 index 0000000..bcd5c7f --- /dev/null +++ b/labs/03/analyzer.y @@ -0,0 +1,139 @@ +%{ + +#include + +#include + + + +int yylex(void); + +void yyerror(const char *s); + +int yywrap(void); + +extern FILE *yyin; + + + +%} + +%token ARTICLE NOUN VERB PREP + +%% + + + +start: sentences '\n' { printf("PASS\n"); } + + + +sentences: /* empty */ + + + + | sentences sentence '\n' + + + + ; + + + +sentence: noun_phrase verb_phrase { printf("PASS\n"); } + + + + | noun_phrase { printf("PASS\n"); } + + + + | verb_phrase { printf("PASS\n"); } + + + + ; + + + +noun_phrase: ARTICLE NOUN + + + + | ARTICLE NOUN prep_phrase + + + + ; + + + +verb_phrase: VERB + + + + | VERB noun_phrase + + + + ; + + + +prep_phrase: PREP noun_phrase + + + + ; + + + +%% + + + +void yyerror(const char *s) { + + printf("FAIL\n"); + +} + +int main(int argc, char *argv[]) { + + + + if (argc != 2) { + + + + fprintf(stderr, "Usage: %s \n", argv[0]); + + + + return 1; + + + + } + + + + FILE *file = fopen(argv[1], "r"); + + if (file == NULL) { + + perror("Error opening file"); + + return 1; + + } + + yyin = file; + + yyparse(); + + fclose(file); + + return 0; + +} diff --git a/labs/03/test.jpg b/labs/03/test.jpg new file mode 100644 index 0000000..57107aa Binary files /dev/null and b/labs/03/test.jpg differ