本次美国代写是一个Rust X语言解析器相关的assignment
1 Overview
For this project you will be writing a Rust program to parse language X. Language X is similar to the C language, but is simpler and slightly different. For this program you will be reading in an X language file and converting it to a syntax highlighted XHTML version. You will be creating several structs (similar as C++ classes) that will solve the various portions of the problem.
2 X Programming Language
The following EBNF describes the X language. The non-terminals on the right are identified by italics.
Literal values are specified in bold. The operators not in bold or italics describe the special options of the
EBNF: fg for repetition, [ ] for optional, () for grouping, and j for or.
The X programming language allows for nested function declarations. Variables and functions must be declared before they are referenced or called. Identifiers have the same scoping rules as C. An identi fier may only be declared once per block, but may be declared more than once per file.
3 Output File
The output text file will output the X language file with fonts and colors specified in format.csv. The token classes are IntConstants, FloatConstants, Keywords, Operators, Variables, and Functions. They are listed in “token.rs”. The keywords of language X are: unsigned, char, short, int, long, float, double,while, if, return, void, and main. The operators of language X are: (, ,, ), {, }, =, ==, <, >, <=, >=, !=, +, -,
*, /, and ;. Each nested block should be indented another level.
4 Instruction
4.1 Getting Started
1. Download and install Rust: https://www.rust-lang.org/learn/get-started
2. In the directory where you want to put your program,
(a) Create a folder (“cargo”) named “parser” for your program by running:
cargo new parser
If the cargo is created successfully, something like this will be displayed:
(b) Inside the “parser” folder, a file named “Cargo.toml” and a folder named “src” are created.
(c) Inside the “src” folder, there is a file named “main.rs”. This is similar to the driver program in C++. The structs you created should be in other files and imported into main.rs.
(d) Down the starting code from Canvas: main.rs, token.rs, character_stream.rs into the “src” folder.
(e) Run your program insider the “parser” directory or “src” using cargo run.
If everything is working correctly, it should show the information of the token created in the mainf unction: Some warning messages will be generated. You may ignore them. They are complaining about the unused items defined in the TokenType.
4.2 Writing the Scanner (Lexical Analyzer)
Write a struct called Scanner that will open the .x file as specified on the command line and tokenize the text of the files into operators, intConstants, floatConstants, keywords, and identifiers.
Note:
• Due to the fact that there is a unary negation “-” operation in X, the scanning has one slight com plication. If a “-” sign is followed by digits, but preceded by an ID or constant, it is considered the subtract operator, and not part of the following constant.
• Don’t worry about differentiating between variables and function names at this stage. Your parser will deal with this issue later.
• The Scanner struct should have a method named get_next_token() or something similar that when called, will return the next token as read from the .x file.
• You need to finish the CharStream struct (in character_stream.rs) to be able to read the input file character by character. Unlike C++, Rust does not have a convenient way of reading a file character by character using FileInputStream. For simplicity, you may read the whole file at once and store it in a string or a vector of strings. Then you may read the stored string or vector of strings character by character. But keep in mind that this is not how modern scanner works because the input program may be too large to be stored as a second copy.
程序辅导定制C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB

本网站支持 Alipay WeChatPay PayPal等支付方式
E-mail: vipdue@outlook.com 微信号:vipnxx
如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。
