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
21 changes: 21 additions & 0 deletions labs/03/analyzer.l
Original file line number Diff line number Diff line change
@@ -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

%%
139 changes: 139 additions & 0 deletions labs/03/analyzer.y
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
%{

#include <stdio.h>

#include <stdlib.h>



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 <input_file>\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;

}
Binary file added labs/03/test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.