SlideShare a Scribd company logo
1 of 8
Download to read offline
Instructions
The first programming project involves writing a program that parses, using recursive descent, a
GUI definition language defined in an input file and generates the GUI that it defines. The
grammar for this language is defined below:
In the above grammar, the red symbols are nonterminals, the blue symbols are tokens and the
black punctuation symbols are BNF metasymbols. Among the tokens those in title case are
keywords. The character literals are punctuation tokens.
Below is an explanation of the meaning of some of the symbols in the above productions that
should help you understand the actions that are to be performed when each of the productions is
parsed:
In the window production the string is name that is to appear in the top border of the window and
the two numbers are the width and height of the window
In the production for layout_type that define the grid layout, the first two numbers represent the
number of rows and columns, and the optional next two the horizontal and vertical gaps
In the production for widget that defines a button, the string is the name of the button
In the production for widget that defines a label, the string is text that is to be placed in the label
In the production for widget that defines a text field, the number is the width of the text field
In the production for radio_button, the string is the label of the button
You parser should properly handle the fact that panels can be nested in other panels. Recursive
productions must be implemented using recursion. Lexical and syntactical errors should be
detected and reported (the first error only; after reporting the first error the program must exit
gracefully).
Below is an example of an input file:
Just to give you an idea where that input file came from, the above input file corresponds to the
GUI shown below:
However, please keep in mind that you are NOT required to re-create the GUI that corresponds
to the input file. Instead, you are only required to:
1. Implement a lexer capable of recognizing all the terminal symbols of the grammar
(tokens/lexemes - those in blue)
2. Implement a recursive descent parser that (using the lexer from 1.) will be able to parse the
input file and detect a syntax error (the first one is enough, then the parser should exit gracefully)
3. As a result of parsing the input file, an output file will be generated, reporting the parsing steps
followed by the parser in a manner similar to the one described by Sebesta (10th edition) on
pages 181-186.
Notes:
- You can implement the parser for this grammar in C, C++, Java or C# 9 6 3 8 0
Solution
This is the codes:
calculator.js
calc_array = new Array();
var calcul=0;
var pas_ch=0;
function $id(id)
{
return document.getElementById(id);
}
function f_calc(id,n)
{
if(n=='ce')
{
init_calc(id);
}
else if(n=='=')
{
if(calc_array[id][0]!='=' && calc_array[id][1]!=1)
{
eval('calcul='+calc_array[id][2]+calc_array[id][0]+calc_array[id][3]+';');
calc_array[id][0] = '=';
$id(id+'_result').value=calcul;
calc_array[id][2]=calcul;
calc_array[id][3]=0;
}
}
else if(n=='+-')
{
$id(id+'_result').value=$id(id+'_result').value*(-1);
if(calc_array[id][0]=='=')
{
calc_array[id][2] = $id(id+'_result').value;
calc_array[id][3] = 0;
}
else
{
calc_array[id][3] = $id(id+'_result').value;
}
pas_ch = 1;
}
else if(n=='nbs')
{
if($id(id+'_result').value<10 && $id(id+'_result').value>-10)
{
$id(id+'_result').value=0;
}
else
{
$id(id+'_result').value=$id(id+'_result').value.slice(0,$id(id+'_result').value.length-1);
}
if(calc_array[id][0]=='=')
{
calc_array[id][2] = $id(id+'_result').value;
calc_array[id][3] = 0;
}
else
{
calc_array[id][3] = $id(id+'_result').value;
}
}
else
{
if(calc_array[id][0]!='=' && calc_array[id][1]!=1)
{
eval('calcul='+calc_array[id][2]+calc_array[id][0]+calc_array[id][3]+';');
$id(id+'_result').value=calcul;
calc_array[id][2]=calcul;
calc_array[id][3]=0;
}
calc_array[id][0] = n;
}
if(pas_ch==0)
{
calc_array[id][1] = 1;
}
else
{
pas_ch=0;
}
document.getElementById(id+'_result').focus();
return true;
}
function add_calc(id,n)
{
if(calc_array[id][1]==1)
{
$id(id+'_result').value=n;
}
else
{
$id(id+'_result').value+=n;
}
if(calc_array[id][0]=='=')
{
calc_array[id][2] = $id(id+'_result').value;
calc_array[id][3] = 0;
}
else
{
calc_array[id][3] = $id(id+'_result').value;
}
calc_array[id][1] = 0;
document.getElementById(id+'_result').focus();
return true;
}
function init_calc(id)
{
$id(id+'_result').value=0;
calc_array[id] = new Array('=',1,'0','0',0);
document.getElementById(id+'_result').focus();
return true;
}
function key_detect_calc(id,evt)
{
if((evt.keyCode>95) && (evt.keyCode<106))
{
var nbr = evt.keyCode-96;
add_calc(id,nbr);
}
else if((evt.keyCode>47) && (evt.keyCode<58))
{
var nbr = evt.keyCode-48;
add_calc(id,nbr);
}
else if(evt.keyCode==107)
{
f_calc(id,'+');
}
else if(evt.keyCode==109)
{
f_calc(id,'-');
}
else if(evt.keyCode==106)
{
f_calc(id,'*');
}
else if(evt.keyCode==111)
{
f_calc(id,'');
}
else if(evt.keyCode==110)
{
add_calc(id,'.');
}
else if(evt.keyCode==190)
{
add_calc(id,'.');
}
else if(evt.keyCode==188)
{
add_calc(id,'.');
}
else if(evt.keyCode==13)
{
f_calc(id,'=');
}
else if(evt.keyCode==46)
{
f_calc(id,'ce');
}
else if(evt.keyCode==8)
{
f_calc(id,'nbs');
}
else if(evt.keyCode==27)
{
f_calc(id,'ce');
}
return true;
}
calculator.css
.calculator
{
width:300px;
height:300px;
background-color:#eeeeee;
border:2px solid #CCCCCC;
margin:auto;
padding-left:5px;
padding-bottom:5px;
}
.calculator td
{
height:16.66%;
}
.calc_td_result
{
text-align:center;
}
.calc_result
{
width:90%;
text-align:right;
}
.calc_td_calculs
{
text-align:center;
}
.calc_calculs
{
width:90%;
text-align:left;
}
.calc_td_btn
{
width:25%;
height:100%;
}
.calc_btn
{
width:90%;
height:90%;
font-size:20px;
}
calculator.html
Javascript Calculator

