summaryrefslogtreecommitdiff
path: root/usr/gri/src/test_parser.go
blob: 78d8d87119cdb36f439b1f1104712f389d8e2fc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// 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 Scanner "scanner"
import Parser "parser"


func Parse(filename, src string, verbose int) {
	S := new(Scanner.Scanner);
	S.Open(filename, src);
	
	P := new(Parser.Parser);
	P.Open(S, verbose);
	
	P.ParseProgram();
}


func main() {
	verbose := 0;
	for i := 1; i < sys.argc(); i++ {
		switch sys.argv(i) {
		case "-v":
			verbose = 1;
			continue;
		case "-vv":
			verbose = 2;
			continue;
		}
		
		src, ok := sys.readfile(sys.argv(i));
		if ok {
			print "parsing " + sys.argv(i) + "\n";
			Parse(sys.argv(i), src, verbose);
		} else {
			print "error: cannot read " + sys.argv(i) + "\n";
		}
	}
}