MCPcopy Create free account
hub / github.com/dengsgo/math-engine / parseBinOpRHS

Method parseBinOpRHS

engine/ast.go:237–267  ·  view source on GitHub ↗
(execPrec int, lhs ExprAST)

Source from the content-addressed store, hash-verified

235}
236
237func (a *AST) parseBinOpRHS(execPrec int, lhs ExprAST) ExprAST {
238 for {
239 tokPrec := a.getTokPrecedence()
240 if tokPrec < execPrec {
241 return lhs
242 }
243 binOp := a.currTok.Tok
244 if a.getNextToken() == nil {
245 a.Err = errors.New(
246 fmt.Sprintf("want '(' or '0-9' but get EOF\n%s",
247 ErrPos(a.source, a.currTok.Offset)))
248 return nil
249 }
250 rhs := a.parsePrimary()
251 if rhs == nil {
252 return nil
253 }
254 nextPrec := a.getTokPrecedence()
255 if tokPrec < nextPrec {
256 rhs = a.parseBinOpRHS(tokPrec+1, rhs)
257 if rhs == nil {
258 return nil
259 }
260 }
261 lhs = BinaryExprAST{
262 Op: binOp,
263 Lhs: lhs,
264 Rhs: rhs,
265 }
266 }
267}

Callers 1

ParseExpressionMethod · 0.95

Calls 4

getTokPrecedenceMethod · 0.95
getNextTokenMethod · 0.95
parsePrimaryMethod · 0.95
ErrPosFunction · 0.85

Tested by

no test coverage detected