日韩精品一区二区三区高清_久久国产热这里只有精品8_天天做爽夜夜做爽_一本岛在免费一二三区

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

代做Micro Language Compiler

時間:2024-02-07  來源:合肥網hfw.cc  作者:hfw.cc 我要糾錯



Assignment 1: Micro Language Compiler
1 Introduction
In this assignment, you are required to design and implement a compiler frontend for Micro
language which transforms the Micro Program into corresponding LLVM Intermediate Representation (IR) and finally translated to RISC-V assembly code and executable with the help of
LLVM optimizer and its RISC-V backend. After that, we can execute the compiled program on our
RISC-V docker container to verify the correctness of your compiler.
Since it is a senior major elective course, we don’t want to set any limitation for you. You are strongly
recommended to use Lex/Flex and Yacc/Bison taught in tutorial 3 to design your compiler frontend,
but it is not forcible. You can choose Any Programming Language you like for this assignment,
but the RISC-V container we use only has C/C++ toolchain installed and you need to provide me a
Dockerfile to run your compiler and execute the RISC-V program, which may need some extra effort.
Some languages also provide tools like Lex and Yacc, and you are free to use them. It is also OK if
you want to design the scanner and parser by hand instead of using tools.
2 Micro Language
Before we move on to the compiler design, it is necessary to have an introduction to Micro Language,
that serves as the input of our compiler. Actually, it is a very simple language, with limited number
of tokens and production rules of context-free grammar (CFG):
• Only integers(i**); No float numbers
• No Declarations
• Variable consists of a-z, A-Z, 0-9, at most ** characters long, must start with character and are
initialized as 0
• Comments begin with ”−−” and end with end-of-line(EOL)
• Three kind of statements:
– assignments, e.g. a:=b+c
– read(list of IDs), e.g. read(a, b)
– write(list of Expressions), e.g. write (a, b, a+b)
• BEGIN, END, READ, WRITE are reserved words
• Tokens may not extend to the following line
1
2.1 Tokens & Regular Expression
Micro Language has 14 Tokens, and the regular expression for each token is listed below. Since BEGIN
is a reserved word in C/C++, we need to use the alternative BEGIN as the token class.
1. BEGIN : begin
2. END: end
3. READ: read
4. WRITE: write
5. LPAREN: (
6. RPAREN: )
7. SEMICOLON: ;
8. COMMA: ,
9. ASSIGNOP: :=
10. PLUSOP: +
11. MINUSOP: −
12. ID: [a−zA−Z][a−zA−Z0−9 ]{0,31}
13. INTLITERAL: −?[0−9]+
14. SCANEOF: <<EOF>>
2.2 Context Free Grammar
Here is the extended context-free grammar (CFG) of Micro Language:
1. <start> → <program> SCANEOF
2. <program> → BEGIN <statement list> END
3. <statement list> → <statement> {<statement>}
4. <statement> → ID ASSIGNOP <expression>;
5. <statement> → READ LPAREN <id list> RPAREN;
6. <statement> → WRITE LPAREN<expr list> RPAREN;
7. <id list > → ID {COMMA ID}
8. <expr list > → <expression> {COMMA <expression>}
9. <expression> → <primary> {<add op> <primary>}
10. <primary> → LPAREN <expression> RPAREN
11. <primary> → ID
12. <primary> → INTLITERAL
13. <add op> → PLUSOP
14. <add op> → MINUSOP
Note: {} means the content inside can appear 0, 1 or multiple times.
2.3 How to Run Micro Compiler
Here is a very simple Micro program that we are going to use as the sample program throughout this
instruction. SCANEOF is the end of line and we do not need to explicitly write it in the program.
−− Expected Output: 30
begin
A := 10;
B := A + 20;
write (B);
end
We can use our compiler to compile, optimize and execute this program to get expected output 30.
Note: The exact command to run your compiler is up to you. Just specify out in your report how
to compile and execute your compiler to get the expected output.
118010200@c2d52c9b1339:˜/A1$ ./compiler ./testcases/test0.m
118010200@c2d52c9b1339:˜/A1$ llc −march=riscv64 ./program.ll −o ./program.s
118010200@c2d52c9b1339:˜/A1$ riscv64−unknown−linux−gnu−gcc ./program.s −o ./program
118010200@c2d52c9b1339:˜/A1$ qemu−riscv64 −L /opt/riscv/sysroot ./program
30
2
3 Compiler Design
Figure 1 shows the overall structure of a compiler. In this assignment, your task is to implement the
frontend only, which contains scanner, parser and intermediate code generator and form a whole →
compiler with LLVM for Micro language.
Figure 1: Compiler Structure
3.1 Scanner
Scanner takes input character stream and extracts out a series of tokens, and your scanner should
be able to print out both token class and lexeme for each token. Figure ?? shows an example of the
sample Micro program.
118010200@c2d52c9b1339:˜/A1$ ./compiler ./testcases/test0.m −−scan−only
BEGIN begin
ID A
ASSIGNOP :=
INTLITERAL 10
SEMICOLON ;
ID B
ASSIGNOP :=
ID A
PLUOP +
INTLITERAL 20
SEMICOLON ;
WRITE write
LPAREN (
ID B
RPAREN )
SEMICOLON ;
END end
SCANEOF
3
3.2 Parser
Parser receives the tokens extracted from scanner, and generates a parse tree (or concrete syntax tree),
and futhermore, the abstract syntax tree (AST) based on the CFG. Your compiler should be able to
print out both the parse tree and the abstract syntax tree, and visualize them with graphviz.
3.2.1 Parse Tree (Concrete Syntax Tree)
Figure 2 shows an example of the concrete syntax tree generated from the sample program:
Figure 2: Concrete Syntax Tree of Sample Program
3.2.2 Abstract Syntax Tree
Figure 3 shows an example of the abstract syntax tree generated from the sample program:
Figure 3: Abstract Syntax Tree of Sample Program
4
3.3 Intermediate Code Generator
For all the assignments in this course, the intermediate representation (IR) of the compiler should be
the LLVM IR. There are mainly two reasons why LLVM IR is chosen. One is that LLVM IR can take
advantage of the powerful LLVM optimizer and make up for the missing backend part of compiler in
this course. The other is that LLVM IR can be easier translated into assembly code for any target
machine, no matter MIPS, x86 64, ARM, or RISC-V. This functionality can make our compiler more
compatible to machines with different architecture. The following shows the LLVM IR generated for
the sample Micro program:
; Declare printf
declare i** @printf (i8 ∗, ...)
; Declare scanf
declare i** @scanf(i8 ∗, ...)
define i** @main() {
% ptr0 = alloca i**
store i** 10, i**∗ % ptr0
%A = load i**, i**∗ % ptr0
% 1 = add i** %A, 20
store i** % 1, i**∗ % ptr0
%B = load i**, i**∗ % ptr0
% scanf format0 = alloca [4 x i8 ]
store [4 x i8 ] c”%d\0A\00”, [4 x i8]∗ % scanf format0
% scanf str0 = getelementptr [4 x i8 ], [4 x i8]∗ % scanf format0, i** 0, i** 0
call i** (i8 ∗, ...) @printf (i8∗ % scanf str0 , i** %B)
ret i** 0
}
3.4 Bonus (Extra Credits 10%)
If you are interested and want to make your compiler better, you may try the following options:
• Add robust syntax error report
• Add a symbol table to make your compiler more complete
• Generate LLVM IR with LLVM C/C++ API instead of simply generating the string
• Optimize the LLVM IR generation plan for more efficient IR
• Any other you can think about...
4 Submission and Grading
4.1 Grading Scheme
• Scanner: 20%
• Parser: 40% (20% for parse tree generator and 20% for AST generation)
• Intermediate Code Generator: 30%
We have prepared 10 test cases, and the points for each section will be graded according to the
number of testcases you passed.
• Technical Report: 10%
If your report properly covers the three required aspects and the format is clean, you will get 10
points.
5
• Bonus: 10%
Refer to section 3.4 for more details. The grading of this part will be very flexible and highly
depend on the TA’s own judgement. Please specify clearly what you have done for the bonus
part so that he do not miss anything.
4.2 Submission with Source Code
If you want to submit source C/C++ program that is executable in our RISC-V docker container,
your submission should look like:
csc4180−a1−118010200.zip
|−
|−−− csc4180−a1−118010200−report.pdf
|−
|−−− testcases
|−
|−−− src
|−
|−−−Makefile
|−−−ir generator.cpp
|−−−ir generator.hpp
|−−−node.cpp
|−−−node.hpp
|−−−scanner.l
|−−−parser.y
|−−−Other possible files
4.3 Submission with Docker
If you want to submit your program in a docker, your submission should look like:
csc4180−a1−118010200.zip
|−
|−−− csc4180−a1−118010200.Dockerfile
|−
|−−− csc4180−a1−118010200−report.pdf
|−
|−−− src
|−
|−−−Makefile
|−
|−−−run compiler.sh
|−
|−−−Your Code Files
4.4 Technical Report
Please answer the following questions in your report:
• How to execute your compiler to get expected output?
• How do you design the Scanner?
• How do you design the Parser?
• How do you design the Intermediate Code Generator?
• Some other things you have done in this assignment?
The report doesn’t need to be very long, but the format should be clean. As long as the three questions
are clearly answered and the format is OK, your report will get full mark.
如有需要,請加QQ:99515681 或WX:codehelp

