Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2754)

Delta Between Two Patch Sets: src/cmd/goyacc/goyacc.go

Issue 879041: code review 879041: Change goyacc to be reentrant. (Closed)
Left Patch Set: code review 879041: Change goyacc to be reentrant. Created 15 years ago
Right Patch Set: code review 879041: Change goyacc to be reentrant. Created 14 years, 12 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/cmd/goyacc/doc.go ('k') | src/cmd/goyacc/units.y » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 MUSTLOOKAHEAD 99 MUSTLOOKAHEAD
100 ) 100 )
101 101
102 // flags for a rule having an action, and being reduced 102 // flags for a rule having an action, and being reduced
103 const ( 103 const (
104 ACTFLAG = 1 << (iota + 2) 104 ACTFLAG = 1 << (iota + 2)
105 REDFLAG 105 REDFLAG
106 ) 106 )
107 107
108 // output parser flags 108 // output parser flags
109 const YYFLAG = -1000 109 const yyFlag = -1000
110 110
111 // parse tokens 111 // parse tokens
112 const ( 112 const (
113 IDENTIFIER = PRIVATE + iota 113 IDENTIFIER = PRIVATE + iota
114 MARK 114 MARK
115 TERM 115 TERM
116 LEFT 116 LEFT
117 RIGHT 117 RIGHT
118 BINARY 118 BINARY
119 PREC 119 PREC
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 // put out non-literal terminals 499 // put out non-literal terminals
500 for i := TOKSTART; i <= ntokens; i++ { 500 for i := TOKSTART; i <= ntokens; i++ {
501 // non-literals 501 // non-literals
502 c := tokset[i].name[0] 502 c := tokset[i].name[0]
503 if c != ' ' && c != '$' { 503 if c != ' ' && c != '$' {
504 fmt.Fprintf(ftable, "const\t%v\t= %v\n", tokset[i].name, tokset[i].value) 504 fmt.Fprintf(ftable, "const\t%v\t= %v\n", tokset[i].name, tokset[i].value)
505 } 505 }
506 } 506 }
507 507
508 // put out names of token names 508 // put out names of token names
509 » fmt.Fprintf(ftable, "var\tToknames\t =[]string {\n") 509 » fmt.Fprintf(ftable, "var\tyyToknames\t =[]string {\n")
510 for i := TOKSTART; i <= ntokens; i++ { 510 for i := TOKSTART; i <= ntokens; i++ {
511 fmt.Fprintf(ftable, "\t\"%v\",\n", tokset[i].name) 511 fmt.Fprintf(ftable, "\t\"%v\",\n", tokset[i].name)
512 } 512 }
513 fmt.Fprintf(ftable, "}\n") 513 fmt.Fprintf(ftable, "}\n")
514 514
515 // put out names of state names 515 // put out names of state names
516 » fmt.Fprintf(ftable, "var\tStatenames\t =[]string {\n") 516 » fmt.Fprintf(ftable, "var\tyyStatenames\t =[]string {\n")
517 // for i:=TOKSTART; i<=ntokens; i++ { 517 // for i:=TOKSTART; i<=ntokens; i++ {
518 // fmt.Fprintf(ftable, "\t\"%v\",\n", tokset[i].name); 518 // fmt.Fprintf(ftable, "\t\"%v\",\n", tokset[i].name);
519 // } 519 // }
520 fmt.Fprintf(ftable, "}\n") 520 fmt.Fprintf(ftable, "}\n")
521 521
522 fmt.Fprintf(fcode, "switch yynt {\n") 522 fmt.Fprintf(fcode, "switch yynt {\n")
523 523
524 moreprod() 524 moreprod()
525 prdptr[0] = []int{NTBASE, start, 1, 0} 525 prdptr[0] = []int{NTBASE, start, 1, 0}
526 526
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 levprd[nprod] = 0 659 levprd[nprod] = 0
660 } 660 }
661 661
662 // 662 //
663 // end of all rules 663 // end of all rules
664 // dump out the prefix code 664 // dump out the prefix code
665 // 665 //
666 666
667 fmt.Fprintf(fcode, "\n\t}") 667 fmt.Fprintf(fcode, "\n\t}")
668 668
669 » fmt.Fprintf(ftable, "const» YYEOFCODE» = 1\n") 669 » fmt.Fprintf(ftable, "const» yyEofCode» = 1\n")
670 » fmt.Fprintf(ftable, "const» YYERRCODE» = 2\n") 670 » fmt.Fprintf(ftable, "const» yyErrCode» = 2\n")
671 » fmt.Fprintf(ftable, "const» YYMAXDEPTH» = %v\n", stacksize) 671 » fmt.Fprintf(ftable, "const» yyMaxDepth» = %v\n", stacksize)
672 672
673 // 673 //
674 // copy any postfix code 674 // copy any postfix code
675 // 675 //
676 if t == MARK { 676 if t == MARK {
677 if !lflag { 677 if !lflag {
678 fmt.Fprintf(ftable, "\n//line %v:%v\n", infile, lineno) 678 fmt.Fprintf(ftable, "\n//line %v:%v\n", infile, lineno)
679 } 679 }
680 for { 680 for {
681 c := getrune(finput) 681 c := getrune(finput)
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 } 1027 }
1028 1028
1029 // 1029 //
1030 // copy the union declaration to the output, and the define file if present 1030 // copy the union declaration to the output, and the define file if present
1031 // 1031 //
1032 func cpyunion() { 1032 func cpyunion() {
1033 1033
1034 if !lflag { 1034 if !lflag {
1035 fmt.Fprintf(ftable, "\n//line %v %v\n", lineno, infile) 1035 fmt.Fprintf(ftable, "\n//line %v %v\n", lineno, infile)
1036 } 1036 }
1037 » fmt.Fprintf(ftable, "type\tYYSTYPE\tstruct") 1037 » fmt.Fprintf(ftable, "type\tyySymType\tstruct")
1038 1038
1039 level := 0 1039 level := 0
1040 1040
1041 out: 1041 out:
1042 for { 1042 for {
1043 c := getrune(finput) 1043 c := getrune(finput)
1044 if c == EOF { 1044 if c == EOF {
1045 error("EOF encountered while processing %%union") 1045 error("EOF encountered while processing %%union")
1046 } 1046 }
1047 ftable.WriteRune(c) 1047 ftable.WriteRune(c)
1048 switch c { 1048 switch c {
1049 case '\n': 1049 case '\n':
1050 lineno++ 1050 lineno++
1051 case '{': 1051 case '{':
1052 if level == 0 { 1052 if level == 0 {
1053 fmt.Fprintf(ftable, "\n\tyys\tint;") 1053 fmt.Fprintf(ftable, "\n\tyys\tint;")
1054 } 1054 }
1055 level++ 1055 level++
1056 case '}': 1056 case '}':
1057 level-- 1057 level--
1058 if level == 0 { 1058 if level == 0 {
1059 break out 1059 break out
1060 } 1060 }
1061 } 1061 }
1062 } 1062 }
1063 fmt.Fprintf(ftable, "\n") 1063 fmt.Fprintf(ftable, "\n")
1064 fmt.Fprintf(ftable, "const MaxStack = %v\n", stacksize)
1065 } 1064 }
1066 1065
1067 // 1066 //
1068 // saves code between %{ and %} 1067 // saves code between %{ and %}
1069 // 1068 //
1070 func cpycode() { 1069 func cpycode() {
1071 lno := lineno 1070 lno := lineno
1072 1071
1073 c := getrune(finput) 1072 c := getrune(finput)
1074 if c == '\n' { 1073 if c == '\n' {
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
2060 error("no space in action table") 2059 error("no space in action table")
2061 return 0 2060 return 0
2062 } 2061 }
2063 2062
2064 // 2063 //
2065 // print the output for the states 2064 // print the output for the states
2066 // 2065 //
2067 func output() { 2066 func output() {
2068 var c, u, v int 2067 var c, u, v int
2069 2068
2070 » fmt.Fprintf(ftable, "var\tYYEXCA = []int {\n") 2069 » fmt.Fprintf(ftable, "var\tyyExca = []int {\n")
2071 2070
2072 noset := mkset() 2071 noset := mkset()
2073 2072
2074 // output the stuff for state i 2073 // output the stuff for state i
2075 for i := 0; i < nstate; i++ { 2074 for i := 0; i < nstate; i++ {
2076 nolook = 0 2075 nolook = 0
2077 if tystate[i] != MUSTLOOKAHEAD { 2076 if tystate[i] != MUSTLOOKAHEAD {
2078 nolook = 1 2077 nolook = 1
2079 } 2078 }
2080 closure(i) 2079 closure(i)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2133 } else { 2132 } else {
2134 // potential shift/reduce conflict 2133 // potential shift/reduce conflict
2135 precftn(lastred, k, i) 2134 precftn(lastred, k, i)
2136 } 2135 }
2137 } 2136 }
2138 } 2137 }
2139 wract(i) 2138 wract(i)
2140 } 2139 }
2141 2140
2142 fmt.Fprintf(ftable, "}\n") 2141 fmt.Fprintf(ftable, "}\n")
2143 » fmt.Fprintf(ftable, "const\tYYNPROD\t= %v\n", nprod) 2142 » fmt.Fprintf(ftable, "const\tyyNprod\t= %v\n", nprod)
2144 » fmt.Fprintf(ftable, "const\tYYPRIVATE\t= %v\n", PRIVATE) 2143 » fmt.Fprintf(ftable, "const\tyyPrivate\t= %v\n", PRIVATE)
2145 » fmt.Fprintf(ftable, "var\tYYTOKENNAMES []string\n") 2144 » fmt.Fprintf(ftable, "var\tyyTokenNames []string\n")
2146 » fmt.Fprintf(ftable, "var\tYYSTATES []string\n") 2145 » fmt.Fprintf(ftable, "var\tyyStates []string\n")
2147 } 2146 }
2148 2147
2149 // 2148 //
2150 // decide a shift/reduce conflict by precedence. 2149 // decide a shift/reduce conflict by precedence.
2151 // r is a rule number, t a token number 2150 // r is a rule number, t a token number
2152 // the conflict is in state s 2151 // the conflict is in state s
2153 // temp1[t] is changed to reflect the action 2152 // temp1[t] is changed to reflect the action
2154 // 2153 //
2155 func precftn(r, t, s int) { 2154 func precftn(r, t, s int) {
2156 var action int 2155 var action int
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
2539 2538
2540 // now, prepare to put the shift actions into the amem array 2539 // now, prepare to put the shift actions into the amem array
2541 for i = 0; i < ACTSIZE; i++ { 2540 for i = 0; i < ACTSIZE; i++ {
2542 amem[i] = 0 2541 amem[i] = 0
2543 } 2542 }
2544 maxa = 0 2543 maxa = 0
2545 for i = 0; i < nstate; i++ { 2544 for i = 0; i < nstate; i++ {
2546 if tystate[i] == 0 && adb > 1 { 2545 if tystate[i] == 0 && adb > 1 {
2547 fmt.Fprintf(ftable, "State %v: null\n", i) 2546 fmt.Fprintf(ftable, "State %v: null\n", i)
2548 } 2547 }
2549 » » indgo[i] = YYFLAG 2548 » » indgo[i] = yyFlag
2550 } 2549 }
2551 2550
2552 i = nxti() 2551 i = nxti()
2553 for i != NOMORE { 2552 for i != NOMORE {
2554 if i >= 0 { 2553 if i >= 0 {
2555 stin(i) 2554 stin(i)
2556 } else { 2555 } else {
2557 gin(-i) 2556 gin(-i)
2558 } 2557 }
2559 i = nxti() 2558 i = nxti()
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2711 return 2710 return
2712 } 2711 }
2713 error("Error; failure to place state %v", i) 2712 error("Error; failure to place state %v", i)
2714 } 2713 }
2715 2714
2716 // 2715 //
2717 // this version is for limbo 2716 // this version is for limbo
2718 // write out the optimized parser 2717 // write out the optimized parser
2719 // 2718 //
2720 func aoutput() { 2719 func aoutput() {
2721 » fmt.Fprintf(ftable, "const\tYYLAST\t= %v\n", maxa+1) 2720 » fmt.Fprintf(ftable, "const\tyyLast\t= %v\n", maxa+1)
2722 » arout("YYACT", amem, maxa+1) 2721 » arout("yyAct", amem, maxa+1)
2723 » arout("YYPACT", indgo, nstate) 2722 » arout("yyPact", indgo, nstate)
2724 » arout("YYPGO", pgo, nnonter+1) 2723 » arout("yyPgo", pgo, nnonter+1)
2725 } 2724 }
2726 2725
2727 // 2726 //
2728 // put out other arrays, copy the parsers 2727 // put out other arrays, copy the parsers
2729 // 2728 //
2730 func others() { 2729 func others() {
2731 var i, j int 2730 var i, j int
2732 2731
2733 » arout("YYR1", levprd, nprod) 2732 » arout("yyR1", levprd, nprod)
2734 aryfil(temp1, nprod, 0) 2733 aryfil(temp1, nprod, 0)
2735 2734
2736 // 2735 //
2737 //yyr2 is the number of rules for each production 2736 //yyr2 is the number of rules for each production
2738 // 2737 //
2739 for i = 1; i < nprod; i++ { 2738 for i = 1; i < nprod; i++ {
2740 temp1[i] = len(prdptr[i]) - 2 2739 temp1[i] = len(prdptr[i]) - 2
2741 } 2740 }
2742 » arout("YYR2", temp1, nprod) 2741 » arout("yyR2", temp1, nprod)
2743 2742
2744 aryfil(temp1, nstate, -1000) 2743 aryfil(temp1, nstate, -1000)
2745 for i = 0; i <= ntokens; i++ { 2744 for i = 0; i <= ntokens; i++ {
2746 for j := tstates[i]; j != 0; j = mstates[j] { 2745 for j := tstates[i]; j != 0; j = mstates[j] {
2747 temp1[j] = i 2746 temp1[j] = i
2748 } 2747 }
2749 } 2748 }
2750 for i = 0; i <= nnonter; i++ { 2749 for i = 0; i <= nnonter; i++ {
2751 for j = ntstates[i]; j != 0; j = mstates[j] { 2750 for j = ntstates[i]; j != 0; j = mstates[j] {
2752 temp1[j] = -i 2751 temp1[j] = -i
2753 } 2752 }
2754 } 2753 }
2755 » arout("YYCHK", temp1, nstate) 2754 » arout("yyChk", temp1, nstate)
2756 » arout("YYDEF", defact, nstate) 2755 » arout("yyDef", defact, nstate)
2757 2756
2758 // put out token translation tables 2757 // put out token translation tables
2759 // table 1 has 0-256 2758 // table 1 has 0-256
2760 aryfil(temp1, 256, 0) 2759 aryfil(temp1, 256, 0)
2761 c := 0 2760 c := 0
2762 for i = 1; i <= ntokens; i++ { 2761 for i = 1; i <= ntokens; i++ {
2763 j = tokset[i].value 2762 j = tokset[i].value
2764 if j >= 0 && j < 256 { 2763 if j >= 0 && j < 256 {
2765 if temp1[j] != 0 { 2764 if temp1[j] != 0 {
2766 print("yacc bug -- cant have 2 different Ts with same value\n") 2765 print("yacc bug -- cant have 2 different Ts with same value\n")
2767 print(" %s and %s\n", tokset[i].name, tokset[tem p1[j]].name) 2766 print(" %s and %s\n", tokset[i].name, tokset[tem p1[j]].name)
2768 nerrors++ 2767 nerrors++
2769 } 2768 }
2770 temp1[j] = i 2769 temp1[j] = i
2771 if j > c { 2770 if j > c {
2772 c = j 2771 c = j
2773 } 2772 }
2774 } 2773 }
2775 } 2774 }
2776 for i = 0; i <= c; i++ { 2775 for i = 0; i <= c; i++ {
2777 if temp1[i] == 0 { 2776 if temp1[i] == 0 {
2778 temp1[i] = YYLEXUNK 2777 temp1[i] = YYLEXUNK
2779 } 2778 }
2780 } 2779 }
2781 » arout("YYTOK1", temp1, c+1) 2780 » arout("yyTok1", temp1, c+1)
2782 2781
2783 // table 2 has PRIVATE-PRIVATE+256 2782 // table 2 has PRIVATE-PRIVATE+256
2784 aryfil(temp1, 256, 0) 2783 aryfil(temp1, 256, 0)
2785 c = 0 2784 c = 0
2786 for i = 1; i <= ntokens; i++ { 2785 for i = 1; i <= ntokens; i++ {
2787 j = tokset[i].value - PRIVATE 2786 j = tokset[i].value - PRIVATE
2788 if j >= 0 && j < 256 { 2787 if j >= 0 && j < 256 {
2789 if temp1[j] != 0 { 2788 if temp1[j] != 0 {
2790 print("yacc bug -- cant have 2 different Ts with same value\n") 2789 print("yacc bug -- cant have 2 different Ts with same value\n")
2791 print(" %s and %s\n", tokset[i].name, tokset[tem p1[j]].name) 2790 print(" %s and %s\n", tokset[i].name, tokset[tem p1[j]].name)
2792 nerrors++ 2791 nerrors++
2793 } 2792 }
2794 temp1[j] = i 2793 temp1[j] = i
2795 if j > c { 2794 if j > c {
2796 c = j 2795 c = j
2797 } 2796 }
2798 } 2797 }
2799 } 2798 }
2800 » arout("YYTOK2", temp1, c+1) 2799 » arout("yyTok2", temp1, c+1)
2801 2800
2802 // table 3 has everything else 2801 // table 3 has everything else
2803 » fmt.Fprintf(ftable, "var\tYYTOK3\t= []int {\n") 2802 » fmt.Fprintf(ftable, "var\tyyTok3\t= []int {\n")
2804 c = 0 2803 c = 0
2805 for i = 1; i <= ntokens; i++ { 2804 for i = 1; i <= ntokens; i++ {
2806 j = tokset[i].value 2805 j = tokset[i].value
2807 if j >= 0 && j < 256 { 2806 if j >= 0 && j < 256 {
2808 continue 2807 continue
2809 } 2808 }
2810 if j >= PRIVATE && j < 256+PRIVATE { 2809 if j >= PRIVATE && j < 256+PRIVATE {
2811 continue 2810 continue
2812 } 2811 }
2813 2812
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2904 for i = 0; i < len(q); i++ { 2903 for i = 0; i < len(q); i++ {
2905 if q[i] == '"' { 2904 if q[i] == '"' {
2906 s += q[j:i] + "\\" 2905 s += q[j:i] + "\\"
2907 j = i 2906 j = i
2908 } 2907 }
2909 } 2908 }
2910 return s + q[j:i] 2909 return s + q[j:i]
2911 } 2910 }
2912 2911
2913 func usage() { 2912 func usage() {
2914 » fmt.Fprintf(stderr, "usage: gacc [-o output] [-v parsetable] input\n") 2913 » fmt.Fprintf(stderr, "usage: goyacc [-o output] [-v parsetable] input\n")
2915 exit(1) 2914 exit(1)
2916 } 2915 }
2917 2916
2918 func bitset(set Lkset, bit int) int { return set[bit>>5] & (1 << uint(bit&31)) } 2917 func bitset(set Lkset, bit int) int { return set[bit>>5] & (1 << uint(bit&31)) }
2919 2918
2920 func setbit(set Lkset, bit int) { set[bit>>5] |= (1 << uint(bit&31)) } 2919 func setbit(set Lkset, bit int) { set[bit>>5] |= (1 << uint(bit&31)) }
2921 2920
2922 func mkset() Lkset { return make([]int, tbitset) } 2921 func mkset() Lkset { return make([]int, tbitset) }
2923 2922
2924 // 2923 //
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
3070 if stderr != nil { 3069 if stderr != nil {
3071 stderr.Flush() 3070 stderr.Flush()
3072 stderr = nil 3071 stderr = nil
3073 } 3072 }
3074 os.Exit(status) 3073 os.Exit(status)
3075 } 3074 }
3076 3075
3077 var yaccpar = ` 3076 var yaccpar = `
3078 /* parser for yacc output */ 3077 /* parser for yacc output */
3079 3078
3080 var Debug = 0 3079 var yyDebug = 0
3081 3080
3082 type Lexer interface { 3081 type yyLexer interface {
3083 » Lex(lval *YYSTYPE) int 3082 » Lex(lval *yySymType) int
3084 } 3083 }
3085 3084
3086 const YYFLAG = -1000 3085 const yyFlag = -1000
3087 3086
3088 func Tokname(yyc int) string { 3087 func yyTokname(yyc int) string {
3089 » if yyc > 0 && yyc <= len(Toknames) { 3088 » if yyc > 0 && yyc <= len(yyToknames) {
3090 » » if Toknames[yyc-1] != "" { 3089 » » if yyToknames[yyc-1] != "" {
3091 » » » return Toknames[yyc-1] 3090 » » » return yyToknames[yyc-1]
3092 } 3091 }
3093 } 3092 }
3094 return fmt.Sprintf("tok-%v", yyc) 3093 return fmt.Sprintf("tok-%v", yyc)
3095 } 3094 }
3096 3095
3097 func Statname(yys int) string { 3096 func yyStatname(yys int) string {
3098 » if yys >= 0 && yys < len(Statenames) { 3097 » if yys >= 0 && yys < len(yyStatenames) {
3099 » » if Statenames[yys] != "" { 3098 » » if yyStatenames[yys] != "" {
3100 » » » return Statenames[yys] 3099 » » » return yyStatenames[yys]
3101 } 3100 }
3102 } 3101 }
3103 return fmt.Sprintf("state-%v", yys) 3102 return fmt.Sprintf("state-%v", yys)
3104 } 3103 }
3105 3104
3106 func lex1(yylex Lexer, lval *YYSTYPE) int { 3105 func yylex1(yylex yyLexer, lval *yySymType) int {
3107 var yychar int 3106 var yychar int
3108 var c int 3107 var c int
3109 3108
3110 yychar = yylex.Lex(lval) 3109 yychar = yylex.Lex(lval)
3111 if yychar <= 0 { 3110 if yychar <= 0 {
3112 » » c = YYTOK1[0] 3111 » » c = yyTok1[0]
3113 goto out 3112 goto out
3114 } 3113 }
3115 » if yychar < len(YYTOK1) { 3114 » if yychar < len(yyTok1) {
3116 » » c = YYTOK1[yychar] 3115 » » c = yyTok1[yychar]
3117 goto out 3116 goto out
3118 } 3117 }
3119 » if yychar >= YYPRIVATE { 3118 » if yychar >= yyPrivate {
3120 » » if yychar < YYPRIVATE+len(YYTOK2) { 3119 » » if yychar < yyPrivate+len(yyTok2) {
3121 » » » c = YYTOK2[yychar-YYPRIVATE] 3120 » » » c = yyTok2[yychar-yyPrivate]
3122 goto out 3121 goto out
3123 } 3122 }
3124 } 3123 }
3125 » for i := 0; i < len(YYTOK3); i += 2 { 3124 » for i := 0; i < len(yyTok3); i += 2 {
3126 » » c = YYTOK3[i+0] 3125 » » c = yyTok3[i+0]
3127 if c == yychar { 3126 if c == yychar {
3128 » » » c = YYTOK3[i+1] 3127 » » » c = yyTok3[i+1]
3129 goto out 3128 goto out
3130 } 3129 }
3131 } 3130 }
3132 c = 0 3131 c = 0
3133 3132
3134 out: 3133 out:
3135 if c == 0 { 3134 if c == 0 {
3136 » » c = YYTOK2[1] /* unknown char */ 3135 » » c = yyTok2[1] /* unknown char */
3137 » } 3136 » }
3138 » if Debug >= 3 { 3137 » if yyDebug >= 3 {
3139 » » fmt.Printf("lex %.4lux %s\n", yychar, Tokname(c)) 3138 » » fmt.Printf("lex %.4x %s\n", uint(yychar), yyTokname(c))
3140 } 3139 }
3141 return c 3140 return c
3142 } 3141 }
3143 3142
3144 func Parse(yylex Lexer) int { 3143 func yyParse(yylex yyLexer) int {
3145 var yyn int 3144 var yyn int
3146 » var yylval YYSTYPE 3145 » var yylval yySymType
3147 » var YYVAL YYSTYPE 3146 » var YYVAL yySymType
3148 » YYS := make([]YYSTYPE, MaxStack) 3147 » YYS := make([]yySymType, yyMaxDepth)
3149 3148
3150 Nerrs := 0 /* number of errors */ 3149 Nerrs := 0 /* number of errors */
3151 Errflag := 0 /* error recovery flag */ 3150 Errflag := 0 /* error recovery flag */
3152 yystate := 0 3151 yystate := 0
3153 yychar := -1 3152 yychar := -1
3154 yyp := -1 3153 yyp := -1
3155 goto yystack 3154 goto yystack
3156 3155
3157 ret0: 3156 ret0:
3158 return 0 3157 return 0
3159 3158
3160 ret1: 3159 ret1:
3161 return 1 3160 return 1
3162 3161
3163 yystack: 3162 yystack:
3164 /* put a state and value onto the stack */ 3163 /* put a state and value onto the stack */
3165 » if Debug >= 4 { 3164 » if yyDebug >= 4 {
3166 » » fmt.Printf("char %v in %v", Tokname(yychar), Statname(yystate)) 3165 » » fmt.Printf("char %v in %v", yyTokname(yychar), yyStatname(yystat e))
3167 } 3166 }
3168 3167
3169 yyp++ 3168 yyp++
3170 if yyp >= len(YYS) { 3169 if yyp >= len(YYS) {
3171 » » nyys := make([]YYSTYPE, len(YYS)*2) 3170 » » nyys := make([]yySymType, len(YYS)*2)
3172 copy(nyys, YYS) 3171 copy(nyys, YYS)
3173 YYS = nyys 3172 YYS = nyys
3174 } 3173 }
3175 YYS[yyp] = YYVAL 3174 YYS[yyp] = YYVAL
3176 YYS[yyp].yys = yystate 3175 YYS[yyp].yys = yystate
3177 3176
3178 yynewstate: 3177 yynewstate:
3179 » yyn = YYPACT[yystate] 3178 » yyn = yyPact[yystate]
3180 » if yyn <= YYFLAG { 3179 » if yyn <= yyFlag {
3181 goto yydefault /* simple state */ 3180 goto yydefault /* simple state */
3182 } 3181 }
3183 if yychar < 0 { 3182 if yychar < 0 {
3184 » » yychar = lex1(yylex, &yylval) 3183 » » yychar = yylex1(yylex, &yylval)
3185 } 3184 }
3186 yyn += yychar 3185 yyn += yychar
3187 » if yyn < 0 || yyn >= YYLAST { 3186 » if yyn < 0 || yyn >= yyLast {
3188 goto yydefault 3187 goto yydefault
3189 } 3188 }
3190 » yyn = YYACT[yyn] 3189 » yyn = yyAct[yyn]
3191 » if YYCHK[yyn] == yychar { /* valid shift */ 3190 » if yyChk[yyn] == yychar { /* valid shift */
3192 yychar = -1 3191 yychar = -1
3193 YYVAL = yylval 3192 YYVAL = yylval
3194 yystate = yyn 3193 yystate = yyn
3195 if Errflag > 0 { 3194 if Errflag > 0 {
3196 Errflag-- 3195 Errflag--
3197 } 3196 }
3198 goto yystack 3197 goto yystack
3199 } 3198 }
3200 3199
3201 yydefault: 3200 yydefault:
3202 /* default state action */ 3201 /* default state action */
3203 » yyn = YYDEF[yystate] 3202 » yyn = yyDef[yystate]
3204 if yyn == -2 { 3203 if yyn == -2 {
3205 if yychar < 0 { 3204 if yychar < 0 {
3206 » » » yychar = lex1(yylex, &yylval) 3205 » » » yychar = yylex1(yylex, &yylval)
3207 } 3206 }
3208 3207
3209 /* look through exception table */ 3208 /* look through exception table */
3210 yyxi := 0 3209 yyxi := 0
3211 for { 3210 for {
3212 » » » if YYEXCA[yyxi+0] == -1 && YYEXCA[yyxi+1] == yystate { 3211 » » » if yyExca[yyxi+0] == -1 && yyExca[yyxi+1] == yystate {
3213 break 3212 break
3214 } 3213 }
3215 yyxi += 2 3214 yyxi += 2
3216 } 3215 }
3217 for yyxi += 2; ; yyxi += 2 { 3216 for yyxi += 2; ; yyxi += 2 {
3218 » » » yyn = YYEXCA[yyxi+0] 3217 » » » yyn = yyExca[yyxi+0]
3219 if yyn < 0 || yyn == yychar { 3218 if yyn < 0 || yyn == yychar {
3220 break 3219 break
3221 } 3220 }
3222 } 3221 }
3223 » » yyn = YYEXCA[yyxi+1] 3222 » » yyn = yyExca[yyxi+1]
3224 if yyn < 0 { 3223 if yyn < 0 {
3225 goto ret0 3224 goto ret0
3226 } 3225 }
3227 } 3226 }
3228 if yyn == 0 { 3227 if yyn == 0 {
3229 /* error ... attempt to resume parsing */ 3228 /* error ... attempt to resume parsing */
3230 switch Errflag { 3229 switch Errflag {
3231 case 0: /* brand new error */ 3230 case 0: /* brand new error */
3232 » » » Error("syntax error") 3231 » » » yyError("syntax error")
3233 Nerrs++ 3232 Nerrs++
3234 » » » if Debug >= 1 { 3233 » » » if yyDebug >= 1 {
3235 » » » » fmt.Printf("%s", Statname(yystate)) 3234 » » » » fmt.Printf("%s", yyStatname(yystate))
3236 » » » » fmt.Printf("saw %s\n", Tokname(yychar)) 3235 » » » » fmt.Printf("saw %s\n", yyTokname(yychar))
3237 } 3236 }
3238 fallthrough 3237 fallthrough
3239 3238
3240 case 1, 2: /* incompletely recovered error ... try again */ 3239 case 1, 2: /* incompletely recovered error ... try again */
3241 Errflag = 3 3240 Errflag = 3
3242 3241
3243 /* find a state where "error" is a legal shift action */ 3242 /* find a state where "error" is a legal shift action */
3244 for yyp >= len(YYS) { 3243 for yyp >= len(YYS) {
3245 » » » » yyn = YYPACT[YYS[yyp].yys] + YYERRCODE 3244 » » » » yyn = yyPact[YYS[yyp].yys] + yyErrCode
3246 » » » » if yyn >= 0 && yyn < YYLAST { 3245 » » » » if yyn >= 0 && yyn < yyLast {
3247 » » » » » yystate = YYACT[yyn] /* simulate a shift of "error" */ 3246 » » » » » yystate = yyAct[yyn] /* simulate a shift of "error" */
3248 » » » » » if YYCHK[yystate] == YYERRCODE { 3247 » » » » » if yyChk[yystate] == yyErrCode {
3249 goto yystack 3248 goto yystack
3250 } 3249 }
3251 } 3250 }
3252 3251
3253 /* the current yyp has no shift onn "error", pop stack */ 3252 /* the current yyp has no shift onn "error", pop stack */
3254 » » » » if Debug >= 2 { 3253 » » » » if yyDebug >= 2 {
3255 fmt.Printf("error recovery pops state %d , uncovers %d\n", 3254 fmt.Printf("error recovery pops state %d , uncovers %d\n",
3256 YYS[yyp].yys, YYS[yyp-1].yys) 3255 YYS[yyp].yys, YYS[yyp-1].yys)
3257 } 3256 }
3258 yyp-- 3257 yyp--
3259 } 3258 }
3260 /* there is no state on the stack with an error shift .. . abort */ 3259 /* there is no state on the stack with an error shift .. . abort */
3261 goto ret1 3260 goto ret1
3262 3261
3263 case 3: /* no shift yet; clobber input char */ 3262 case 3: /* no shift yet; clobber input char */
3264 » » » if Debug >= 2 { 3263 » » » if yyDebug >= 2 {
3265 » » » » fmt.Printf("error recovery discards %s\n", Tokna me(yychar)) 3264 » » » » fmt.Printf("error recovery discards %s\n", yyTok name(yychar))
3266 » » » } 3265 » » » }
3267 » » » if yychar == YYEOFCODE { 3266 » » » if yychar == yyEofCode {
3268 goto ret1 3267 goto ret1
3269 } 3268 }
3270 yychar = -1 3269 yychar = -1
3271 goto yynewstate /* try again in the same state */ 3270 goto yynewstate /* try again in the same state */
3272 } 3271 }
3273 } 3272 }
3274 3273
3275 /* reduction by production yyn */ 3274 /* reduction by production yyn */
3276 » if Debug >= 2 { 3275 » if yyDebug >= 2 {
3277 » » fmt.Printf("reduce %v in:\n\t%v", yyn, Statname(yystate)) 3276 » » fmt.Printf("reduce %v in:\n\t%v", yyn, yyStatname(yystate))
3278 } 3277 }
3279 3278
3280 yynt := yyn 3279 yynt := yyn
3281 yypt := yyp 3280 yypt := yyp
3282 3281 » _ = yypt» » // guard against "declared and not used"
3283 » yyp -= YYR2[yyn] 3282
3283 » yyp -= yyR2[yyn]
3284 YYVAL = YYS[yyp+1] 3284 YYVAL = YYS[yyp+1]
3285 3285
3286 /* consult goto table to find next state */ 3286 /* consult goto table to find next state */
3287 » yyn = YYR1[yyn] 3287 » yyn = yyR1[yyn]
3288 » yyg := YYPGO[yyn] 3288 » yyg := yyPgo[yyn]
3289 yyj := yyg + YYS[yyp].yys + 1 3289 yyj := yyg + YYS[yyp].yys + 1
3290 3290
3291 » if yyj >= YYLAST { 3291 » if yyj >= yyLast {
3292 » » yystate = YYACT[yyg] 3292 » » yystate = yyAct[yyg]
3293 } else { 3293 } else {
3294 » » yystate = YYACT[yyj] 3294 » » yystate = yyAct[yyj]
3295 » » if YYCHK[yystate] != -yyn { 3295 » » if yyChk[yystate] != -yyn {
3296 » » » yystate = YYACT[yyg] 3296 » » » yystate = yyAct[yyg]
3297 } 3297 }
3298 } 3298 }
3299 // dummy call; replaced with literal code 3299 // dummy call; replaced with literal code
3300 yyrun() 3300 yyrun()
3301 goto yystack /* stack new state and value */ 3301 goto yystack /* stack new state and value */
3302 } 3302 }
3303 ` 3303 `
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b