tags:

views:

16

answers:

1
curs.l :
%{
#include <stdlib.h>
#include "tree.c"
#include "yycurs.h"
%}

L [a-zA-Z_]

D [0-9]

D4 [0-3]

IDENTIFIER ({L})({L}|{D})*

INT4 {D4}+'q'

INT {D}+

%%

{IDENTIFIER} {return VARIABLE;}

%%

int yywrap(void){
   return 0;
}



curs.y:
%{
#include stdio.h


void yyerror(char*);
int yylex(void);
%}

%token VARIABLE INTEGER

%%

var: VARIABLE {printf($1);};

%%

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

int main(void){
   yyparse();
   return 0;
}

when i run my compiled progrum, i have such result:

./curs 

ff  //I introduced

   //result

ff //I introduced

11 //result

syntax error //result

evgeniy@evgeniy-desktop:~/documents/compilers$ 

Can anybody explain me, why there appears 'syntax error'? Thanks in advance.

A: 

Your grammar defiles that a valid file consists of exactly one VARIABLE. To have more then one, you need to introduce a recursive rule.

%start vars

%%

var: VARIABLE {printf($1);};

vars: var
    | vars var;

%%
Rudi
thanks, i already solve this problem. Errors occurs becouse, my program didn't handle symbols like '\n'. Thank you for your reply.
evgeniy44