trivial commit
This commit is contained in:
parent
8f24012862
commit
90aa2cbdf9
8
.gitignore
vendored
8
.gitignore
vendored
@ -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
|
||||||
|
|||||||
12
CS143体验报告.md
12
CS143体验报告.md
@ -31,4 +31,14 @@
|
|||||||
- `let` 语法也是究极奇葩,我是不能理解为什么要设计成这个样子。想定义一个局部变量都得加一层嵌套,这个嵌套多得让我觉得我 tm 是在写 `scheme`。
|
- `let` 语法也是究极奇葩,我是不能理解为什么要设计成这个样子。想定义一个局部变量都得加一层嵌套,这个嵌套多得让我觉得我 tm 是在写 `scheme`。
|
||||||
- 它的 `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` 应该就不会找不到头文件之类的了
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user