Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
6440c59e
Commit
6440c59e
authored
Oct 20, 2008
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- removed need for lhs field in stat node
- as a result deleted some more code R=r OCL=17449 CL=17449
parent
61361af9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
24 deletions
+21
-24
node.go
usr/gri/pretty/node.go
+1
-1
parser.go
usr/gri/pretty/parser.go
+6
-4
printer.go
usr/gri/pretty/printer.go
+6
-18
scanner.go
usr/gri/pretty/scanner.go
+8
-1
No files found.
usr/gri/pretty/node.go
View file @
6440c59e
...
...
@@ -173,7 +173,7 @@ export var BadType = NewType(0, Scanner.ILLEGAL);
export
type
Stat
struct
{
pos
,
tok
int
;
init
,
post
*
Stat
;
lhs
,
expr
*
Expr
;
expr
*
Expr
;
block
*
List
;
decl
*
Decl
;
}
...
...
usr/gri/pretty/parser.go
View file @
6440c59e
...
...
@@ -904,13 +904,15 @@ func (P *Parser) ParseSimpleStat() *Node.Stat {
Scanner
.
SUB_ASSIGN
,
Scanner
.
MUL_ASSIGN
,
Scanner
.
QUO_ASSIGN
,
Scanner
.
REM_ASSIGN
,
Scanner
.
AND_ASSIGN
,
Scanner
.
OR_ASSIGN
,
Scanner
.
XOR_ASSIGN
,
Scanner
.
SHL_ASSIGN
,
Scanner
.
SHR_ASSIGN
:
s
=
Node
.
NewStat
(
P
.
pos
,
P
.
tok
);
// assignment
pos
,
tok
:=
P
.
pos
,
P
.
tok
;
P
.
Next
();
s
.
lhs
=
x
;
s
.
expr
=
P
.
ParseExpressionList
();
if
l
,
r
:=
x
.
len
(),
s
.
expr
.
len
();
l
>
1
&&
r
>
1
&&
l
!=
r
{
y
:=
P
.
ParseExpressionList
();
if
xl
,
yl
:=
x
.
len
(),
y
.
len
();
xl
>
1
&&
yl
>
1
&&
xl
!=
yl
{
P
.
Error
(
x
.
pos
,
"arity of lhs doesn't match rhs"
);
}
s
=
Node
.
NewStat
(
x
.
pos
,
Scanner
.
EXPRSTAT
);
s
.
expr
=
Node
.
NewExpr
(
pos
,
tok
,
x
,
y
);
default
:
var
pos
,
tok
int
;
...
...
usr/gri/pretty/printer.go
View file @
6440c59e
...
...
@@ -232,10 +232,10 @@ func (P *Printer) Expr1(x *Node.Expr, prec1 int) {
case
Scanner
.
PERIOD
:
// selector or type guard
P
.
Expr1
(
x
.
x
,
8
);
// 8 == highest precedence
P
.
Expr1
(
x
.
x
,
Scanner
.
HighestPrec
);
P
.
String
(
x
.
pos
,
"."
);
if
x
.
y
!=
nil
{
P
.
Expr1
(
x
.
y
,
8
);
P
.
Expr1
(
x
.
y
,
Scanner
.
HighestPrec
);
}
else
{
P
.
String
(
0
,
"("
);
P
.
Type
(
x
.
t
);
...
...
@@ -244,14 +244,14 @@ func (P *Printer) Expr1(x *Node.Expr, prec1 int) {
case
Scanner
.
LBRACK
:
// index
P
.
Expr1
(
x
.
x
,
8
);
P
.
Expr1
(
x
.
x
,
Scanner
.
HighestPrec
);
P
.
String
(
x
.
pos
,
"["
);
P
.
Expr1
(
x
.
y
,
0
);
P
.
String
(
0
,
"]"
);
case
Scanner
.
LPAREN
:
// call
P
.
Expr1
(
x
.
x
,
8
);
P
.
Expr1
(
x
.
x
,
Scanner
.
HighestPrec
);
P
.
String
(
x
.
pos
,
"("
);
P
.
Expr1
(
x
.
y
,
0
);
P
.
String
(
0
,
")"
);
...
...
@@ -268,7 +268,7 @@ func (P *Printer) Expr1(x *Node.Expr, prec1 int) {
if
x
.
x
==
nil
{
// unary expression
P
.
Token
(
x
.
pos
,
x
.
tok
);
P
.
Expr1
(
x
.
y
,
7
);
// 7 == unary operator precedence
P
.
Expr1
(
x
.
y
,
Scanner
.
UnaryPrec
);
}
else
{
// binary expression: print ()'s if necessary
prec
:=
Scanner
.
Precedence
(
x
.
tok
);
...
...
@@ -289,7 +289,7 @@ func (P *Printer) Expr1(x *Node.Expr, prec1 int) {
func
(
P
*
Printer
)
Expr
(
x
*
Node
.
Expr
)
{
P
.
Expr1
(
x
,
0
);
P
.
Expr1
(
x
,
Scanner
.
LowestPrec
);
}
...
...
@@ -372,18 +372,6 @@ func (P *Printer) Stat(s *Node.Stat) {
// declaration
P
.
Declaration
(
s
.
decl
,
false
);
case
Scanner
.
DEFINE
,
Scanner
.
ASSIGN
,
Scanner
.
ADD_ASSIGN
,
Scanner
.
SUB_ASSIGN
,
Scanner
.
MUL_ASSIGN
,
Scanner
.
QUO_ASSIGN
,
Scanner
.
REM_ASSIGN
,
Scanner
.
AND_ASSIGN
,
Scanner
.
OR_ASSIGN
,
Scanner
.
XOR_ASSIGN
,
Scanner
.
SHL_ASSIGN
,
Scanner
.
SHR_ASSIGN
:
// assignment
P
.
Expr
(
s
.
lhs
);
P
.
Blank
();
P
.
Token
(
s
.
pos
,
s
.
tok
);
P
.
Blank
();
P
.
Expr
(
s
.
expr
);
P
.
semi
=
true
;
case
Scanner
.
INC
,
Scanner
.
DEC
:
P
.
Expr
(
s
.
expr
);
P
.
Token
(
s
.
pos
,
s
.
tok
);
...
...
usr/gri/pretty/scanner.go
View file @
6440c59e
...
...
@@ -210,6 +210,13 @@ export func TokenString(tok int) string {
}
export
const
(
LowestPrec
=
-
1
;
UnaryPrec
=
7
;
HighestPrec
=
8
;
)
export
func
Precedence
(
tok
int
)
int
{
switch
tok
{
case
COLON
:
...
...
@@ -227,7 +234,7 @@ export func Precedence(tok int) int {
case
MUL
,
QUO
,
REM
,
SHL
,
SHR
,
AND
:
return
6
;
}
return
-
1
;
return
LowestPrec
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment