国产人妻人伦精品_欧美一区二区三区图_亚洲欧洲久久_日韩美女av在线免费观看

合肥生活安徽新聞合肥交通合肥房產生活服務合肥教育合肥招聘合肥旅游文化藝術合肥美食合肥地圖合肥社保合肥醫院企業服務合肥法律

代做Tiny Calculator parsing with YACC
代做Tiny Calculator parsing with YACC

時間:2025-03-25  來源:合肥網hfw.cc  作者:hfw.cc 我要糾錯



Homework 3: Tiny Calculator parsing with YACC/Bison)

Overview
This assignment builds on Homework 2 and focuses on extending your knowledge of compiler design. Specifically, you will
complete the syntax analysis phase by combining the deliverables from Homework 2 (lexical analysis using flex) with this
assignment's deliverable (syntax analysis using yacc or its GNU version, bison).
Feel free to seek ChatGPT help under the following guidelines:
Use it for suggestions, but ensure the work you submit is your own.
Share your experience in details in your README or submission comments if ChatGPT played a significant role in
solving the problem.
Objectives
Similar to Homework 2 (Lexical Analysis), the objectives of this assignment are:
1. Understanding the syntax analysis process as the application of the grammar of any programming language.
2. Many other business applications outside of the programming language domain need lexical and syntax analysis to handle
the user inputs in a more rigorous and user-friendly way.
3. Learning aged but extremely useful and popular tools, (f)lex and yacc (or bison). In homework 3, you are asked to use both
(f)lex and bison (yacc).
Before you start: Preparation
Read "Section 4.1 Introduction" in the textbook to get the basic ideas and background knowledge.
The front end of the compiler design is syntax analysis, which consists of two parts: lexical analysis, and syntactic
analysis. In the previous homework, you used the Unix (f)lex tool to understand how lexical analysis works. In this
homework, you are asked to combine the deliverable of the previous homework with the deliverable of this homework to
complete the full syntax analysis. You will be using yet another Unix tool, yacc (Yet Another Compiler Compiler) or bison
(yacc's GNU version) for syntax analysis (parsing).
Review class notes on the yacc/bison tool.
Refer to the diagram illustrating interactions between lex and yacc , noting that every time the parser ( yacc/bison ) needs
a token, it calls Lex::yylex() .
Below is the diagram describing lex and yacc interactions. Note that every time the parser (yacc/bison) needs a token,
Yacc/bison::yyparese() calls Lex::yylex().
 Homework 3: Tiny Calculator parsing with YACC/Bison)
%23view_name%3Dmon   1/7
Additional references: yacc/bison tool references:

precedence as well as associativity
Read both the   Operator Precedence   and   Context-Dependent Precedence   sections for handling general
operator precedence rules and unary minus operator
To Do
1. Write BNF grammar rules
Write BNF grammar rules to implement the tiny calculator with the following features. The grammar rules with detailed
descriptions must be listed in a comment section at the beginning of your code file or in a separate Markdown file.
statement_list: list of binary expression statements
statement (assignment): var = expression
expression:
(expression) : An expression in parenthesis to allow users to set precedence
5 binary arithmetic operations: +, -, *, /, ^.
- The behavior of each binary operation is the same as in Homework 2.
Variables: Support C-like identifiers to store numbers
Numbers: Support C-like signed integer or signed float numbers. (stored as double type internally)
NOTE: The calculator should support signs (+, -) e.g., 2 - -3 + 2 - 7 - -2 (output: 2)
2. Implement the Tiny Calculator
Use Unix yacc/bison tool to implement a rudimentary tiny calculator that:
computes the following basic arithmetic operation expressions.
I. addition: +
II. subtract: -
III. multiplication: *
IV. division: /
 Homework 3: Tiny Calculator parsing with YACC/Bison)
