Question: / * CMSC 4 3 0 Compiler Theory and Design Project 2 Skeleton UMGC CITE Summer 2 0 2 3 Project 2 Parser * /

/* CMSC 430 Compiler Theory and Design
Project 2 Skeleton
UMGC CITE
Summer 2023
Project 2 Parser */
%{
#include
using namespace std;
#include "listing.h"
int yylex();
void yyerror(const char* message);
%}
%define parse.error verbose
%token IDENTIFIER INT_LITERAL CHAR_LITERAL REAL_LITERAL
%token ADDOP MULOP ANDOP RELOP ARROW OROP NOTOP BEGIN_ CASE CHARACTER
END ENDSWITCH FUNCTION INTEGER IS LIST OF OTHERS RETURNS SWITCH WHEN
ELSE ELSIF ENDFOLD ENDIF FOLD IF LEFT REAL RIGHT THEN REMOP EXPOP
NEGOP PUNC
%%
function:
function_header optional_variable body ;
function_header:
FUNCTION IDENTIFIER RETURNS type ';' ;
type:
INTEGER |
CHARACTER |
REAL ; /* Modified to include REAL type */
optional_variable:
variable |
%empty ;
variable:
IDENTIFIER ':' type IS statement ';'|
IDENTIFIER ':' LIST OF type IS list ';' ;
list:
'(' expressions ')' ;
expressions:
expressions ',' expression|
expression ;
body:
BEGIN_ statement_ END ';' ;
statement_:
statement ';'|
error ';' ;
statement:
expression |
WHEN condition ',' expression ':' expression |
SWITCH expression IS cases OTHERS ARROW statement ';' ENDSWITCH ;
cases:
cases case |
%empty ;
case:
CASE INT_LITERAL ARROW statement ';' ;
condition:
condition ANDOP relation |
relation ;
relation:
'(' condition ')'|
expression RELOP expression ;
expression:
expression ADDOP term |
term ;
term:
term MULOP primary |
primary ;
primary:
'(' expression ')'|
INT_LITERAL |
CHAR_LITERAL |
REAL_LITERAL |/* Added REAL_LITERAL */
IDENTIFIER '(' expression ')'|
IDENTIFIER ;
%%
void yyerror(const char* message){
appendError(SYNTAX, message);
}
int main(int argc, char *argv[]){
firstLine();
yyparse();
lastLine();
return 0;
} Please fix this within this grammar
 /* CMSC 430 Compiler Theory and Design Project 2 Skeleton UMGC

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!