Esempio n. 1
0
func findStartState(root *ast.Root, inits []*ast.Init, tab table.Table) (int, error) {
	for _, init := range inits {
		if init.GetMessage() == root.GetMessage() {
			if init.GetPackage() == root.GetPackage() {
				startState, err := tab.NameToState(init.GetState())
				if err != nil {
					return 0, err
				}
				return startState, nil
			}
		}
	}
	return 0, &errNoStartState{root.GetPackage(), root.GetMessage()}
}
Esempio n. 2
0
File: link.go Progetto: katydid/v0.1
func NewLink(rules *ast.Rules, tokens Tokens, tab table.Table, c ifexpr.Catcher) (Link, error) {
	l := tokens.Len()
	link := &link{
		tokenToStart: make([]int, l),
		tokenToIf:    make([]ifexpr.StateExpr, l),
	}
	for _, rule := range rules.Rules {
		if init := rule.Init; init != nil {
			pstate, err := tokens.GetTokenId(init.GetPackage() + "." + init.GetMessage())
			if err != nil {
				return nil, err
			}
			tstate, err := tab.NameToState(init.GetState())
			if err != nil {
				return nil, err
			}
			link.tokenToStart[pstate] = tstate
		}
	}
	for _, rule := range rules.Rules {
		if ifExpr := rule.IfExpr; ifExpr != nil {
			var1, err := ifExpr.GetVariable()
			if err != nil {
				return nil, err
			}
			pstate, err := tokens.GetTokenId(var1.Name)
			if err != nil {
				return nil, err
			}
			stateExpr, err := ifexpr.Compile(ifExpr, tab, c)
			if err != nil {
				return nil, err
			}
			link.tokenToIf[pstate] = stateExpr
		}
	}
	return link, nil
}