go-pattern-examples/behavior/08_interpreter/interpreter.go
2020-05-05 00:01:23 +08:00

70 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package interpreter
import (
"strconv"
"strings"
)
//用会议交流的例子
// A表示左边发言者B表示右边发言者
// A "->" B 表示 A说B听,此时B不能发言。
// A "<-" B 表示 B说A听,此时B不能发言。
// A "<->" B 表示 A 和 B 可以自由发言。
// A "-" B 表示 A 和 B 都不能发言,只能倾听。
type IActionInterpret interface {
Interpret()
}
//Speaker 发言者
type Speaker struct {
Name string
Age int
}
func (s *Speaker) Interpret() {
}
//LeftIntroduce A向B介绍自己
type LeftIntroduce struct {
leftSpeaker, rightSpeaker Speaker
}
func (l *LeftIntroduce) Interpret() {
}
//RightIntroduce B向A介绍自己
type RightIntroduce struct {
leftSpeaker, rightSpeaker Speaker
}
func (n *MinNode) Interpret() int {
return n.left.Interpret() - n.right.Interpret()
}
//标识解析器
type SignParser struct {
actionsMark []string
}
//Parse 标识解析器进行解析
func (p *SignParser) Parse(exp string) {
p.exp = strings.Split(exp, " ")
s := p.actionsMark[0]
for len(s) >0 {
switch s.actionsMark[0] {
}
}
}