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
Binary file added labs/03/cfgAnalyzer
Binary file not shown.
19 changes: 19 additions & 0 deletions labs/03/cfgAnalyzer.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%{
#include "y.tab.h"
%}

%%

"a" { return ARTICLE; }
"the" { return ARTICLE; }
"boy" { return NOUN; }
"girl" { return NOUN; }
"flower" { return NOUN; }
"touches" { return VERB; }
"likes" { return VERB; }
"sees" { return VERB; }
"with" { return PREPOSITION; }
\n { return SALTO; }
[ \t] { /* ignore whitespace */ }
. { return yytext[0];}
%%
71 changes: 71 additions & 0 deletions labs/03/cfgAnalyzer.y
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
%{
#include <stdio.h>
#include <stdlib.h>

extern int yylex();
extern char* yytext;
extern FILE* yyin;

void yyerror(const char *s) {
fprintf(stderr, "FAIL: %s\n", s);
}

%}

%token ARTICLE NOUN VERB PREPOSITION SALTO
%start SENTENCE

%%
SENTENCE : NOUN_PHRASE VERB_PHRASE SALTO
| SALTO NOUN_PHRASE VERB_PHRASE
| SALTO NOUN_PHRASE VERB_PHRASE SALTO
;
NOUN_PHRASE : CMPLX_NOUN
| CMPLX_NOUN PREPOSITION_PHRASE
;
CMPLX_VERB : VERB
| PREPOSITION VERB
| VERB NOUN_PHRASE
;
CMPLX_NOUN : ARTICLE NOUN
;
PREPOSITION_PHRASE : PREPOSITION CMPLX_NOUN
;
VERB_PHRASE : CMPLX_VERB
| CMPLX_VERB PREPOSITION_PHRASE
;

%%

int main(int argc, char **argv) {


FILE *f = fopen(argv[1], "r");
if (!f) {
perror(argv[1]);
exit(1);
}

yyin = f;

int parseResult;

while ((parseResult = yyparse()) != 0) {
switch(parseResult) {
case 1:
printf("PASS\n");
break;

default:
printf("FAIL\n");
break;
}
}

fclose(f);
return 0;
}

int yywrap() {
return 1;
}
Loading