// Analyze the input string ans split the token sequences
Analyze the input string ans split the token sequences
// Analyze the input string ans split the token sequences
func (l *Lexer) Analyze() {
	var tok token.Token
	for ; l.Pos < len(l.Input); l.Pos++ {
		l.skip()
		switch l.Input[l.Pos] {
		case '+':
			tok = token.New(token.ADD, "+")
		case '-':
			tok = token.New(token.SUB, "-")
		case '*':
			tok = token.New(token.MUL, "*")
		case '/':
			tok = token.New(token.DIV, "/")
		case '%':
			tok = token.New(token.REM, "%")
		case '<':
			if l.Input[l.Pos+1] == '<' {
				l.Pos++
				tok = token.New(token.LSHIFT, "<<")
			} else if l.Input[l.Pos+1] == '=' {
				l.Pos++
				tok = token.New(token.LTE, "<=")
			} else {
				tok = token.New(token.LT, "<")
			}
		case '>':
			if l.Input[l.Pos+1] == '>' {
				l.Pos++
				tok = token.New(token.RSHIFT, ">>")
			} else if l.Input[l.Pos+1] == '=' {
				l.Pos++
				tok = token.New(token.GTE, ">=")
			} else {
				tok = token.New(token.GT, ">")
			}
		case '&':
			if l.Input[l.Pos+1] == '&' {
				l.Pos++
				tok = token.New(token.CAND, "&&")
			} else if l.Input[l.Pos+1] == '^' {
				l.Pos++
				tok = token.New(token.BCLR, "&^")
			} else {
				tok = token.New(token.BAND, "&")
			}
		case '|':
			if l.Input[l.Pos+1] == '|' {
				l.Pos++
				tok = token.New(token.COR, "||")
			} else {
				tok = token.New(token.BOR, "|")
			}
		case '^':
			tok = token.New(token.BXOR, "^")
		case '=':
			if l.Input[l.Pos+1] == '=' {
				l.Pos++
				tok = token.New(token.EQ, "==")
			} else {
				tok = token.New(token.ASSIGN, "=")
			}
		case '!':
			if l.Input[l.Pos+1] == '=' {
				l.Pos++
				tok = token.New(token.NQ, "!=")
			} else {
				tok = token.New(token.NOT, "!")
			}
		case '(':
			tok = token.New(token.LPAREN, "(")
		case ')':
			tok = token.New(token.RPAREN, ")")
		case '{':
			tok = token.New(token.LBRACE, "{")
		case '}':
			tok = token.New(token.RBRACE, "}")
		case ':':
			if l.Input[l.Pos+1] == '=' {
				l.Pos++
				tok = token.New(token.SVDECL, ":=")
			}
		case ';':
			tok = token.New(token.SEMICOLON, ";")
		case '\000':
			tok = token.New(token.EOF, "")
			l.Tokens = append(l.Tokens, tok)
			return
		default:
			if isDigit(l.Input[l.Pos]) {
				tok = token.New(token.INT, l.readDigit())
			} else if isChar(l.Input[l.Pos]) {
				str := l.readIdent()
				tt, ok := keywords[str]
				if ok {
					tok = token.New(tt, str)
				} else {
					tt, ok = predeclaredIdents[str]
					if ok {
						tok = token.New(tt, str)
					} else {
						tok = token.New(token.IDENT, str)
					}
				}
			}
		}
		l.Tokens = append(l.Tokens, tok)
	}
}
func ( l * Lexer ) Analyze ( ) { var tok token . Token for ; l . Pos < len ( l . Input ) ; l . Pos ++ { l . skip ( ) switch l . Input [ l . Pos ] { case '+' : tok = token . New ( token . ADD , " " ) case '-' : tok = token . New ( token . SUB , " " ) case '*' : tok = token . New ( token . MUL , " " ) case '/' : tok = token . New ( token . DIV , " " ) case '%' : tok = token . New ( token . REM , " " ) case '<' : if l . Input [ l . Pos + 1 ] == '<' { l . Pos ++ tok = token . New ( token . LSHIFT , " " ) } else if l . Input [ l . Pos + 1 ] == '=' { l . Pos ++ tok = token . New ( token . LTE , " " ) } else { tok = token . New ( token . LT , " " ) } case '>' : if l . Input [ l . Pos + 1 ] == '>' { l . Pos ++ tok = token . New ( token . RSHIFT , " " ) } else if l . Input [ l . Pos + 1 ] == '=' { l . Pos ++ tok = token . New ( token . GTE , " " ) } else { tok = token . New ( token . GT , " " ) } case '&' : if l . Input [ l . Pos + 1 ] == '&' { l . Pos ++ tok = token . New ( token . CAND , " " ) } else if l . Input [ l . Pos + 1 ] == '^' { l . Pos ++ tok = token . New ( token . BCLR , " " ) } else { tok = token . New ( token . BAND , " " ) } case '|' : if l . Input [ l . Pos + 1 ] == '|' { l . Pos ++ tok = token . New ( token . COR , " " ) } else { tok = token . New ( token . BOR , " " ) } case '^' : tok = token . New ( token . BXOR , " " ) case '=' : if l . Input [ l . Pos + 1 ] == '=' { l . Pos ++ tok = token . New ( token . EQ , " " ) } else { tok = token . New ( token . ASSIGN , " " ) } case '!' : if l . Input [ l . Pos + 1 ] == '=' { l . Pos ++ tok = token . New ( token . NQ , " " ) } else { tok = token . New ( token . NOT , " " ) } case '(' : tok = token . New ( token . LPAREN , " " ) case ')' : tok = token . New ( token . RPAREN , " " ) case '{' : tok = token . New ( token . LBRACE , " " ) case '}' : tok = token . New ( token . RBRACE , " " ) case ':' : if l . Input [ l . Pos + 1 ] == '=' { l . Pos ++ tok = token . New ( token . SVDECL , " " ) } case ';' : tok = token . New ( token . SEMICOLON , " " ) case '\000' : tok = token . New ( token . EOF , " " ) l . Tokens = append ( l . Tokens , tok ) return default : if isDigit ( l . Input [ l . Pos ] ) { tok = token . New ( token . INT , l . readDigit ( ) ) } else if isChar ( l . Input [ l . Pos ] ) { str := l . readIdent ( ) tt , ok := keywords [ str ] if ok { tok = token . New ( tt , str ) } else { tt , ok = predeclaredIdents [ str ] if ok { tok = token . New ( tt , str ) } else { tok = token . New ( token . IDENT , str ) } } } } l . Tokens = append ( l . Tokens , tok ) } }
Analyze the input string ans split the token sequences
Analyze the input string ans split the token sequences
// keyword // predeclared identifier // identifier