diff --git a/errors/errors.go b/errors/errors.go index ec57ded..9652d3f 100755 --- a/errors/errors.go +++ b/errors/errors.go @@ -1,7 +1,6 @@ - package errors -import( +import ( "bytes" "fmt" "github.com/localhots/penny/token" diff --git a/lexer/acttab.go b/lexer/acttab.go index 674583f..e48e2d9 100755 --- a/lexer/acttab.go +++ b/lexer/acttab.go @@ -1,12 +1,11 @@ - package lexer -import( +import ( "fmt" "github.com/localhots/penny/token" ) -type ActionTable [NumStates] ActionRow +type ActionTable [NumStates]ActionRow type ActionRow struct { Accept token.Type @@ -18,297 +17,296 @@ func (this ActionRow) String() string { } var ActTab = ActionTable{ - ActionRow{ // S0 + ActionRow{ // S0 Accept: 0, - Ignore: "", - }, - ActionRow{ // S1 + Ignore: "", + }, + ActionRow{ // S1 Accept: -1, - Ignore: "!whitespace", - }, - ActionRow{ // S2 + Ignore: "!whitespace", + }, + ActionRow{ // S2 Accept: 7, - Ignore: "", - }, - ActionRow{ // S3 + Ignore: "", + }, + ActionRow{ // S3 Accept: 39, - Ignore: "", - }, - ActionRow{ // S4 + Ignore: "", + }, + ActionRow{ // S4 Accept: 9, - Ignore: "", - }, - ActionRow{ // S5 + Ignore: "", + }, + ActionRow{ // S5 Accept: 10, - Ignore: "", - }, - ActionRow{ // S6 + Ignore: "", + }, + ActionRow{ // S6 Accept: 3, - Ignore: "", - }, - ActionRow{ // S7 + Ignore: "", + }, + ActionRow{ // S7 Accept: 40, - Ignore: "", - }, - ActionRow{ // S8 + Ignore: "", + }, + ActionRow{ // S8 Accept: 28, - Ignore: "", - }, - ActionRow{ // S9 + Ignore: "", + }, + ActionRow{ // S9 Accept: 4, - Ignore: "", - }, - ActionRow{ // S10 + Ignore: "", + }, + ActionRow{ // S10 Accept: 30, - Ignore: "", - }, - ActionRow{ // S11 + Ignore: "", + }, + ActionRow{ // S11 Accept: 0, - Ignore: "", - }, - ActionRow{ // S12 + Ignore: "", + }, + ActionRow{ // S12 Accept: 13, - Ignore: "", - }, - ActionRow{ // S13 + Ignore: "", + }, + ActionRow{ // S13 Accept: 0, - Ignore: "", - }, - ActionRow{ // S14 + Ignore: "", + }, + ActionRow{ // S14 Accept: 0, - Ignore: "", - }, - ActionRow{ // S15 + Ignore: "", + }, + ActionRow{ // S15 Accept: 0, - Ignore: "", - }, - ActionRow{ // S16 + Ignore: "", + }, + ActionRow{ // S16 Accept: 0, - Ignore: "", - }, - ActionRow{ // S17 + Ignore: "", + }, + ActionRow{ // S17 Accept: 0, - Ignore: "", - }, - ActionRow{ // S18 + Ignore: "", + }, + ActionRow{ // S18 Accept: 0, - Ignore: "", - }, - ActionRow{ // S19 + Ignore: "", + }, + ActionRow{ // S19 Accept: 0, - Ignore: "", - }, - ActionRow{ // S20 + Ignore: "", + }, + ActionRow{ // S20 Accept: 0, - Ignore: "", - }, - ActionRow{ // S21 + Ignore: "", + }, + ActionRow{ // S21 Accept: 0, - Ignore: "", - }, - ActionRow{ // S22 + Ignore: "", + }, + ActionRow{ // S22 Accept: 24, - Ignore: "", - }, - ActionRow{ // S23 + Ignore: "", + }, + ActionRow{ // S23 Accept: 8, - Ignore: "", - }, - ActionRow{ // S24 + Ignore: "", + }, + ActionRow{ // S24 Accept: 25, - Ignore: "", - }, - ActionRow{ // S25 + Ignore: "", + }, + ActionRow{ // S25 Accept: 38, - Ignore: "", - }, - ActionRow{ // S26 + Ignore: "", + }, + ActionRow{ // S26 Accept: 5, - Ignore: "", - }, - ActionRow{ // S27 + Ignore: "", + }, + ActionRow{ // S27 Accept: 16, - Ignore: "", - }, - ActionRow{ // S28 + Ignore: "", + }, + ActionRow{ // S28 Accept: 29, - Ignore: "", - }, - ActionRow{ // S29 + Ignore: "", + }, + ActionRow{ // S29 Accept: 35, - Ignore: "", - }, - ActionRow{ // S30 + Ignore: "", + }, + ActionRow{ // S30 Accept: 33, - Ignore: "", - }, - ActionRow{ // S31 + Ignore: "", + }, + ActionRow{ // S31 Accept: 31, - Ignore: "", - }, - ActionRow{ // S32 + Ignore: "", + }, + ActionRow{ // S32 Accept: 32, - Ignore: "", - }, - ActionRow{ // S33 + Ignore: "", + }, + ActionRow{ // S33 Accept: 34, - Ignore: "", - }, - ActionRow{ // S34 + Ignore: "", + }, + ActionRow{ // S34 Accept: 37, - Ignore: "", - }, - ActionRow{ // S35 + Ignore: "", + }, + ActionRow{ // S35 Accept: 13, - Ignore: "", - }, - ActionRow{ // S36 + Ignore: "", + }, + ActionRow{ // S36 Accept: 0, - Ignore: "", - }, - ActionRow{ // S37 + Ignore: "", + }, + ActionRow{ // S37 Accept: 2, - Ignore: "", - }, - ActionRow{ // S38 + Ignore: "", + }, + ActionRow{ // S38 Accept: 0, - Ignore: "", - }, - ActionRow{ // S39 + Ignore: "", + }, + ActionRow{ // S39 Accept: 26, - Ignore: "", - }, - ActionRow{ // S40 + Ignore: "", + }, + ActionRow{ // S40 Accept: 0, - Ignore: "", - }, - ActionRow{ // S41 + Ignore: "", + }, + ActionRow{ // S41 Accept: 0, - Ignore: "", - }, - ActionRow{ // S42 + Ignore: "", + }, + ActionRow{ // S42 Accept: 19, - Ignore: "", - }, - ActionRow{ // S43 + Ignore: "", + }, + ActionRow{ // S43 Accept: 0, - Ignore: "", - }, - ActionRow{ // S44 + Ignore: "", + }, + ActionRow{ // S44 Accept: 17, - Ignore: "", - }, - ActionRow{ // S45 + Ignore: "", + }, + ActionRow{ // S45 Accept: 12, - Ignore: "", - }, - ActionRow{ // S46 + Ignore: "", + }, + ActionRow{ // S46 Accept: 0, - Ignore: "", - }, - ActionRow{ // S47 + Ignore: "", + }, + ActionRow{ // S47 Accept: 0, - Ignore: "", - }, - ActionRow{ // S48 + Ignore: "", + }, + ActionRow{ // S48 Accept: 0, - Ignore: "", - }, - ActionRow{ // S49 + Ignore: "", + }, + ActionRow{ // S49 Accept: 6, - Ignore: "", - }, - ActionRow{ // S50 + Ignore: "", + }, + ActionRow{ // S50 Accept: 36, - Ignore: "", - }, - ActionRow{ // S51 + Ignore: "", + }, + ActionRow{ // S51 Accept: 13, - Ignore: "", - }, - ActionRow{ // S52 + Ignore: "", + }, + ActionRow{ // S52 Accept: 2, - Ignore: "", - }, - ActionRow{ // S53 + Ignore: "", + }, + ActionRow{ // S53 Accept: 0, - Ignore: "", - }, - ActionRow{ // S54 + Ignore: "", + }, + ActionRow{ // S54 Accept: 0, - Ignore: "", - }, - ActionRow{ // S55 + Ignore: "", + }, + ActionRow{ // S55 Accept: 0, - Ignore: "", - }, - ActionRow{ // S56 + Ignore: "", + }, + ActionRow{ // S56 Accept: 0, - Ignore: "", - }, - ActionRow{ // S57 + Ignore: "", + }, + ActionRow{ // S57 Accept: 0, - Ignore: "", - }, - ActionRow{ // S58 + Ignore: "", + }, + ActionRow{ // S58 Accept: 0, - Ignore: "", - }, - ActionRow{ // S59 + Ignore: "", + }, + ActionRow{ // S59 Accept: 11, - Ignore: "", - }, - ActionRow{ // S60 + Ignore: "", + }, + ActionRow{ // S60 Accept: 0, - Ignore: "", - }, - ActionRow{ // S61 + Ignore: "", + }, + ActionRow{ // S61 Accept: 0, - Ignore: "", - }, - ActionRow{ // S62 + Ignore: "", + }, + ActionRow{ // S62 Accept: 0, - Ignore: "", - }, - ActionRow{ // S63 + Ignore: "", + }, + ActionRow{ // S63 Accept: 14, - Ignore: "", - }, - ActionRow{ // S64 + Ignore: "", + }, + ActionRow{ // S64 Accept: 27, - Ignore: "", - }, - ActionRow{ // S65 + Ignore: "", + }, + ActionRow{ // S65 Accept: 20, - Ignore: "", - }, - ActionRow{ // S66 + Ignore: "", + }, + ActionRow{ // S66 Accept: 21, - Ignore: "", - }, - ActionRow{ // S67 + Ignore: "", + }, + ActionRow{ // S67 Accept: 15, - Ignore: "", - }, - ActionRow{ // S68 + Ignore: "", + }, + ActionRow{ // S68 Accept: 18, - Ignore: "", - }, - ActionRow{ // S69 + Ignore: "", + }, + ActionRow{ // S69 Accept: 0, - Ignore: "", - }, - ActionRow{ // S70 + Ignore: "", + }, + ActionRow{ // S70 Accept: 0, - Ignore: "", - }, - ActionRow{ // S71 + Ignore: "", + }, + ActionRow{ // S71 Accept: 23, - Ignore: "", - }, - ActionRow{ // S72 + Ignore: "", + }, + ActionRow{ // S72 Accept: 22, - Ignore: "", - }, - + Ignore: "", + }, } diff --git a/lexer/lexer.go b/lexer/lexer.go index 5b8b27c..a9b5ce3 100755 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -1,27 +1,26 @@ - package lexer import ( - + // "fmt" // "github.com/localhots/penny/util" - + + "github.com/localhots/penny/token" "io/ioutil" "unicode/utf8" - "github.com/localhots/penny/token" ) -const( - NoState = -1 - NumStates = 73 +const ( + NoState = -1 + NumStates = 73 NumSymbols = 90 -) +) type Lexer struct { - src []byte - pos int - line int - column int + src []byte + pos int + line int + column int } func NewLexer(src []byte) *Lexer { @@ -43,9 +42,9 @@ func NewLexerFile(fpath string) (*Lexer, error) { } func (this *Lexer) Scan() (tok *token.Token) { - + // fmt.Printf("Lexer.Scan() pos=%d\n", this.pos) - + tok = new(token.Token) if this.pos >= len(this.src) { tok.Type = token.EOF @@ -56,9 +55,9 @@ func (this *Lexer) Scan() (tok *token.Token) { tok.Type = token.INVALID state, rune1, size := 0, rune(-1), 0 for state != -1 { - + // fmt.Printf("\tpos=%d, line=%d, col=%d, state=%d\n", this.pos, this.line, this.column, state) - + if this.pos >= len(this.src) { rune1 = -1 } else { @@ -77,7 +76,6 @@ func (this *Lexer) Scan() (tok *token.Token) { this.column++ } - // Production start if rune1 != -1 { state = TransTab[state](rune1) @@ -98,7 +96,6 @@ func (this *Lexer) Scan() (tok *token.Token) { // } // state = nextState // Debug end - if state != -1 { switch { diff --git a/lexer/transitiontable.go b/lexer/transitiontable.go index 5ed6168..43491d3 100755 --- a/lexer/transitiontable.go +++ b/lexer/transitiontable.go @@ -1,1016 +1,867 @@ - package lexer - - /* Let s be the current state Let r be the current input rune transitionTable[s](r) returns the next state. */ -type TransitionTable [NumStates] func(rune) int +type TransitionTable [NumStates]func(rune) int var TransTab = TransitionTable{ - - // S0 - func(r rune) int { - switch { - case r == 9 : // ['\t','\t'] - return 1 - case r == 10 : // ['\n','\n'] - return 1 - case r == 13 : // ['\r','\r'] - return 1 - case r == 32 : // [' ',' '] - return 1 - case r == 33 : // ['!','!'] - return 2 - case r == 38 : // ['&','&'] - return 3 - case r == 40 : // ['(','('] - return 4 - case r == 41 : // [')',')'] - return 5 - case 48 <= r && r <= 57 : // ['0','9'] - return 6 - case r == 59 : // [';',';'] - return 7 - case r == 60 : // ['<','<'] - return 8 - case r == 61 : // ['=','='] - return 9 - case r == 62 : // ['>','>'] - return 10 - case r == 92 : // ['\','\'] - return 11 - case r == 95 : // ['_','_'] - return 12 - case 97 <= r && r <= 98 : // ['a','b'] - return 13 - case r == 99 : // ['c','c'] - return 14 - case r == 100 : // ['d','d'] - return 15 - case r == 101 : // ['e','e'] - return 16 - case r == 102 : // ['f','f'] - return 17 - case 103 <= r && r <= 104 : // ['g','h'] - return 13 - case r == 105 : // ['i','i'] - return 18 - case 106 <= r && r <= 115 : // ['j','s'] - return 13 - case r == 116 : // ['t','t'] - return 19 - case r == 117 : // ['u','u'] - return 20 - case r == 118 : // ['v','v'] - return 13 - case r == 119 : // ['w','w'] - return 21 - case 120 <= r && r <= 122 : // ['x','z'] - return 13 - case r == 123 : // ['{','{'] - return 22 - case r == 124 : // ['|','|'] - return 23 - case r == 125 : // ['}','}'] - return 24 - - - default: - return 25 - } - - }, - - // S1 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S2 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S3 - func(r rune) int { - switch { - case r == 38 : // ['&','&'] - return 26 - - - - } - return NoState - - }, - - // S4 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S5 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S6 - func(r rune) int { - switch { - case 48 <= r && r <= 57 : // ['0','9'] - return 6 - - - - } - return NoState - - }, - - // S7 - func(r rune) int { - switch { - case r == 59 : // [';',';'] - return 27 - - - - } - return NoState - - }, - - // S8 - func(r rune) int { - switch { - case r == 38 : // ['&','&'] - return 28 - case r == 60 : // ['<','<'] - return 29 - case r == 62 : // ['>','>'] - return 30 - - - - } - return NoState - - }, - - // S9 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S10 - func(r rune) int { - switch { - case r == 38 : // ['&','&'] - return 31 - case r == 62 : // ['>','>'] - return 32 - case r == 124 : // ['|','|'] - return 33 - - - - } - return NoState - - }, - - // S11 - func(r rune) int { - switch { - case r == 110 : // ['n','n'] - return 34 - - - - } - return NoState - - }, - - // S12 - func(r rune) int { - switch { - case 48 <= r && r <= 57 : // ['0','9'] - return 35 - case r == 95 : // ['_','_'] - return 12 - case 97 <= r && r <= 122 : // ['a','z'] - return 36 - - - - } - return NoState - - }, - - // S13 - func(r rune) int { - switch { - case 65 <= r && r <= 90 : // ['A','Z'] - return 37 - - - - } - return NoState - - }, - - // S14 - func(r rune) int { - switch { - case 65 <= r && r <= 90 : // ['A','Z'] - return 37 - case r == 97 : // ['a','a'] - return 38 - - - - } - return NoState - - }, - - // S15 - func(r rune) int { - switch { - case 65 <= r && r <= 90 : // ['A','Z'] - return 37 - case r == 111 : // ['o','o'] - return 39 - - - - } - return NoState - - }, - - // S16 - func(r rune) int { - switch { - case 65 <= r && r <= 90 : // ['A','Z'] - return 37 - case r == 108 : // ['l','l'] - return 40 - case r == 115 : // ['s','s'] - return 41 - - - - } - return NoState - - }, - - // S17 - func(r rune) int { - switch { - case 65 <= r && r <= 90 : // ['A','Z'] - return 37 - case r == 105 : // ['i','i'] - return 42 - case r == 111 : // ['o','o'] - return 43 - - - - } - return NoState - - }, - - // S18 - func(r rune) int { - switch { - case 65 <= r && r <= 90 : // ['A','Z'] - return 37 - case r == 102 : // ['f','f'] - return 44 - case r == 110 : // ['n','n'] - return 45 - - - - } - return NoState - - }, - - // S19 - func(r rune) int { - switch { - case 65 <= r && r <= 90 : // ['A','Z'] - return 37 - case r == 104 : // ['h','h'] - return 46 - - - - } - return NoState - - }, - - // S20 - func(r rune) int { - switch { - case 65 <= r && r <= 90 : // ['A','Z'] - return 37 - case r == 110 : // ['n','n'] - return 47 - - - - } - return NoState - - }, - - // S21 - func(r rune) int { - switch { - case 65 <= r && r <= 90 : // ['A','Z'] - return 37 - case r == 104 : // ['h','h'] - return 48 - - - - } - return NoState - - }, - - // S22 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S23 - func(r rune) int { - switch { - case r == 124 : // ['|','|'] - return 49 - - - - } - return NoState - - }, - - // S24 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S25 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S26 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S27 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S28 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S29 - func(r rune) int { - switch { - case r == 45 : // ['-','-'] - return 50 - - - - } - return NoState - - }, - - // S30 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S31 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S32 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S33 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S34 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S35 - func(r rune) int { - switch { - case 48 <= r && r <= 57 : // ['0','9'] - return 35 - case r == 95 : // ['_','_'] - return 12 - case 97 <= r && r <= 122 : // ['a','z'] - return 36 - - - - } - return NoState - - }, - - // S36 - func(r rune) int { - switch { - case 65 <= r && r <= 90 : // ['A','Z'] - return 51 - - - - } - return NoState - - }, - - // S37 - func(r rune) int { - switch { - case 48 <= r && r <= 57 : // ['0','9'] - return 35 - case r == 95 : // ['_','_'] - return 52 - case 97 <= r && r <= 122 : // ['a','z'] - return 53 - - - - } - return NoState - - }, - - // S38 - func(r rune) int { - switch { - case r == 115 : // ['s','s'] - return 54 - - - - } - return NoState - - }, - - // S39 - func(r rune) int { - switch { - case r == 110 : // ['n','n'] - return 55 - - - - } - return NoState - - }, - - // S40 - func(r rune) int { - switch { - case r == 105 : // ['i','i'] - return 56 - case r == 115 : // ['s','s'] - return 57 - - - - } - return NoState - - }, - - // S41 - func(r rune) int { - switch { - case r == 97 : // ['a','a'] - return 58 - - - - } - return NoState - - }, - - // S42 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S43 - func(r rune) int { - switch { - case r == 114 : // ['r','r'] - return 59 - - - - } - return NoState - - }, - - // S44 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S45 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S46 - func(r rune) int { - switch { - case r == 101 : // ['e','e'] - return 60 - - - - } - return NoState - - }, - - // S47 - func(r rune) int { - switch { - case r == 116 : // ['t','t'] - return 61 - - - - } - return NoState - - }, - - // S48 - func(r rune) int { - switch { - case r == 105 : // ['i','i'] - return 62 - - - - } - return NoState - - }, - - // S49 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S50 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S51 - func(r rune) int { - switch { - case 48 <= r && r <= 57 : // ['0','9'] - return 35 - case r == 95 : // ['_','_'] - return 12 - case 97 <= r && r <= 122 : // ['a','z'] - return 36 - - - - } - return NoState - - }, - - // S52 - func(r rune) int { - switch { - case 48 <= r && r <= 57 : // ['0','9'] - return 35 - case r == 95 : // ['_','_'] - return 52 - case 97 <= r && r <= 122 : // ['a','z'] - return 53 - - - - } - return NoState - - }, - - // S53 - func(r rune) int { - switch { - case 65 <= r && r <= 90 : // ['A','Z'] - return 37 - - - - } - return NoState - - }, - - // S54 - func(r rune) int { - switch { - case r == 101 : // ['e','e'] - return 63 - - - - } - return NoState - - }, - - // S55 - func(r rune) int { - switch { - case r == 101 : // ['e','e'] - return 64 - - - - } - return NoState - - }, - - // S56 - func(r rune) int { - switch { - case r == 102 : // ['f','f'] - return 65 - - - - } - return NoState - - }, - - // S57 - func(r rune) int { - switch { - case r == 101 : // ['e','e'] - return 66 - - - - } - return NoState - - }, - - // S58 - func(r rune) int { - switch { - case r == 99 : // ['c','c'] - return 67 - - - - } - return NoState - - }, - - // S59 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S60 - func(r rune) int { - switch { - case r == 110 : // ['n','n'] - return 68 - - - - } - return NoState - - }, - - // S61 - func(r rune) int { - switch { - case r == 105 : // ['i','i'] - return 69 - - - - } - return NoState - - }, - - // S62 - func(r rune) int { - switch { - case r == 108 : // ['l','l'] - return 70 - - - - } - return NoState - - }, - - // S63 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S64 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S65 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S66 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S67 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S68 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S69 - func(r rune) int { - switch { - case r == 108 : // ['l','l'] - return 71 - - - - } - return NoState - - }, - - // S70 - func(r rune) int { - switch { - case r == 101 : // ['e','e'] - return 72 - - - - } - return NoState - - }, - - // S71 - func(r rune) int { - switch { - - - - } - return NoState - - }, - - // S72 - func(r rune) int { - switch { - - - - } - return NoState - - }, - + + // S0 + func(r rune) int { + switch { + case r == 9: // ['\t','\t'] + return 1 + case r == 10: // ['\n','\n'] + return 1 + case r == 13: // ['\r','\r'] + return 1 + case r == 32: // [' ',' '] + return 1 + case r == 33: // ['!','!'] + return 2 + case r == 38: // ['&','&'] + return 3 + case r == 40: // ['(','('] + return 4 + case r == 41: // [')',')'] + return 5 + case 48 <= r && r <= 57: // ['0','9'] + return 6 + case r == 59: // [';',';'] + return 7 + case r == 60: // ['<','<'] + return 8 + case r == 61: // ['=','='] + return 9 + case r == 62: // ['>','>'] + return 10 + case r == 92: // ['\','\'] + return 11 + case r == 95: // ['_','_'] + return 12 + case 97 <= r && r <= 98: // ['a','b'] + return 13 + case r == 99: // ['c','c'] + return 14 + case r == 100: // ['d','d'] + return 15 + case r == 101: // ['e','e'] + return 16 + case r == 102: // ['f','f'] + return 17 + case 103 <= r && r <= 104: // ['g','h'] + return 13 + case r == 105: // ['i','i'] + return 18 + case 106 <= r && r <= 115: // ['j','s'] + return 13 + case r == 116: // ['t','t'] + return 19 + case r == 117: // ['u','u'] + return 20 + case r == 118: // ['v','v'] + return 13 + case r == 119: // ['w','w'] + return 21 + case 120 <= r && r <= 122: // ['x','z'] + return 13 + case r == 123: // ['{','{'] + return 22 + case r == 124: // ['|','|'] + return 23 + case r == 125: // ['}','}'] + return 24 + + default: + return 25 + } + + }, + + // S1 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S2 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S3 + func(r rune) int { + switch { + case r == 38: // ['&','&'] + return 26 + + } + return NoState + + }, + + // S4 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S5 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S6 + func(r rune) int { + switch { + case 48 <= r && r <= 57: // ['0','9'] + return 6 + + } + return NoState + + }, + + // S7 + func(r rune) int { + switch { + case r == 59: // [';',';'] + return 27 + + } + return NoState + + }, + + // S8 + func(r rune) int { + switch { + case r == 38: // ['&','&'] + return 28 + case r == 60: // ['<','<'] + return 29 + case r == 62: // ['>','>'] + return 30 + + } + return NoState + + }, + + // S9 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S10 + func(r rune) int { + switch { + case r == 38: // ['&','&'] + return 31 + case r == 62: // ['>','>'] + return 32 + case r == 124: // ['|','|'] + return 33 + + } + return NoState + + }, + + // S11 + func(r rune) int { + switch { + case r == 110: // ['n','n'] + return 34 + + } + return NoState + + }, + + // S12 + func(r rune) int { + switch { + case 48 <= r && r <= 57: // ['0','9'] + return 35 + case r == 95: // ['_','_'] + return 12 + case 97 <= r && r <= 122: // ['a','z'] + return 36 + + } + return NoState + + }, + + // S13 + func(r rune) int { + switch { + case 65 <= r && r <= 90: // ['A','Z'] + return 37 + + } + return NoState + + }, + + // S14 + func(r rune) int { + switch { + case 65 <= r && r <= 90: // ['A','Z'] + return 37 + case r == 97: // ['a','a'] + return 38 + + } + return NoState + + }, + + // S15 + func(r rune) int { + switch { + case 65 <= r && r <= 90: // ['A','Z'] + return 37 + case r == 111: // ['o','o'] + return 39 + + } + return NoState + + }, + + // S16 + func(r rune) int { + switch { + case 65 <= r && r <= 90: // ['A','Z'] + return 37 + case r == 108: // ['l','l'] + return 40 + case r == 115: // ['s','s'] + return 41 + + } + return NoState + + }, + + // S17 + func(r rune) int { + switch { + case 65 <= r && r <= 90: // ['A','Z'] + return 37 + case r == 105: // ['i','i'] + return 42 + case r == 111: // ['o','o'] + return 43 + + } + return NoState + + }, + + // S18 + func(r rune) int { + switch { + case 65 <= r && r <= 90: // ['A','Z'] + return 37 + case r == 102: // ['f','f'] + return 44 + case r == 110: // ['n','n'] + return 45 + + } + return NoState + + }, + + // S19 + func(r rune) int { + switch { + case 65 <= r && r <= 90: // ['A','Z'] + return 37 + case r == 104: // ['h','h'] + return 46 + + } + return NoState + + }, + + // S20 + func(r rune) int { + switch { + case 65 <= r && r <= 90: // ['A','Z'] + return 37 + case r == 110: // ['n','n'] + return 47 + + } + return NoState + + }, + + // S21 + func(r rune) int { + switch { + case 65 <= r && r <= 90: // ['A','Z'] + return 37 + case r == 104: // ['h','h'] + return 48 + + } + return NoState + + }, + + // S22 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S23 + func(r rune) int { + switch { + case r == 124: // ['|','|'] + return 49 + + } + return NoState + + }, + + // S24 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S25 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S26 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S27 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S28 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S29 + func(r rune) int { + switch { + case r == 45: // ['-','-'] + return 50 + + } + return NoState + + }, + + // S30 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S31 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S32 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S33 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S34 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S35 + func(r rune) int { + switch { + case 48 <= r && r <= 57: // ['0','9'] + return 35 + case r == 95: // ['_','_'] + return 12 + case 97 <= r && r <= 122: // ['a','z'] + return 36 + + } + return NoState + + }, + + // S36 + func(r rune) int { + switch { + case 65 <= r && r <= 90: // ['A','Z'] + return 51 + + } + return NoState + + }, + + // S37 + func(r rune) int { + switch { + case 48 <= r && r <= 57: // ['0','9'] + return 35 + case r == 95: // ['_','_'] + return 52 + case 97 <= r && r <= 122: // ['a','z'] + return 53 + + } + return NoState + + }, + + // S38 + func(r rune) int { + switch { + case r == 115: // ['s','s'] + return 54 + + } + return NoState + + }, + + // S39 + func(r rune) int { + switch { + case r == 110: // ['n','n'] + return 55 + + } + return NoState + + }, + + // S40 + func(r rune) int { + switch { + case r == 105: // ['i','i'] + return 56 + case r == 115: // ['s','s'] + return 57 + + } + return NoState + + }, + + // S41 + func(r rune) int { + switch { + case r == 97: // ['a','a'] + return 58 + + } + return NoState + + }, + + // S42 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S43 + func(r rune) int { + switch { + case r == 114: // ['r','r'] + return 59 + + } + return NoState + + }, + + // S44 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S45 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S46 + func(r rune) int { + switch { + case r == 101: // ['e','e'] + return 60 + + } + return NoState + + }, + + // S47 + func(r rune) int { + switch { + case r == 116: // ['t','t'] + return 61 + + } + return NoState + + }, + + // S48 + func(r rune) int { + switch { + case r == 105: // ['i','i'] + return 62 + + } + return NoState + + }, + + // S49 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S50 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S51 + func(r rune) int { + switch { + case 48 <= r && r <= 57: // ['0','9'] + return 35 + case r == 95: // ['_','_'] + return 12 + case 97 <= r && r <= 122: // ['a','z'] + return 36 + + } + return NoState + + }, + + // S52 + func(r rune) int { + switch { + case 48 <= r && r <= 57: // ['0','9'] + return 35 + case r == 95: // ['_','_'] + return 52 + case 97 <= r && r <= 122: // ['a','z'] + return 53 + + } + return NoState + + }, + + // S53 + func(r rune) int { + switch { + case 65 <= r && r <= 90: // ['A','Z'] + return 37 + + } + return NoState + + }, + + // S54 + func(r rune) int { + switch { + case r == 101: // ['e','e'] + return 63 + + } + return NoState + + }, + + // S55 + func(r rune) int { + switch { + case r == 101: // ['e','e'] + return 64 + + } + return NoState + + }, + + // S56 + func(r rune) int { + switch { + case r == 102: // ['f','f'] + return 65 + + } + return NoState + + }, + + // S57 + func(r rune) int { + switch { + case r == 101: // ['e','e'] + return 66 + + } + return NoState + + }, + + // S58 + func(r rune) int { + switch { + case r == 99: // ['c','c'] + return 67 + + } + return NoState + + }, + + // S59 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S60 + func(r rune) int { + switch { + case r == 110: // ['n','n'] + return 68 + + } + return NoState + + }, + + // S61 + func(r rune) int { + switch { + case r == 105: // ['i','i'] + return 69 + + } + return NoState + + }, + + // S62 + func(r rune) int { + switch { + case r == 108: // ['l','l'] + return 70 + + } + return NoState + + }, + + // S63 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S64 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S65 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S66 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S67 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S68 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S69 + func(r rune) int { + switch { + case r == 108: // ['l','l'] + return 71 + + } + return NoState + + }, + + // S70 + func(r rune) int { + switch { + case r == 101: // ['e','e'] + return 72 + + } + return NoState + + }, + + // S71 + func(r rune) int { + switch { + + } + return NoState + + }, + + // S72 + func(r rune) int { + switch { + + } + return NoState + + }, } diff --git a/parser/action.go b/parser/action.go index ee72aa0..d3a08fb 100755 --- a/parser/action.go +++ b/parser/action.go @@ -1,4 +1,3 @@ - package parser import ( diff --git a/parser/actiontable.go b/parser/actiontable.go index 28cfb80..8790434 100755 --- a/parser/actiontable.go +++ b/parser/actiontable.go @@ -1,159 +1,153 @@ - package parser -type( +type ( actionTable [numStates]actionRow - actionRow struct { + actionRow struct { canRecover bool - actions [numSymbols]action + actions [numSymbols]action } ) var actionTab = actionTable{ actionRow{ // S0 - canRecover: false, + canRecover: false, actions: [numSymbols]action{ - nil, /* INVALID */ - nil, /* $ */ - shift(2), /* word */ - nil, /* number */ - nil, /* = */ - nil, /* && */ - nil, /* || */ - nil, /* ! */ - nil, /* | */ - nil, /* ( */ - nil, /* ) */ - nil, /* for */ - nil, /* in */ - nil, /* name */ - nil, /* case */ - nil, /* esac */ - nil, /* ;; */ - nil, /* if */ - nil, /* then */ - nil, /* fi */ - nil, /* elif */ - nil, /* else */ - nil, /* while */ - nil, /* until */ - nil, /* { */ - nil, /* } */ - nil, /* do */ - nil, /* done */ - nil, /* < */ - nil, /* <& */ - nil, /* > */ - nil, /* >& */ - nil, /* >> */ - nil, /* <> */ - nil, /* >| */ - nil, /* << */ - nil, /* <<- */ - nil, /* \n */ - nil, /* nothing */ - nil, /* & */ - nil, /* ; */ - - }, + nil, /* INVALID */ + nil, /* $ */ + shift(2), /* word */ + nil, /* number */ + nil, /* = */ + nil, /* && */ + nil, /* || */ + nil, /* ! */ + nil, /* | */ + nil, /* ( */ + nil, /* ) */ + nil, /* for */ + nil, /* in */ + nil, /* name */ + nil, /* case */ + nil, /* esac */ + nil, /* ;; */ + nil, /* if */ + nil, /* then */ + nil, /* fi */ + nil, /* elif */ + nil, /* else */ + nil, /* while */ + nil, /* until */ + nil, /* { */ + nil, /* } */ + nil, /* do */ + nil, /* done */ + nil, /* < */ + nil, /* <& */ + nil, /* > */ + nil, /* >& */ + nil, /* >> */ + nil, /* <> */ + nil, /* >| */ + nil, /* << */ + nil, /* <<- */ + nil, /* \n */ + nil, /* nothing */ + nil, /* & */ + nil, /* ; */ + }, }, actionRow{ // S1 - canRecover: false, + canRecover: false, actions: [numSymbols]action{ - nil, /* INVALID */ - accept(true), /* $ */ - nil, /* word */ - nil, /* number */ - nil, /* = */ - nil, /* && */ - nil, /* || */ - nil, /* ! */ - nil, /* | */ - nil, /* ( */ - nil, /* ) */ - nil, /* for */ - nil, /* in */ - nil, /* name */ - nil, /* case */ - nil, /* esac */ - nil, /* ;; */ - nil, /* if */ - nil, /* then */ - nil, /* fi */ - nil, /* elif */ - nil, /* else */ - nil, /* while */ - nil, /* until */ - nil, /* { */ - nil, /* } */ - nil, /* do */ - nil, /* done */ - nil, /* < */ - nil, /* <& */ - nil, /* > */ - nil, /* >& */ - nil, /* >> */ - nil, /* <> */ - nil, /* >| */ - nil, /* << */ - nil, /* <<- */ - nil, /* \n */ - nil, /* nothing */ - nil, /* & */ - nil, /* ; */ - - }, + nil, /* INVALID */ + accept(true), /* $ */ + nil, /* word */ + nil, /* number */ + nil, /* = */ + nil, /* && */ + nil, /* || */ + nil, /* ! */ + nil, /* | */ + nil, /* ( */ + nil, /* ) */ + nil, /* for */ + nil, /* in */ + nil, /* name */ + nil, /* case */ + nil, /* esac */ + nil, /* ;; */ + nil, /* if */ + nil, /* then */ + nil, /* fi */ + nil, /* elif */ + nil, /* else */ + nil, /* while */ + nil, /* until */ + nil, /* { */ + nil, /* } */ + nil, /* do */ + nil, /* done */ + nil, /* < */ + nil, /* <& */ + nil, /* > */ + nil, /* >& */ + nil, /* >> */ + nil, /* <> */ + nil, /* >| */ + nil, /* << */ + nil, /* <<- */ + nil, /* \n */ + nil, /* nothing */ + nil, /* & */ + nil, /* ; */ + }, }, actionRow{ // S2 - canRecover: false, + canRecover: false, actions: [numSymbols]action{ - nil, /* INVALID */ - reduce(1), /* $, reduce: Word */ - nil, /* word */ - nil, /* number */ - nil, /* = */ - nil, /* && */ - nil, /* || */ - nil, /* ! */ - nil, /* | */ - nil, /* ( */ - nil, /* ) */ - nil, /* for */ - nil, /* in */ - nil, /* name */ - nil, /* case */ - nil, /* esac */ - nil, /* ;; */ - nil, /* if */ - nil, /* then */ - nil, /* fi */ - nil, /* elif */ - nil, /* else */ - nil, /* while */ - nil, /* until */ - nil, /* { */ - nil, /* } */ - nil, /* do */ - nil, /* done */ - nil, /* < */ - nil, /* <& */ - nil, /* > */ - nil, /* >& */ - nil, /* >> */ - nil, /* <> */ - nil, /* >| */ - nil, /* << */ - nil, /* <<- */ - nil, /* \n */ - nil, /* nothing */ - nil, /* & */ - nil, /* ; */ - + nil, /* INVALID */ + reduce(1), /* $, reduce: Word */ + nil, /* word */ + nil, /* number */ + nil, /* = */ + nil, /* && */ + nil, /* || */ + nil, /* ! */ + nil, /* | */ + nil, /* ( */ + nil, /* ) */ + nil, /* for */ + nil, /* in */ + nil, /* name */ + nil, /* case */ + nil, /* esac */ + nil, /* ;; */ + nil, /* if */ + nil, /* then */ + nil, /* fi */ + nil, /* elif */ + nil, /* else */ + nil, /* while */ + nil, /* until */ + nil, /* { */ + nil, /* } */ + nil, /* do */ + nil, /* done */ + nil, /* < */ + nil, /* <& */ + nil, /* > */ + nil, /* >& */ + nil, /* >> */ + nil, /* <> */ + nil, /* >| */ + nil, /* << */ + nil, /* <<- */ + nil, /* \n */ + nil, /* nothing */ + nil, /* & */ + nil, /* ; */ + }, - }, - } - diff --git a/parser/gototable.go b/parser/gototable.go index cd6a124..c8b15fe 100755 --- a/parser/gototable.go +++ b/parser/gototable.go @@ -1,19 +1,19 @@ - /* -*/ + */ package parser const numNTSymbols = 47 -type( + +type ( gotoTable [numStates]gotoRow - gotoRow [numNTSymbols] int + gotoRow [numNTSymbols]int ) var gotoTab = gotoTable{ gotoRow{ // S0 - + -1, // S' - 1, // Word + 1, // Word -1, // IoNumber -1, // AssignmentWord -1, // List @@ -59,11 +59,10 @@ var gotoTab = gotoTable{ -1, // SeparatorOp -1, // Separator -1, // SequentialSep - }, gotoRow{ // S1 - + -1, // S' -1, // Word -1, // IoNumber @@ -111,11 +110,10 @@ var gotoTab = gotoTable{ -1, // SeparatorOp -1, // Separator -1, // SequentialSep - }, gotoRow{ // S2 - + -1, // S' -1, // Word -1, // IoNumber @@ -163,8 +161,6 @@ var gotoTab = gotoTable{ -1, // SeparatorOp -1, // Separator -1, // SequentialSep - }, - } diff --git a/parser/parser.go b/parser/parser.go index 432a150..8f726e6 100755 --- a/parser/parser.go +++ b/parser/parser.go @@ -1,10 +1,9 @@ - package parser -import( +import ( "bytes" - "fmt" "errors" + "fmt" parseError "github.com/localhots/penny/errors" "github.com/localhots/penny/token" ) @@ -18,16 +17,16 @@ const ( // Stack type stack struct { - state []int - attrib []Attrib + state []int + attrib []Attrib } const iNITIAL_STACK_SIZE = 100 func newStack() *stack { - return &stack{ state: make([]int, 0, iNITIAL_STACK_SIZE), - attrib: make([]Attrib, 0, iNITIAL_STACK_SIZE), - } + return &stack{state: make([]int, 0, iNITIAL_STACK_SIZE), + attrib: make([]Attrib, 0, iNITIAL_STACK_SIZE), + } } func (this *stack) reset() { @@ -40,8 +39,8 @@ func (this *stack) push(s int, a Attrib) { this.attrib = append(this.attrib, a) } -func(this *stack) top() int { - return this.state[len(this.state) - 1] +func (this *stack) top() int { + return this.state[len(this.state)-1] } func (this *stack) peek(pos int) int { @@ -53,13 +52,13 @@ func (this *stack) topIndex() int { } func (this *stack) popN(items int) []Attrib { - lo, hi := len(this.state) - items, len(this.state) - - attrib := this.attrib[lo: hi] - + lo, hi := len(this.state)-items, len(this.state) + + attrib := this.attrib[lo:hi] + this.state = this.state[:lo] this.attrib = this.attrib[:lo] - + return attrib } @@ -187,9 +186,8 @@ func (this *Parser) Parse(scanner Scanner) (res interface{}, err error) { panic("Error recovery led to invalid action") } } - + // fmt.Printf("S%d %s %s\n", this.stack.top(), token.TokMap.TokenString(this.nextToken), action.String()) - switch act := action.(type) { case accept: diff --git a/parser/productionstable.go b/parser/productionstable.go index 2306c9e..2a98b7c 100755 --- a/parser/productionstable.go +++ b/parser/productionstable.go @@ -1,4 +1,3 @@ - package parser import "github.com/localhots/penny/ast" @@ -10,7 +9,7 @@ type ( String string Id string NTType int - Index int + Index int NumSymbols int ReduceFunc func([]Attrib) (Attrib, error) } @@ -18,12 +17,12 @@ type ( } ) -var productionsTable = ProdTab { +var productionsTable = ProdTab{ ProdTabEntry{ String: `S' : Word << >>`, - Id: "S'", - NTType: 0, - Index: 0, + Id: "S'", + NTType: 0, + Index: 0, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return X[0], nil @@ -31,9 +30,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Word : word << ast.NewWord(X[0]) >>`, - Id: "Word", - NTType: 1, - Index: 1, + Id: "Word", + NTType: 1, + Index: 1, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewWord(X[0]) @@ -41,9 +40,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IoNumber : number << ast.NewIoNumber(X[0]) >>`, - Id: "IoNumber", - NTType: 2, - Index: 2, + Id: "IoNumber", + NTType: 2, + Index: 2, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIoNumber(X[0]) @@ -51,9 +50,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `AssignmentWord : Word "=" Word << ast.NewAssignment(X[0], X[2]) >>`, - Id: "AssignmentWord", - NTType: 3, - Index: 3, + Id: "AssignmentWord", + NTType: 3, + Index: 3, NumSymbols: 3, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewAssignment(X[0], X[2]) @@ -61,9 +60,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `List : List SeparatorOp AndOr << ast.AppendToList(X[0], X[2]) >>`, - Id: "List", - NTType: 4, - Index: 4, + Id: "List", + NTType: 4, + Index: 4, NumSymbols: 3, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.AppendToList(X[0], X[2]) @@ -71,9 +70,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `List : AndOr << ast.NewList(X[0]) >>`, - Id: "List", - NTType: 4, - Index: 5, + Id: "List", + NTType: 4, + Index: 5, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewList(X[0]) @@ -81,9 +80,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `AndOr : Pipeline << ast.NewAndOr(X[0]) >>`, - Id: "AndOr", - NTType: 5, - Index: 6, + Id: "AndOr", + NTType: 5, + Index: 6, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewAndOr(X[0]) @@ -91,9 +90,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `AndOr : AndOr "&&" Linebreak Pipeline << ast.AppendAnd(X[0], X[3]) >>`, - Id: "AndOr", - NTType: 5, - Index: 7, + Id: "AndOr", + NTType: 5, + Index: 7, NumSymbols: 4, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.AppendAnd(X[0], X[3]) @@ -101,9 +100,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `AndOr : AndOr "||" Linebreak Pipeline << ast.AppendOr(X[0], X[3]) >>`, - Id: "AndOr", - NTType: 5, - Index: 8, + Id: "AndOr", + NTType: 5, + Index: 8, NumSymbols: 4, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.AppendOr(X[0], X[3]) @@ -111,9 +110,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Pipeline : PipeSequence << ast.NewPipeline(X[1], false) >>`, - Id: "Pipeline", - NTType: 6, - Index: 9, + Id: "Pipeline", + NTType: 6, + Index: 9, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewPipeline(X[1], false) @@ -121,9 +120,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Pipeline : "!" PipeSequence << ast.NewPipeline(X[1], true) >>`, - Id: "Pipeline", - NTType: 6, - Index: 10, + Id: "Pipeline", + NTType: 6, + Index: 10, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewPipeline(X[1], true) @@ -131,9 +130,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `PipeSequence : Command << ast.NewPipeSequence(X[0]) >>`, - Id: "PipeSequence", - NTType: 7, - Index: 11, + Id: "PipeSequence", + NTType: 7, + Index: 11, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewPipeSequence(X[0]) @@ -141,9 +140,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `PipeSequence : PipeSequence "|" Linebreak Command << ast.AppendToPipeSequence(X[0], X[3]) >>`, - Id: "PipeSequence", - NTType: 7, - Index: 12, + Id: "PipeSequence", + NTType: 7, + Index: 12, NumSymbols: 4, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.AppendToPipeSequence(X[0], X[3]) @@ -151,9 +150,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Command : SimpleCommand << ast.NewCommand(X[0], nil) >>`, - Id: "Command", - NTType: 8, - Index: 13, + Id: "Command", + NTType: 8, + Index: 13, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCommand(X[0], nil) @@ -161,9 +160,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Command : CompoundCommand << ast.NewCommand(X[0], nil) >>`, - Id: "Command", - NTType: 8, - Index: 14, + Id: "Command", + NTType: 8, + Index: 14, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCommand(X[0], nil) @@ -171,9 +170,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Command : CompoundCommand RedirectList << ast.NewCommand(X[0], X[1]) >>`, - Id: "Command", - NTType: 8, - Index: 15, + Id: "Command", + NTType: 8, + Index: 15, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCommand(X[0], X[1]) @@ -181,9 +180,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Command : FunctionDefinition << ast.NewCommand(X[0], nil) >>`, - Id: "Command", - NTType: 8, - Index: 16, + Id: "Command", + NTType: 8, + Index: 16, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCommand(X[0], nil) @@ -191,9 +190,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CompoundCommand : BraceGroup << ast.NewCompoundCommand(X[0]) >>`, - Id: "CompoundCommand", - NTType: 9, - Index: 17, + Id: "CompoundCommand", + NTType: 9, + Index: 17, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCompoundCommand(X[0]) @@ -201,9 +200,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CompoundCommand : Subshell << ast.NewCompoundCommand(X[0]) >>`, - Id: "CompoundCommand", - NTType: 9, - Index: 18, + Id: "CompoundCommand", + NTType: 9, + Index: 18, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCompoundCommand(X[0]) @@ -211,9 +210,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CompoundCommand : ForClause << ast.NewCompoundCommand(X[0]) >>`, - Id: "CompoundCommand", - NTType: 9, - Index: 19, + Id: "CompoundCommand", + NTType: 9, + Index: 19, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCompoundCommand(X[0]) @@ -221,9 +220,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CompoundCommand : CaseClause << ast.NewCompoundCommand(X[0]) >>`, - Id: "CompoundCommand", - NTType: 9, - Index: 20, + Id: "CompoundCommand", + NTType: 9, + Index: 20, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCompoundCommand(X[0]) @@ -231,9 +230,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CompoundCommand : IfClause << ast.NewCompoundCommand(X[0]) >>`, - Id: "CompoundCommand", - NTType: 9, - Index: 21, + Id: "CompoundCommand", + NTType: 9, + Index: 21, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCompoundCommand(X[0]) @@ -241,9 +240,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CompoundCommand : WhileClause << ast.NewCompoundCommand(X[0]) >>`, - Id: "CompoundCommand", - NTType: 9, - Index: 22, + Id: "CompoundCommand", + NTType: 9, + Index: 22, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCompoundCommand(X[0]) @@ -251,9 +250,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CompoundCommand : UntilClause << ast.NewCompoundCommand(X[0]) >>`, - Id: "CompoundCommand", - NTType: 9, - Index: 23, + Id: "CompoundCommand", + NTType: 9, + Index: 23, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCompoundCommand(X[0]) @@ -261,9 +260,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Subshell : "(" CompoundList ")" << ast.NewSubshell(X[1]) >>`, - Id: "Subshell", - NTType: 10, - Index: 24, + Id: "Subshell", + NTType: 10, + Index: 24, NumSymbols: 3, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewSubshell(X[1]) @@ -271,9 +270,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CompoundList : Term << ast.NewCompoundList(X[0], nil) >>`, - Id: "CompoundList", - NTType: 11, - Index: 25, + Id: "CompoundList", + NTType: 11, + Index: 25, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCompoundList(X[0], nil) @@ -281,9 +280,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CompoundList : NewlineList Term << ast.NewCompoundList(X[1], X[2]) >>`, - Id: "CompoundList", - NTType: 11, - Index: 26, + Id: "CompoundList", + NTType: 11, + Index: 26, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCompoundList(X[1], X[2]) @@ -291,9 +290,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CompoundList : Term Separator << ast.NewCompoundList(X[0], X[1]) >>`, - Id: "CompoundList", - NTType: 11, - Index: 27, + Id: "CompoundList", + NTType: 11, + Index: 27, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCompoundList(X[0], X[1]) @@ -301,9 +300,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CompoundList : NewlineList Term Separator << ast.NewCompoundList(X[1], X[2]) >>`, - Id: "CompoundList", - NTType: 11, - Index: 28, + Id: "CompoundList", + NTType: 11, + Index: 28, NumSymbols: 3, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCompoundList(X[1], X[2]) @@ -311,9 +310,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Term : Term Separator AndOr << ast.AppendToTerm(X[0], X[2], X[1]) >>`, - Id: "Term", - NTType: 12, - Index: 29, + Id: "Term", + NTType: 12, + Index: 29, NumSymbols: 3, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.AppendToTerm(X[0], X[2], X[1]) @@ -321,9 +320,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Term : AndOr << ast.NewTerm(X[0]) >>`, - Id: "Term", - NTType: 12, - Index: 30, + Id: "Term", + NTType: 12, + Index: 30, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewTerm(X[0]) @@ -331,9 +330,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `ForClause : "for" Name Linebreak DoGroup << ast.NewForClause(X[1], ast.Wordlist{}, X[3]) >>`, - Id: "ForClause", - NTType: 13, - Index: 31, + Id: "ForClause", + NTType: 13, + Index: 31, NumSymbols: 4, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewForClause(X[1], ast.Wordlist{}, X[3]) @@ -341,9 +340,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `ForClause : "for" Name Linebreak "in" SequentialSep DoGroup << ast.NewForClause(X[1], ast.Wordlist{}, X[5]) >>`, - Id: "ForClause", - NTType: 13, - Index: 32, + Id: "ForClause", + NTType: 13, + Index: 32, NumSymbols: 6, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewForClause(X[1], ast.Wordlist{}, X[5]) @@ -351,9 +350,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `ForClause : "for" Name Linebreak "in" Wordlist SequentialSep DoGroup << ast.NewForClause(X[1], X[4], X[6]) >>`, - Id: "ForClause", - NTType: 13, - Index: 33, + Id: "ForClause", + NTType: 13, + Index: 33, NumSymbols: 7, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewForClause(X[1], X[4], X[6]) @@ -361,9 +360,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Name : name << ast.NewName(X[0]) >>`, - Id: "Name", - NTType: 14, - Index: 34, + Id: "Name", + NTType: 14, + Index: 34, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewName(X[0]) @@ -371,9 +370,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Wordlist : Wordlist Word << ast.AppendToWordlist(X[0], X[1]) >>`, - Id: "Wordlist", - NTType: 15, - Index: 35, + Id: "Wordlist", + NTType: 15, + Index: 35, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.AppendToWordlist(X[0], X[1]) @@ -381,9 +380,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Wordlist : Word << ast.NewWordlist(X[0]) >>`, - Id: "Wordlist", - NTType: 15, - Index: 36, + Id: "Wordlist", + NTType: 15, + Index: 36, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewWordlist(X[0]) @@ -391,9 +390,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseClause : "case" Word Linebreak "in" Linebreak CaseList "esac" << ast.NewCaseClause(X[1], X[5]) >>`, - Id: "CaseClause", - NTType: 16, - Index: 37, + Id: "CaseClause", + NTType: 16, + Index: 37, NumSymbols: 7, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCaseClause(X[1], X[5]) @@ -401,9 +400,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseClause : "case" Word Linebreak "in" Linebreak CaseListNs "esac" << ast.NewCaseClause(X[1], X[5]) >>`, - Id: "CaseClause", - NTType: 16, - Index: 38, + Id: "CaseClause", + NTType: 16, + Index: 38, NumSymbols: 7, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCaseClause(X[1], X[5]) @@ -411,9 +410,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseClause : "case" Word Linebreak "in" Linebreak "esac" << ast.NewCaseClause(X[1], ast.CaseList{}) >>`, - Id: "CaseClause", - NTType: 16, - Index: 39, + Id: "CaseClause", + NTType: 16, + Index: 39, NumSymbols: 6, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCaseClause(X[1], ast.CaseList{}) @@ -421,9 +420,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseListNs : CaseList CaseItemNs << ast.AppendToCaseList(X[0], X[1]) >>`, - Id: "CaseListNs", - NTType: 17, - Index: 40, + Id: "CaseListNs", + NTType: 17, + Index: 40, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.AppendToCaseList(X[0], X[1]) @@ -431,9 +430,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseListNs : CaseItemNs << ast.NewCaseList(X[0]) >>`, - Id: "CaseListNs", - NTType: 17, - Index: 41, + Id: "CaseListNs", + NTType: 17, + Index: 41, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCaseList(X[0]) @@ -441,9 +440,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseList : CaseList CaseItem << ast.AppendToCaseList(X[0], X[1]) >>`, - Id: "CaseList", - NTType: 18, - Index: 42, + Id: "CaseList", + NTType: 18, + Index: 42, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.AppendToCaseList(X[0], X[1]) @@ -451,9 +450,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseList : CaseItem << ast.NewCaseList(X[0]) >>`, - Id: "CaseList", - NTType: 18, - Index: 43, + Id: "CaseList", + NTType: 18, + Index: 43, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCaseList(X[0]) @@ -461,9 +460,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseItemNs : Pattern ")" Linebreak << ast.NewCaseItem(X[0], nil) >>`, - Id: "CaseItemNs", - NTType: 19, - Index: 44, + Id: "CaseItemNs", + NTType: 19, + Index: 44, NumSymbols: 3, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCaseItem(X[0], nil) @@ -471,9 +470,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseItemNs : Pattern ")" CompoundList Linebreak << ast.NewCaseItem(X[0], X[2]) >>`, - Id: "CaseItemNs", - NTType: 19, - Index: 45, + Id: "CaseItemNs", + NTType: 19, + Index: 45, NumSymbols: 4, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCaseItem(X[0], X[2]) @@ -481,9 +480,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseItemNs : "(" Pattern ")" Linebreak << ast.NewCaseItem(X[1], nil) >>`, - Id: "CaseItemNs", - NTType: 19, - Index: 46, + Id: "CaseItemNs", + NTType: 19, + Index: 46, NumSymbols: 4, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCaseItem(X[1], nil) @@ -491,9 +490,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseItemNs : "(" Pattern ")" CompoundList Linebreak << ast.NewCaseItem(X[1], X[3]) >>`, - Id: "CaseItemNs", - NTType: 19, - Index: 47, + Id: "CaseItemNs", + NTType: 19, + Index: 47, NumSymbols: 5, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCaseItem(X[1], X[3]) @@ -501,9 +500,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseItem : Pattern ")" Linebreak ";;" Linebreak << ast.NewCaseItem(X[0], nil) >>`, - Id: "CaseItem", - NTType: 20, - Index: 48, + Id: "CaseItem", + NTType: 20, + Index: 48, NumSymbols: 5, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCaseItem(X[0], nil) @@ -511,9 +510,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseItem : Pattern ")" CompoundList ";;" Linebreak << ast.NewCaseItem(X[0], X[2]) >>`, - Id: "CaseItem", - NTType: 20, - Index: 49, + Id: "CaseItem", + NTType: 20, + Index: 49, NumSymbols: 5, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCaseItem(X[0], X[2]) @@ -521,9 +520,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseItem : "(" Pattern ")" Linebreak ";;" Linebreak << ast.NewCaseItem(X[1], nil) >>`, - Id: "CaseItem", - NTType: 20, - Index: 50, + Id: "CaseItem", + NTType: 20, + Index: 50, NumSymbols: 6, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCaseItem(X[1], nil) @@ -531,9 +530,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CaseItem : "(" Pattern ")" CompoundList ";;" Linebreak << ast.NewCaseItem(X[1], X[3]) >>`, - Id: "CaseItem", - NTType: 20, - Index: 51, + Id: "CaseItem", + NTType: 20, + Index: 51, NumSymbols: 6, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCaseItem(X[1], X[3]) @@ -541,9 +540,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Pattern : Word << ast.NewPattern(X[0]) >>`, - Id: "Pattern", - NTType: 21, - Index: 52, + Id: "Pattern", + NTType: 21, + Index: 52, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewPattern(X[0]) @@ -551,9 +550,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Pattern : Pattern "|" Word << ast.AppendToPattern(X[0], X[2]) >>`, - Id: "Pattern", - NTType: 21, - Index: 53, + Id: "Pattern", + NTType: 21, + Index: 53, NumSymbols: 3, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.AppendToPattern(X[0], X[2]) @@ -561,9 +560,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IfClause : "if" CompoundList "then" CompoundList ElsePart "fi" << ast.NewIfClause(X[1], X[3], X[4]) >>`, - Id: "IfClause", - NTType: 22, - Index: 54, + Id: "IfClause", + NTType: 22, + Index: 54, NumSymbols: 6, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIfClause(X[1], X[3], X[4]) @@ -571,9 +570,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IfClause : "if" CompoundList "then" CompoundList "fi" << ast.NewIfClause(X[1], X[3], nil) >>`, - Id: "IfClause", - NTType: 22, - Index: 55, + Id: "IfClause", + NTType: 22, + Index: 55, NumSymbols: 5, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIfClause(X[1], X[3], nil) @@ -581,9 +580,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `ElsePart : "elif" CompoundList "then" ElsePart << ast.NewIfClause(X[1], nil, X[3]) >>`, - Id: "ElsePart", - NTType: 23, - Index: 56, + Id: "ElsePart", + NTType: 23, + Index: 56, NumSymbols: 4, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIfClause(X[1], nil, X[3]) @@ -591,9 +590,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `ElsePart : "else" CompoundList << ast.NewIfClause(nil, X[1], nil) >>`, - Id: "ElsePart", - NTType: 23, - Index: 57, + Id: "ElsePart", + NTType: 23, + Index: 57, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIfClause(nil, X[1], nil) @@ -601,9 +600,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `WhileClause : "while" CompoundList DoGroup << ast.NewWhileClause(X[1], X[2]) >>`, - Id: "WhileClause", - NTType: 24, - Index: 58, + Id: "WhileClause", + NTType: 24, + Index: 58, NumSymbols: 3, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewWhileClause(X[1], X[2]) @@ -611,9 +610,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `UntilClause : "until" CompoundList DoGroup << ast.NewUntilClause(X[1], X[2]) >>`, - Id: "UntilClause", - NTType: 25, - Index: 59, + Id: "UntilClause", + NTType: 25, + Index: 59, NumSymbols: 3, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewUntilClause(X[1], X[2]) @@ -621,9 +620,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `FunctionDefinition : FunctionName "(" ")" Linebreak FunctionBody << ast.NewFunctionDefinition(X[0], X[4]) >>`, - Id: "FunctionDefinition", - NTType: 26, - Index: 60, + Id: "FunctionDefinition", + NTType: 26, + Index: 60, NumSymbols: 5, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewFunctionDefinition(X[0], X[4]) @@ -631,9 +630,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `FunctionBody : CompoundCommand << ast.NewFunctionBody(X[0], ast.RedirectList{}) >>`, - Id: "FunctionBody", - NTType: 27, - Index: 61, + Id: "FunctionBody", + NTType: 27, + Index: 61, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewFunctionBody(X[0], ast.RedirectList{}) @@ -641,9 +640,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `FunctionBody : CompoundCommand RedirectList << ast.NewFunctionBody(X[0], X[1]) >>`, - Id: "FunctionBody", - NTType: 27, - Index: 62, + Id: "FunctionBody", + NTType: 27, + Index: 62, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewFunctionBody(X[0], X[1]) @@ -651,9 +650,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `FunctionName : Word << ast.NewFunctionName(X[0]) >>`, - Id: "FunctionName", - NTType: 28, - Index: 63, + Id: "FunctionName", + NTType: 28, + Index: 63, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewFunctionName(X[0]) @@ -661,9 +660,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `BraceGroup : "{" CompoundList "}" << ast.NewBraceGroup(X[1]) >>`, - Id: "BraceGroup", - NTType: 29, - Index: 64, + Id: "BraceGroup", + NTType: 29, + Index: 64, NumSymbols: 3, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewBraceGroup(X[1]) @@ -671,9 +670,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `DoGroup : "do" CompoundList "done" << ast.NewDoGroup(X[1]) >>`, - Id: "DoGroup", - NTType: 30, - Index: 65, + Id: "DoGroup", + NTType: 30, + Index: 65, NumSymbols: 3, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewDoGroup(X[1]) @@ -681,59 +680,59 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `SimpleCommand : CmdPrefix CmdWord CmdSuffix << ast.NewSimpleCommand(X[0], nil, X[1], X[2]) >>`, - Id: "SimpleCommand", - NTType: 31, - Index: 66, + Id: "SimpleCommand", + NTType: 31, + Index: 66, NumSymbols: 3, ReduceFunc: func(X []Attrib) (Attrib, error) { - return ast.NewSimpleCommand(X[0], nil, X[1], X[2]) + return ast.NewSimpleCommand(X[0], nil, X[1], X[2]) }, }, ProdTabEntry{ String: `SimpleCommand : CmdPrefix CmdWord << ast.NewSimpleCommand(X[0], nil, X[1], nil) >>`, - Id: "SimpleCommand", - NTType: 31, - Index: 67, + Id: "SimpleCommand", + NTType: 31, + Index: 67, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { - return ast.NewSimpleCommand(X[0], nil, X[1], nil) + return ast.NewSimpleCommand(X[0], nil, X[1], nil) }, }, ProdTabEntry{ String: `SimpleCommand : CmdPrefix << ast.NewSimpleCommand(X[0], nil, nil, nil) >>`, - Id: "SimpleCommand", - NTType: 31, - Index: 68, + Id: "SimpleCommand", + NTType: 31, + Index: 68, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { - return ast.NewSimpleCommand(X[0], nil, nil, nil) + return ast.NewSimpleCommand(X[0], nil, nil, nil) }, }, ProdTabEntry{ String: `SimpleCommand : CmdName CmdSuffix << ast.NewSimpleCommand(nil, X[0], nil, X[1]) >>`, - Id: "SimpleCommand", - NTType: 31, - Index: 69, + Id: "SimpleCommand", + NTType: 31, + Index: 69, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { - return ast.NewSimpleCommand(nil, X[0], nil, X[1]) + return ast.NewSimpleCommand(nil, X[0], nil, X[1]) }, }, ProdTabEntry{ String: `SimpleCommand : CmdName << ast.NewSimpleCommand(nil, X[0], nil, nil) >>`, - Id: "SimpleCommand", - NTType: 31, - Index: 70, + Id: "SimpleCommand", + NTType: 31, + Index: 70, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { - return ast.NewSimpleCommand(nil, X[0], nil, nil) + return ast.NewSimpleCommand(nil, X[0], nil, nil) }, }, ProdTabEntry{ String: `CmdName : Word << ast.NewCmdName(X[0]) >>`, - Id: "CmdName", - NTType: 32, - Index: 71, + Id: "CmdName", + NTType: 32, + Index: 71, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCmdName(X[0]) @@ -741,9 +740,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CmdWord : Word << ast.NewCmdWord(X[0]) >>`, - Id: "CmdWord", - NTType: 33, - Index: 72, + Id: "CmdWord", + NTType: 33, + Index: 72, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCmdWord(X[0]) @@ -751,9 +750,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CmdPrefix : IoRedirect << ast.NewCmdPrefix(nil, X[0], nil) >>`, - Id: "CmdPrefix", - NTType: 34, - Index: 73, + Id: "CmdPrefix", + NTType: 34, + Index: 73, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCmdPrefix(nil, X[0], nil) @@ -761,9 +760,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CmdPrefix : CmdPrefix IoRedirect << ast.NewCmdPrefix(nil, X[1], X[0]) >>`, - Id: "CmdPrefix", - NTType: 34, - Index: 74, + Id: "CmdPrefix", + NTType: 34, + Index: 74, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCmdPrefix(nil, X[1], X[0]) @@ -771,9 +770,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CmdPrefix : AssignmentWord << ast.NewCmdPrefix(X[0], nil, nil) >>`, - Id: "CmdPrefix", - NTType: 34, - Index: 75, + Id: "CmdPrefix", + NTType: 34, + Index: 75, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCmdPrefix(X[0], nil, nil) @@ -781,9 +780,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CmdPrefix : CmdPrefix AssignmentWord << ast.NewCmdPrefix(X[1], nil, X[0]) >>`, - Id: "CmdPrefix", - NTType: 34, - Index: 76, + Id: "CmdPrefix", + NTType: 34, + Index: 76, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCmdPrefix(X[1], nil, X[0]) @@ -791,9 +790,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CmdSuffix : IoRedirect << ast.NewCmdSuffix(ast.Word(""), X[0], nil) >>`, - Id: "CmdSuffix", - NTType: 35, - Index: 77, + Id: "CmdSuffix", + NTType: 35, + Index: 77, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCmdSuffix(ast.Word(""), X[0], nil) @@ -801,9 +800,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CmdSuffix : CmdSuffix IoRedirect << ast.NewCmdSuffix(ast.Word(""), X[1], X[0]) >>`, - Id: "CmdSuffix", - NTType: 35, - Index: 78, + Id: "CmdSuffix", + NTType: 35, + Index: 78, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCmdSuffix(ast.Word(""), X[1], X[0]) @@ -811,9 +810,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CmdSuffix : Word << ast.NewCmdSuffix(X[0], nil, nil) >>`, - Id: "CmdSuffix", - NTType: 35, - Index: 79, + Id: "CmdSuffix", + NTType: 35, + Index: 79, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCmdSuffix(X[0], nil, nil) @@ -821,9 +820,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `CmdSuffix : CmdSuffix Word << ast.NewCmdSuffix(X[1], nil, X[0]) >>`, - Id: "CmdSuffix", - NTType: 35, - Index: 80, + Id: "CmdSuffix", + NTType: 35, + Index: 80, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewCmdSuffix(X[1], nil, X[0]) @@ -831,9 +830,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `RedirectList : IoRedirect << ast.NewRedirectList(X[0]) >>`, - Id: "RedirectList", - NTType: 36, - Index: 81, + Id: "RedirectList", + NTType: 36, + Index: 81, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewRedirectList(X[0]) @@ -841,9 +840,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `RedirectList : RedirectList IoRedirect << ast.AppendToRedirectList(X[0], X[1]) >>`, - Id: "RedirectList", - NTType: 36, - Index: 82, + Id: "RedirectList", + NTType: 36, + Index: 82, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.AppendToRedirectList(X[0], X[1]) @@ -851,9 +850,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IoRedirect : IoFile << ast.NewIoRedirect(X[0], ast.IoNumber(0), nil) >>`, - Id: "IoRedirect", - NTType: 37, - Index: 83, + Id: "IoRedirect", + NTType: 37, + Index: 83, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIoRedirect(X[0], ast.IoNumber(0), nil) @@ -861,9 +860,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IoRedirect : IoNumber IoFile << ast.NewIoRedirect(X[1], X[0], nil) >>`, - Id: "IoRedirect", - NTType: 37, - Index: 84, + Id: "IoRedirect", + NTType: 37, + Index: 84, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIoRedirect(X[1], X[0], nil) @@ -871,9 +870,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IoRedirect : IoHere << ast.NewIoRedirect(nil, ast.IoNumber(0), X[0]) >>`, - Id: "IoRedirect", - NTType: 37, - Index: 85, + Id: "IoRedirect", + NTType: 37, + Index: 85, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIoRedirect(nil, ast.IoNumber(0), X[0]) @@ -881,9 +880,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IoRedirect : IoNumber IoHere << ast.NewIoRedirect(nil, X[0], X[1]) >>`, - Id: "IoRedirect", - NTType: 37, - Index: 86, + Id: "IoRedirect", + NTType: 37, + Index: 86, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIoRedirect(nil, X[0], X[1]) @@ -891,9 +890,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IoFile : "<" Filename << ast.NewIoFile(X[1], ast.R_STDIN) >>`, - Id: "IoFile", - NTType: 38, - Index: 87, + Id: "IoFile", + NTType: 38, + Index: 87, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIoFile(X[1], ast.R_STDIN) @@ -901,9 +900,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IoFile : "<&" Filename << ast.NewIoFile(X[1], ast.R_INFD) >>`, - Id: "IoFile", - NTType: 38, - Index: 88, + Id: "IoFile", + NTType: 38, + Index: 88, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIoFile(X[1], ast.R_INFD) @@ -911,9 +910,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IoFile : ">" Filename << ast.NewIoFile(X[1], ast.R_STDOUT) >>`, - Id: "IoFile", - NTType: 38, - Index: 89, + Id: "IoFile", + NTType: 38, + Index: 89, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIoFile(X[1], ast.R_STDOUT) @@ -921,9 +920,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IoFile : ">&" Filename << ast.NewIoFile(X[1], ast.R_OUTFD) >>`, - Id: "IoFile", - NTType: 38, - Index: 90, + Id: "IoFile", + NTType: 38, + Index: 90, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIoFile(X[1], ast.R_OUTFD) @@ -931,9 +930,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IoFile : ">>" Filename << ast.NewIoFile(X[1], ast.R_APPEND) >>`, - Id: "IoFile", - NTType: 38, - Index: 91, + Id: "IoFile", + NTType: 38, + Index: 91, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIoFile(X[1], ast.R_APPEND) @@ -941,9 +940,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IoFile : "<>" Filename << ast.NewIoFile(X[1], ast.R_ORWFD) >>`, - Id: "IoFile", - NTType: 38, - Index: 92, + Id: "IoFile", + NTType: 38, + Index: 92, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIoFile(X[1], ast.R_ORWFD) @@ -951,9 +950,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IoFile : ">|" Filename << ast.NewIoFile(X[1], ast.R_OUTSP) >>`, - Id: "IoFile", - NTType: 38, - Index: 93, + Id: "IoFile", + NTType: 38, + Index: 93, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIoFile(X[1], ast.R_OUTSP) @@ -961,9 +960,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Filename : Word << ast.NewFilename(X[0]) >>`, - Id: "Filename", - NTType: 39, - Index: 94, + Id: "Filename", + NTType: 39, + Index: 94, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewFilename(X[0]) @@ -971,9 +970,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IoHere : "<<" HereEnd << ast.NewIoHere(X[1], false) >>`, - Id: "IoHere", - NTType: 40, - Index: 95, + Id: "IoHere", + NTType: 40, + Index: 95, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIoHere(X[1], false) @@ -981,9 +980,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `IoHere : "<<-" HereEnd << ast.NewIoHere(X[1], true) >>`, - Id: "IoHere", - NTType: 40, - Index: 96, + Id: "IoHere", + NTType: 40, + Index: 96, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewIoHere(X[1], true) @@ -991,9 +990,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `HereEnd : Word << ast.NewHereEnd(X[0]) >>`, - Id: "HereEnd", - NTType: 41, - Index: 97, + Id: "HereEnd", + NTType: 41, + Index: 97, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewHereEnd(X[0]) @@ -1001,9 +1000,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `NewlineList : "\n" << >>`, - Id: "NewlineList", - NTType: 42, - Index: 98, + Id: "NewlineList", + NTType: 42, + Index: 98, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return X[0], nil @@ -1011,9 +1010,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `NewlineList : NewlineList "\n" << >>`, - Id: "NewlineList", - NTType: 42, - Index: 99, + Id: "NewlineList", + NTType: 42, + Index: 99, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return X[0], nil @@ -1021,9 +1020,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Linebreak : NewlineList << >>`, - Id: "Linebreak", - NTType: 43, - Index: 100, + Id: "Linebreak", + NTType: 43, + Index: 100, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return X[0], nil @@ -1031,9 +1030,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Linebreak : nothing << >>`, - Id: "Linebreak", - NTType: 43, - Index: 101, + Id: "Linebreak", + NTType: 43, + Index: 101, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return X[0], nil @@ -1041,9 +1040,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `SeparatorOp : "&" << ast.S_AMP, nil >>`, - Id: "SeparatorOp", - NTType: 44, - Index: 102, + Id: "SeparatorOp", + NTType: 44, + Index: 102, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.S_AMP, nil @@ -1051,9 +1050,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `SeparatorOp : ";" << ast.S_SEMICOLON, nil >>`, - Id: "SeparatorOp", - NTType: 44, - Index: 103, + Id: "SeparatorOp", + NTType: 44, + Index: 103, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.S_SEMICOLON, nil @@ -1061,9 +1060,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Separator : SeparatorOp Linebreak << ast.NewSeparator(X[0]) >>`, - Id: "Separator", - NTType: 45, - Index: 104, + Id: "Separator", + NTType: 45, + Index: 104, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return ast.NewSeparator(X[0]) @@ -1071,9 +1070,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `Separator : NewlineList << >>`, - Id: "Separator", - NTType: 45, - Index: 105, + Id: "Separator", + NTType: 45, + Index: 105, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return X[0], nil @@ -1081,9 +1080,9 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `SequentialSep : ";" Linebreak << >>`, - Id: "SequentialSep", - NTType: 46, - Index: 106, + Id: "SequentialSep", + NTType: 46, + Index: 106, NumSymbols: 2, ReduceFunc: func(X []Attrib) (Attrib, error) { return X[0], nil @@ -1091,13 +1090,12 @@ var productionsTable = ProdTab { }, ProdTabEntry{ String: `SequentialSep : NewlineList << >>`, - Id: "SequentialSep", - NTType: 46, - Index: 107, + Id: "SequentialSep", + NTType: 46, + Index: 107, NumSymbols: 1, ReduceFunc: func(X []Attrib) (Attrib, error) { return X[0], nil }, }, - } diff --git a/token/token.go b/token/token.go index 3690e86..d2edf09 100755 --- a/token/token.go +++ b/token/token.go @@ -1,7 +1,6 @@ - package token -import( +import ( "fmt" ) @@ -13,14 +12,14 @@ type Token struct { type Type int -const( +const ( INVALID Type = iota EOF ) type Pos struct { Offset int - Line int + Line int Column int } @@ -29,8 +28,8 @@ func (this Pos) String() string { } type TokenMap struct { - typeMap []string - idMap map[string]Type + typeMap []string + idMap map[string]Type } func (this TokenMap) Id(tok Type) string { @@ -101,48 +100,47 @@ var TokMap = TokenMap{ ";", }, - idMap: map[string]Type { + idMap: map[string]Type{ "INVALID": 0, - "$": 1, - "word": 2, - "number": 3, - "=": 4, - "&&": 5, - "||": 6, - "!": 7, - "|": 8, - "(": 9, - ")": 10, - "for": 11, - "in": 12, - "name": 13, - "case": 14, - "esac": 15, - ";;": 16, - "if": 17, - "then": 18, - "fi": 19, - "elif": 20, - "else": 21, - "while": 22, - "until": 23, - "{": 24, - "}": 25, - "do": 26, - "done": 27, - "<": 28, - "<&": 29, - ">": 30, - ">&": 31, - ">>": 32, - "<>": 33, - ">|": 34, - "<<": 35, - "<<-": 36, - "\n": 37, + "$": 1, + "word": 2, + "number": 3, + "=": 4, + "&&": 5, + "||": 6, + "!": 7, + "|": 8, + "(": 9, + ")": 10, + "for": 11, + "in": 12, + "name": 13, + "case": 14, + "esac": 15, + ";;": 16, + "if": 17, + "then": 18, + "fi": 19, + "elif": 20, + "else": 21, + "while": 22, + "until": 23, + "{": 24, + "}": 25, + "do": 26, + "done": 27, + "<": 28, + "<&": 29, + ">": 30, + ">&": 31, + ">>": 32, + "<>": 33, + ">|": 34, + "<<": 35, + "<<-": 36, + "\n": 37, "nothing": 38, - "&": 39, - ";": 40, + "&": 39, + ";": 40, }, } - diff --git a/util/litconv.go b/util/litconv.go index 7785776..b59772c 100755 --- a/util/litconv.go +++ b/util/litconv.go @@ -1,4 +1,3 @@ - //Copyright 2013 Vastech SA (PTY) LTD // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/util/rune.go b/util/rune.go index ace597c..8b72af5 100755 --- a/util/rune.go +++ b/util/rune.go @@ -1,4 +1,3 @@ - //Copyright 2013 Vastech SA (PTY) LTD // // Licensed under the Apache License, Version 2.0 (the "License");