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