Commit 920df48f authored by Anthony Martin's avatar Anthony Martin Committed by Russ Cox

gc: support for building with Plan 9 yacc

I've modified Plan 9's yacc to work with
the grammar in go.y.  These are the only
changes necessary on the Go side.

R=rsc
CC=golang-dev
https://golang.org/cl/5375104
parent d0b9a84a
...@@ -46,24 +46,36 @@ bison && /^state 0/ { grammar = 0; states = 1 } ...@@ -46,24 +46,36 @@ bison && /^state 0/ { grammar = 0; states = 1 }
states && /^state / { state = $2 } states && /^state / { state = $2 }
states { statetext[state] = statetext[state] $0 "\n" } states { statetext[state] = statetext[state] $0 "\n" }
states && / shift, and go to state/ { states && / shift/ {
n = nshift[state]++ n = nshift[state]++
shift[state,n] = $7 if($0 ~ /and go to/)
shift[state,n] = $7 # GNU Bison
else
shift[state,n] = $3 # Plan 9 Yacc
shifttoken[state,n] = $1 shifttoken[state,n] = $1
next next
} }
states && / go to state/ { states && / (go to|goto)/ {
n = nshift[state]++ n = nshift[state]++
shift[state,n] = $5 if($0 ~ /go to/)
shift[state,n] = $5 # GNU Bison
else
shift[state,n] = $3 # Plan 9 Yacc
shifttoken[state,n] = $1 shifttoken[state,n] = $1
next next
} }
states && / reduce using rule/ { states && / reduce/ {
n = nreduce[state]++ n = nreduce[state]++
reduce[state,n] = $5 if($0 ~ /reduce using rule/)
reduce[state,n] = $5 # GNU Bison
else
reduce[state,n] = $3 # Plan 9 yacc
reducetoken[state,n] = $1 reducetoken[state,n] = $1
next next
} }
# Skip over the summary information printed by Plan 9 yacc.
/nonterminals$/,/^maximum spread/ { next }
# First // comment marks the beginning of the pattern file. # First // comment marks the beginning of the pattern file.
/^\/\// { bison = 0; grammar = 0; state = 0 } /^\/\// { bison = 0; grammar = 0; state = 0 }
...@@ -96,7 +108,8 @@ $1 == "%" { ...@@ -96,7 +108,8 @@ $1 == "%" {
if(found) if(found)
continue continue
for(j=0; j<nreduce[state]; j++) { for(j=0; j<nreduce[state]; j++) {
if(reducetoken[state,j] == tok || reducetoken[state,j] == "$default") { t = reducetoken[state,j]
if(t == tok || t == "$default" || t == ".") {
stack[nstack++] = state stack[nstack++] = state
rule = reduce[state,j] rule = reduce[state,j]
nstack -= rulesize[rule] nstack -= rulesize[rule]
......
...@@ -16,6 +16,12 @@ ...@@ -16,6 +16,12 @@
#undef BUFSIZ #undef BUFSIZ
// The parser's maximum stack size.
// We have to use a #define macro here since yacc
// or bison will check for its definition and use
// a potentially smaller value if it is undefined.
#define YYMAXDEPTH 500
enum enum
{ {
NHUNK = 50000, NHUNK = 50000,
...@@ -23,7 +29,6 @@ enum ...@@ -23,7 +29,6 @@ enum
NSYMB = 500, NSYMB = 500,
NHASH = 1024, NHASH = 1024,
STRINGSZ = 200, STRINGSZ = 200,
YYMAXDEPTH = 500,
MAXALIGN = 7, MAXALIGN = 7,
UINF = 100, UINF = 100,
HISTSZ = 10, HISTSZ = 10,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment