Description
The file attached has the instructions, let me know if you have questions. Thank you for your time and effort.
There is only one file attached:
lab4_IntroToPython.docx
Unformatted Attachment Preview
[IFT 383] Shell & Script Programming with Unix
LAB ACTIVITY: INTRO TO PYTHON
Directions
1) Your programs must be save in a file with extension .py so they can be run from the
command line as: python youfile.py
2) For every program, you must first develop an algorithm.
3) Your output should be formatted exactly as the sample runs provided, including the
precisions for decimal numbers.
Introduction
This is the introductory part and doesn’t use control structure, functions, or files I/O.
The learning objectives are twofold:
1) Develop proper algorithm for solving a given program. The instructions in the
algorithm will serve as comments in your program
2) Turn the algorithm into code
Activities
Part 1: Minimum Number of Coins
Suppose you want to develop a program that classifies a given amount of money
into smaller monetary units. The program lets the user enter an amount as a
floating-point value representing a total dollars and cents, and then outputs a
report listing the monetary equivalent in dollars, quarters, dimes, nickels, and
pennies.
Your program should report the maximum number of dollars, then the number of
quarters, dimes, nickels, and pennies, in this order, to result in the minimum
number of coins.
Sample Run
Enter an amount, for example, 11.56: 11.56
Your amount 11.56 consists of:
11 dollars
2 quarters
0 dimes
1 nickels
1 pennies
Page | 1
[IFT 383] Shell & Script Programming with Unix
Part 2: Displaying the current time
The problem is to develop a program that displays the current time in Greenwich
Mean Time (GMT) in the format hour:minute:second, such as 13:19:18
The time() function in the time module returns the current time in seconds with
millisecond precision elapsed since the time 00:00:00 on January 1, 1970 GMT.
This time is known as the UNIX epoch. The epoch is the point when time starts.
1970 was the year when UNIX operating system was formally introduced. For
example, time.time() returns 1285543663.205, which means 1285543663
seconds and 205 milliseconds.
You can use this function (the time() function in the time module) to obtain the
current time, and then compute the current second, minute, and hour.
Sample Run:
Current time is 17:31:8 GMT
Part 3: Computing Distances
Given two points, the formula for computing the distance is
√(𝑥2 − 𝑥1 )2 + (𝑦2 − 𝑦1 )2
Write a program that prompts the user to enter two points and computes the distance
between them. Note that each point is characterized by two float values, representing
the x-axis and y-axis.
Sample Run
Enter x1 and y1 for Point 1: 1.5, -3.4
Enter x2 and y2 for Point 2: 4, 5
The distance between (1.5, -3.4) and (4, 5) is 8.8
Submissions
Submit all the required files through Blackboard.
You are to submit two (2) files:
(1) A zip file of your 3 .py files
(2) This document with your test run incorporated.
Note that the comments (which result from writing an algorithm first) are a major part
of the grading criteria.
Page | 2
Purchase answer to see full attachment
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Explanation & Answer
The scripts are written. I am uploading zip file with thre...
Completion Status:
100%
Review
Review
Anonymous
Excellent! Definitely coming back for more study materials.
Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Most Popular Content
CTU Public Awareness Campaign to Prevent High School Dropout Discussion
Goals and ObjectivesFor two of the needs you identified in your first assignment, develop a set of two goals and objective ...
CTU Public Awareness Campaign to Prevent High School Dropout Discussion
Goals and ObjectivesFor two of the needs you identified in your first assignment, develop a set of two goals and objectives, using the example provided in Table 7.3 on page 114 of your Designing and Managing Programs textbook.Pg 114The Formulation of ObjectivesIn effectiveness-based program planning, one should be able to make explicit two things about a program: (1) the results that are to be achieved and (2) the manner in which these results will be achieved. The specification of results is a statement of the ends or expectations of the program. In the program-planning literature, these ends are referred to as outcome objectives (Brody, 2005; Coley & Scheinberg, 2000; Poertner, 2000). The specification of service provision is an articulation of the means that will be used to achieve the ends, and these are referred to as process objectives. Finally, under process objectives, we find listings of specific activities that represent a further breakdown or refinement of the details of program implementation.This approach further supports the logic model as presented in Chapter 1 and as illustrated in Figure 7.3. Outcome objectives identify and define expected program outcomes. Process objectives and activities work together to define the process of service provision to the client. Outputs become measures of processes and activities invested in the program.Figure 7.3 Logic Model as Applied to Process and Outcome ObjectivesThroughout the literature, a variety of terms are used by planners to distinguish these three different levels, including strategies, milestones, operational objectives, and program objectives. In the following discussion, we will use the program-planning terms outcome objectives, process objectives, and activities. The hierarchy is similar to that depicted i
CMSC 430 Project 2
Could someone help me fix the code below in cgywin64 to correct the errors in bold at the bottom Below is the description ...
CMSC 430 Project 2
Could someone help me fix the code below in cgywin64 to correct the errors in bold at the bottom Below is the description of the question, followed by the codes, and the errors in bold. Thank you so much for the help. Please modify the given code instead of making a new one.Description:The question involves modifying the syntactic analyzer for the attached compiler by adding to the existing grammar. The full grammar of the language is shown below. The highlighted portions of the grammar show what you must either modify or add to the existing grammar.function: function_header {variable} body function_header: FUNCTION IDENTIFIER [parameters] RETURNS type ; variable: IDENTIFIER : type IS statement parameters: parameter {, parameter} parameter: IDENTIFIER : type type: INTEGER | REAL | BOOLEAN body: BEGIN statement END ; statement: expression ; | REDUCE operator {statement} ENDREDUCE ; | IF expression THEN statement ELSE statement ENDIF ; | CASE expression IS {case} OTHERS ARROW statement ENDCASE ; operator: ADDOP | MULOP case: WHEN INT_LITERAL ARROW statement expression: ( expression ) | expression binary_operator expression | NOTOP expression | INT_LITERAL | REAL_LITERAL | BOOL_LITERAL | IDENTIFIER binary_operator: ADDOP | MULOP | REMOP | EXPOP | RELOP | ANDOP |OROPIn the above grammar, the red symbols are nonterminals, the blue symbols are terminals and the black punctuation are EBNF metasymbols. The braces denote repetition 0 or more times and the brackets denote optional. You must rewrite the grammar to eliminate the EBNF brace and bracket metasymbols and to incorporate the significance of parentheses, operator precedence and associativity for all operators. Among arithmetic operators the exponentiation operator has highest precedence following by the multiplying operators and then the adding operators. All relational operators have the same precedence. Among the binary logical operators, and has higher precedence than or. Of the categories of operators, the unary logical operator has highest precedence, the arithmetic operators have next highest precedence, followed by the relational operators and finally the binary logical operators. All operators except the exponentiation operator are left associative. The directives to specify precedence and associativity, such as %prec and %left, may not be used Your parser should be able to correctly parse any syntactically correct program without any problem. You must modify the syntactic analyzer to detect and recover from additional syntax errors using the semicolon as the synchronization token. To accomplish detecting additional errors an error production must be added to the function header, another to the variable declaration and a final one to the when clause of the case statement. Your bison input file should not produce any shift/reduce or reduce/reduce errors. Eliminating them can be difficult so the best strategy is not introduce any. That is best achieved by making small incremental additions to the grammar and ensuring that no addition introduces any such errors. An example of compilation listing output containing syntax errors is shown below: 1 -- Multiple errors 2 3 function main a integer returns real; Syntax Error, Unexpected INTEGER, expecting ':' 4 b: integer is * 2; Syntax Error, Unexpected MULOP 5 c: real is 6.0; 6 begin 7 if a > c then 8 b 3.0; Syntax Error, Unexpected REAL_LITERAL, expecting ';' 9 else 10 b = 4.; 11 endif; 12 ; Syntax Error, Unexpected ';', expecting END Lexical Errors 0 Syntax Errors 4 Semantic Errors 0 listing.cc:// This file contains the bodies of the functions that produces the compilation// listing#include <cstdio>#include <string>using namespace std;#include "listing.h"static int lineNumber;static string error = "";static int totalErrors = 0;static void displayErrors();void firstLine(){lineNumber = 1;printf("\n%4d ",lineNumber);}void nextLine(){displayErrors();lineNumber++;printf("%4d ",lineNumber);}int lastLine(){printf("\r");displayErrors();printf(" \n");return totalErrors;} void appendError(ErrorCategories errorCategory, string message){string messages[] = { "Lexical Error, Invalid Character ", "", "Semantic Error, ", "Semantic Error, Duplicate Identifier: ", "Semantic Error, Undeclared " };error = messages[errorCategory] + message;totalErrors++;}void displayErrors(){if (error != "") printf("%s\n", error.c_str());error = "";}listing.h:// This file contains the function prototypes for the functions that produce the // compilation listingenum ErrorCategories {LEXICAL, SYNTAX, GENERAL_SEMANTIC, DUPLICATE_IDENTIFIER,UNDECLARED};void firstLine();void nextLine();int lastLine();void appendError(ErrorCategories errorCategory, string message);makefile:compile: scanner.o parser.o listing.og++ -o compile scanner.o parser.o listing.oscanner.o: scanner.c listing.h tokens.hg++ -c scanner.cscanner.c: scanner.lflex scanner.lmv lex.yy.c scanner.cparser.o: parser.c listing.h g++ -c parser.cparser.c tokens.h: parser.ybison -d -v parser.ymv parser.tab.c parser.ccp parser.tab.h tokens.hlisting.o: listing.cc listing.hg++ -c listing.ccparser.y:%{#include <string>using namespace std;#include "listing.h"int yylex();void yyerror(const char* message);%}%define parse.error verbose%token IDENTIFIER%token INT_LITERAL%token REAL_LITERAL%token BOOL_LITERAL%token ADDOP MULOP RELOP OROP ANDOP EXPOP REMOP%token BEGIN_ BOOLEAN END ENDREDUCE FUNCTION INTEGER IS REDUCE RETURNS CASE ELSE ARROW%token ENDCASE ENDIF IF OTHERS REAL THEN WHEN NOT%%function:function_header different_parameter body ;function_header:FUNCTION IDENTIFIER diff_parameter RETURNS type ';' ;different_parameter:different_parameter variable |;variable:IDENTIFIER ':' type IS statement_ ;diff_parameter:diff_parameter RETURNS type ',' |parameter ;parameter:IDENTIFIER ':' type |;type: INTEGER | REAL | BOOLEAN ;body:BEGIN_ statement_ END ';' ;statement_:statement ';' |error ';' ;statement:expression |REDUCE operator reductions ENDREDUCE |IF expression THEN statement_ ELSE statement_ ENDIF |CASE expression IS various_cases OTHERS ARROW statement_ ENDCASE ;reductions:reductions statement_ |;various_cases:various_cases case |;case: WHEN INT_LITERAL ARROW statement_ ;operator:ADDOP |MULOP | REMOP |EXPOP ;expression:expression ANDOP relation |expression2;expression2:expression OROP relation |relation;relation:relation RELOP term |term;term:term ADDOP factor |factor ;factor:factor MULOP primary |factor REMOP |exponent ;exponent:factor EXPOP notion |notion;notion:notion NOT primary |primary;primary:'(' expression ')' |INT_LITERAL | REAL_LITERAL | BOOL_LITERAL |IDENTIFIER ;%%void yyerror(const char* message){appendError(SYNTAX, message);}int main(int argc, char *argv[]){firstLine();yyparse();lastLine();return 0;}scanner.l:/* This file contains flex input file */%{#include <cstdio>#include <string>using namespace std;#include "listing.h"#include "tokens.h"%}%option noyywrapws [ \t\r]+comment ("//"|"--").*\nid [A-Za-z](_?[A-Za-z0-9])*real {digit}+\.{digit}*([Ee][+-]?{digit}+)?line [\n]digit [0-9]int {digit}+punc [\(\),:;]%%{ws} { ECHO; }{comment} { ECHO; nextLine();}{line} { ECHO; nextLine();}"+" { ECHO; return(ADDOP); }"*" { ECHO; return(MULOP); }"=>" { ECHO; return(ARROW); }"<" { ECHO; return(RELOP); }"=" { ECHO; return(RELOP); }"/=" { ECHO; return(RELOP); }">" { ECHO; return(RELOP); }">=" { ECHO; return(RELOP); }"<=" { ECHO; return(RELOP); }"-" { ECHO; return(ADDOP); }"/" { ECHO; return(MULOP); }"**" { ECHO; return(EXPOP); }"." { ECHO; return(MULOP); }rem { ECHO; return(REMOP); }or { ECHO; return(OROP); }not { ECHO; return(NOTOP); }case { ECHO; return(CASE); }else { ECHO; return(ELSE); }endcase { ECHO; return(ENDCASE); }others { ECHO; return(OTHERS); }endif { ECHO; return(ENDIF); }if { ECHO; return(IF); }real { ECHO; return(REAL); }then { ECHO; return(THEN); }when { ECHO; return(WHEN); }begin { ECHO; return(BEGIN_); }boolean { ECHO; return(BOOLEAN); }end { ECHO; return(END); }endreduce { ECHO; return(ENDREDUCE); }function { ECHO; return(FUNCTION); }integer { ECHO; return(INTEGER); }is { ECHO; return(IS); }reduce { ECHO; return (REDUCE); }returns { ECHO; return(RETURNS); }and { ECHO; return(ANDOP); }true { ECHO; return(BOOL_LITERAL); }false { ECHO; return(BOOL_LITERAL); }{id} { ECHO; return(IDENTIFIER);}{real} {ECHO; return(REAL_LITERAL);}{int} { ECHO; return(INT_LITERAL); }{punc} { ECHO; return(yytext[0]); }. { ECHO; appendError(LEXICAL, yytext); }%%tokens.h:/* A Bison parser, made by GNU Bison 3.8.2. *//* Bison interface for Yacc-like parsers in C Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *//* As a special exception, you may make a larger work that contains part or all of the Bison parser skeleton and distribute that work under terms of your choice, so long as that work isn't itself a parser generator using the skeleton or a modified version thereof as a parser skeleton. Alternatively, if you modify or redistribute the parser skeleton itself, you may (at your option) remove this special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. This special exception was added by the Free Software Foundation in version 2.2 of Bison. *//* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, especially those whose name start with YY_ or yy_. They are private implementation details that can be changed or removed. */#ifndef YY_YY_PARSER_TAB_H_INCLUDED# define YY_YY_PARSER_TAB_H_INCLUDED/* Debug traces. */#ifndef YYDEBUG# define YYDEBUG 0#endif#if YYDEBUGextern int yydebug;#endif/* Token kinds. */#ifndef YYTOKENTYPE# define YYTOKENTYPE enum yytokentype { YYEMPTY = -2, YYEOF = 0, /* "end of file" */ YYerror = 256, /* error */ YYUNDEF = 257, /* "invalid token" */ IDENTIFIER = 258, /* IDENTIFIER */ INT_LITERAL = 259, /* INT_LITERAL */ REAL_LITERAL = 260, /* REAL_LITERAL */ BOOL_LITERAL = 261, /* BOOL_LITERAL */ ADDOP = 262, /* ADDOP */ MULOP = 263, /* MULOP */ RELOP = 264, /* RELOP */ OROP = 265, /* OROP */ ANDOP = 266, /* ANDOP */ EXPOP = 267, /* EXPOP */ REMOP = 268, /* REMOP */ BEGIN_ = 269, /* BEGIN_ */ BOOLEAN = 270, /* BOOLEAN */ END = 271, /* END */ ENDREDUCE = 272, /* ENDREDUCE */ FUNCTION = 273, /* FUNCTION */ INTEGER = 274, /* INTEGER */ IS = 275, /* IS */ REDUCE = 276, /* REDUCE */ RETURNS = 277, /* RETURNS */ CASE = 278, /* CASE */ ELSE = 279, /* ELSE */ ARROW = 280, /* ARROW */ ENDCASE = 281, /* ENDCASE */ ENDIF = 282, /* ENDIF */ IF = 283, /* IF */ OTHERS = 284, /* OTHERS */ REAL = 285, /* REAL */ THEN = 286, /* THEN */ WHEN = 287, /* WHEN */ NOT = 288, /* NOT */ NOTOP = 289 }; typedef enum yytokentype yytoken_kind_t;#endif/* Value type. */#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLAREDtypedef int YYSTYPE;# define YYSTYPE_IS_TRIVIAL 1# define YYSTYPE_IS_DECLARED 1#endifextern YYSTYPE yylval;int yyparse (void);#endif /* !YY_YY_PARSER_TAB_H_INCLUDED */ This production is not correct:function: function_header different_parameter body ;What is the diferent_parameter there for? Parameters are inside the function header not after it.Also this one does not look right:diff_parameter:diff_parameter RETURNS type ',' |parameter ;Professors notes: The RETURNS is already in function header. It should not be part of the parameter production.What you need is something like this:function_header: FUNCTION IDENTIFIER optional_parameters RETURNS type ;Then you need a production for optional_parameters that has two RHSs. One is empty, the other another nonterminal, call it parameters, for example.Then the parameters production must have a recursive RHS that separates parameters by a comma and a non-recursive RHS that defines a single parameter.The only other thing is see that obviously looks wrong is you production for not. Not is a unary operator. It should only have one operand.I have attached the Project Requirements, the Project Approach and the test cases. Please make sure that all the test cases work and match the Project Approach.
Murach's Visual Basic 2015 Extra Exercise 18-1
Read Chapters 17 & 18 in Murach's Visual Basic 2015Complete extra exercise 18-1. Starter project and instructions here: We ...
Murach's Visual Basic 2015 Extra Exercise 18-1
Read Chapters 17 & 18 in Murach's Visual Basic 2015Complete extra exercise 18-1. Starter project and instructions here: Week 5 Assignment.zip.
19 pages
Iris Dataset R Final Project
The Use of regression and graphical techniques to classify the Iris species The Use of regression and graphical techniques ...
Iris Dataset R Final Project
The Use of regression and graphical techniques to classify the Iris species The Use of regression and graphical techniques to classify the Iris ...
15 pages
Public Key Encryption
Cryptography is a technique that has existed since the Roman Empire; it entailed concealing the information sent so that u ...
Public Key Encryption
Cryptography is a technique that has existed since the Roman Empire; it entailed concealing the information sent so that unintended individuals cannot ...
Data Flow Diagram Project
Using the Microsoft Word document created in W4 Project, add to it by including the following:
Now that you have created u ...
Data Flow Diagram Project
Using the Microsoft Word document created in W4 Project, add to it by including the following:
Now that you have created use-case models for your system, you will continue your system design by completing your class diagram and applying behavioral diagrams.
Extend your class diagram by including associations, indicating the object role and multiplicity on each end of your associations. Add any new classes, attributes, or operations that you may not have considered in your Week 4 diagram.
Develop sequence diagrams for two use-case scenarios from your W4 Project.
Justify any assumptions on some of the messages passed between objects.
Clearly indicate what objects are involved in each diagram.
Develop activity diagrams for your two use-case scenarios.
Develop a state diagram for at least one of your use-case scenarios above.
Similar Content
ITCS 214 Harvard Find the Sequence of Vertices in The Graph Data Structure Test MCQs
the test is on 5/1/2021 at 11:30-13:30 GMT+3there will be 3 programs writing and 10 MCQ'sSingle Linked ListDouble Linked L...
CSC 00240 Southern Cross University Network Design Modern Software Company Paper
Hello, I have attached a file below include all detail I know for now. I will make sure to check with you always after you...
Course Project: Part 4—Completing the Web Pages, computer science homework help
Course Project: Part 4—Completing the Web Pages Continuing with your course project, this week, complete the following ...
what ie Cehalus' opinion of the advantages of old age and wealth?
According to the question, write a 3-page article, you don't have to do citation.According to the question, write a 3-page...
Homework assignment
There are three parts to the Homework.please keep it simple. No need for //comments. just the code is fine.Please submit e...
MIS 301 Florida International University Programming Questions
Grader - Instructions
Access 2016 Project
MIS 301 - Access Test
Project Description:
Flyer University (FlyerU) uses a MS...
Related Tags
Book Guides
Persuasion
by Jane Austen
Cry the Beloved Country
by Alan Paton
I Cant Make This Up - Life Lessons
by Kevin Hart
Girl Stop Apologizing
by Rachel Hollis
The Lost Man
by Jane Harper
Faust
by Johann Wolfgang von Goethe
The Adventures of Huckleberry Finn
by Mark Twain
A Farewell To Arms
by Ernest Hemingway
Oliver Twist
by Charles Dickens
Get 24/7
Homework help
Our tutors provide high quality explanations & answers.
Post question
Most Popular Content
CTU Public Awareness Campaign to Prevent High School Dropout Discussion
Goals and ObjectivesFor two of the needs you identified in your first assignment, develop a set of two goals and objective ...
CTU Public Awareness Campaign to Prevent High School Dropout Discussion
Goals and ObjectivesFor two of the needs you identified in your first assignment, develop a set of two goals and objectives, using the example provided in Table 7.3 on page 114 of your Designing and Managing Programs textbook.Pg 114The Formulation of ObjectivesIn effectiveness-based program planning, one should be able to make explicit two things about a program: (1) the results that are to be achieved and (2) the manner in which these results will be achieved. The specification of results is a statement of the ends or expectations of the program. In the program-planning literature, these ends are referred to as outcome objectives (Brody, 2005; Coley & Scheinberg, 2000; Poertner, 2000). The specification of service provision is an articulation of the means that will be used to achieve the ends, and these are referred to as process objectives. Finally, under process objectives, we find listings of specific activities that represent a further breakdown or refinement of the details of program implementation.This approach further supports the logic model as presented in Chapter 1 and as illustrated in Figure 7.3. Outcome objectives identify and define expected program outcomes. Process objectives and activities work together to define the process of service provision to the client. Outputs become measures of processes and activities invested in the program.Figure 7.3 Logic Model as Applied to Process and Outcome ObjectivesThroughout the literature, a variety of terms are used by planners to distinguish these three different levels, including strategies, milestones, operational objectives, and program objectives. In the following discussion, we will use the program-planning terms outcome objectives, process objectives, and activities. The hierarchy is similar to that depicted i
CMSC 430 Project 2
Could someone help me fix the code below in cgywin64 to correct the errors in bold at the bottom Below is the description ...
CMSC 430 Project 2
Could someone help me fix the code below in cgywin64 to correct the errors in bold at the bottom Below is the description of the question, followed by the codes, and the errors in bold. Thank you so much for the help. Please modify the given code instead of making a new one.Description:The question involves modifying the syntactic analyzer for the attached compiler by adding to the existing grammar. The full grammar of the language is shown below. The highlighted portions of the grammar show what you must either modify or add to the existing grammar.function: function_header {variable} body function_header: FUNCTION IDENTIFIER [parameters] RETURNS type ; variable: IDENTIFIER : type IS statement parameters: parameter {, parameter} parameter: IDENTIFIER : type type: INTEGER | REAL | BOOLEAN body: BEGIN statement END ; statement: expression ; | REDUCE operator {statement} ENDREDUCE ; | IF expression THEN statement ELSE statement ENDIF ; | CASE expression IS {case} OTHERS ARROW statement ENDCASE ; operator: ADDOP | MULOP case: WHEN INT_LITERAL ARROW statement expression: ( expression ) | expression binary_operator expression | NOTOP expression | INT_LITERAL | REAL_LITERAL | BOOL_LITERAL | IDENTIFIER binary_operator: ADDOP | MULOP | REMOP | EXPOP | RELOP | ANDOP |OROPIn the above grammar, the red symbols are nonterminals, the blue symbols are terminals and the black punctuation are EBNF metasymbols. The braces denote repetition 0 or more times and the brackets denote optional. You must rewrite the grammar to eliminate the EBNF brace and bracket metasymbols and to incorporate the significance of parentheses, operator precedence and associativity for all operators. Among arithmetic operators the exponentiation operator has highest precedence following by the multiplying operators and then the adding operators. All relational operators have the same precedence. Among the binary logical operators, and has higher precedence than or. Of the categories of operators, the unary logical operator has highest precedence, the arithmetic operators have next highest precedence, followed by the relational operators and finally the binary logical operators. All operators except the exponentiation operator are left associative. The directives to specify precedence and associativity, such as %prec and %left, may not be used Your parser should be able to correctly parse any syntactically correct program without any problem. You must modify the syntactic analyzer to detect and recover from additional syntax errors using the semicolon as the synchronization token. To accomplish detecting additional errors an error production must be added to the function header, another to the variable declaration and a final one to the when clause of the case statement. Your bison input file should not produce any shift/reduce or reduce/reduce errors. Eliminating them can be difficult so the best strategy is not introduce any. That is best achieved by making small incremental additions to the grammar and ensuring that no addition introduces any such errors. An example of compilation listing output containing syntax errors is shown below: 1 -- Multiple errors 2 3 function main a integer returns real; Syntax Error, Unexpected INTEGER, expecting ':' 4 b: integer is * 2; Syntax Error, Unexpected MULOP 5 c: real is 6.0; 6 begin 7 if a > c then 8 b 3.0; Syntax Error, Unexpected REAL_LITERAL, expecting ';' 9 else 10 b = 4.; 11 endif; 12 ; Syntax Error, Unexpected ';', expecting END Lexical Errors 0 Syntax Errors 4 Semantic Errors 0 listing.cc:// This file contains the bodies of the functions that produces the compilation// listing#include <cstdio>#include <string>using namespace std;#include "listing.h"static int lineNumber;static string error = "";static int totalErrors = 0;static void displayErrors();void firstLine(){lineNumber = 1;printf("\n%4d ",lineNumber);}void nextLine(){displayErrors();lineNumber++;printf("%4d ",lineNumber);}int lastLine(){printf("\r");displayErrors();printf(" \n");return totalErrors;} void appendError(ErrorCategories errorCategory, string message){string messages[] = { "Lexical Error, Invalid Character ", "", "Semantic Error, ", "Semantic Error, Duplicate Identifier: ", "Semantic Error, Undeclared " };error = messages[errorCategory] + message;totalErrors++;}void displayErrors(){if (error != "") printf("%s\n", error.c_str());error = "";}listing.h:// This file contains the function prototypes for the functions that produce the // compilation listingenum ErrorCategories {LEXICAL, SYNTAX, GENERAL_SEMANTIC, DUPLICATE_IDENTIFIER,UNDECLARED};void firstLine();void nextLine();int lastLine();void appendError(ErrorCategories errorCategory, string message);makefile:compile: scanner.o parser.o listing.og++ -o compile scanner.o parser.o listing.oscanner.o: scanner.c listing.h tokens.hg++ -c scanner.cscanner.c: scanner.lflex scanner.lmv lex.yy.c scanner.cparser.o: parser.c listing.h g++ -c parser.cparser.c tokens.h: parser.ybison -d -v parser.ymv parser.tab.c parser.ccp parser.tab.h tokens.hlisting.o: listing.cc listing.hg++ -c listing.ccparser.y:%{#include <string>using namespace std;#include "listing.h"int yylex();void yyerror(const char* message);%}%define parse.error verbose%token IDENTIFIER%token INT_LITERAL%token REAL_LITERAL%token BOOL_LITERAL%token ADDOP MULOP RELOP OROP ANDOP EXPOP REMOP%token BEGIN_ BOOLEAN END ENDREDUCE FUNCTION INTEGER IS REDUCE RETURNS CASE ELSE ARROW%token ENDCASE ENDIF IF OTHERS REAL THEN WHEN NOT%%function:function_header different_parameter body ;function_header:FUNCTION IDENTIFIER diff_parameter RETURNS type ';' ;different_parameter:different_parameter variable |;variable:IDENTIFIER ':' type IS statement_ ;diff_parameter:diff_parameter RETURNS type ',' |parameter ;parameter:IDENTIFIER ':' type |;type: INTEGER | REAL | BOOLEAN ;body:BEGIN_ statement_ END ';' ;statement_:statement ';' |error ';' ;statement:expression |REDUCE operator reductions ENDREDUCE |IF expression THEN statement_ ELSE statement_ ENDIF |CASE expression IS various_cases OTHERS ARROW statement_ ENDCASE ;reductions:reductions statement_ |;various_cases:various_cases case |;case: WHEN INT_LITERAL ARROW statement_ ;operator:ADDOP |MULOP | REMOP |EXPOP ;expression:expression ANDOP relation |expression2;expression2:expression OROP relation |relation;relation:relation RELOP term |term;term:term ADDOP factor |factor ;factor:factor MULOP primary |factor REMOP |exponent ;exponent:factor EXPOP notion |notion;notion:notion NOT primary |primary;primary:'(' expression ')' |INT_LITERAL | REAL_LITERAL | BOOL_LITERAL |IDENTIFIER ;%%void yyerror(const char* message){appendError(SYNTAX, message);}int main(int argc, char *argv[]){firstLine();yyparse();lastLine();return 0;}scanner.l:/* This file contains flex input file */%{#include <cstdio>#include <string>using namespace std;#include "listing.h"#include "tokens.h"%}%option noyywrapws [ \t\r]+comment ("//"|"--").*\nid [A-Za-z](_?[A-Za-z0-9])*real {digit}+\.{digit}*([Ee][+-]?{digit}+)?line [\n]digit [0-9]int {digit}+punc [\(\),:;]%%{ws} { ECHO; }{comment} { ECHO; nextLine();}{line} { ECHO; nextLine();}"+" { ECHO; return(ADDOP); }"*" { ECHO; return(MULOP); }"=>" { ECHO; return(ARROW); }"<" { ECHO; return(RELOP); }"=" { ECHO; return(RELOP); }"/=" { ECHO; return(RELOP); }">" { ECHO; return(RELOP); }">=" { ECHO; return(RELOP); }"<=" { ECHO; return(RELOP); }"-" { ECHO; return(ADDOP); }"/" { ECHO; return(MULOP); }"**" { ECHO; return(EXPOP); }"." { ECHO; return(MULOP); }rem { ECHO; return(REMOP); }or { ECHO; return(OROP); }not { ECHO; return(NOTOP); }case { ECHO; return(CASE); }else { ECHO; return(ELSE); }endcase { ECHO; return(ENDCASE); }others { ECHO; return(OTHERS); }endif { ECHO; return(ENDIF); }if { ECHO; return(IF); }real { ECHO; return(REAL); }then { ECHO; return(THEN); }when { ECHO; return(WHEN); }begin { ECHO; return(BEGIN_); }boolean { ECHO; return(BOOLEAN); }end { ECHO; return(END); }endreduce { ECHO; return(ENDREDUCE); }function { ECHO; return(FUNCTION); }integer { ECHO; return(INTEGER); }is { ECHO; return(IS); }reduce { ECHO; return (REDUCE); }returns { ECHO; return(RETURNS); }and { ECHO; return(ANDOP); }true { ECHO; return(BOOL_LITERAL); }false { ECHO; return(BOOL_LITERAL); }{id} { ECHO; return(IDENTIFIER);}{real} {ECHO; return(REAL_LITERAL);}{int} { ECHO; return(INT_LITERAL); }{punc} { ECHO; return(yytext[0]); }. { ECHO; appendError(LEXICAL, yytext); }%%tokens.h:/* A Bison parser, made by GNU Bison 3.8.2. *//* Bison interface for Yacc-like parsers in C Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *//* As a special exception, you may make a larger work that contains part or all of the Bison parser skeleton and distribute that work under terms of your choice, so long as that work isn't itself a parser generator using the skeleton or a modified version thereof as a parser skeleton. Alternatively, if you modify or redistribute the parser skeleton itself, you may (at your option) remove this special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. This special exception was added by the Free Software Foundation in version 2.2 of Bison. *//* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, especially those whose name start with YY_ or yy_. They are private implementation details that can be changed or removed. */#ifndef YY_YY_PARSER_TAB_H_INCLUDED# define YY_YY_PARSER_TAB_H_INCLUDED/* Debug traces. */#ifndef YYDEBUG# define YYDEBUG 0#endif#if YYDEBUGextern int yydebug;#endif/* Token kinds. */#ifndef YYTOKENTYPE# define YYTOKENTYPE enum yytokentype { YYEMPTY = -2, YYEOF = 0, /* "end of file" */ YYerror = 256, /* error */ YYUNDEF = 257, /* "invalid token" */ IDENTIFIER = 258, /* IDENTIFIER */ INT_LITERAL = 259, /* INT_LITERAL */ REAL_LITERAL = 260, /* REAL_LITERAL */ BOOL_LITERAL = 261, /* BOOL_LITERAL */ ADDOP = 262, /* ADDOP */ MULOP = 263, /* MULOP */ RELOP = 264, /* RELOP */ OROP = 265, /* OROP */ ANDOP = 266, /* ANDOP */ EXPOP = 267, /* EXPOP */ REMOP = 268, /* REMOP */ BEGIN_ = 269, /* BEGIN_ */ BOOLEAN = 270, /* BOOLEAN */ END = 271, /* END */ ENDREDUCE = 272, /* ENDREDUCE */ FUNCTION = 273, /* FUNCTION */ INTEGER = 274, /* INTEGER */ IS = 275, /* IS */ REDUCE = 276, /* REDUCE */ RETURNS = 277, /* RETURNS */ CASE = 278, /* CASE */ ELSE = 279, /* ELSE */ ARROW = 280, /* ARROW */ ENDCASE = 281, /* ENDCASE */ ENDIF = 282, /* ENDIF */ IF = 283, /* IF */ OTHERS = 284, /* OTHERS */ REAL = 285, /* REAL */ THEN = 286, /* THEN */ WHEN = 287, /* WHEN */ NOT = 288, /* NOT */ NOTOP = 289 }; typedef enum yytokentype yytoken_kind_t;#endif/* Value type. */#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLAREDtypedef int YYSTYPE;# define YYSTYPE_IS_TRIVIAL 1# define YYSTYPE_IS_DECLARED 1#endifextern YYSTYPE yylval;int yyparse (void);#endif /* !YY_YY_PARSER_TAB_H_INCLUDED */ This production is not correct:function: function_header different_parameter body ;What is the diferent_parameter there for? Parameters are inside the function header not after it.Also this one does not look right:diff_parameter:diff_parameter RETURNS type ',' |parameter ;Professors notes: The RETURNS is already in function header. It should not be part of the parameter production.What you need is something like this:function_header: FUNCTION IDENTIFIER optional_parameters RETURNS type ;Then you need a production for optional_parameters that has two RHSs. One is empty, the other another nonterminal, call it parameters, for example.Then the parameters production must have a recursive RHS that separates parameters by a comma and a non-recursive RHS that defines a single parameter.The only other thing is see that obviously looks wrong is you production for not. Not is a unary operator. It should only have one operand.I have attached the Project Requirements, the Project Approach and the test cases. Please make sure that all the test cases work and match the Project Approach.
Murach's Visual Basic 2015 Extra Exercise 18-1
Read Chapters 17 & 18 in Murach's Visual Basic 2015Complete extra exercise 18-1. Starter project and instructions here: We ...
Murach's Visual Basic 2015 Extra Exercise 18-1
Read Chapters 17 & 18 in Murach's Visual Basic 2015Complete extra exercise 18-1. Starter project and instructions here: Week 5 Assignment.zip.
19 pages
Iris Dataset R Final Project
The Use of regression and graphical techniques to classify the Iris species The Use of regression and graphical techniques ...
Iris Dataset R Final Project
The Use of regression and graphical techniques to classify the Iris species The Use of regression and graphical techniques to classify the Iris ...
15 pages
Public Key Encryption
Cryptography is a technique that has existed since the Roman Empire; it entailed concealing the information sent so that u ...
Public Key Encryption
Cryptography is a technique that has existed since the Roman Empire; it entailed concealing the information sent so that unintended individuals cannot ...
Data Flow Diagram Project
Using the Microsoft Word document created in W4 Project, add to it by including the following:
Now that you have created u ...
Data Flow Diagram Project
Using the Microsoft Word document created in W4 Project, add to it by including the following:
Now that you have created use-case models for your system, you will continue your system design by completing your class diagram and applying behavioral diagrams.
Extend your class diagram by including associations, indicating the object role and multiplicity on each end of your associations. Add any new classes, attributes, or operations that you may not have considered in your Week 4 diagram.
Develop sequence diagrams for two use-case scenarios from your W4 Project.
Justify any assumptions on some of the messages passed between objects.
Clearly indicate what objects are involved in each diagram.
Develop activity diagrams for your two use-case scenarios.
Develop a state diagram for at least one of your use-case scenarios above.
Earn money selling
your Study Documents