I am trying to make a syntax analyzer that will recognize a valid statement and will print success upon doing so. However, after making the lex and yacc files, I keep getting errors in my yacc file which says:
In function 'yyparse'fofo.y: In function 'yyparse':
fofo.y:13:5: error: stray '\223' in program
fofo.y:13:5: error: stray '\' in program
fofo.y:13:16: error: 'n' undeclared (first use in this function)
fofo.y:13:16: note: each undeclared identifier is reported only once for each function it appears in
fofo.y:13:18: error: expected ')' before 'Invalid'
fofo.y:13:18: error: stray '\' in program
fofo.y:13:18: error: stray '\224' in program
Here's my yacc file contents:
%{
#include <stdio.h>
%}
%start Stmt_list
%token Id Num Relop Addop Mulop Assignop Not
%%
Stmt_list : Stmt ';' '\n' {printf ("\n Success. \n"); exit(0);}
| Stmt_list Stmt ';' '\n' {printf ("\n Success. \n"); exit(0);}
| error '\n' {printf (“\n Invalid. \n”); exit(1);}
;
Stmt : Variable Assignop Expression
;
Variable : Id
| Id '['Expression']'
;
Expression : Simple_expression
| Simple_expression Relop Simple_expression
;
Simple_expression : Term
| Simple_expression Addop Term
;
Term : Factor
| Term Mulop Factor
;
Factor : Id
| Num
| '('Expression')'
| Id '['Expression']'
| Not Factor
;
%%
#include"lex.yy.c"
int main()
{
yyparse();
yylex();
}
yyerror(char *s)
{
printf("\nError\n");
}