monna/parser/parser.go
tijani cf651aa1b8 ast and parser
git-svn-id: https://svn.tlawal.org/svn/monkey@7 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-22 06:51:19 +00:00

40 lines
1.0 KiB
Go

/* NOTE(tijani):
* l_ in variables names stand for local_ identifiers. The reason is because I do not like
* single letter variable names, but I also do not want to confuse the myself
* when I come back to reading this code after a while hence l_ to signify that it is local to that function.
*/
package parser
import (
"monkey/ast"
"monkey/lexer"
"monkey/token"
)
type Parser struct {
l_lexer *lexer.Lexer
current_token token.Token
peek_token token.Token
}
func (l_parser *Parser) next_token(){
l_parser.current_token = l_parser.peek_token
l_parser.peek_token = l_parser.l_lexer.NextToken()
}
func (p *Parser) ParseProgram() *ast.Program {
return nil
}
func New(lexer *lexer.Lexer) *Parser {
l_parser := &Parser {l_lexer: lexer}
// Read two tokens so current_token and peek_token are set.
// NOTE(tijani): the first time l_parser.next_token() is called, current_token and peek_token will be pointing to the same token.
l_parser.next_token()
l_parser.next_token()
return l_parser
}