Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ * CMSC 4 3 0 Compiler Theory and Design Project 2 Skeleton UMGC CITE Summer 2 0 2 3 Project 2 Parser * /
CMSC Compiler Theory and Design
Project Skeleton
UMGC CITE
Summer
Project Parser
#include
using namespace std;
#include "listing.h
int yylex;
void yyerrorconst char message;
define parse.error verbose
token IDENTIFIER INTLITERAL CHARLITERAL REALLITERAL
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:
functionheader optionalvariable body ;
functionheader:
FUNCTION IDENTIFIER RETURNS type ; ;
type:
INTEGER
CHARACTER
REAL ; Modified to include REAL type
optionalvariable:
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 INTLITERAL ARROW statement ; ;
condition:
condition ANDOP relation
relation ;
relation:
condition
expression RELOP expression ;
expression:
expression ADDOP term
term ;
term:
term MULOP primary
primary ;
primary:
expression
INTLITERAL
CHARLITERAL
REALLITERAL Added REALLITERAL
IDENTIFIER expression
IDENTIFIER ;
void yyerrorconst char message
appendErrorSYNTAX message;
int mainint argc, char argv
firstLine;
yyparse;
lastLine;
return ;
Please fix this within this grammar
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