More Related Content

Similar to InstructionsThe first programming project involves writing a progr.pdf

Unit 1 c - all topics
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topicsveningstonk
 
CMSC 330 PROJECT 1
CMSC 330 PROJECT 1CMSC 330 PROJECT 1
CMSC 330 PROJECT 1HamesKellor
 
match the following attributes to the parts of a compilerstrips ou.pdf
match the following attributes to the parts of a compilerstrips ou.pdfmatch the following attributes to the parts of a compilerstrips ou.pdf
match the following attributes to the parts of a compilerstrips ou.pdfarpitaeron555
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdfAkarTaher
 
Introduction to compiler development
Introduction to compiler developmentIntroduction to compiler development
Introduction to compiler developmentDeepOad
 
unit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfunit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfDrIsikoIsaac
 
Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfDrIsikoIsaac
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptxssuser3b4934
 
Chapter 3(1)
Chapter 3(1)Chapter 3(1)
Chapter 3(1)TejaswiB4
 
Basics Of C++.pptx
Basics Of C++.pptxBasics Of C++.pptx
Basics Of C++.pptxDineshDhuri4
 
C programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfC programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfComedyTechnology
 

Similar to InstructionsThe first programming project involves writing a progr.pdf (20)

Unit 1 c - all topics
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topics
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
CMSC 330 PROJECT 1
CMSC 330 PROJECT 1CMSC 330 PROJECT 1
CMSC 330 PROJECT 1
 
Assignment1
Assignment1Assignment1
Assignment1
 
match the following attributes to the parts of a compilerstrips ou.pdf
match the following attributes to the parts of a compilerstrips ou.pdfmatch the following attributes to the parts of a compilerstrips ou.pdf
match the following attributes to the parts of a compilerstrips ou.pdf
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdf
 
Introduction to compiler development
Introduction to compiler developmentIntroduction to compiler development
Introduction to compiler development
 
3.2
3.23.2
3.2
 
unit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfunit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdf
 
C-PROGRAM
C-PROGRAMC-PROGRAM
C-PROGRAM
 
Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdf
 
How a Compiler Works ?
How a Compiler Works ?How a Compiler Works ?
How a Compiler Works ?
 
