--- /dev/null
+%{
+ #include <stdio.h>
+ #include <stdlib.h>
+%}
+
+%start Program
+%token FUNC END STRUCT VAR IF THEN ELSE WHILE DO RETURN OR NOT
+%token ID NUM ASSIGN GREATER
+
+%%
+
+Program: Funcdef ';' Program
+ | Structdef ';' Program
+ |
+ ;
+
+Funcdef: FUNC ID '(' Pars ')' Stats END
+ | FUNC ID '(' ')' Stats END
+ ;
+
+Structdef: STRUCT Ids END
+ ;
+
+Ids: ID Ids
+ |
+ ;
+
+Pars: Pars ',' ID
+ | ID
+ ;
+
+Stats: Stat ';' Stats
+ |
+ ;
+
+Stat: VAR ID ASSIGN Expr
+ | Lexpr ASSIGN Expr
+ | IF Bool THEN Stats END
+ | IF Bool THEN Stats ELSE Stats END
+ | WHILE Bool DO Stats END
+ | Call
+ | RETURN Expr
+ ;
+
+Lexpr: ID
+ | Field
+ ;
+
+Expr: '-' Term
+ | Term
+ | Term Plusterm
+ | Term Malterm
+ ;
+
+Plusterm: '+' Term Plusterm
+ | '+' Term
+ ;
+
+Malterm: '*' Term Malterm
+ | '*' Term
+ ;
+
+Term: '(' Expr ')'
+ | ID
+ | NUM
+ | Call
+ | Field
+ ;
+
+Bool: Bterm
+ | Bterm Orterm
+ | NOT Bterm
+ ;
+
+Orterm: OR Bterm Orterm
+ | OR Bterm
+ ;
+
+Bterm: Term GREATER Term
+ | Term '=' Term
+ | '(' Bool ')'
+ ;
+
+Field: Term '.' ID
+ ;
+
+Call: ID '(' Exprs ')'
+ | ID '(' ')'
+ ;
+
+Exprs: Expr
+ | Exprs ',' Expr
+ ;
+
+%%
+
+extern int yylex();
+extern int yylineno;
+
+int yyerror(char *error_text) {
+ fprintf(stderr,"Line %i: %s\n",yylineno, error_text);
+ exit(2);
+}
+
+int main(int argc, char **argv) {
+/* yydebug=1; */
+ yyparse();
+ return 0;
+}
+