trivial commit

This commit is contained in:
ridethepig 2023-03-18 16:23:33 +08:00
parent 8f24012862
commit 90aa2cbdf9
4 changed files with 51 additions and 6 deletions

8
.gitignore vendored
View File

@ -1 +1,9 @@
*.s *.s
assignments/PA2/cgen
assignments/PA2/cool-lex.cc
assignments/PA2/parser
assignments/PA2/semant
assignments/PA2/lexer
*.o
.cache/
compile_commands.json

View File

@ -32,3 +32,13 @@
- 它的 `case` 也是奇葩,居然是用来做动态类型匹配的,匹配的是类型而不是值,和正常的 `switch-case` 完全不一样,倒是有点像 `rust` 里面的那种感觉。 - 它的 `case` 也是奇葩,居然是用来做动态类型匹配的,匹配的是类型而不是值,和正常的 `switch-case` 完全不一样,倒是有点像 `rust` 里面的那种感觉。
测试的话,虽然 handout 里面说是直接 `make test` 然后对比输出,不过我也没看到它哪里有所谓的 reference implementation自己看了看测例觉着没啥问题就行了。 测试的话,虽然 handout 里面说是直接 `make test` 然后对比输出,不过我也没看到它哪里有所谓的 reference implementation自己看了看测例觉着没啥问题就行了。
### PA2
PA 2-5 正式写编译器。PA2 写词法分析器,首先读一遍 README 和 handout。
> 环境配置
> 因为这个项目的结构非常的智障,导致需要进行一些配置才能让 `clangd` 正常工作。因为是 `Makefile` 项目,所以不能直接生成 `compile_commands.json`
> 1. 安装 `apt install bear`,这个工具可以拦截 `make` 命令来生成上述的文件。
> 2. 在 PA2 目录下,运行 `make clean && bear -- make lexer`,然后 `clangd` 应该就不会找不到头文件之类的了

View File

@ -1,5 +1,5 @@
cool-lex.o cool-lex.d : cool-lex.cc ../../include/PA2/cool-parse.h \ cool-lex.o cool-lex.d : cool-lex.cc ../../include/PA2/cool-parse.h \
../../include/PA2/copyright.h ../../include/PA2/cool-io.h \ ../../include/PA2/copyright.h ../../include/PA2/cool-io.h \
../../include/PA2/tree.h ../../include/PA2/stringtab.h \ ../../include/PA2/tree.h ../../include/PA2/stringtab.h \
../../include/PA2/list.h ../../include/PA2/stringtab.h \ ../../include/PA2/list.h ../../include/PA2/stringtab.h \
../../include/PA2/utilities.h ../../include/PA2/utilities.h

View File

@ -1,3 +1,4 @@
%{
/* /*
* The scanner definition for COOL. * The scanner definition for COOL.
*/ */
@ -7,7 +8,6 @@
* output, so headers and global definitions are placed here to be visible * output, so headers and global definitions are placed here to be visible
* to the code in the file. Don't remove anything that was here initially * to the code in the file. Don't remove anything that was here initially
*/ */
%{
#include <cool-parse.h> #include <cool-parse.h>
#include <stringtab.h> #include <stringtab.h>
#include <utilities.h> #include <utilities.h>
@ -50,6 +50,33 @@ extern YYSTYPE cool_yylval;
*/ */
DARROW => DARROW =>
DIGIT [0-9]
DIGITS {DIGIT}+
/* */
/* Keywords Definition*/
/* Except for the constants true and false, keywords are case insensitive */
K_CLASS (?i:class)
K_ELSE (?i:else)
K_FI (?i:fi)
K_IF (?i:if)
K_IN (?i:in)
K_INHERITS (?i:inherits)
K_ISVOID (?i:isvoid)
K_LET (?i:let)
K_LOOP (?i:loop)
K_POOL (?i:pool)
K_THEN (?i:then)
K_WHILE (?i:while)
K_CASE (?i:case)
K_ESAC (?i:esac)
K_NEW (?i:new)
K_OF (?i:of)
K_NOT (?i:not)
/* the first letter of true/false must be lowercase; the trailing may be upper or lower case. */
K_TRUE t(?i:rue)
K_FALSE f(?i:alse)
%% %%