SlideShare a Scribd company logo
1 of 3
Download to read offline
In this programming assignment, you will be building a parser for the Simple Perl-Like (SPL)
programming language. The syntax definitions of SPL programming language are given below
using EBNF notations. Your implementation of a parser to the language is based on the
following grammar rules specified in EBNF notations. 1. Prog ::= StmtList 2. Stmtlist ::= Stmt ;{
Stmt; } 3. Stmt ::= AssignStme| Writelnstmt Ifstmt 4. WritelnStmt ::= writeln (ExprList) 5.
IfStmt : := if (Expr) ' f ' StmtList ' } ' [ else ' { 'StmtList ' } ' ] 6. Assignstmt ::=Var=Expr 7. Var
::= NIDENT | SIDENT 8. Exprlist ::=Expr{,Expr} 9. Expr ::= RelExpr [( eq ==) RelExpr ] 10.
Relexpr : := AddExpr [ ( -lt gt<1>) AddExpr ] 11. AddExpr :: Multexpr {(+11. ) MultExpr } 12.
Multexpr : := ExponExpr {(/) ExponExpr } 13. ExponExpr : := UnaryExpr { UnaryExpr } 14.
Unaryexpr ::=[(1+)] PrimaryExpr 15. PrimaryExpr ::= IDENT | SIDENT | NIDENT | ICONST |
RCONST | SCONST (Expr) The following points describe the SPL programming language.
Note that not all of these points will be addressed in this assignment. However, they are listed in
order to give you an understanding of the language semantics and what to be considered for
implementing an interpreter for the language in Programming Assignment 3. These points are:
Table of Operators Precedence Levels 1. The language has two types: Numeric, and String. 2.
The SPL language does not have explicit declaration statements. However, variables are
implicitly declared as Numeric type by a variable name starting with "$", or as String type by a
variable name starting with "@". 3. All SPL variables must first be initialized by an assignment
statement before being used. 4. The precedence rules of operators in the language are as shown
in the table of operators' precedence levels. 5. The PLUS, MINUS, MULT, DIV, CAT, and
SREPEAT operators are left associative. 6. An IfStmt evaluates a logical expression (Expr) as a
condition. If the logical condition value is true, then the StmtList in the If-clause are executed,
otherwise they are not. An else clause for an IfSmt is optional. Therefore, If an Else-clause is
defined, the StmtList in the Else-clause are executed when the logical condition value is false. 7.
A WritelnStmt evaluates the list of expressions (ExprList), and prints their values in order from
left to right followed by a newline. 8. The ASSOP operator (=) in the AssignStmt assigns a value
to a variable. It evaluates the Expr on the right-hand side and saves its value in a memory
location associated with the left-hand side variable (Var). A left-hand side variable of a Numeric
type must be assigned a numeric value. While a left-hand side variable of a String type must be
assigned a string value. Type conversion must be automatically applied if the right-hand side
value of the evaluated expression does not match the type of the left-hand side variable. 9. The
binary operations of numeric operators as addition, subtraction, multiplication, and division are
performed upon two numeric operands. While the binary string operator for concatenation is
performed upon two string operands. If one of the operands does not match the type of the
operator, that operand is automatically converted to the type of the operator. 10. Similarly,
numeric relational and equality operators (=,<, and > ) operate upon two numeric type operands.
While, string relational and equality operators (-eq, -lt, -gt) operate upon two string type
operands. The evaluation of a relational or an equality expression, produces either a true or false
value. If one of the operands does not match the type of the operator, that operand is
automatically converted to the type of the operator. For all relational and equality operators, no
cascading is allowed. 11. The exponent operator is applied on a numeric type operand, and the
exponent value must be a numeric type value. No automatic conversion to numeric type operand
is applied in case of
an expression with exponent operator. Note that, exponent operators follow right-to-left
association. 12. The binary operation for string repetition () operates upon a string operand as the
first operand, where the second operand must be a numeric expression of integer value. 13. The
unary sign operators (+ or -) are applied upon unary numeric type operands only. 14. It is an
error to use a variable in an expression before it has been assigned. Parser Requirements:
Implement a recursive-descent parser for the given language. You may use the lexical analyzer
you wrote for Programming Assignment 1, OR you may use the provided implementation when
it is posted. The parser should provide the following: - The results of an unsuccessful parsing are
a set of error messages printed by the parser functions, as well as the error messages that might
be detected by the lexical analyzer. - If the parser fails, the program should stop after the parser
function returns. - The assignment does not specify the exact error messages that should be
printed out by the parser; however, the format of the messages should be the line number,
followed by a colon and a space, followed by some descriptive text. Suggested messages might
include "Missing semicolon at end of Statement.", "Incorrect Declaration Statement.", "Missing
Right Parenthesis", "Undefined Variable", "Missing END", etc. - If the scanning of the input file
is completed with no detected errors, the parser should display the message (DONE) on a new
line before returning successfully to the caller program. Provided Files You are given the header
file for the parser, "parser.h" and an incomplete file for the "parser.cnp", You should use
"parser.cpp" to complete the implementation of the parser. In addition, "lex.h", "lex.cpp", and
"prog2.cpp" files are also provided. The descriptions of the files are as follows: "Parser.h"
"parser.h" includes the following: - Prototype definitions of the parser functions (e.g., Prog,
StmtList, Stmt, etc.) "Parser.cpp" - A map container that keeps a record of the defined variables
in the parsed program, defined as: map defvar; - The key of the defvar is a variable name, and
the value is a Boolean that is set to true when the first time the variable has been initialized,
otherwise it is false. - A function definition for handling the display of error messages, called
ParserError. - Functions to handle the process of token lookahead, GetNextToken and
PushBackToken, defined in a namespace domain called Parser.
- Static int variable for counting errors, called error_count, and a function to return its value,
called ErrCount (). - Implementations of some functions of the recursive-descent parser.
"prog2.cpp" - You are given the testing program "prog2.cpp" that reads a file name from the
command line. The file is opened for syntax analysis, as a source code for your parser. - A call to
Prog( function is made. If the call fails, the program should stop and display a message as
"Unsuccessful Parsing ", and display the number of errors detected. For example: Unsuccessful
Parsing Number of Syntax Errors: 3 - If the call to Prog0 function succeeds, the program should
stop and display the message "Successful Parsing ", and the program stops. Vocareum Automatic
Grading - You are provided by a set of 19 testing files associated with Programming Assignment
2. Vocareum automatic grading will be based on these testing files. You may use them to check
and test your implementation. These are available in compressed archive as "PA 2 Test
Cases.zip" on Canvas assignment. The testing case of each file is defined in the Grading table
below. - The automatic grading of a clean source code file will be based on checking against the
output message: (DONE) Successful Parsing - In each of the other testing files, there is one
syntactic error at a specific line. The automatic grading process will be based on the statement
number at which this error has been found and the number of associated error messages with this
syntactic error. - You can use whatever error message you like. There is no check against the
contents of the error messages. - A check of the number of errors your parser has produced and
the number of errors printed out by the program are made. Submission Guidelines - Submit your
"parse.cpp" implementation through Vocareum. The "lex.h", "parser.h", "lex.cpp" and
"prog2.cpp" files will be propagated to your Work Directory.
Grading Table

More Related Content

Similar to Build an SPL Parser (SPLParser

Maxbox starter
Maxbox starterMaxbox starter
Maxbox starterMax Kleiner
 
This first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxThis first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxabhi353063
 
Python For Data Science.pptx
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptxrohithprabhas1
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingAMAN ANAND
 
Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptxmalekaanjum1
 
Debugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programsDebugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programsPVS-Studio
 
Introduction to R for beginners
Introduction to R for beginnersIntroduction to R for beginners
Introduction to R for beginnersAbishek Purushothaman
 
Current C++ code- parse-h -- This file contains the function prototype (1).pdf
Current C++ code- parse-h -- This file contains the function prototype (1).pdfCurrent C++ code- parse-h -- This file contains the function prototype (1).pdf
Current C++ code- parse-h -- This file contains the function prototype (1).pdfshyamsunder1211
 
2. Stack. Write a program that uses the stack class (you can use.pdf
2. Stack. Write a program that uses the stack class (you can use.pdf2. Stack. Write a program that uses the stack class (you can use.pdf
2. Stack. Write a program that uses the stack class (you can use.pdfaniarihant
 
Parameter Estimation User Guide
Parameter Estimation User GuideParameter Estimation User Guide
Parameter Estimation User GuideAndy Salmon
 
Rechecking Apache HTTP Server
Rechecking Apache HTTP ServerRechecking Apache HTTP Server
Rechecking Apache HTTP ServerPVS-Studio
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxjane3dyson92312
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxfestockton
 
Declaring a PointerTo define a pointer, use an asterisk, (), in t.pdf
Declaring a PointerTo define a pointer, use an asterisk, (), in t.pdfDeclaring a PointerTo define a pointer, use an asterisk, (), in t.pdf
Declaring a PointerTo define a pointer, use an asterisk, (), in t.pdfmalavshah9013
 
Pattern Matching using Computational and Automata Theory
Pattern Matching using Computational and Automata TheoryPattern Matching using Computational and Automata Theory
Pattern Matching using Computational and Automata TheoryIRJET Journal
 

Similar to Build an SPL Parser (SPLParser (20)

Maxbox starter
Maxbox starterMaxbox starter
Maxbox starter
 
This first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxThis first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docx
 
Python For Data Science.pptx
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptx
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptx
 
Debugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programsDebugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programs
 
Introduction to R for beginners
Introduction to R for beginnersIntroduction to R for beginners
Introduction to R for beginners
 
Current C++ code- parse-h -- This file contains the function prototype (1).pdf
Current C++ code- parse-h -- This file contains the function prototype (1).pdfCurrent C++ code- parse-h -- This file contains the function prototype (1).pdf
Current C++ code- parse-h -- This file contains the function prototype (1).pdf
 
C Language Part 1
C Language Part 1C Language Part 1
C Language Part 1
 
2. Stack. Write a program that uses the stack class (you can use.pdf
2. Stack. Write a program that uses the stack class (you can use.pdf2. Stack. Write a program that uses the stack class (you can use.pdf
2. Stack. Write a program that uses the stack class (you can use.pdf
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
 
Input-output
Input-outputInput-output
Input-output
 
Parameter Estimation User Guide
Parameter Estimation User GuideParameter Estimation User Guide
Parameter Estimation User Guide
 
Rechecking Apache HTTP Server
Rechecking Apache HTTP ServerRechecking Apache HTTP Server
Rechecking Apache HTTP Server
 
Mule expression
Mule expressionMule expression
Mule expression
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
 
Declaring a PointerTo define a pointer, use an asterisk, (), in t.pdf
Declaring a PointerTo define a pointer, use an asterisk, (), in t.pdfDeclaring a PointerTo define a pointer, use an asterisk, (), in t.pdf
Declaring a PointerTo define a pointer, use an asterisk, (), in t.pdf
 
Pattern Matching using Computational and Automata Theory
Pattern Matching using Computational and Automata TheoryPattern Matching using Computational and Automata Theory
Pattern Matching using Computational and Automata Theory
 
C question
C questionC question
C question
 

More from nijamabdulkarim

In the context of an IDS, we define a false positive to be an alarm g.pdf
 In the context of an IDS, we define a false positive to be an alarm g.pdf In the context of an IDS, we define a false positive to be an alarm g.pdf
In the context of an IDS, we define a false positive to be an alarm g.pdfnijamabdulkarim
 
In the above figure, which point represents an attain.pdf
 In the above figure, which point represents an attain.pdf In the above figure, which point represents an attain.pdf
In the above figure, which point represents an attain.pdfnijamabdulkarim
 
In the 01 knapsack recurrence formula f(x,1)=max[v1+fxw1,1,f[x,1]] Th.pdf
 In the 01 knapsack recurrence formula f(x,1)=max[v1+fxw1,1,f[x,1]] Th.pdf In the 01 knapsack recurrence formula f(x,1)=max[v1+fxw1,1,f[x,1]] Th.pdf
In the 01 knapsack recurrence formula f(x,1)=max[v1+fxw1,1,f[x,1]] Th.pdfnijamabdulkarim
 
in minimum. 350 words the course is intercultural commun.pdf
 in minimum. 350 words  the course is intercultural commun.pdf in minimum. 350 words  the course is intercultural commun.pdf
in minimum. 350 words the course is intercultural commun.pdfnijamabdulkarim
 
In San Fernando the dry season is between February to July November t.pdf
 In San Fernando the dry season is between February to July November t.pdf In San Fernando the dry season is between February to July November t.pdf
In San Fernando the dry season is between February to July November t.pdfnijamabdulkarim
 
In its first year of operations Matthew Doe Products paid for the fol.pdf
 In its first year of operations Matthew Doe Products paid for the fol.pdf In its first year of operations Matthew Doe Products paid for the fol.pdf
In its first year of operations Matthew Doe Products paid for the fol.pdfnijamabdulkarim
 
In order to identify genetic factors affecting susceptibility to lepr.pdf
 In order to identify genetic factors affecting susceptibility to lepr.pdf In order to identify genetic factors affecting susceptibility to lepr.pdf
In order to identify genetic factors affecting susceptibility to lepr.pdfnijamabdulkarim
 
In rare cases, as a goologist you might encounter a sedimentary depos.pdf
 In rare cases, as a goologist you might encounter a sedimentary depos.pdf In rare cases, as a goologist you might encounter a sedimentary depos.pdf
In rare cases, as a goologist you might encounter a sedimentary depos.pdfnijamabdulkarim
 
In order to identify genetic factors affecting susceptibiity to lepro.pdf
 In order to identify genetic factors affecting susceptibiity to lepro.pdf In order to identify genetic factors affecting susceptibiity to lepro.pdf
In order to identify genetic factors affecting susceptibiity to lepro.pdfnijamabdulkarim
 
In ecology, the number of people, other living organisms, or crops th.pdf
 In ecology, the number of people, other living organisms, or crops th.pdf In ecology, the number of people, other living organisms, or crops th.pdf
In ecology, the number of people, other living organisms, or crops th.pdfnijamabdulkarim
 
Inflation and the Quantity Theory of Money End of Chapter Problem 14.pdf
 Inflation and the Quantity Theory of Money End of Chapter Problem 14.pdf Inflation and the Quantity Theory of Money End of Chapter Problem 14.pdf
Inflation and the Quantity Theory of Money End of Chapter Problem 14.pdfnijamabdulkarim
 
Individuals with Swyers Syndrome (XYSRY)tend to not develop gonads. .pdf
 Individuals with Swyers Syndrome (XYSRY)tend to not develop gonads. .pdf Individuals with Swyers Syndrome (XYSRY)tend to not develop gonads. .pdf
Individuals with Swyers Syndrome (XYSRY)tend to not develop gonads. .pdfnijamabdulkarim
 
Indicate whether the following items are Included in or Excluded f.pdf
 Indicate whether the following items are Included in or Excluded f.pdf Indicate whether the following items are Included in or Excluded f.pdf
Indicate whether the following items are Included in or Excluded f.pdfnijamabdulkarim
 
Indicate whether the items described below are inputs (I), outputs (O.pdf
 Indicate whether the items described below are inputs (I), outputs (O.pdf Indicate whether the items described below are inputs (I), outputs (O.pdf
Indicate whether the items described below are inputs (I), outputs (O.pdfnijamabdulkarim
 
Indicate whether each of the following statements is true or false. C.pdf
 Indicate whether each of the following statements is true or false. C.pdf Indicate whether each of the following statements is true or false. C.pdf
Indicate whether each of the following statements is true or false. C.pdfnijamabdulkarim
 
Indigo The grandmother hypothesis speculates that women raise their .pdf
 Indigo The grandmother hypothesis speculates that women raise their .pdf Indigo The grandmother hypothesis speculates that women raise their .pdf
Indigo The grandmother hypothesis speculates that women raise their .pdfnijamabdulkarim
 
Indicate the balances in the three stockholders equity accounts afte.pdf
 Indicate the balances in the three stockholders equity accounts afte.pdf Indicate the balances in the three stockholders equity accounts afte.pdf
Indicate the balances in the three stockholders equity accounts afte.pdfnijamabdulkarim
 
ind let Y denote the number of defective tires. (b) Compute P(X1 and .pdf
 ind let Y denote the number of defective tires. (b) Compute P(X1 and .pdf ind let Y denote the number of defective tires. (b) Compute P(X1 and .pdf
ind let Y denote the number of defective tires. (b) Compute P(X1 and .pdfnijamabdulkarim
 
In which of these circumstances is it advisable to use a POST request.pdf
 In which of these circumstances is it advisable to use a POST request.pdf In which of these circumstances is it advisable to use a POST request.pdf
In which of these circumstances is it advisable to use a POST request.pdfnijamabdulkarim
 
In development of an embryonic axis of Drosophila, segregation of cyt.pdf
 In development of an embryonic axis of Drosophila, segregation of cyt.pdf In development of an embryonic axis of Drosophila, segregation of cyt.pdf
In development of an embryonic axis of Drosophila, segregation of cyt.pdfnijamabdulkarim
 

More from nijamabdulkarim (20)

In the context of an IDS, we define a false positive to be an alarm g.pdf
 In the context of an IDS, we define a false positive to be an alarm g.pdf In the context of an IDS, we define a false positive to be an alarm g.pdf
In the context of an IDS, we define a false positive to be an alarm g.pdf
 
In the above figure, which point represents an attain.pdf
 In the above figure, which point represents an attain.pdf In the above figure, which point represents an attain.pdf
In the above figure, which point represents an attain.pdf
 
In the 01 knapsack recurrence formula f(x,1)=max[v1+fxw1,1,f[x,1]] Th.pdf
 In the 01 knapsack recurrence formula f(x,1)=max[v1+fxw1,1,f[x,1]] Th.pdf In the 01 knapsack recurrence formula f(x,1)=max[v1+fxw1,1,f[x,1]] Th.pdf
In the 01 knapsack recurrence formula f(x,1)=max[v1+fxw1,1,f[x,1]] Th.pdf
 
in minimum. 350 words the course is intercultural commun.pdf
 in minimum. 350 words  the course is intercultural commun.pdf in minimum. 350 words  the course is intercultural commun.pdf
in minimum. 350 words the course is intercultural commun.pdf
 
In San Fernando the dry season is between February to July November t.pdf
 In San Fernando the dry season is between February to July November t.pdf In San Fernando the dry season is between February to July November t.pdf
In San Fernando the dry season is between February to July November t.pdf
 
In its first year of operations Matthew Doe Products paid for the fol.pdf
 In its first year of operations Matthew Doe Products paid for the fol.pdf In its first year of operations Matthew Doe Products paid for the fol.pdf
In its first year of operations Matthew Doe Products paid for the fol.pdf
 
In order to identify genetic factors affecting susceptibility to lepr.pdf
 In order to identify genetic factors affecting susceptibility to lepr.pdf In order to identify genetic factors affecting susceptibility to lepr.pdf
In order to identify genetic factors affecting susceptibility to lepr.pdf
 
In rare cases, as a goologist you might encounter a sedimentary depos.pdf
 In rare cases, as a goologist you might encounter a sedimentary depos.pdf In rare cases, as a goologist you might encounter a sedimentary depos.pdf
In rare cases, as a goologist you might encounter a sedimentary depos.pdf
 
In order to identify genetic factors affecting susceptibiity to lepro.pdf
 In order to identify genetic factors affecting susceptibiity to lepro.pdf In order to identify genetic factors affecting susceptibiity to lepro.pdf
In order to identify genetic factors affecting susceptibiity to lepro.pdf
 
In ecology, the number of people, other living organisms, or crops th.pdf
 In ecology, the number of people, other living organisms, or crops th.pdf In ecology, the number of people, other living organisms, or crops th.pdf
In ecology, the number of people, other living organisms, or crops th.pdf
 
Inflation and the Quantity Theory of Money End of Chapter Problem 14.pdf
 Inflation and the Quantity Theory of Money End of Chapter Problem 14.pdf Inflation and the Quantity Theory of Money End of Chapter Problem 14.pdf
Inflation and the Quantity Theory of Money End of Chapter Problem 14.pdf
 
Individuals with Swyers Syndrome (XYSRY)tend to not develop gonads. .pdf
 Individuals with Swyers Syndrome (XYSRY)tend to not develop gonads. .pdf Individuals with Swyers Syndrome (XYSRY)tend to not develop gonads. .pdf
Individuals with Swyers Syndrome (XYSRY)tend to not develop gonads. .pdf
 
Indicate whether the following items are Included in or Excluded f.pdf
 Indicate whether the following items are Included in or Excluded f.pdf Indicate whether the following items are Included in or Excluded f.pdf
Indicate whether the following items are Included in or Excluded f.pdf
 
Indicate whether the items described below are inputs (I), outputs (O.pdf
 Indicate whether the items described below are inputs (I), outputs (O.pdf Indicate whether the items described below are inputs (I), outputs (O.pdf
Indicate whether the items described below are inputs (I), outputs (O.pdf
 
Indicate whether each of the following statements is true or false. C.pdf
 Indicate whether each of the following statements is true or false. C.pdf Indicate whether each of the following statements is true or false. C.pdf
Indicate whether each of the following statements is true or false. C.pdf
 
Indigo The grandmother hypothesis speculates that women raise their .pdf
 Indigo The grandmother hypothesis speculates that women raise their .pdf Indigo The grandmother hypothesis speculates that women raise their .pdf
Indigo The grandmother hypothesis speculates that women raise their .pdf
 
Indicate the balances in the three stockholders equity accounts afte.pdf
 Indicate the balances in the three stockholders equity accounts afte.pdf Indicate the balances in the three stockholders equity accounts afte.pdf
Indicate the balances in the three stockholders equity accounts afte.pdf
 
ind let Y denote the number of defective tires. (b) Compute P(X1 and .pdf
 ind let Y denote the number of defective tires. (b) Compute P(X1 and .pdf ind let Y denote the number of defective tires. (b) Compute P(X1 and .pdf
ind let Y denote the number of defective tires. (b) Compute P(X1 and .pdf
 
In which of these circumstances is it advisable to use a POST request.pdf
 In which of these circumstances is it advisable to use a POST request.pdf In which of these circumstances is it advisable to use a POST request.pdf
In which of these circumstances is it advisable to use a POST request.pdf
 
In development of an embryonic axis of Drosophila, segregation of cyt.pdf
 In development of an embryonic axis of Drosophila, segregation of cyt.pdf In development of an embryonic axis of Drosophila, segregation of cyt.pdf
In development of an embryonic axis of Drosophila, segregation of cyt.pdf
 

Recently uploaded

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 

Recently uploaded (20)

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 

Build an SPL Parser (SPLParser

  • 1. In this programming assignment, you will be building a parser for the Simple Perl-Like (SPL) programming language. The syntax definitions of SPL programming language are given below using EBNF notations. Your implementation of a parser to the language is based on the following grammar rules specified in EBNF notations. 1. Prog ::= StmtList 2. Stmtlist ::= Stmt ;{ Stmt; } 3. Stmt ::= AssignStme| Writelnstmt Ifstmt 4. WritelnStmt ::= writeln (ExprList) 5. IfStmt : := if (Expr) ' f ' StmtList ' } ' [ else ' { 'StmtList ' } ' ] 6. Assignstmt ::=Var=Expr 7. Var ::= NIDENT | SIDENT 8. Exprlist ::=Expr{,Expr} 9. Expr ::= RelExpr [( eq ==) RelExpr ] 10. Relexpr : := AddExpr [ ( -lt gt<1>) AddExpr ] 11. AddExpr :: Multexpr {(+11. ) MultExpr } 12. Multexpr : := ExponExpr {(/) ExponExpr } 13. ExponExpr : := UnaryExpr { UnaryExpr } 14. Unaryexpr ::=[(1+)] PrimaryExpr 15. PrimaryExpr ::= IDENT | SIDENT | NIDENT | ICONST | RCONST | SCONST (Expr) The following points describe the SPL programming language. Note that not all of these points will be addressed in this assignment. However, they are listed in order to give you an understanding of the language semantics and what to be considered for implementing an interpreter for the language in Programming Assignment 3. These points are: Table of Operators Precedence Levels 1. The language has two types: Numeric, and String. 2. The SPL language does not have explicit declaration statements. However, variables are implicitly declared as Numeric type by a variable name starting with "$", or as String type by a variable name starting with "@". 3. All SPL variables must first be initialized by an assignment statement before being used. 4. The precedence rules of operators in the language are as shown in the table of operators' precedence levels. 5. The PLUS, MINUS, MULT, DIV, CAT, and SREPEAT operators are left associative. 6. An IfStmt evaluates a logical expression (Expr) as a condition. If the logical condition value is true, then the StmtList in the If-clause are executed, otherwise they are not. An else clause for an IfSmt is optional. Therefore, If an Else-clause is defined, the StmtList in the Else-clause are executed when the logical condition value is false. 7. A WritelnStmt evaluates the list of expressions (ExprList), and prints their values in order from left to right followed by a newline. 8. The ASSOP operator (=) in the AssignStmt assigns a value to a variable. It evaluates the Expr on the right-hand side and saves its value in a memory location associated with the left-hand side variable (Var). A left-hand side variable of a Numeric type must be assigned a numeric value. While a left-hand side variable of a String type must be assigned a string value. Type conversion must be automatically applied if the right-hand side value of the evaluated expression does not match the type of the left-hand side variable. 9. The binary operations of numeric operators as addition, subtraction, multiplication, and division are performed upon two numeric operands. While the binary string operator for concatenation is performed upon two string operands. If one of the operands does not match the type of the
  • 2. operator, that operand is automatically converted to the type of the operator. 10. Similarly, numeric relational and equality operators (=,<, and > ) operate upon two numeric type operands. While, string relational and equality operators (-eq, -lt, -gt) operate upon two string type operands. The evaluation of a relational or an equality expression, produces either a true or false value. If one of the operands does not match the type of the operator, that operand is automatically converted to the type of the operator. For all relational and equality operators, no cascading is allowed. 11. The exponent operator is applied on a numeric type operand, and the exponent value must be a numeric type value. No automatic conversion to numeric type operand is applied in case of an expression with exponent operator. Note that, exponent operators follow right-to-left association. 12. The binary operation for string repetition () operates upon a string operand as the first operand, where the second operand must be a numeric expression of integer value. 13. The unary sign operators (+ or -) are applied upon unary numeric type operands only. 14. It is an error to use a variable in an expression before it has been assigned. Parser Requirements: Implement a recursive-descent parser for the given language. You may use the lexical analyzer you wrote for Programming Assignment 1, OR you may use the provided implementation when it is posted. The parser should provide the following: - The results of an unsuccessful parsing are a set of error messages printed by the parser functions, as well as the error messages that might be detected by the lexical analyzer. - If the parser fails, the program should stop after the parser function returns. - The assignment does not specify the exact error messages that should be printed out by the parser; however, the format of the messages should be the line number, followed by a colon and a space, followed by some descriptive text. Suggested messages might include "Missing semicolon at end of Statement.", "Incorrect Declaration Statement.", "Missing Right Parenthesis", "Undefined Variable", "Missing END", etc. - If the scanning of the input file is completed with no detected errors, the parser should display the message (DONE) on a new line before returning successfully to the caller program. Provided Files You are given the header file for the parser, "parser.h" and an incomplete file for the "parser.cnp", You should use "parser.cpp" to complete the implementation of the parser. In addition, "lex.h", "lex.cpp", and "prog2.cpp" files are also provided. The descriptions of the files are as follows: "Parser.h" "parser.h" includes the following: - Prototype definitions of the parser functions (e.g., Prog, StmtList, Stmt, etc.) "Parser.cpp" - A map container that keeps a record of the defined variables in the parsed program, defined as: map defvar; - The key of the defvar is a variable name, and the value is a Boolean that is set to true when the first time the variable has been initialized, otherwise it is false. - A function definition for handling the display of error messages, called ParserError. - Functions to handle the process of token lookahead, GetNextToken and
  • 3. PushBackToken, defined in a namespace domain called Parser. - Static int variable for counting errors, called error_count, and a function to return its value, called ErrCount (). - Implementations of some functions of the recursive-descent parser. "prog2.cpp" - You are given the testing program "prog2.cpp" that reads a file name from the command line. The file is opened for syntax analysis, as a source code for your parser. - A call to Prog( function is made. If the call fails, the program should stop and display a message as "Unsuccessful Parsing ", and display the number of errors detected. For example: Unsuccessful Parsing Number of Syntax Errors: 3 - If the call to Prog0 function succeeds, the program should stop and display the message "Successful Parsing ", and the program stops. Vocareum Automatic Grading - You are provided by a set of 19 testing files associated with Programming Assignment 2. Vocareum automatic grading will be based on these testing files. You may use them to check and test your implementation. These are available in compressed archive as "PA 2 Test Cases.zip" on Canvas assignment. The testing case of each file is defined in the Grading table below. - The automatic grading of a clean source code file will be based on checking against the output message: (DONE) Successful Parsing - In each of the other testing files, there is one syntactic error at a specific line. The automatic grading process will be based on the statement number at which this error has been found and the number of associated error messages with this syntactic error. - You can use whatever error message you like. There is no check against the contents of the error messages. - A check of the number of errors your parser has produced and the number of errors printed out by the program are made. Submission Guidelines - Submit your "parse.cpp" implementation through Vocareum. The "lex.h", "parser.h", "lex.cpp" and "prog2.cpp" files will be propagated to your Work Directory. Grading Table