Commit a1ee6804 authored by Robert Griesemer's avatar Robert Griesemer

- fixed bug which prevented parser.go from compiling

  (typo in ptr decl lead to an unresolved forward declaration)
- fixed parser bugs
- fixed Makefile
- now successfully parses most code

Issues:
- composite literals (cannot be identified easily from syntax alone)
- new(T, ...) (cannot be identified easily from syntax alone since
  new is not a keyword and thus could be a different function then
  the allocation function at which point "new((x + y))" is legal,
  but the inner "(x" looks like the beginning of a function type)

R=r
OCL=15515
CL=15515
parent 81d7c518
master go1.12-nxd go18-fannkuch-entryshift go19 x/sched y/unqotechar-err weekly.2012-03-27 weekly.2012-03-22 weekly.2012-03-13 weekly.2012-03-04 weekly.2012-02-22 weekly.2012-02-14 weekly.2012-02-07 weekly.2012-01-27 weekly.2012-01-20 weekly.2012-01-15 weekly.2011-12-22 weekly.2011-12-14 weekly.2011-12-06 weekly.2011-12-02 weekly.2011-12-01 weekly.2011-11-18 weekly.2011-11-09 weekly.2011-11-08 weekly.2011-11-02 weekly.2011-11-01 weekly.2011-10-26 weekly.2011-10-25 weekly.2011-10-18 weekly.2011-10-06 weekly.2011-09-21 weekly.2011-09-16 weekly.2011-09-07 weekly.2011-09-01 weekly.2011-08-17 weekly.2011-08-10 weekly.2011-07-29 weekly.2011-07-19 weekly.2011-07-07 weekly.2011-06-23 weekly.2011-06-16 weekly.2011-06-09 weekly.2011-06-02 weekly.2011-05-22 weekly.2011-04-27 weekly.2011-04-13 weekly.2011-04-04 weekly.2011-03-28 weekly.2011-03-15 weekly.2011-03-07.1 weekly.2011-03-07 weekly.2011-02-24 weekly.2011-02-15 weekly.2011-02-01.1 weekly.2011-02-01 weekly.2011-01-20 weekly.2011-01-19 weekly.2011-01-12 weekly.2011-01-06 weekly.2010-12-22 weekly.2010-12-15.1 weekly.2010-12-15 weekly.2010-12-08 weekly.2010-12-02 weekly.2010-11-23 weekly.2010-11-10 weekly.2010-11-02 weekly.2010-10-27 weekly.2010-10-20 weekly.2010-10-13.1 weekly.2010-10-13 weekly.2010-09-29 weekly.2010-09-22 weekly.2010-09-15 weekly.2010-09-06 weekly.2010-08-25 weekly.2010-08-11 weekly.2010-08-04 weekly.2010-07-29 weekly.2010-07-14 weekly.2010-07-01 weekly.2010-06-21 weekly.2010-06-09 weekly.2010-05-27 weekly.2010-05-04 weekly.2010-04-27 weekly.2010-04-13 weekly.2010-03-30 weekly.2010-03-22 weekly.2010-03-15 weekly.2010-03-04 weekly.2010-02-23 weekly.2010-02-17 weekly.2010-02-04 weekly.2010-01-27 weekly.2010-01-13 weekly.2010-01-05 weekly.2009-12-22 weekly.2009-12-09 weekly.2009-12-07 weekly.2009-11-17 weekly.2009-11-12 weekly.2009-11-10.1 weekly.2009-11-10 weekly.2009-11-06 weekly release.r60.3 release.r60.2 release.r60.1 release.r60 release.r59 release.r58.2 release.r58.1 release.r58 release.r57.2 release.r57.1 release.r57 release.r56 go1.9 go1.9rc2 go1.9rc1 go1.9beta2 go1.9beta1 go1.8.3 go1.8.2 go1.8.1 go1.8 go1.8rc3 go1.8rc2 go1.8rc1 go1.8beta2 go1.8beta1 go1.7.6 go1.7.5 go1.7.4 go1.7.3 go1.7.2 go1.7.1 go1.7 go1.7rc6 go1.7rc5 go1.7rc4 go1.7rc3 go1.7rc2 go1.7rc1 go1.7beta2 go1.7beta1 go1.6.4 go1.6.3 go1.6.2 go1.6.1 go1.6 go1.6rc2 go1.6rc1 go1.6beta2 go1.6beta1 go1.5.4 go1.5.3 go1.5.2 go1.5.1 go1.5 go1.5rc1 go1.5beta3 go1.5beta2 go1.5beta1 go1.4.3 go1.4.2 go1.4.1 go1.4 go1.4rc2 go1.4rc1 go1.4beta1 go1.3.3 go1.3.2 go1.3.1 go1.3 go1.3rc2 go1.3rc1 go1.3beta2 go1.3beta1 go1.2.2 go1.2.1 go1.2 go1.2rc5 go1.2rc4 go1.2rc3 go1.2rc2 go1.1.2 go1.1.1 go1.1 go1.1rc3 go1.1rc2 go1.0.3 go1.0.2 go1.0.1 go1
No related merge requests found
......@@ -8,9 +8,9 @@ L=6l
pretty: pretty.6
$(L) -o pretty pretty.6
test: all
test: pretty
pretty *.go
# pretty $(GOROOT)/test/fixedbugs/*.go # some files legally don't compile
pretty $(GOROOT)/test/fixedbugs/*.go # some files legally don't compile
pretty $(GOROOT)/test/sieve.go
pretty $(GOROOT)/src/pkg/*.go
pretty $(GOROOT)/src/lib/flag.go
......@@ -19,8 +19,6 @@ test: all
pretty $(GOROOT)/src/lib/math/*.go
pretty $(GOROOT)/src/lib/container/*.go
pretty $(GOROOT)/src/syscall/*.go
pretty base.go decls.go
pretty -token_chan base.go decls.go
echo "PASSED"
install: pretty
......
......@@ -136,16 +136,19 @@ func (P *Parser) ParseIdent() *AST.Ident {
}
func (P *Parser) ParseIdentList() {
func (P *Parser) ParseIdentList() int {
P.Trace("IdentList");
P.ParseIdent();
n := 1;
for P.tok == Scanner.COMMA {
P.Next();
P.ParseIdent();
n++;
}
P.Ecart();
return n;
}
......@@ -155,6 +158,10 @@ func (P *Parser) ParseQualifiedIdent(ident *AST.Ident) AST.Expr {
if ident == nil {
ident = P.ParseIdent();
}
if P.tok == Scanner.PERIOD {
P.Next();
ident = P.ParseIdent();
}
P.Ecart();
return ident;
......@@ -204,6 +211,7 @@ func (P *Parser) ParseArrayType() {
P.ParseExpression();
}
P.Expect(Scanner.RBRACK);
P.ParseType();
P.Ecart();
}
......@@ -227,39 +235,43 @@ func (P *Parser) ParseChannelType() {
}
func (P *Parser) ParseVarDeclList() {
func (P *Parser) ParseVarDeclList() int {
P.Trace("VarDeclList");
P.ParseIdentList();
n := P.ParseIdentList();
P.ParseVarType();
P.Ecart();
return n;
}
func (P *Parser) ParseParameterList() {
func (P *Parser) ParseParameterList() int {
P.Trace("ParameterList");
P.ParseVarDeclList();
n := P.ParseVarDeclList();
for P.tok == Scanner.COMMA {
P.Next();
P.ParseVarDeclList();
n += P.ParseVarDeclList();
}
P.Ecart();
return n;
}
func (P *Parser) ParseParameters() {
func (P *Parser) ParseParameters() int {
P.Trace("Parameters");
n := 0;
P.Expect(Scanner.LPAREN);
if P.tok != Scanner.RPAREN {
P.ParseParameterList();
n = P.ParseParameterList();
}
P.Expect(Scanner.RPAREN);
P.Ecart();
return n;
}
......@@ -268,7 +280,7 @@ func (P *Parser) ParseResult() {
if P.tok == Scanner.LPAREN {
// one or more named results
// TODO: here we allow empty returns - should proably fix this
// TODO: here we allow empty returns - should probably fix this
P.ParseParameters();
} else {
......@@ -316,14 +328,11 @@ func (P *Parser) ParseNamedSignature() *AST.Ident {
P.OpenScope();
P.level--;
p0 := 0;
if P.tok == Scanner.LPAREN {
recv_pos := P.pos;
P.ParseParameters();
//p0 = sig.entries.len;
if p0 != 1 {
print("p0 = ", p0, "\n");
n := P.ParseParameters();
if n != 1 {
P.Error(recv_pos, "must have exactly one receiver");
panic("UNIMPLEMENTED (ParseNamedSignature)");
// TODO do something useful here
......@@ -334,7 +343,6 @@ func (P *Parser) ParseNamedSignature() *AST.Ident {
P.ParseParameters();
//r0 := sig.entries.len;
P.ParseResult();
P.level++;
P.CloseScope();
......@@ -348,7 +356,7 @@ func (P *Parser) ParseFunctionType() {
P.Trace("FunctionType");
typ := P.ParseSignature();
P.Ecart();
}
......@@ -515,7 +523,7 @@ func (P *Parser) ParseFunctionLit() AST.Expr {
P.Trace("FunctionLit");
P.Expect(Scanner.FUNC);
P.ParseFunctionType();
P.ParseSignature(); // replace this with ParseFunctionType() and it won't work - 6g bug?
P.ParseBlock();
P.Ecart();
......@@ -671,7 +679,17 @@ func (P *Parser) ParseCall(x AST.Expr) AST.Expr {
P.Expect(Scanner.LPAREN);
if P.tok != Scanner.RPAREN {
P.ParseExpressionList();
// first arguments could be a type if the call is to "new"
if P.tok != Scanner.IDENT && P.TryType() {
if P.tok == Scanner.COMMA {
P.Next();
if P.tok != Scanner.RPAREN {
P.ParseExpressionList();
}
}
} else {
P.ParseExpressionList();
}
}
P.Expect(Scanner.RPAREN);
......@@ -866,7 +884,7 @@ func (P *Parser) ParseControlFlowStat(tok int) {
}
func (P *Parser) ParseIfStat() *AST.IfStat {
func (P *Parser) ParseIfStat() {
P.Trace("IfStat");
P.Expect(Scanner.IF);
......@@ -895,7 +913,6 @@ func (P *Parser) ParseIfStat() *AST.IfStat {
P.CloseScope();
P.Ecart();
return nil;
}
......@@ -1152,7 +1169,7 @@ func (P *Parser) ParseTypeSpec(exported bool) {
func (P *Parser) ParseVarSpec(exported bool) {
P.Trace("VarSpec");
list := P.ParseIdentList();
P.ParseIdentList();
if P.tok == Scanner.ASSIGN {
P.Next();
P.ParseExpressionList();
......
......@@ -32,6 +32,7 @@ func main() {
return;
}
print("- ", src_file, "\n");
scanner := new(Scanner.Scanner);
scanner.Open(src_file, src);
......
......@@ -777,7 +777,7 @@ export type Token struct {
func (S *Scanner) TokenStream() *<-chan *Token {
ch := new(chan *Token);
ch := new(chan *Token, 100);
go func(S *Scanner, ch *chan <- *Token) {
for {
t := new(Token);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment