@@ -156,7 +156,6 @@ var foutput *bufio.Writer // y.output file
156
156
157
157
var fmtImported bool // output file has recorded an import of "fmt"
158
158
159
- var tflag bool // -t - enable Bison style token location tracking
160
159
var oflag string // -o [y.go] - y.go file
161
160
var vflag string // -v [y.output] - y.output file
162
161
var lflag bool // -l - disable line directives
@@ -167,7 +166,6 @@ func init() {
167
166
flag .StringVar (& prefix , "p" , "yy" , "name prefix to use in generated code" )
168
167
flag .StringVar (& vflag , "v" , "y.output" , "create parsing tables" )
169
168
flag .BoolVar (& lflag , "l" , false , "disable line directives" )
170
- flag .BoolVar (& tflag , "t" , false , "enable token location tracking" )
171
169
}
172
170
173
171
var initialstacksize = 16
@@ -386,25 +384,7 @@ func setup() {
386
384
fmt .Fprintf (stderr , "yacc: stack size too small\n " )
387
385
usage ()
388
386
}
389
- yaccpar = yaccpartext
390
- if tflag {
391
- lexMethStr := fmt .Sprintf ("Lex(lval *$$SymType, loc *%sLTYPE)" ,
392
- strings .ToUpper (prefix ))
393
- yaccpar = strings .Replace (yaccpar , "Lex(lval *$$SymType)" ,
394
- lexMethStr , 1 )
395
- errMethStr := fmt .Sprintf ("Error(loc *%sLTYPE, s string)" ,
396
- strings .ToUpper (prefix ))
397
- yaccpar = strings .Replace (yaccpar , "Error(s string)" , errMethStr , 1 )
398
- yaccpar = strings .Replace (yaccpar , "lex.Error(" ,
399
- "lex.Error(&$$rcvr.lval.$$lloc, " , 1 )
400
- lexMethStr = fmt .Sprintf ("lex.Lex(lval, &lval.$$lloc)" )
401
- yaccpar = strings .Replace (yaccpar , "lex.Lex(lval)" , lexMethStr , 1 )
402
- } else {
403
- yaccpar = strings .Replace (yaccpar , "$$VAL.$$lloc.firstColumn = $$S[$$p+1].$$lloc.firstColumn" , "" , 1 )
404
- yaccpar = strings .Replace (yaccpar , "$$VAL.$$lloc.lastColumn = $$S[$$pt].$$lloc.lastColumn" , "" , 1 )
405
- }
406
- yaccpar = strings .ReplaceAll (yaccpar , "$$" , prefix )
407
-
387
+ yaccpar = strings .ReplaceAll (yaccpartext , "$$" , prefix )
408
388
openup ()
409
389
410
390
fmt .Fprintf (ftable , "// Code generated by goyacc %s. DO NOT EDIT.\n " , strings .Join (os .Args [1 :], " " ))
@@ -1072,15 +1052,15 @@ func chfind(t int, s string) int {
1072
1052
// copy the union declaration to the output, and the define file if present
1073
1053
//
1074
1054
func cpyunion () {
1075
- if tflag {
1076
- fmt .Fprintf (ftable , "\n type %sLTYPE struct {" ,
1077
- strings . ToUpper ( prefix ) )
1078
- fmt .Fprintf (ftable , "\n \t firstLine int " )
1079
- fmt . Fprintf ( ftable , " \n \t firstColumn int" )
1080
- fmt .Fprintf (ftable , "\n \t lastLine int" )
1081
- fmt .Fprintf (ftable , "\n \t lastColumn int" )
1082
- fmt .Fprintf (ftable , "\n } \n " )
1083
- }
1055
+ fmt . Fprintf ( ftable , " \n type %sPos struct {" , prefix )
1056
+ fmt .Fprintf (ftable , "\n \t line \t int" )
1057
+ fmt . Fprintf ( ftable , " \n \t column \t int" )
1058
+ fmt .Fprintf (ftable , "\n } \n " )
1059
+
1060
+ fmt .Fprintf (ftable , "\n type %sSymLoc struct {" , prefix )
1061
+ fmt .Fprintf (ftable , "\n \t pos %sPos" , prefix )
1062
+ fmt .Fprintf (ftable , "\n \t end %sPos" , prefix )
1063
+ fmt . Fprintf ( ftable , " \n } \n " )
1084
1064
1085
1065
if ! lflag {
1086
1066
fmt .Fprintf (ftable , "\n //line %v:%v\n " , infile , lineno )
@@ -1101,11 +1081,8 @@ out:
1101
1081
lineno ++
1102
1082
case '{' :
1103
1083
if level == 0 {
1104
- fmt .Fprintf (ftable , "\n \t yys int" )
1105
- if tflag {
1106
- fmt .Fprintf (ftable , "\n \t %slloc %sLTYPE" , prefix ,
1107
- strings .ToUpper (prefix ))
1108
- }
1084
+ fmt .Fprintf (ftable , "\n \t yys\t int" )
1085
+ fmt .Fprintf (ftable , "\n \t symLoc\t %sSymLoc" , prefix )
1109
1086
}
1110
1087
level ++
1111
1088
case '}' :
@@ -1329,13 +1306,10 @@ loop:
1329
1306
brac ++
1330
1307
1331
1308
case '@' :
1332
- if ! tflag {
1333
- errorf ("@ not valid without -tflag!" )
1334
- }
1335
1309
c2 := getrune (finput )
1336
1310
if isdigit (c2 ) {
1337
- fmt .Fprintf (fcode , "%sDollar[%d].%slloc " ,
1338
- prefix , int (c2 - '0' ), prefix )
1311
+ fmt .Fprintf (fcode , "%sDollar[%d].symLoc " ,
1312
+ prefix , int (c2 - '0' ))
1339
1313
continue loop
1340
1314
} else {
1341
1315
errorf ("unexpected @" )
@@ -3313,6 +3287,7 @@ var yaccpartext = `
3313
3287
var (
3314
3288
$$Debug = 0
3315
3289
$$ErrorVerbose = false
3290
+ $$ErrLoc *$$SymLoc
3316
3291
)
3317
3292
3318
3293
type $$Lexer interface {
@@ -3559,6 +3534,7 @@ $$default:
3559
3534
/* error ... attempt to resume parsing */
3560
3535
switch Errflag {
3561
3536
case 0: /* brand new error */
3537
+ $$ErrLoc = &$$rcvr.lval.symLoc
3562
3538
$$lex.Error($$ErrorMessage($$state, $$token))
3563
3539
Nerrs++
3564
3540
if $$Debug >= 1 {
@@ -3621,8 +3597,10 @@ $$default:
3621
3597
}
3622
3598
$$VAL = $$S[$$p+1]
3623
3599
3624
- $$VAL.$$lloc.firstColumn = $$S[$$p+1].$$lloc.firstColumn
3625
- $$VAL.$$lloc.lastColumn = $$S[$$pt].$$lloc.lastColumn
3600
+ $$VAL.symLoc.pos.line = $$S[$$p+1].symLoc.pos.line
3601
+ $$VAL.symLoc.pos.column = $$S[$$p+1].symLoc.pos.column
3602
+ $$VAL.symLoc.end.line = $$S[$$pt].symLoc.end.line
3603
+ $$VAL.symLoc.end.column = $$S[$$pt].symLoc.end.column
3626
3604
3627
3605
/* consult goto table to find next state */
3628
3606
$$n = $$R1[$$n]
0 commit comments