LEFT | RIGHT |
1 /* | 1 /* |
2 Derived from Inferno's utils/iyacc/yacc.c | 2 Derived from Inferno's utils/iyacc/yacc.c |
3 http://code.google.com/p/inferno-os/source/browse/utils/iyacc/yacc.c | 3 http://code.google.com/p/inferno-os/source/browse/utils/iyacc/yacc.c |
4 | 4 |
5 This copyright NOTICE applies to all files in this directory and | 5 This copyright NOTICE applies to all files in this directory and |
6 subdirectories, unless another copyright notice appears in a given | 6 subdirectories, unless another copyright notice appears in a given |
7 file or subdirectory. If you take substantial code from this software to use in | 7 file or subdirectory. If you take substantial code from this software to use in |
8 other programs, you must somehow include with it an appropriate | 8 other programs, you must somehow include with it an appropriate |
9 copyright notice that includes the copyright notice and the other | 9 copyright notice that includes the copyright notice and the other |
10 notices below. It is fine (and often tidier) to do that in a separate | 10 notices below. It is fine (and often tidier) to do that in a separate |
(...skipping 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1354 | 1354 |
1355 func openup() { | 1355 func openup() { |
1356 infile = flag.Arg(0) | 1356 infile = flag.Arg(0) |
1357 finput = open(infile) | 1357 finput = open(infile) |
1358 if finput == nil { | 1358 if finput == nil { |
1359 error("cannot open %v", infile) | 1359 error("cannot open %v", infile) |
1360 } | 1360 } |
1361 | 1361 |
1362 foutput = nil | 1362 foutput = nil |
1363 if vflag != "" { | 1363 if vflag != "" { |
1364 » » foutput = create(vflag, 0666) | 1364 » » foutput = create(vflag) |
1365 if foutput == nil { | 1365 if foutput == nil { |
1366 error("can't create file %v", vflag) | 1366 error("can't create file %v", vflag) |
1367 } | 1367 } |
1368 } | 1368 } |
1369 | 1369 |
1370 ftable = nil | 1370 ftable = nil |
1371 if oflag == "" { | 1371 if oflag == "" { |
1372 oflag = "y.go" | 1372 oflag = "y.go" |
1373 } | 1373 } |
1374 » ftable = create(oflag, 0666) | 1374 » ftable = create(oflag) |
1375 if ftable == nil { | 1375 if ftable == nil { |
1376 error("can't create file %v", oflag) | 1376 error("can't create file %v", oflag) |
1377 } | 1377 } |
1378 | 1378 |
1379 } | 1379 } |
1380 | 1380 |
1381 // | 1381 // |
1382 // return a pointer to the name of symbol i | 1382 // return a pointer to the name of symbol i |
1383 // | 1383 // |
1384 func symnam(i int) string { | 1384 func symnam(i int) string { |
(...skipping 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3037 | 3037 |
3038 func open(s string) *bufio.Reader { | 3038 func open(s string) *bufio.Reader { |
3039 fi, err := os.Open(s) | 3039 fi, err := os.Open(s) |
3040 if err != nil { | 3040 if err != nil { |
3041 error("error opening %v: %v", s, err) | 3041 error("error opening %v: %v", s, err) |
3042 } | 3042 } |
3043 //fmt.Printf("open %v\n", s); | 3043 //fmt.Printf("open %v\n", s); |
3044 return bufio.NewReader(fi) | 3044 return bufio.NewReader(fi) |
3045 } | 3045 } |
3046 | 3046 |
3047 func create(s string, m uint32) *bufio.Writer { | 3047 func create(s string) *bufio.Writer { |
3048 » fo, err := os.OpenFile(s, os.O_WRONLY|os.O_CREAT|os.O_TRUNC, m) | 3048 » fo, err := os.Create(s) |
3049 if err != nil { | 3049 if err != nil { |
3050 » » error("error opening %v: %v", s, err) | 3050 » » error("error creating %v: %v", s, err) |
3051 » } | 3051 » } |
3052 » //fmt.Printf("create %v mode %v\n", s, m); | 3052 » //fmt.Printf("create %v mode %v\n", s); |
3053 return bufio.NewWriter(fo) | 3053 return bufio.NewWriter(fo) |
3054 } | 3054 } |
3055 | 3055 |
3056 // | 3056 // |
3057 // write out error comment | 3057 // write out error comment |
3058 // | 3058 // |
3059 func error(s string, v ...interface{}) { | 3059 func error(s string, v ...interface{}) { |
3060 nerrors++ | 3060 nerrors++ |
3061 fmt.Fprintf(stderr, s, v...) | 3061 fmt.Fprintf(stderr, s, v...) |
3062 fmt.Fprintf(stderr, ": %v:%v\n", infile, lineno) | 3062 fmt.Fprintf(stderr, ": %v:%v\n", infile, lineno) |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3302 $$state = $$Act[$$j] | 3302 $$state = $$Act[$$j] |
3303 if $$Chk[$$state] != -$$n { | 3303 if $$Chk[$$state] != -$$n { |
3304 $$state = $$Act[$$g] | 3304 $$state = $$Act[$$g] |
3305 } | 3305 } |
3306 } | 3306 } |
3307 // dummy call; replaced with literal code | 3307 // dummy call; replaced with literal code |
3308 $$run() | 3308 $$run() |
3309 goto $$stack /* stack new state and value */ | 3309 goto $$stack /* stack new state and value */ |
3310 } | 3310 } |
3311 ` | 3311 ` |
LEFT | RIGHT |