Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
fbea4d04
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fbea4d04
编写于
9月 28, 2010
作者:
G
Graydon Hoare
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More rustc expr-parsing logic.
上级
5b4b035c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
238 addition
and
22 deletion
+238
-22
src/comp/front/ast.rs
src/comp/front/ast.rs
+14
-16
src/comp/front/parser.rs
src/comp/front/parser.rs
+224
-6
未找到文件。
src/comp/front/ast.rs
浏览文件 @
fbea4d04
...
...
@@ -10,12 +10,14 @@
type
block
=
vec
[
@
stmt
];
tag
binop
{
plus
;
minus
;
star
;
slash
;
percent
;
caret
;
add
;
sub
;
mul
;
div
;
rem
;
and
;
or
;
bitxor
;
bitand
;
bitor
;
lsl
;
...
...
@@ -30,11 +32,11 @@
}
tag
unop
{
box
;
deref
;
bitnot
;
not
;
neg
;
deref
;
cast
(
@
ty
);
}
tag
stmt
{
...
...
@@ -49,14 +51,7 @@
decl_item
(
ident
,
@
item
);
}
tag
lval
{
lval_ident
(
ident
);
lval_ext
(
@
lval
,
ident
);
lval_idx
(
@
lval
,
@
expr
);
}
tag
expr
{
expr_box
(
@
expr
);
expr_vec
(
vec
[
@
expr
]);
expr_tup
(
vec
[
@
expr
]);
expr_rec
(
vec
[
tup
(
ident
,
@
expr
)]);
...
...
@@ -64,7 +59,10 @@
expr_binary
(
binop
,
@
expr
,
@
expr
);
expr_unary
(
unop
,
@
expr
);
expr_lit
(
@
lit
);
expr_lval
(
@
lval
);
expr_ident
(
ident
);
expr_field
(
@
expr
,
ident
);
expr_index
(
@
expr
,
@
expr
);
expr_cast
(
@
expr
,
ty
);
}
tag
lit
{
...
...
src/comp/front/parser.rs
浏览文件 @
fbea4d04
...
...
@@ -166,34 +166,252 @@ fn get_span() -> common.span {
ret
e
;
}
case
(
token
.TUP
)
{
p
.bump
();
auto
pf
=
parse_expr
;
auto
es
=
parse_seq
[
@
ast
.expr
](
token
.LPAREN
,
token
.RPAREN
,
some
(
token
.COMMA
),
pf
,
p
);
ret
@
ast
.expr_tup
(
es
);
}
case
(
token
.VEC
)
{
p
.bump
();
auto
pf
=
parse_expr
;
auto
es
=
parse_seq
[
@
ast
.expr
](
token
.LPAREN
,
token
.RPAREN
,
some
(
token
.COMMA
),
pf
,
p
);
ret
@
ast
.expr_vec
(
es
);
}
case
(
token
.REC
)
{
p
.bump
();
state
fn
parse_entry
(
parser
p
)
->
tup
(
ast
.ident
,
@
ast
.expr
)
{
auto
i
=
parse_ident
(
p
);
expect
(
p
,
token
.EQ
);
auto
e
=
parse_expr
(
p
);
ret
tup
(
i
,
e
);
}
auto
pf
=
parse_entry
;
auto
es
=
parse_seq
[
tup
(
ast
.ident
,
@
ast
.expr
)](
token
.LPAREN
,
token
.RPAREN
,
some
(
token
.COMMA
),
pf
,
p
);
ret
@
ast
.expr_rec
(
es
);
}
case
(
token
.IDENT
(
?
i
))
{
p
.bump
();
ret
@
ast
.expr_ident
(
i
);
}
case
(
_
)
{
ret
@
ast
.expr_lit
(
parse_lit
(
p
));
}
}
}
state
fn
parse_path_expr
(
parser
p
)
->
@
ast
.expr
{
auto
e
=
parse_bottom_expr
(
p
);
while
(
true
)
{
alt
(
p
.peek
())
{
case
(
token
.DOT
)
{
p
.bump
();
alt
(
p
.peek
())
{
case
(
token
.IDENT
(
?
i
))
{
p
.bump
();
e
=
@
ast
.expr_field
(
e
,
i
);
}
case
(
token
.LPAREN
)
{
auto
ix
=
parse_bottom_expr
(
p
);
e
=
@
ast
.expr_index
(
e
,
ix
);
}
}
}
case
(
_
)
{
ret
e
;
}
}
}
ret
e
;
}
state
fn
parse_
negation
_expr
(
parser
p
)
->
@
ast
.expr
{
state
fn
parse_
prefix
_expr
(
parser
p
)
->
@
ast
.expr
{
alt
(
p
.peek
())
{
case
(
token
.NOT
)
{
auto
e
=
parse_
negation
_expr
(
p
);
auto
e
=
parse_
prefix
_expr
(
p
);
ret
@
ast
.expr_unary
(
ast
.not
,
e
);
}
case
(
token
.TILDE
)
{
auto
e
=
parse_
negation
_expr
(
p
);
auto
e
=
parse_
prefix
_expr
(
p
);
ret
@
ast
.expr_unary
(
ast
.bitnot
,
e
);
}
case
(
token
.BINOP
(
?
b
))
{
alt
(
b
)
{
case
(
token
.MINUS
)
{
auto
e
=
parse_prefix_expr
(
p
);
ret
@
ast
.expr_unary
(
ast
.neg
,
e
);
}
case
(
token
.STAR
)
{
auto
e
=
parse_prefix_expr
(
p
);
ret
@
ast
.expr_unary
(
ast
.deref
,
e
);
}
case
(
_
)
{
ret
parse_path_expr
(
p
);
}
}
}
case
(
token
.AT
)
{
p
.bump
();
auto
e
=
parse_prefix_expr
(
p
);
ret
@
ast
.expr_unary
(
ast
.box
,
e
);
}
case
(
_
)
{
ret
parse_bottom_expr
(
p
);
ret
parse_path_expr
(
p
);
}
}
}
state
fn
parse_binops
(
parser
p
,
(
state
fn
(
parser
)
->
@
ast
.expr
)
sub
,
vec
[
tup
(
token
.binop
,
ast
.binop
)]
ops
)
->
@
ast
.expr
{
auto
e
=
sub
(
p
);
auto
more
=
true
;
while
(
more
)
{
more
=
false
;
auto
t
=
p
.peek
();
alt
(
t
)
{
case
(
token
.BINOP
(
?
op
))
{
for
(
tup
(
token
.binop
,
ast
.binop
)
pair
in
ops
)
{
if
(
pair
._0
==
op
)
{
e
=
@
ast
.expr_binary
(
pair
._1
,
e
,
sub
(
p
));
more
=
true
;
t
=
p
.peek
();
}
}
}
case
(
_
)
{
}
}
}
ret
e
;
}
state
fn
parse_binary_exprs
(
parser
p
,
(
state
fn
(
parser
)
->
@
ast
.expr
)
sub
,
vec
[
tup
(
token
.token
,
ast
.binop
)]
ops
)
->
@
ast
.expr
{
auto
e
=
sub
(
p
);
auto
more
=
true
;
while
(
more
)
{
more
=
false
;
auto
t
=
p
.peek
();
for
(
tup
(
token
.token
,
ast
.binop
)
pair
in
ops
)
{
if
(
pair
._0
==
t
)
{
e
=
@
ast
.expr_binary
(
pair
._1
,
e
,
sub
(
p
));
more
=
true
;
t
=
p
.peek
();
}
}
}
ret
e
;
}
state
fn
parse_factor_expr
(
parser
p
)
->
@
ast
.expr
{
auto
sub
=
parse_prefix_expr
;
ret
parse_binops
(
p
,
sub
,
vec
(
tup
(
token
.STAR
,
ast
.mul
),
tup
(
token
.SLASH
,
ast
.div
),
tup
(
token
.PERCENT
,
ast
.rem
)));
}
state
fn
parse_term_expr
(
parser
p
)
->
@
ast
.expr
{
auto
sub
=
parse_factor_expr
;
ret
parse_binops
(
p
,
sub
,
vec
(
tup
(
token
.PLUS
,
ast
.add
),
tup
(
token
.MINUS
,
ast
.sub
)));
}
state
fn
parse_shift_expr
(
parser
p
)
->
@
ast
.expr
{
auto
sub
=
parse_term_expr
;
ret
parse_binops
(
p
,
sub
,
vec
(
tup
(
token
.LSL
,
ast
.lsl
),
tup
(
token
.LSR
,
ast
.lsr
),
tup
(
token
.ASR
,
ast
.asr
)));
}
state
fn
parse_bitand_expr
(
parser
p
)
->
@
ast
.expr
{
auto
sub
=
parse_shift_expr
;
ret
parse_binops
(
p
,
sub
,
vec
(
tup
(
token
.AND
,
ast
.bitand
)));
}
state
fn
parse_bitxor_expr
(
parser
p
)
->
@
ast
.expr
{
auto
sub
=
parse_bitand_expr
;
ret
parse_binops
(
p
,
sub
,
vec
(
tup
(
token
.CARET
,
ast
.bitxor
)));
}
state
fn
parse_bitor_expr
(
parser
p
)
->
@
ast
.expr
{
auto
sub
=
parse_bitxor_expr
;
ret
parse_binops
(
p
,
sub
,
vec
(
tup
(
token
.OR
,
ast
.bitor
)));
}
state
fn
parse_cast_expr
(
parser
p
)
->
@
ast
.expr
{
auto
e
=
parse_bitor_expr
(
p
);
while
(
true
)
{
alt
(
p
.peek
())
{
case
(
token
.AS
)
{
p
.bump
();
auto
t
=
parse_ty
(
p
);
e
=
@
ast
.expr_cast
(
e
,
t
);
}
case
(
_
)
{
ret
e
;
}
}
}
ret
e
;
}
state
fn
parse_relational_expr
(
parser
p
)
->
@
ast
.expr
{
auto
sub
=
parse_cast_expr
;
ret
parse_binary_exprs
(
p
,
sub
,
vec
(
tup
(
token
.LT
,
ast
.lt
),
tup
(
token
.LE
,
ast
.le
),
tup
(
token
.GE
,
ast
.ge
),
tup
(
token
.GT
,
ast
.gt
)));
}
state
fn
parse_equality_expr
(
parser
p
)
->
@
ast
.expr
{
auto
sub
=
parse_relational_expr
;
ret
parse_binary_exprs
(
p
,
sub
,
vec
(
tup
(
token
.EQEQ
,
ast
.eq
),
tup
(
token
.NE
,
ast
.ne
)));
}
state
fn
parse_and_expr
(
parser
p
)
->
@
ast
.expr
{
auto
sub
=
parse_equality_expr
;
ret
parse_binary_exprs
(
p
,
sub
,
vec
(
tup
(
token
.ANDAND
,
ast
.and
)));
}
state
fn
parse_or_expr
(
parser
p
)
->
@
ast
.expr
{
auto
sub
=
parse_and_expr
;
ret
parse_binary_exprs
(
p
,
sub
,
vec
(
tup
(
token
.OROR
,
ast
.or
)));
}
state
fn
parse_expr
(
parser
p
)
->
@
ast
.expr
{
ret
parse_
negation
_expr
(
p
);
ret
parse_
or
_expr
(
p
);
}
state
fn
parse_stmt
(
parser
p
)
->
@
ast
.stmt
{
...
...
@@ -221,7 +439,7 @@ fn get_span() -> common.span {
state
fn
parse_slot_ident_pair
(
parser
p
)
->
rec
(
ast
.slot
slot
,
ast
.ident
ident
)
{
auto
s
=
parse_slot
(
p
);
auto
i
=
parse_ident
(
p
);
auto
i
=
parse_ident
(
p
);
ret
rec
(
slot
=
s
,
ident
=
i
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录