parser
This commit is contained in:
+19
@@ -1,5 +1,7 @@
|
||||
package ast
|
||||
|
||||
import "gointerpreter/token"
|
||||
|
||||
type Node interface {
|
||||
TokenLiteral() string
|
||||
}
|
||||
@@ -25,3 +27,20 @@ func (p *Program) TokenLiteral() string {
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
type LetStatement struct {
|
||||
Token token.Token
|
||||
Name *Identifier
|
||||
Value Expression
|
||||
}
|
||||
|
||||
func (ls *LetStatement) statementNode() {}
|
||||
func (ls *LetStatement) TokenLiteral() string { return ls.Token.Literal }
|
||||
|
||||
type Identifier struct {
|
||||
Token token.Token
|
||||
Value string
|
||||
}
|
||||
|
||||
func (i *Identifier) expressionNode() {}
|
||||
func (i *Identifier) TokenLiteral() string { return i.Token.Literal }
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"gointerpreter/ast"
|
||||
"gointerpreter/lexer"
|
||||
"gointerpreter/token"
|
||||
)
|
||||
|
||||
type Parser struct {
|
||||
l *lexer.Lexer
|
||||
|
||||
currToken token.Token
|
||||
peekToken token.Token
|
||||
}
|
||||
|
||||
func New(l *lexer.Lexer) *Parser {
|
||||
p := &Parser{l: l}
|
||||
|
||||
p.nextToken()
|
||||
p.nextToken()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Parser) nextToken() {
|
||||
p.currToken = p.peekToken
|
||||
p.peekToken = p.l.NextToken()
|
||||
}
|
||||
|
||||
func (p *Parser) ParseProgram() *ast.Program {
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user