Example #1
0
func newLexer(nm string, sz int, r io.RuneReader, report *xc.Report) (*lexer, error) {
	file := xc.FileSet.AddFile(nm, -1, sz+2)
	lx, err := lex.New(
		file,
		r,
		lex.ErrorFunc(func(pos token.Pos, msg string) {
			report.Err(pos, msg)
		}),
		lex.RuneClass(func(r rune) int { return int(r) }),
	)
	if err != nil {
		return nil, err
	}

	l := &lexer{
		Lexer:  lx,
		report: report,
	}
	l.emit(&Call{Target: 2})
	l.emit(&Halt{})
	l.enter = &Enter{NVars: -1}
	l.jmp = &Jmp{Target: -1}
	l.emit(l.enter)
	l.emit(l.jmp)
	return l, nil
}
Example #2
0
// Bind attempts to bind the name in t to node. Errors are reported to report.
func (b *Bindings) Bind(t xc.Token, node Node, report *xc.Report) {
	nm := t.Val
	if x := b.Map[nm]; x != nil {
		ok := false
		switch e := x.Node.(type) {
		case *ConstSpec, *Variable:
		case *ProcSpec:
			ok = e == nil
		default:
			panic("internal error")
		}

		if !ok {
			report.ErrTok(t, "redeclaration of %s at %s", xc.Dict.S(nm), position(x.Pos))
			return
		}
	}

	b.Map[nm] = &Binding{node, t.Pos()}
}