/* Definition Section */
%{
#include <stdio.h>
// Global counters, initialized to zero
int vowels = 0;
int consonants = 0;
int operators = 0;
int commas = 0;
int semicolons = 0;
int newlines = 0;
%}
/* Rules Section */
%%
[aeiouAEIOU] { vowels++; }
[b-df-hj-np-tv-zB-DF-HJ-NP-TV-Z] { consonants++; }
[+\-*/%<>=!&|~^] { operators++; }
"," { commas++; }
";" { semicolons++; }
"\n" { newlines++; }
. { /* This rule matches and ignores all other characters */ }
%%
/* User Code Section */
int yywrap(void) {
// This function is called at the end of the file.
// Returning 1 signals that there are no more files to process.
return 1;
}
int main(int argc, char *argv[]) {
// If a filename is provided as an argument, open it.
if (argc > 1) {
FILE *file = fopen(argv[1], "r");
if (!file) {
perror("Error opening file");
return 1;
}
// Set the input stream for the lexer
yyin = file;
}
// Otherwise, the lexer will read from standard input by default.
// Start the analysis
yylex();
// Print the final report
printf("\n------------------------------------\n");
printf(" ANALYSIS REPORT \n");
printf("------------------------------------\n");
printf(" Vowels : %d\n", vowels);
printf(" Consonants : %d\n", consonants);
printf(" Operators : %d\n", operators);
printf(" Commas : %d\n", commas);
printf(" Semicolons : %d\n", semicolons);
printf(" New Lines : %d\n", newlines);
printf("------------------------------------\n");
return 0;
}
Standard output is empty
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? [Illegal port specification]
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? [Illegal port specification]
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? [Illegal port specification]
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: No previous search
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? [Illegal port specification]
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? [Illegal port specification]
Exception: (3) program ? [Illegal port specification]
Exception: (3) program ? Call: (3) program ? ERROR: Unknown option (h for help)
Call: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? [Illegal port specification]
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? Exception: (3) program ? Call: (3) program ? ERROR: Unknown option (h for help)
Call: (3) program ? [Illegal port specification]
Call: (3) program ? ERROR: Unknown option (h for help)
Call: (3) program ? ERROR: Unknown option (h for help)
Call: (3) program ? [Illegal port specification]
Call: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? [Illegal port specification]
Exception: (3) program ? ERROR: Unknown option (h for help)
Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? [Illegal port specification]
Exception: (3) program ? Exception: (3) program ? Exception: (3) program ? Exception: (3) program ? Exception: (3) program ? Exception: (3) program ? Exception: (3) program ? Exception: (3) program ? Exception: (3) program ? Exception: (3) program ? Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
Exception: (3) program ? Call: (3) program ? ERROR: Unknown option (h for help)
Call: (3) program ? EOF: exit