%23view_name%3Dmon   2/7
V. exponents: ^
Accepts user-entered binary arithmetic expressions, one per line.
Processes multiple expressions interactively until the user exits.
To commit operations, the user enters the RETURN key at the end of the statement.
Note that the user should be able to enter any number of expressions. See the Expected Output [8][9][10] cases.
For each calculation, the user may enter either an expression or assignment, as shown in the expected output file.
The input number for each operand can be an integer or double-precision floating point number.
Follows operator precedence and associativity rules.
Error Handling
Your program must recognize and handle the following errors:
Incorrect number format
Invalid grammar or missing operators
invalid infix binary arithmetic operation
rejecting any letters in the expression (invalid operands and/or operator type)
unmatching (nested) parentheses
Divide by zero error
Referring to undefined variables
You should test all the test cases in the Expected Outputs section below. Your results must be consistent with
the expected outputs.
3. Compare flex vs. yacc/bison
In your README, explain what tasks could not be performed using only the flex tool in Homework 2 but can now be
achieved using the yacc/bison tool. Provide clear reasoning for your observations.
Hints and guidelines:
1. Full implementation of the MIT bison Example: readme.md - Postfix Notation Calculator - Replit
(https://replit.com/@sungheenam/Postfix-Notation-Calculator#readme.md)
This REPL fully implements the example in the MIT example (Bison - Examples (mit.edu)
(http://web.mit.edu/gnu/doc/html/bison_5.html) ) above.
You may fork from the repl and read the readme.md file and sample output first before playing around with it. The
repl also has a makefile example; it is not the best one, but it would help you simplify the build process.
2. More examples in addition to the MIT example above
Example program for the lex and yacc programs - IBM Documentation (https://www.ibm.com/docs/en/aix/7.1?
topic=information-example-program-lex-yacc-programs) (A good starting point. It's somewhat similar to this
assignment)
3. flex programming
Update the flex program from HW2 to work with the bison code in HW3. Note that most of the programming logic
would be moved to the bison file. Basically, using the flex tool truly as the lexical analyzer purpose only.
Include "<your program>.tab.h" in the flex program. The *.tab.h file will be automatically generated when the bison
script gets processed. Read the postfix readme.md file linked above.
For this homework, you don't need to define any subroutines except yywrap() in flex because those subroutines in
flex including main() will be migrated to the bison program.
In the regular expression rules section of your flex code, you need to return the token and its lexeme when a token
defined in the bison file is recognized. For example, for var token in "stmt: var = expr",
In the definition section of the flex code:
var [_[:alpha:]][_[:alnum:]]*?
 Homework 3: Tiny Calculator parsing with YACC/Bison)
%23view_name%3Dmon   3/7
In the rules section, write a C++ code to pass the var token:
{var} {yylval.var = new std::string(yytext); return VAR;}??
4. yacc/bison programming.
Feel free to use C++ instead of C for Bison programming. Refer to the makefile example below to compile with
"g++" instead of "GCC".
Note that in your C++ code, you can't use the "using namespace std" macro, rather, you must use fully qualified
identifiers such as std::string, std::map, std::cout, std::endl, ...
Define the following in the declaration section:
In the C code definition section:
A. external functions?
extern int yylex();
extern int yyparse();
extern void yyerror(const char* s);
B. Storing values for the variables: You can use any data structure for the purpose, but I recommend using a C++
map (dictionary) data structure.
std::map<std::string, double> vars; // a dictionary storing variable names and their values
In the bison definition section:
A. Associating yylval with tokens' Values:
yylval is used to pass semantic values from the lexer (Flex) to the parser (Bison). It acts as a communication
channel between the scanner (lexer) and the parser.
Steps to Associate yylval with Tokens' Values
1. Define a union for Token Values ( %union )
2. Associate Each Token with a Data Type ( %token <type> )
3. Assign Values in the Lexer ( yylex() ) - see above in "flex programming"
4. Use yylval in the Grammar Rules
Data structure to store the values of some tokens (see below for hints of its usage)
%union {
 ? double dval; /* to store numbers token value */
 ? std::string *var; /* to store variable ID */
}
A. token (from flex) for terminals. Tokens are what's returned by the flex tool:
%token e.g., % token <dval> NUMBER /* NUMBER token returns a double number */
B. type for non-terminals defined in the grammar if they return values:
%type e.g., % type <dval> expr /* expr return a double number */
C. Association rules for operators:
%right or
%left
D. Precedence rules for operators - Order matters!
The precedence of operators is determined by the order in which they appear, with the lowest precedence at
the top and the highest at the bottom
Define rules (grammar)
An assignment rule (stmt: var = expr) may associate a variable in the dictionary (vars) with the value of expr
e.g. vars[*$1] = $3;
 Homework 3: Tiny Calculator parsing with YACC/Bison)
%23view_name%3Dmon   4/7
A good example of defining rules that is similar to this assignment: Bison - Examples (mit.edu):
(http://web.mit.edu/gnu/doc/html/bison_5.html) Infix Notation Calculator: calc
(http://web.mit.edu/gnu/doc/html/bison_toc.html#SEC27)
Build Instructions example
A make file example: (https://ucdenver.instructure.com/courses/558317/files/25220969?wrap=1)
(https://ucdenver.instructure.com/courses/558317/files/25220969/download?download_frd=1)
Disclaimer: This makefile includes a basic set of commands and is intended as a beginner's guide to understanding
makefile formats. It should be treated as a starting point.
For effective use, always execute 'make clean' before running 'make' from the "Shell" tab rather than clicking the green
"Run" button. Additionally, note that this makefile contains additional commands designed to rename generated *.c files
to *.cpp files, as the 'g++' compiler is employed instead of 'gcc'.
Entering command sequence for C++ manually:
//lex program : calc.l, yacc program : calc.y
$flex calc.l
$bison -dtv calc.y # use bison instead of yacc
$mv -f lex.yy.c lex.yy.cpp
$mv -f calc.tab.c calc.tab.cpp
g++ -c -std=c++11 lex.yy.cpp -lm
g++ -c -std=c++11 calc.tab.cpp -lm
g++ -o calc *.o -lstdc++ -lm
Expected Outputs
Expected Output example file (https://ucdenver.instructure.com/courses/558317/files/25872913?wrap=1)
(https://ucdenver.instructure.com/courses/558317/files/25872913/download?download_frd=1)
Your output should include, at least, all the test cases in the file
REPL Setup:
First, create a new REPL with "Bash", not a "C++" or "C".
Installing Flex: When you execute the 'flex' command for the first time from the REPL console, it will prompt you to
install flex. From the two available options, select the "flex" option.
Installing Bison/Yacc: Upon running the 'bison' or 'yacc' command from the REPL console, you will be prompted to
install a bison/yacc application. Select the "yacc" option, not 'bison_3_5'. The current REPL version encounters
installation issues with the 'bison_3_5' application for reasons unknown to us.
In Case that Bison_3_5 has been installed:
If you have installed bison_3_5 already, perform the following steps to fix the issue:
1. Click on the three dots (the "more" icon) located in the File Navigation window  s leftmost column.
2. Choose "Show hidden ..." (the last option in the list). This will show all hidden files.
3. In the File Navigation window  s lower section, locate the "replit.nix" file.
 Homework 3: Tiny Calculator parsing with YACC/Bison)
%23view_name%3Dmon   5/7
4. This file holds your REPL configuration information. Within the 'deps = [ .... ]' section, if an entry for the
"pkgs.bison_3_5" instance is present, manually remove the line.
5. Run the "bison -dtv <your yacc code>.y" command from the command line window, ensuring you choose the
"yacc" option this time.
Note: For our assignment  s intent, "yacc" is equally good as "bison".
Deliverable
Read the rubric first before you submit it. Submit the following items:
(f)lex and yacc/bison source codes. Please submit two sets of identical files - one with the original source code files and the
other with *.txt extensions for my review.
An output file demonstrating the test results, which cover the operations in the Expected Output section above.
A readme.md containing:
the answers to the comparison task from Step 3 in the "ToDo" list
BNF grammar rules and program documentation
Or
REPL "join" link containing
flex and bison source codes
The output file with your test results covers at least the operations in the Expected Output section above.
readme.md file for answering the tasks and the BNF documentation of your program
Extra Credit (Your own project): up to 10 points
Can you think of any project you have worked on or would work on in the future where yacc/lex can help to simplify a front-end
interface? Submit:
A one-page proposal with a synopsis of the project that describes how the lex/yacc tool would help your project.
(f)lex and yacc/bison source code and output demonstrating implementation of the project.
View Rubric
HW3 Bison - Tiny Calculator
Criteria Points
Description of
criterion
/5 pts
why_bison
Using this assignment as example, describe the tasks that could not be done or were
extremely difficult to implement if flex alone were used.
5 pts
 Homework 3: Tiny Calculator parsing with YACC/Bison)
%23view_name%3Dmon   6/7
Choose a submission type
Bison
Implementation
/40 pts
Rules
/5 pts
Extra credit
/0 pts
Bison Implementation
- General arithmetic operations completeness: 10
* -2 if not displaying calculation number
- Precedence and association of operators: 5
* -2 if unary sign precedence (+/-) is not properly handled
- Handling variables correctly: 10 points
* -3 if no variable update message is displayed
* -3 if the variable output is not properly displayed
- Interworking with flex: 5 points
- Error handling: 10 points
* -2 if not check if a referenced variable is defined or not
* -3 if no DBZ check
* -2 if displaying output when there is an error
40 pts
Rules
- Correctly listing all the rules (productions)
5 pts
Extra Credit
- Proposal: 2
- Completeness of implementation: 8
0 pts
Text Web URL Upload More
Submit Assignment
 Homework 3: Tiny Calculator parsing with YACC/Bison)

請加QQ:99515681  郵箱:99515681@qq.com   WX:codinghelp

掃一掃在手機打開當前頁
  • 上一篇:彩虹花全國客服電話-彩虹花24小時人工服務熱線
  • 下一篇:297.201代做、代寫python編程語言
  • 無相關信息
    合肥生活資訊

    合肥圖文信息
    流體仿真外包多少錢_專業CFD分析代做_友商科技CAE仿真
    流體仿真外包多少錢_專業CFD分析代做_友商科
    CAE仿真分析代做公司 CFD流體仿真服務 管路流場仿真外包
    CAE仿真分析代做公司 CFD流體仿真服務 管路
    流體CFD仿真分析_代做咨詢服務_Fluent 仿真技術服務
    流體CFD仿真分析_代做咨詢服務_Fluent 仿真
    結構仿真分析服務_CAE代做咨詢外包_剛強度疲勞振動
    結構仿真分析服務_CAE代做咨詢外包_剛強度疲
    流體cfd仿真分析服務 7類仿真分析代做服務40個行業
    流體cfd仿真分析服務 7類仿真分析代做服務4
    超全面的拼多多電商運營技巧,多多開團助手,多多出評軟件徽y1698861
    超全面的拼多多電商運營技巧,多多開團助手
    CAE有限元仿真分析團隊,2026仿真代做咨詢服務平臺
    CAE有限元仿真分析團隊,2026仿真代做咨詢服
    釘釘簽到打卡位置修改神器,2026怎么修改定位在范圍內
    釘釘簽到打卡位置修改神器,2026怎么修改定
  • 短信驗證碼 豆包網頁版入口 破天一劍 目錄網 排行網

    關于我們 | 打賞支持 | 廣告服務 | 聯系我們 | 網站地圖 | 免責聲明 | 幫助中心 | 友情鏈接 |

    Copyright © 2025 hfw.cc Inc. All Rights Reserved. 合肥網 版權所有
    ICP備06013414號-3 公安備 42010502001045

    国产人妻人伦精品_欧美一区二区三区图_亚洲欧洲久久_日韩美女av在线免费观看
    色天天综合狠狠色| 美女福利视频一区| 久久777国产线看观看精品| 日本丰满少妇黄大片在线观看| 国产精品一区二区免费看| 久久天天躁狠狠躁老女人| 少妇久久久久久被弄到高潮| 99视频在线免费播放| 久久国产精品免费视频| 精品无码一区二区三区爱欲| 久久久午夜视频| 亚洲国产精品一区二区第一页 | 韩国一区二区av| 国产精品无码专区在线观看| 欧美综合一区第一页| 久久久久久久久久久久久国产| 日本网站免费在线观看| 久久婷婷五月综合色国产香蕉| 亚洲欧洲一二三| 88国产精品欧美一区二区三区| 亚洲欧洲一区二区| 777精品视频| 日本一区视频在线观看| 国产成人在线小视频| 日本精品免费观看| www.日韩.com| 黄色一级片黄色| 九色精品免费永久在线| 成人国产精品日本在线| 亚洲mm色国产网站| 久久riav二区三区| 欧美亚州在线观看| 国产精品日韩欧美一区二区| 国产日韩欧美综合精品| 一区二区三区日韩视频| 91久久精品美女高潮| 日本一区二区免费高清视频| 色偷偷噜噜噜亚洲男人的天堂| 青青影院一区二区三区四区| 国产成人看片| 国产欧亚日韩视频| 午夜免费在线观看精品视频| 久久99久久99精品蜜柚传媒| 黄www在线观看| 欧美激情精品久久久久久变态| 99久久国产宗和精品1上映| 日韩中文字幕组| 国产精品区二区三区日本| 国产欧美va欧美va香蕉在线| 亚洲欧美国产一区二区| 国产黄色片免费在线观看| 欧美专区福利在线| 欧美激情一二区| 久久精品第九区免费观看| 欧美在线精品免播放器视频| 国产精品精品视频一区二区三区| 国产日韩第一页| 亚洲黄色成人久久久| 久久久精品日本| 国产乱肥老妇国产一区二 | 国产主播精品在线| 午夜精品一区二区三区在线观看| xxav国产精品美女主播| 国产情侣第一页| 日韩国产高清一区| 欧美精品一二区| 久久国产精品精品国产色婷婷| 黄色大片中文字幕| 亚洲区成人777777精品| 久久精品久久久久久| www国产精品内射老熟女| 欧美亚洲在线播放| 亚洲天堂电影网| 国产精品偷伦视频免费观看国产| 97人人模人人爽人人喊中文字| 欧美在线视频一区二区三区| 欧美激情18p| 国产精品私拍pans大尺度在线 | 91九色国产社区在线观看| 欧美亚洲在线视频| 亚洲一卡二卡区| 国产精品极品美女在线观看免费| 久久久影院一区二区三区| 黄色免费视频大全| 色噜噜一区二区| 综合久久国产| 国产精品久久久久福利| 久久久免费av| 97精品视频在线| 国内精品视频一区二区三区| 日韩av电影在线播放| 欧美日产国产成人免费图片| 国产精品偷伦一区二区| 久久最新免费视频| 俄罗斯精品一区二区三区| 欧美亚洲国产视频| 手机成人av在线| 亚洲综合成人婷婷小说| 欧美成人精品三级在线观看| 国产v片免费观看| 97欧美精品一区二区三区| 国产色综合天天综合网| 黄色国产小视频| 欧美日韩精品免费观看 | 久久久久久久久久国产精品| av无码精品一区二区三区| 国内自拍欧美激情| 欧美极品日韩| 日本一区视频在线观看| 亚洲熟女乱色一区二区三区| 色综合五月天导航| 欧美巨大黑人极品精男| 国产精品久久久久aaaa九色| 国产精品欧美日韩一区二区| 色妞色视频一区二区三区四区| 国产高清免费在线| 久久人91精品久久久久久不卡| 成人国产精品日本在线| 风间由美久久久| 国产九色porny| 国产精品一区二区久久精品| 国产一区二区久久久| 免费看a级黄色片| 青草青草久热精品视频在线网站| 色之综合天天综合色天天棕色| 亚洲国产一区二区三区在线 | 国产精品久久久久久久午夜| 国产精品久久网| 国产精品久久久久久久久久ktv| 国产精品久久久一区| 国产精品成人观看视频免费| 久久av.com| 九色成人免费视频| 伊人久久在线观看| 亚洲欧洲在线一区| 天堂v在线视频| 热久久免费国产视频| 欧美日韩电影一区二区三区| 欧美成人蜜桃| 国产日产欧美一区二区| 国产女女做受ⅹxx高潮| 国产伦精品一区二区三区免| 国产精品夜夜夜一区二区三区尤| 成人免费淫片aa视频免费| 99久久精品免费看国产四区 | 丁香六月激情婷婷| 日本福利视频导航| 欧美极品一区二区| 国产日韩精品电影| 97久久精品人搡人人玩| 国产激情美女久久久久久吹潮| 久久久久久久香蕉| 国产精品日韩一区二区三区| 欧美激情精品久久久久久蜜臀| 亚洲综合av一区| 日本成人在线不卡| 欧美激情 国产精品| 国产欧美日韩在线播放| 91精品视频免费| 久久久久久久91| 欧美成人亚洲成人| 亚洲精品一区二区三区av| 日韩美女av在线免费观看| 欧美激情第一页在线观看| 国产精品一区在线播放| 国产成人一区二| 国产精品二区三区| 亚洲欧美日韩不卡一区二区三区| 欧美又大粗又爽又黄大片视频| 国产在线精品一区免费香蕉| 国产精品91久久| 国产精品免费一区二区三区| 亚洲一区免费看| 欧美日韩一区二区三| 国产伦精品一区二区三区视频孕妇| 久久久久国产精品熟女影院| 国产精品久久久久久av下载红粉| 亚洲国产精品久久久久爰色欲 | www.亚洲免费视频| 一区二区免费电影| 欧美日韩大片一区二区三区| 97国产精品视频| 国产精品爽爽ⅴa在线观看| 一区二区免费电影| 黄色片视频在线播放| 国产激情一区二区三区在线观看| 国产精品男人爽免费视频1| 亚洲v日韩v欧美v综合| 精品一区久久久久久| 国产av人人夜夜澡人人爽麻豆| 欧美区二区三区| 日本久久亚洲电影| 成人av在线不卡| 国产精品久久久久久av福利软件 | 日本一区二区在线| 国产乱码精品一区二区三区卡 | 丰满人妻中伦妇伦精品app| 国产精品久久久久久搜索| 日本免费一级视频| 91精品国产亚洲|