Commit f6462961 authored by Rob Pike's avatar Rob Pike

Update goyacc to new syntax, still with semicolons.

Update units.y too.
Fixes #417.

R=rsc
CC=golang-dev
https://golang.org/cl/176063
parent bedfc2c2
...@@ -2195,7 +2195,7 @@ func output() { ...@@ -2195,7 +2195,7 @@ func output() {
fmt.Fprintf(ftable, "const\tYYNPROD\t= %v\n", nprod); fmt.Fprintf(ftable, "const\tYYNPROD\t= %v\n", nprod);
fmt.Fprintf(ftable, "const\tYYPRIVATE\t= %v\n", PRIVATE); fmt.Fprintf(ftable, "const\tYYPRIVATE\t= %v\n", PRIVATE);
fmt.Fprintf(ftable, "var\tYYTOKENNAMES []string\n"); fmt.Fprintf(ftable, "var\tYYTOKENNAMES []string\n");
fmt.Fprintf(ftable, "var\tYYSTATES\n[]string\n"); fmt.Fprintf(ftable, "var\tYYSTATES []string\n");
} }
// //
...@@ -2869,7 +2869,7 @@ func others() { ...@@ -2869,7 +2869,7 @@ func others() {
putrune(ftable, '\n') putrune(ftable, '\n')
} }
} }
fmt.Fprintf(ftable, "%4d\n };\n", 0); fmt.Fprintf(ftable, "%4d,\n };\n", 0);
// copy parser text // copy parser text
c = getrune(finput); c = getrune(finput);
...@@ -3123,10 +3123,7 @@ func exit(status int) { ...@@ -3123,10 +3123,7 @@ func exit(status int) {
os.Exit(status); os.Exit(status);
} }
var yaccpar = var yaccpar = `
// from here to the end of the file is
// a single string containing the old yaccpar file
`
/* parser for yacc output */ /* parser for yacc output */
var Nerrs = 0 /* number of errors */ var Nerrs = 0 /* number of errors */
...@@ -3135,8 +3132,7 @@ var Debug = 0 ...@@ -3135,8 +3132,7 @@ var Debug = 0
const YYFLAG = -1000 const YYFLAG = -1000
func func
Tokname(yyc int) string Tokname(yyc int) string {
{
if yyc > 0 && yyc <= len(Toknames) { if yyc > 0 && yyc <= len(Toknames) {
if Toknames[yyc-1] != "" { if Toknames[yyc-1] != "" {
return Toknames[yyc-1]; return Toknames[yyc-1];
...@@ -3146,8 +3142,7 @@ Tokname(yyc int) string ...@@ -3146,8 +3142,7 @@ Tokname(yyc int) string
} }
func func
Statname(yys int) string Statname(yys int) string {
{
if yys >= 0 && yys < len(Statenames) { if yys >= 0 && yys < len(Statenames) {
if Statenames[yys] != "" { if Statenames[yys] != "" {
return Statenames[yys]; return Statenames[yys];
...@@ -3157,8 +3152,7 @@ Statname(yys int) string ...@@ -3157,8 +3152,7 @@ Statname(yys int) string
} }
func func
lex1() int lex1() int {
{
var yychar int; var yychar int;
var c int; var c int;
...@@ -3197,8 +3191,7 @@ out: ...@@ -3197,8 +3191,7 @@ out:
} }
func func
Parse() int Parse() int {
{
var yyj, yystate, yyn, yyg, yyxi, yyp int; var yyj, yystate, yyn, yyg, yyxi, yyp int;
var yychar int; var yychar int;
var yypt, yynt int; var yypt, yynt int;
......
...@@ -40,16 +40,14 @@ const ...@@ -40,16 +40,14 @@ const
Maxe = 695; // log of largest number Maxe = 695; // log of largest number
) )
type Node type
struct Node struct {
{
vval float64; vval float64;
dim [Ndim]int8; dim [Ndim]int8;
} }
type Var type
struct Var struct {
{
name string; name string;
node Node; node Node;
} }
...@@ -220,8 +218,7 @@ expr0: ...@@ -220,8 +218,7 @@ expr0:
%% %%
func func
Lex() int Lex() int {
{
var c, i int; var c, i int;
c = peekrune; c = peekrune;
...@@ -287,8 +284,7 @@ numb: ...@@ -287,8 +284,7 @@ numb:
} }
func func
main() main() {
{
var file string; var file string;
flag.BoolVar(&vflag, "v", false, "verbose"); flag.BoolVar(&vflag, "v", false, "verbose");
...@@ -369,8 +365,7 @@ main() ...@@ -369,8 +365,7 @@ main()
* meaning. rest are usable as names * meaning. rest are usable as names
*/ */
func func
ralpha(c int) bool ralpha(c int) bool {
{
switch c { switch c {
case 0, '+', '-', '*', '/', '[', ']', '(', ')', case 0, '+', '-', '*', '/', '[', ']', '(', ')',
'^', ':', '?', ' ', '\t', '.', '|', '#', '^', ':', '?', ' ', '\t', '.', '|', '#',
...@@ -384,8 +379,7 @@ ralpha(c int) bool ...@@ -384,8 +379,7 @@ ralpha(c int) bool
* number forming character * number forming character
*/ */
func func
rdigit(c int) bool rdigit(c int) bool {
{
switch c { switch c {
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'.', 'e', '+', '-': '.', 'e', '+', '-':
...@@ -395,8 +389,7 @@ rdigit(c int) bool ...@@ -395,8 +389,7 @@ rdigit(c int) bool
} }
func func
Error(s string, v ...) Error(s string, v ...) {
{
/* /*
* hack to intercept message from yaccpar * hack to intercept message from yaccpar
...@@ -417,8 +410,7 @@ Error(s string, v ...) ...@@ -417,8 +410,7 @@ Error(s string, v ...)
} }
func func
add(c,a,b *Node) add(c,a,b *Node) {
{
var i int; var i int;
var d int8; var d int8;
...@@ -433,8 +425,7 @@ add(c,a,b *Node) ...@@ -433,8 +425,7 @@ add(c,a,b *Node)
} }
func func
sub(c,a,b *Node) sub(c,a,b *Node) {
{
var i int; var i int;
var d int8; var d int8;
...@@ -449,8 +440,7 @@ sub(c,a,b *Node) ...@@ -449,8 +440,7 @@ sub(c,a,b *Node)
} }
func func
mul(c,a,b *Node) mul(c,a,b *Node) {
{
var i int; var i int;
for i=0; i<Ndim; i++ { for i=0; i<Ndim; i++ {
...@@ -460,8 +450,7 @@ mul(c,a,b *Node) ...@@ -460,8 +450,7 @@ mul(c,a,b *Node)
} }
func func
div(c,a,b *Node) div(c,a,b *Node) {
{
var i int; var i int;
for i=0; i<Ndim; i++ { for i=0; i<Ndim; i++ {
...@@ -471,8 +460,7 @@ div(c,a,b *Node) ...@@ -471,8 +460,7 @@ div(c,a,b *Node)
} }
func func
xpn(c,a *Node, b int) xpn(c,a *Node, b int) {
{
var i int; var i int;
*c = one; *c = one;
...@@ -488,8 +476,7 @@ xpn(c,a *Node, b int) ...@@ -488,8 +476,7 @@ xpn(c,a *Node, b int)
} }
func func
specialcase(c,a,b *Node) bool specialcase(c,a,b *Node) bool {
{
var i int; var i int;
var d, d1, d2 int8; var d, d1, d2 int8;
...@@ -536,8 +523,7 @@ specialcase(c,a,b *Node) bool ...@@ -536,8 +523,7 @@ specialcase(c,a,b *Node) bool
} }
func func
printdim(str string, d, n int) string printdim(str string, d, n int) string {
{
var v *Var; var v *Var;
if n != 0 { if n != 0 {
...@@ -560,9 +546,8 @@ printdim(str string, d, n int) string ...@@ -560,9 +546,8 @@ printdim(str string, d, n int) string
return str; return str;
} }
func (n Node) func
String() string (n Node) String() string {
{
var str string; var str string;
var f, i, d int; var f, i, d int;
...@@ -592,17 +577,15 @@ String() string ...@@ -592,17 +577,15 @@ String() string
return str; return str;
} }
func (v *Var) func
String() string (v *Var) String() string {
{
var str string; var str string;
str = fmt.Sprintf("%v %v", v.name, v.node); str = fmt.Sprintf("%v %v", v.name, v.node);
return str; return str;
} }
func func
readline() bool readline() bool {
{
s,err := fi.ReadString('\n'); s,err := fi.ReadString('\n');
if err != nil { if err != nil {
return true; return true;
...@@ -613,8 +596,7 @@ readline() bool ...@@ -613,8 +596,7 @@ readline() bool
} }
func func
getrune() int getrune() int {
{
var c,n int; var c,n int;
if linep >= len(line) { if linep >= len(line) {
...@@ -631,8 +613,7 @@ getrune() int ...@@ -631,8 +613,7 @@ getrune() int
var symmap = make(map[string]*Var); // symbol table var symmap = make(map[string]*Var); // symbol table
func func
lookup(f int) *Var lookup(f int) *Var {
{
var p float64; var p float64;
var w *Var; var w *Var;
...@@ -663,8 +644,8 @@ lookup(f int) *Var ...@@ -663,8 +644,8 @@ lookup(f int) *Var
return v; return v;
} }
type Prefix type
struct Prefix struct
{ {
vval float64; vval float64;
name string; name string;
...@@ -693,12 +674,11 @@ var prefix = []Prefix { // prefix table ...@@ -693,12 +674,11 @@ var prefix = []Prefix { // prefix table
Prefix { 1e15, "peta" }, Prefix { 1e15, "peta" },
Prefix { 1e18, "exa" }, Prefix { 1e18, "exa" },
Prefix { 1e21, "zetta" }, Prefix { 1e21, "zetta" },
Prefix { 1e24, "yotta" } Prefix { 1e24, "yotta" },
} }
func func
pname() float64 pname() float64 {
{
var i, j, n int; var i, j, n int;
var s string; var s string;
...@@ -730,8 +710,7 @@ pname() float64 ...@@ -730,8 +710,7 @@ pname() float64
// careful multiplication // careful multiplication
// exponents (log) are checked before multiply // exponents (log) are checked before multiply
func func
fmul(a, b float64) float64 fmul(a, b float64) float64 {
{
var l float64; var l float64;
if b <= 0 { if b <= 0 {
...@@ -764,8 +743,7 @@ fmul(a, b float64) float64 ...@@ -764,8 +743,7 @@ fmul(a, b float64) float64
// careful division // careful division
// exponents (log) are checked before divide // exponents (log) are checked before divide
func func
fdiv(a, b float64) float64 fdiv(a, b float64) float64 {
{
var l float64; var l float64;
if b <= 0 { if b <= 0 {
...@@ -797,7 +775,6 @@ fdiv(a, b float64) float64 ...@@ -797,7 +775,6 @@ fdiv(a, b float64) float64
} }
func func
fadd(a, b float64) float64 fadd(a, b float64) float64 {
{
return a + b; return a + b;
} }
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