Question
These are my C-MINUS BNF Yacc implementation: My current problem is that I have no idea how to solve is when running ./Assignment1 <
These are my C-MINUS BNF Yacc implementation:
My current problem is that I have no idea how to solve is when running " ./Assignment1 < Assignment1Test.c " I get a syntax error on line 1(of Assingment1Test.c), I currently have no idea how to fix it I only know that the problem is located in my Param_List, IF someone could help me and guide me toward the right place.
if an answer is provided I'll make sure to upvote your response.
******************************************************************************************************************************************************************
Assingment1.Y
%{
/* begin specs */ #include
int yylex(); extern int lineno; // from lex extern int mydebug; // from lex
void yyerror(s) // called by yyparse char *s; { printf ("YACC PARSE ERROR: %s on line number %d ", s,lineno); }
%}
%union { int value; char *string; }
%start Program
%token
%% /* end specs, begin rules */ Program : Declaration_List ; Declaration_List: Declaration | Declaration '{' Declaration '}' | Declaration Declaration_List ; Declaration : Var_Declaration | Fun_Declaration ; Var_Declaration : Type_Specifier Var_List ';' ; Var_List: T_ID T_NUM {printf("Var_LIST ID is %s ", $1);} | T_ID '[' T_NUM ']' Var_List {printf("Var_LIST ID is %s ", $1);} | T_ID ',' Var_List {printf("Var_LIST ID is %s ", $1);} ; Type_Specifier: T_INT | T_VOID ; Fun_Declaration : Type_Specifier T_ID '(' Params ')' Compound_Stmt ; Params : T_VOID | Param_List ; Param_List : Param | Param_List ',' Param ; Param : Type_Specifier T_ID '[' ']' ;
Compound_Stmt : '{'Local_Declarations Statement_List '}' ; Local_Declarations: '{' Var_Declaration '}' ;
Statement_List : Statement ; Statement: Expression_Stmt | Compound_Stmt | Selection_Stmt | Iteration_Stmt | Assignment_Stmt | Return_Stmt | Read_Stmt | Write_Stmt ; Expression_Stmt: Expression ';' | ';' ;
Selection_Stmt:T_IF '(' Expression ')' Statement '[' T_ELSE Statement ']' ;
Iteration_Stmt: T_WHILE '(' Expression ')' Statement ;
Return_Stmt: T_RETURN '[' Expression ']' ';' ;
Read_Stmt: T_READ Var ';' ;
Write_Stmt:T_WRITE Expression ';' | T_WRITE T_STRING ';' ;
Assignment_Stmt: Var '=' Simple_Expression ;
Var: T_ID '[' Expression ']' ;
Expression: Simple_Expression ;
Simple_Expression: Additive_Expression | Additive_Expression '[' Relop Additive_Expression ']' ; Relop: T_LE | T_LT | T_GT | T_GE | T_EQ | T_NE ;
Additive_Expression: Term | Additive_Expression Addop Term ; Addop: '+' | '-' ;
Term: Factor | Multop Factor ;
Multop: '*' | '/' ; Factor: '(' Expression ')' | T_NUM | Var | Call | '-' Factor ; Call: T_ID '(' Args ')' ; Args: Arg_List | /*empty*/ ; Arg_List: Expression '{' ',' Expression '}'
%%
/* end of rules, start of program */ int main() { yyparse(); }
/********************************************************************************************************************************************************/
Assingment1.L
%{ int mydebug=0; int lineno=1; #include "y.tab.h" %} %% int {return(T_INT);} void {return(T_VOID);} write {return(T_WRITE);} read {return(T_READ);} if {return(T_IF);} else {return(T_ELSE);} while {return(T_WHILE);} return {return(T_RETURN);} '<' {return(T_LT);} '>' {return(T_GT);} '<=' {return(T_LE);} '>=' {return(T_GE);} '==' {return(T_EQ);} '!=' {return(T_NE);} \/\/.* {/*do nothing just eat */ } \".*\" {yylval.string=strdup(yytext); return (T_STRING);} [a-zA-Z][a-zA-z0-9_]* {if (mydebug) fprintf(stderr,"ID found "); yylval.string=strdup(yytext); return(T_ID);} [0-9][0-9]* {if (mydebug) fprintf(stderr,"Digit found "); yylval.value=atoi((const char *)yytext); return(T_NUM);} [ \t] {if (mydebug) fprintf(stderr,"Whitespace found ");} [;()=\-+*/%&{},[\]|] { if (mydebug) fprintf(stderr,"return a token%c ",*yytext); return (*yytext);} { if (mydebug) fprintf(stderr,"carriage return %c ",*yytext); lineno++; } %% int yywrap(void) { return 1;}
/************************************************************************************************************************************************/
Assignment1Test.c
int x; int x,x;
int main(int a, void b, int a[]) { int x , A[100]; read x; read y[ 3+4 ]; read x; write "helo"; write 3+4+f(3,2,A[20]) ; return; return 3+4+f(3,2,A[20]); 3+4+f(3,2,A[20]); ;;; {{while ( x < 3) read x; }}
read x; if ( x ) write 5 ; if( x < 3) return 5; else write "great";
} // of main
void f(void) {}
int x , A[100]; void A[100]; void A[100], x; void A[100], B[2];
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started