Answered step by step
Verified Expert Solution
Link Copied!

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 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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

What skills and behaviours does this require you to demonstrate?

Answered: 1 week ago