Example #1
0
func phelp(t xc.Token) string {
	if len(t.S()) != 0 {
		return fmt.Sprintf(" %s", t.S())
	}

	return ""
}
Example #2
0
func (l *lexer) mustIdent(t xc.Token) (Node, int) {
	b, f := l.scope.lookup(t.Val)
	if b == nil {
		l.report.ErrTok(t, "undeclared identifier %s", t.S())
		return nil, -1
	}

	return b.Node, f
}
Example #3
0
func (l *lexer) mustProc(t xc.Token) (Node, int) {
	n, f := l.mustIdent(t)
	if n == nil {
		return nil, -1
	}

	if _, ok := n.(*ProcSpec); !ok {
		l.report.ErrTok(t, "%s is not a procedure", t.S())
		return nil, -1
	}

	return n, f
}
Example #4
0
func (l *lexer) mustVar(t xc.Token) (Node, int) {
	n, f := l.mustIdent(t)
	if n == nil {
		return nil, -1
	}

	if _, ok := n.(*Variable); !ok {
		l.report.ErrTok(t, "%s is not a variable", t.S())
		return nil, -1
	}

	return n, f
}
Example #5
0
func (l *lexer) mustVarOrConst(t xc.Token) (Node, int) {
	n, f := l.mustIdent(t)
	if n == nil {
		return nil, -1
	}

	switch n.(type) {
	case *Variable, *ConstSpec:
		return n, f
	default:
		l.report.ErrTok(t, "%s is not a constant or a variable", t.S())
		return nil, -1
	}
}
Example #6
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()}
}