Доброго времени суток, вот программа на яке
/* Simplest Context free grammar (0^n1^n) */
%{ #include <ctype.h>
#include <stdio.h>
#define YYSTYPE char // Type of input
int yylex (void);
void yyerror (char const *);
%}
// Main symbols of grammar (synonyms: terminals, tokens, etc.)
%token ONE
%token TWO
%left UR
%% /* Grammar rules and actions follow. */
input: /* empty */ { printf("\n\tThis program expecting string as\n");}
| input line
;
line: '\n' { printf ("empty line was introduced\n");}
|error '\n' {yyerrok;}
| exp '\n' { printf ("\t n = %i\n", $1); }
;
exp: ONE TWO { $$ = 1; }
| TWO ONE
|ONE exp TWO
|TWO exp ONE { $$ = $2 + 1;}
;
%%
int yylex (void)
{
int c;
/* Skip white space */
while ((c = getchar ()) == ' ' || c == '\t')
;
/* Process symbols */
if (c == '0') {
return ONE;
}
else
if (c == '1') {
return TWO;
}
else
/* Return end-of-input. */
if (c == EOF)
return 0;
/* Return a single char. */
return c;
}
void yyerror (char const *s)
{
fprintf (stderr, "stderror: %s\n", s);
}
int
main (void)
{
return yyparse ();
}