# 编译原理 **Repository Path**: zzhpalus/compilation-principle ## Basic Information - **Project Name**: 编译原理 - **Description**: java实现编译=》词法分析、语法分析 - **Primary Language**: Java - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-10-24 - **Last Updated**: 2024-11-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 编译原理 #### 介绍 java实现编译=》词法分析、语法分析 #### 软件架构 软件架构说明 #### 解析种别码 关键字类 0 => 数字 1 => begin 2 => if 3 => then 4 => while 5 => do 6 => end 10 => 变量名 18 => := 19 => > 20 => < 21 => <> 22 => <= 24 => = 25 => ; 28 => # 30 => + 31 => - 32 => * 33 => / 34 => ( 35 => ) 36 => , 37 => . 38 => : 39 => <- 40 => => 41 => // 42 => /* 43 => */ 不认识的种别 为 -1 #### 使用说明 1. 测试用例说明输入: begin x:53; /赋值 if x>0 then a12avc:=2*x; else a:2*(-x) /* 这次的实验 就是我的实验 */ end 最后输入#结束 2. 测试用例说明输出: line:1 (1, begin) line:2 (10, x) line:2 (38, :) line:2 (0, 53) line:2 (25, ;) line:2 (33, /) line:2 (-1, Error:中文!:赋值) line:3 (2, if) line:3 (10, x) line:3 (-1, >) line:3 (0, 0) line:4 (3, then) line:4 (10, a) line:4 (0, 12) line:4 (10, avc) line:4 (18, :=) line:4 (0, 2) line:4 (32, *) line:4 (10, x) line:4 (25, ;) line:5 (10, else) line:5 (10, a) line:5 (38, :) line:5 (0, 2) line:5 (32, *) line:5 (34, () line:5 (31, -) line:5 (10, x) line:5 (35, )) line:9 (6, end) 2. 实验二语法分析 测试用例1:缺少begin a := 5; b := 3 * (a + 2); end # # line:1 (10, a) line:1 (18, :=) line:1 (0, 5) line:1 (25, ;) line:2 (10, b) line:2 (18, :=) line:2 (0, 3) line:2 (32, *) line:2 (34, () line:2 (10, a) line:2 (30, +) line:2 (0, 2) line:2 (35, )) line:2 (25, ;) line:3 (6, end) line:3 (28, #) error: syntax analyze - Line 1: Missing 'begin' keyword at the start 测试用例2:缺少end (有bug!) Enter your code (end with # on a new line): begin a := 5; b := 3 * (a + 2); # line:1 (1, begin) line:2 (10, a) line:2 (18, :=) line:2 (0, 5) line:2 (25, ;) line:3 (10, b) line:3 (18, :=) line:3 (0, 3) line:3 (32, *) line:3 (34, () line:3 (10, a) line:3 (30, +) line:3 (0, 2) line:3 (35, )) line:3 (25, ;) error: syntax analyze - At the end of input: Missing 'end' keyword 测试用例3: 缺少) begin a := (5 + 3; end # # line:1 (1, begin) line:2 (10, a) line:2 (18, :=) line:2 (34, () line:2 (0, 5) line:2 (30, +) line:2 (0, 3) line:2 (25, ;) line:3 (6, end) line:3 (28, #) error: syntax analyze - Line 2: Missing closing parenthesis ')' 测试用例4: 缺少:= Enter your code (end with # on a new line): begin a = 5; end# # line:1 (1, begin) line:2 (10, a) line:2 (24, =) line:2 (0, 5) line:2 (25, ;) line:3 (6, end) line:3 (28, #) error: syntax analyze - Line 2: Missing ':=' after variable name 测试用例5: 缺少; begin a := 5 b := 3 * (a + 2) end# # line:1 (1, begin) line:2 (10, a) line:2 (18, :=) line:2 (0, 5) line:3 (10, b) line:3 (18, :=) line:3 (0, 3) line:3 (32, *) line:3 (34, () line:3 (10, a) line:3 (30, +) line:3 (0, 2) line:3 (35, )) line:4 (6, end) line:4 (28, #) error: syntax analyze - Line 3: Missing ';' between statements 3. xxxx #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)