go/usr/gri/pretty/pretty.go
Robert Griesemer a1ee6804dd - 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
2008-09-18 22:53:54 -07:00

50 lines
1.2 KiB
Go

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import Flag "flag"
import Platform "platform"
import Scanner "scanner"
import AST "ast" // should not be needed
import Parser "parser"
import Printer "printer"
var (
verbose = Flag.Bool("v", false, nil, "verbose mode");
sixg = Flag.Bool("6g", false, nil, "6g compatibility mode");
tokenchan = Flag.Bool("token_chan", false, nil, "use token channel for scanner-parser connection");
)
func main() {
Flag.Parse();
// process files
for i := 0; i < Flag.NArg(); i++ {
src_file := Flag.Arg(i);
src, ok := Platform.ReadSourceFile(src_file);
if !ok {
print("cannot open ", src_file, "\n");
return;
}
print("- ", src_file, "\n");
scanner := new(Scanner.Scanner);
scanner.Open(src_file, src);
var tstream *<-chan *Scanner.Token;
if tokenchan.BVal() {
tstream = scanner.TokenStream();
}
parser := new(Parser.Parser);
parser.Open(verbose.BVal(), scanner, tstream);
parser.ParseProgram();
}
}