C Lang notes.ppt
C Lang notes.pptC Lang notes.ppt
C Lang notes.ppt
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
Chapter 3(1)
Chapter 3(1)Chapter 3(1)
Chapter 3(1)
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Basics Of C++.pptx
Basics Of C++.pptxBasics Of C++.pptx
Basics Of C++.pptx
 
C programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfC programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdf
 
COMPILER DESIGN- Introduction & Lexical Analysis:
COMPILER DESIGN- Introduction & Lexical Analysis: COMPILER DESIGN- Introduction & Lexical Analysis:
COMPILER DESIGN- Introduction & Lexical Analysis:
 

More from nitinarora01

Describe the movement of yeast cells once ingested by a paramecium &.pdf
Describe the movement of yeast cells once ingested by a paramecium &.pdfDescribe the movement of yeast cells once ingested by a paramecium &.pdf
Describe the movement of yeast cells once ingested by a paramecium &.pdfnitinarora01
 
Chapter 2 problems.1.            (Problem 1) Of the following, whi.pdf
Chapter 2 problems.1.            (Problem 1) Of the following, whi.pdfChapter 2 problems.1.            (Problem 1) Of the following, whi.pdf
Chapter 2 problems.1.            (Problem 1) Of the following, whi.pdfnitinarora01
 
By equity . Party A owns a factory that emits large quantities of f.pdf
By equity . Party A owns a factory that emits large quantities of f.pdfBy equity . Party A owns a factory that emits large quantities of f.pdf
By equity . Party A owns a factory that emits large quantities of f.pdfnitinarora01
 
An Overview of Transport Mechanisms In Plants. Relate the structure .pdf
An Overview of Transport Mechanisms In Plants.  Relate the structure .pdfAn Overview of Transport Mechanisms In Plants.  Relate the structure .pdf
An Overview of Transport Mechanisms In Plants. Relate the structure .pdfnitinarora01
 
amazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdf
amazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdfamazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdf
amazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdfnitinarora01
 
All organelles (check all that apply) Are membrane bound Contain th.pdf
All organelles (check all that apply)  Are membrane bound  Contain th.pdfAll organelles (check all that apply)  Are membrane bound  Contain th.pdf
All organelles (check all that apply) Are membrane bound Contain th.pdfnitinarora01
 
A study designed to evaluate the effect of the herbal remedy Echinac.pdf
A study designed to evaluate the effect of the herbal remedy Echinac.pdfA study designed to evaluate the effect of the herbal remedy Echinac.pdf
A study designed to evaluate the effect of the herbal remedy Echinac.pdfnitinarora01
 
37. If the material below the sandstone of problem 26 is a shale with.pdf
37. If the material below the sandstone of problem 26 is a shale with.pdf37. If the material below the sandstone of problem 26 is a shale with.pdf
37. If the material below the sandstone of problem 26 is a shale with.pdfnitinarora01
 
Why didnt implementation of robots in the 1980s continue to increas.pdf
Why didnt implementation of robots in the 1980s continue to increas.pdfWhy didnt implementation of robots in the 1980s continue to increas.pdf
Why didnt implementation of robots in the 1980s continue to increas.pdfnitinarora01
 
Which property of life (e.g. homeostasis) is illustrated by each of .pdf
Which property of life (e.g. homeostasis) is illustrated by each of .pdfWhich property of life (e.g. homeostasis) is illustrated by each of .pdf
Which property of life (e.g. homeostasis) is illustrated by each of .pdfnitinarora01
 
Which of the following statements is FALSE regarding microbial mats.pdf
Which of the following statements is FALSE regarding microbial mats.pdfWhich of the following statements is FALSE regarding microbial mats.pdf
Which of the following statements is FALSE regarding microbial mats.pdfnitinarora01
 
What roles do membranes play in a cellWhat are cell membranes com.pdf
What roles do membranes play in a cellWhat are cell membranes com.pdfWhat roles do membranes play in a cellWhat are cell membranes com.pdf
What roles do membranes play in a cellWhat are cell membranes com.pdfnitinarora01
 
26. The gecko is a reptile that has the amazing ability to climb smo.pdf
26. The gecko is a reptile that has the amazing ability to climb smo.pdf26. The gecko is a reptile that has the amazing ability to climb smo.pdf
26. The gecko is a reptile that has the amazing ability to climb smo.pdfnitinarora01
 
