Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 23d9c1b8eb9c6c8024f74ba224dd4daeb996eab8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
RoomModel RemoveComment {
	import room.basic.types.* from "../../../org.eclipse.etrice.modellib.c/model/Types.room"
	
	PrimitiveType file:ptInteger -> FILE default "0"

	SubSystemClass RemoveCommentSubSys {
		ActorRef Topref:ATop 
	}
	ActorClass ATop {
		Structure {
			ActorRef reader: AFileReader
			ActorRef cParser: ACParser
			Binding reader.outPort and cParser.readerPort
		}
		Behavior { }
	}
	ActorClass AFileReader{
		Interface {
			Port outPort: FileReaderProtocol
		}
		Structure {
			usercode3{"#include <stdio.h>"
			}
			external Port outPort
			Attribute f:file ref
		}
		Behavior {
			StateMachine {
				Transition init: initial -> reading {
					action {
						"if ((f = fopen(\"test.txt\",\"r\")) != 0) {"
						"\tprintf(\"file open ok !\\r\\n\");"
						"\t}"
						"\telse {"
						"\tprintf(\"file not found !\\r\\n\");"
						"\tSubSysClass_shutdown();"
						"\t}"
					}
				}
				Transition tr0: reading -> reading {
					triggers {
						<getNextChar: outPort>
					}
					action {
						"int8 c;"
						"if ((c=fgetc(f)) != EOF) {"
						"\toutPort.nextChar(c);"
						"\t}"
						"\telse {"
						"\tfclose(f);"
						"\tprintf(\"file closed !\\r\\n\");"
						"\tSubSysClass_shutdown();"
						"\t}"
					}
				}
				State reading
			}
		}
	}
	ActorClass ACParser{
		Interface {
			conjugated Port readerPort: FileReaderProtocol
		}
		Structure {
			external Port readerPort
		}
		Behavior {
			StateMachine {
				Transition init: initial -> code {
					action {
						"readerPort.getNextChar();"
					}
				}
				Transition tr0: code -> cp cp0 {
					triggers {
						<nextChar: readerPort>
					}
					action {
						"readerPort.getNextChar();"
					}
				}
				Transition tr1: cp cp0 -> code {
					action {
						"printf(\"%c\",c);"
					}
				}
				Transition tr2: cp cp0 -> firstSlash {
					cond {
						"c==\'/\'"
					}
				}
				Transition tr3: firstSlash -> cp cp1 {
					triggers {
						<nextChar: readerPort>
					}
					action {
						"readerPort.getNextChar();"
					}
				}
				Transition tr4: cp cp1 -> cp cp4
				Transition tr5: cp cp1 -> blockComment {
					cond {
						"c==\'*\'"
					}
				}
				Transition tr6: blockComment -> cp cp2 {
					triggers {
						<nextChar: readerPort>
					}
					action {
						"readerPort.getNextChar();"
					}
				}
				Transition tr7: cp cp2 -> blockComment
				Transition tr8: cp cp2 -> firstStar {
					cond {
						"c==\'*\'"
					}
				}
				Transition tr9: firstStar -> cp cp3 {
					triggers {
						<nextChar: readerPort>
					}
					action {
						"readerPort.getNextChar();"
					}
				}
				Transition tr10: cp cp3 -> blockComment
				Transition tr11: cp cp3 -> code {
					cond {
						"c==\'/\'"
					}
				}
				Transition tr12: cp cp4 -> code {
					action {
						"printf(\"%c%c\",\'/\',c);"
					}
				}
				Transition tr13: cp cp4 -> lineComment {
					cond {
						"c==\'/\'"
					}
				}
				Transition tr14: cp cp5 -> lineComment
				Transition tr15: lineComment -> cp cp5 {
					triggers {
						<nextChar: readerPort>
					}
					action {
						"readerPort.getNextChar();"
					}
				}
				Transition tr16: cp cp5 -> code {
					cond {
						"c==\'\\n\'"
					}
				}
				ChoicePoint cp0
				ChoicePoint cp1
				ChoicePoint cp2
				ChoicePoint cp3
				ChoicePoint cp4
				ChoicePoint cp5
				State code
				State firstSlash
				State blockComment
				State firstStar
				State lineComment
			}
		}
	}

	ProtocolClass FileReaderProtocol {
		incoming {
			Message getNextChar()
		}
		outgoing {
			Message nextChar(c:char)
		}
	}
}

Back to the top