掃一掃在手機打開當前頁
  • 上一篇:COM3524代做、代寫Java,Python編程設計
  • 下一篇:CISC3025代做、代寫Java,c++設計編程
  • 無相關信息
    合肥生活資訊

    合肥圖文信息
    2025年10月份更新拼多多改銷助手小象助手多多出評軟件
    2025年10月份更新拼多多改銷助手小象助手多
    有限元分析 CAE仿真分析服務-企業/產品研發/客戶要求/設計優化
    有限元分析 CAE仿真分析服務-企業/產品研發
    急尋熱仿真分析?代做熱仿真服務+熱設計優化
    急尋熱仿真分析?代做熱仿真服務+熱設計優化
    出評 開團工具
    出評 開團工具
    挖掘機濾芯提升發動機性能
    挖掘機濾芯提升發動機性能
    海信羅馬假日洗衣機亮相AWE  復古美學與現代科技完美結合
    海信羅馬假日洗衣機亮相AWE 復古美學與現代
    合肥機場巴士4號線
    合肥機場巴士4號線
    合肥機場巴士3號線
    合肥機場巴士3號線
  • 短信驗證碼 trae 豆包網頁版入口 目錄網 排行網

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

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

    日韩精品一区二区三区高清_久久国产热这里只有精品8_天天做爽夜夜做爽_一本岛在免费一二三区

      <em id="rw4ev"></em>

        <tr id="rw4ev"></tr>

        <nav id="rw4ev"></nav>
        <strike id="rw4ev"><pre id="rw4ev"></pre></strike>
        一区二区亚洲精品| 欧美日韩成人综合在线一区二区| 国产日韩欧美日韩| 在线观看不卡| 国产日韩精品视频一区二区三区| 一区二区三区欧美在线| 国产精品一页| 久久精品一级爱片| 精品1区2区3区4区| 亚洲一区二区三区精品动漫| 国产精品国码视频| 久久亚洲色图| 一本久道久久综合婷婷鲸鱼| 国产伦精品一区二区三区在线观看| 亚洲天堂av综合网| 午夜影视日本亚洲欧洲精品| 日韩午夜在线观看视频| 亚洲美女少妇无套啪啪呻吟| 国产精品国产自产拍高清av| 麻豆精品传媒视频| 亚洲美女尤物影院| 国产日韩精品入口| 狼狼综合久久久久综合网| 一本色道久久综合| 国产一区视频在线观看免费| 妖精视频成人观看www| 日韩亚洲欧美在线观看| 亚洲精品视频免费在线观看| 亚洲综合视频一区| 国产精品久久久久久久久久久久久| 欧美一级视频| 亚洲综合久久久久| 亚洲一区二区三区在线播放| 久久精品国产99国产精品澳门| 国产精品一区二区你懂得| 韩国一区二区三区美女美女秀| 国产午夜精品久久久久久免费视| 国产亚洲欧美另类中文| 免费成人在线观看视频| 亚洲视频久久| 亚洲欧美精品在线| 狠狠入ady亚洲精品经典电影| 国产精品r级在线| 激情欧美一区二区三区| 亚洲黄色免费电影| 国产精品色网| 国产精品久久久久久久久果冻传媒| 亚洲国产另类精品专区| 国产亚洲精品久久久久婷婷瑜伽| 欧美视频在线一区二区三区| 免费成年人欧美视频| 欧美人与性动交α欧美精品济南到| 国内成人精品一区| 国产欧美一区二区三区久久| 亚洲免费在线看| 久久九九免费视频| 久久夜色精品国产噜噜av| 久久婷婷激情| 亚洲一区影音先锋| 欧美aⅴ一区二区三区视频| 久久精品国产69国产精品亚洲| 日韩亚洲欧美成人| 欧美a级片一区| 亚洲国产二区| 狠狠色伊人亚洲综合成人| 女人色偷偷aa久久天堂| 欧美一级电影久久| 欧美尤物一区| 国产丝袜一区二区三区| 国产亚洲免费的视频看| 久久亚洲精品中文字幕冲田杏梨| 麻豆精品视频在线观看视频| 性色av一区二区三区红粉影视| 一区二区三区精品视频在线观看| 香蕉av福利精品导航| 国产裸体写真av一区二区| 国产亚洲一区二区三区| 亚洲伦理在线免费看| 国产精品国产三级国产| 欧美国产视频在线观看| 乱人伦精品视频在线观看| 国产精品看片资源| 91久久精品一区| 欧美精品一区二区高清在线观看| 欧美高清视频免费观看| 欧美激情导航| 午夜国产欧美理论在线播放| 欧美一区2区三区4区公司二百| 一本高清dvd不卡在线观看| 香蕉久久精品日日躁夜夜躁| 久久av一区二区三区| 亚洲高清av| 亚洲午夜一区二区| 欧美精品在线观看| 国产精品综合久久久| 亚洲在线不卡| 国产精品国产三级国产| 亚洲免费视频中文字幕| 宅男精品视频| 久久米奇亚洲| 一卡二卡3卡四卡高清精品视频| 久久蜜桃香蕉精品一区二区三区| 欧美大片一区二区三区| 欧美一级网站| 黄色亚洲精品| 国产女人18毛片水18精品| 在线观看欧美日韩国产| 欧美色播在线播放| 国产精品夫妻自拍| 另类人畜视频在线| 一区二区三区欧美在线| 亚洲午夜久久久久久久久电影院| 欧美国产亚洲视频| 亚洲一区欧美| 国产精品视频福利| 午夜宅男欧美| 国产精品高潮在线| 在线亚洲免费视频| 国产精品亚洲欧美| 亚洲电影免费观看高清| 国产亚洲亚洲| 亚洲国产精品一区二区三区| 欧美a级片一区| 国产精品久久久久久久久动漫| 亚洲无线一线二线三线区别av| 亚洲免费影视第一页| 一区二区欧美国产| 一区二区在线观看视频| 国产精品影音先锋| 国精品一区二区| 国产日韩欧美精品在线| 欧美日韩亚洲综合| 欧美一级精品大片| 国产一区二区三区网站| 久久综合九色综合网站| 国产精品99久久久久久白浆小说| 久热精品视频在线| 在线观看日韩国产| 欧美—级a级欧美特级ar全黄| 欧美日韩一区二区高清| 在线成人免费视频| 亚洲欧美另类在线观看| 亚洲综合日韩中文字幕v在线| 国产欧美精品va在线观看| 国产精品国产三级欧美二区| 国产精品视频不卡| 亚洲精品在线一区二区| 久久国产精品久久久久久| 99国产精品一区| 在线观看福利一区| 亚洲高清网站| 亚洲一区二区高清视频| 香蕉久久久久久久av网站| 欧美日韩在线播放一区| 亚洲在线观看视频网站| 亚洲午夜电影| 性感少妇一区| 国产精品国产自产拍高清av王其| 久久成人精品电影| 国产精品视频大全| 一区二区欧美国产| 国产精品一页| 国产精品入口日韩视频大尺度| 亚洲天堂免费观看|