What is soft trend vs. hard trend Analyze a specific software engin.pdf
What is soft trend vs. hard trend Analyze a specific software engin.pdfWhat is soft trend vs. hard trend Analyze a specific software engin.pdf
What is soft trend vs. hard trend Analyze a specific software engin.pdfnitinarora01
 
what does it mean to be a social scientistSolutionSocial .pdf
what does it mean to be a social scientistSolutionSocial .pdfwhat does it mean to be a social scientistSolutionSocial .pdf
what does it mean to be a social scientistSolutionSocial .pdfnitinarora01
 
What are the advantages for proteins to form three-dimensional struc.pdf
What are the advantages for proteins to form three-dimensional struc.pdfWhat are the advantages for proteins to form three-dimensional struc.pdf
What are the advantages for proteins to form three-dimensional struc.pdfnitinarora01
 
Weather List the types of materials used to create a concrete sidewal.pdf
Weather List the types of materials used to create a concrete sidewal.pdfWeather List the types of materials used to create a concrete sidewal.pdf
Weather List the types of materials used to create a concrete sidewal.pdfnitinarora01
 
The OSI Reference Model layers, in order from top to bottom, areA.pdf
The OSI Reference Model layers, in order from top to bottom, areA.pdfThe OSI Reference Model layers, in order from top to bottom, areA.pdf
The OSI Reference Model layers, in order from top to bottom, areA.pdfnitinarora01
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfnitinarora01
 
Question 1 (1 point)Tjhe pH of blood is __________ and when the .pdf
Question 1 (1 point)Tjhe pH of blood is __________ and when the .pdfQuestion 1 (1 point)Tjhe pH of blood is __________ and when the .pdf
Question 1 (1 point)Tjhe pH of blood is __________ and when the .pdfnitinarora01
 

More from nitinarora01 (20)

Describe the movement of yeast cells once ingested by a paramecium &.pdf
Describe the movement of yeast cells once ingested by a paramecium &.pdfDescribe the movement of yeast cells once ingested by a paramecium &.pdf
Describe the movement of yeast cells once ingested by a paramecium &.pdf
 
Chapter 2 problems.1.            (Problem 1) Of the following, whi.pdf
Chapter 2 problems.1.            (Problem 1) Of the following, whi.pdfChapter 2 problems.1.            (Problem 1) Of the following, whi.pdf
Chapter 2 problems.1.            (Problem 1) Of the following, whi.pdf
 
By equity . Party A owns a factory that emits large quantities of f.pdf
By equity . Party A owns a factory that emits large quantities of f.pdfBy equity . Party A owns a factory that emits large quantities of f.pdf
By equity . Party A owns a factory that emits large quantities of f.pdf
 
An Overview of Transport Mechanisms In Plants. Relate the structure .pdf
An Overview of Transport Mechanisms In Plants.  Relate the structure .pdfAn Overview of Transport Mechanisms In Plants.  Relate the structure .pdf
An Overview of Transport Mechanisms In Plants. Relate the structure .pdf
 
amazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdf
amazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdfamazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdf
amazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdf
 
All organelles (check all that apply) Are membrane bound Contain th.pdf
All organelles (check all that apply)  Are membrane bound  Contain th.pdfAll organelles (check all that apply)  Are membrane bound  Contain th.pdf
All organelles (check all that apply) Are membrane bound Contain th.pdf
 
A study designed to evaluate the effect of the herbal remedy Echinac.pdf
A study designed to evaluate the effect of the herbal remedy Echinac.pdfA study designed to evaluate the effect of the herbal remedy Echinac.pdf
A study designed to evaluate the effect of the herbal remedy Echinac.pdf
 
37. If the material below the sandstone of problem 26 is a shale with.pdf
37. If the material below the sandstone of problem 26 is a shale with.pdf37. If the material below the sandstone of problem 26 is a shale with.pdf
37. If the material below the sandstone of problem 26 is a shale with.pdf
 
Why didnt implementation of robots in the 1980s continue to increas.pdf
Why didnt implementation of robots in the 1980s continue to increas.pdfWhy didnt implementation of robots in the 1980s continue to increas.pdf
Why didnt implementation of robots in the 1980s continue to increas.pdf
 
Which property of life (e.g. homeostasis) is illustrated by each of .pdf
Which property of life (e.g. homeostasis) is illustrated by each of .pdfWhich property of life (e.g. homeostasis) is illustrated by each of .pdf
Which property of life (e.g. homeostasis) is illustrated by each of .pdf
 
Which of the following statements is FALSE regarding microbial mats.pdf
Which of the following statements is FALSE regarding microbial mats.pdfWhich of the following statements is FALSE regarding microbial mats.pdf
Which of the following statements is FALSE regarding microbial mats.pdf
 
What roles do membranes play in a cellWhat are cell membranes com.pdf
What roles do membranes play in a cellWhat are cell membranes com.pdfWhat roles do membranes play in a cellWhat are cell membranes com.pdf
What roles do membranes play in a cellWhat are cell membranes com.pdf
 
26. The gecko is a reptile that has the amazing ability to climb smo.pdf
26. The gecko is a reptile that has the amazing ability to climb smo.pdf26. The gecko is a reptile that has the amazing ability to climb smo.pdf
26. The gecko is a reptile that has the amazing ability to climb smo.pdf
 
What is soft trend vs. hard trend Analyze a specific software engin.pdf
What is soft trend vs. hard trend Analyze a specific software engin.pdfWhat is soft trend vs. hard trend Analyze a specific software engin.pdf
What is soft trend vs. hard trend Analyze a specific software engin.pdf
 
what does it mean to be a social scientistSolutionSocial .pdf
what does it mean to be a social scientistSolutionSocial .pdfwhat does it mean to be a social scientistSolutionSocial .pdf
what does it mean to be a social scientistSolutionSocial .pdf
 
What are the advantages for proteins to form three-dimensional struc.pdf
What are the advantages for proteins to form three-dimensional struc.pdfWhat are the advantages for proteins to form three-dimensional struc.pdf
What are the advantages for proteins to form three-dimensional struc.pdf
 
Weather List the types of materials used to create a concrete sidewal.pdf
Weather List the types of materials used to create a concrete sidewal.pdfWeather List the types of materials used to create a concrete sidewal.pdf
Weather List the types of materials used to create a concrete sidewal.pdf
 
The OSI Reference Model layers, in order from top to bottom, areA.pdf
The OSI Reference Model layers, in order from top to bottom, areA.pdfThe OSI Reference Model layers, in order from top to bottom, areA.pdf
The OSI Reference Model layers, in order from top to bottom, areA.pdf
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
 
Question 1 (1 point)Tjhe pH of blood is __________ and when the .pdf
Question 1 (1 point)Tjhe pH of blood is __________ and when the .pdfQuestion 1 (1 point)Tjhe pH of blood is __________ and when the .pdf
Question 1 (1 point)Tjhe pH of blood is __________ and when the .pdf
 

Recently uploaded

MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...Nguyen Thanh Tu Collection
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsISCOPE Publication
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscapingDr. M. Kumaresan Hort.
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 

Recently uploaded (20)

MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS Publications
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscaping
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 

InstructionsThe first programming project involves writing a progr.pdf

  • 1. Instructions The first programming project involves writing a program that parses, using recursive descent, a GUI definition language defined in an input file and generates the GUI that it defines. The grammar for this language is defined below: In the above grammar, the red symbols are nonterminals, the blue symbols are tokens and the black punctuation symbols are BNF metasymbols. Among the tokens those in title case are keywords. The character literals are punctuation tokens. Below is an explanation of the meaning of some of the symbols in the above productions that should help you understand the actions that are to be performed when each of the productions is parsed: In the window production the string is name that is to appear in the top border of the window and the two numbers are the width and height of the window In the production for layout_type that define the grid layout, the first two numbers represent the number of rows and columns, and the optional next two the horizontal and vertical gaps In the production for widget that defines a button, the string is the name of the button In the production for widget that defines a label, the string is text that is to be placed in the label In the production for widget that defines a text field, the number is the width of the text field In the production for radio_button, the string is the label of the button You parser should properly handle the fact that panels can be nested in other panels. Recursive productions must be implemented using recursion. Lexical and syntactical errors should be detected and reported (the first error only; after reporting the first error the program must exit gracefully). Below is an example of an input file: Just to give you an idea where that input file came from, the above input file corresponds to the GUI shown below: However, please keep in mind that you are NOT required to re-create the GUI that corresponds to the input file. Instead, you are only required to: 1. Implement a lexer capable of recognizing all the terminal symbols of the grammar (tokens/lexemes - those in blue) 2. Implement a recursive descent parser that (using the lexer from 1.) will be able to parse the input file and detect a syntax error (the first one is enough, then the parser should exit gracefully) 3. As a result of parsing the input file, an output file will be generated, reporting the parsing steps followed by the parser in a manner similar to the one described by Sebesta (10th edition) on pages 181-186. Notes:
  • 2. - You can implement the parser for this grammar in C, C++, Java or C# 9 6 3 8 0 Solution This is the codes: calculator.js calc_array = new Array(); var calcul=0; var pas_ch=0; function $id(id) { return document.getElementById(id); } function f_calc(id,n) { if(n=='ce') { init_calc(id); } else if(n=='=') { if(calc_array[id][0]!='=' && calc_array[id][1]!=1) { eval('calcul='+calc_array[id][2]+calc_array[id][0]+calc_array[id][3]+';'); calc_array[id][0] = '='; $id(id+'_result').value=calcul; calc_array[id][2]=calcul; calc_array[id][3]=0; } } else if(n=='+-') { $id(id+'_result').value=$id(id+'_result').value*(-1); if(calc_array[id][0]=='=') { calc_array[id][2] = $id(id+'_result').value;
  • 3. calc_array[id][3] = 0; } else { calc_array[id][3] = $id(id+'_result').value; } pas_ch = 1; } else if(n=='nbs') { if($id(id+'_result').value<10 && $id(id+'_result').value>-10) { $id(id+'_result').value=0; } else { $id(id+'_result').value=$id(id+'_result').value.slice(0,$id(id+'_result').value.length-1); } if(calc_array[id][0]=='=') { calc_array[id][2] = $id(id+'_result').value; calc_array[id][3] = 0; } else { calc_array[id][3] = $id(id+'_result').value; } } else { if(calc_array[id][0]!='=' && calc_array[id][1]!=1) { eval('calcul='+calc_array[id][2]+calc_array[id][0]+calc_array[id][3]+';'); $id(id+'_result').value=calcul; calc_array[id][2]=calcul; calc_array[id][3]=0;
  • 4. } calc_array[id][0] = n; } if(pas_ch==0) { calc_array[id][1] = 1; } else { pas_ch=0; } document.getElementById(id+'_result').focus(); return true; } function add_calc(id,n) { if(calc_array[id][1]==1) { $id(id+'_result').value=n; } else { $id(id+'_result').value+=n; } if(calc_array[id][0]=='=') { calc_array[id][2] = $id(id+'_result').value; calc_array[id][3] = 0; } else { calc_array[id][3] = $id(id+'_result').value; } calc_array[id][1] = 0; document.getElementById(id+'_result').focus(); return true;
  • 5. } function init_calc(id) { $id(id+'_result').value=0; calc_array[id] = new Array('=',1,'0','0',0); document.getElementById(id+'_result').focus(); return true; } function key_detect_calc(id,evt) { if((evt.keyCode>95) && (evt.keyCode<106)) { var nbr = evt.keyCode-96; add_calc(id,nbr); } else if((evt.keyCode>47) && (evt.keyCode<58)) { var nbr = evt.keyCode-48; add_calc(id,nbr); } else if(evt.keyCode==107) { f_calc(id,'+'); } else if(evt.keyCode==109) { f_calc(id,'-'); } else if(evt.keyCode==106) { f_calc(id,'*'); } else if(evt.keyCode==111) { f_calc(id,''); }
  • 6. else if(evt.keyCode==110) { add_calc(id,'.'); } else if(evt.keyCode==190) { add_calc(id,'.'); } else if(evt.keyCode==188) { add_calc(id,'.'); } else if(evt.keyCode==13) { f_calc(id,'='); } else if(evt.keyCode==46) { f_calc(id,'ce'); } else if(evt.keyCode==8) { f_calc(id,'nbs'); } else if(evt.keyCode==27) { f_calc(id,'ce'); } return true; } calculator.css .calculator { width:300px; height:300px; background-color:#eeeeee;
  • 7. border:2px solid #CCCCCC; margin:auto; padding-left:5px; padding-bottom:5px; } .calculator td { height:16.66%; } .calc_td_result { text-align:center; } .calc_result { width:90%; text-align:right; } .calc_td_calculs { text-align:center; } .calc_calculs { width:90%; text-align:left; } .calc_td_btn { width:25%; height:100%; } .calc_btn { width:90%; height:90%;