Lex "Error: Action does not terminate" error - lex

I am creating a .lex file for an independent study. I am running into a lex error as stated in the title of this question. It is happening on line 119, (the lines are numbered). I am not sure why I am getting this error. Can anyone spot what I might be doing wrong? I did not include the token.h file but if it is needed I will post it. My .lex file is named scanner.lex and is as follows:
1 %{
2 #include <string.h>
3 #include "token.h"
4
5 int current_line_number = 1;
6
7 void newLine() {
8 current_line_number++;
9 }
10
11 int yywrap(void) {
12 return 1;
13 }
14
15 %}
16
17 %%
18 " " { }
19 \n {newLine();}
20 and {yylval.line_number = current_line_number;
21 return AND;}
22 array {yylval.line_number = current_line_number;
23 return ARRAY;}
24 begin {yylval.line_number = current_line_number;
25 return BEGIN;}
26 boolean {yylval.line_number = current_line_number;
27 return BOOLEAN;}
28 div {yylval.line_number = current_line_number;
29 return DIV;}
30 do {yylval.line_number = current_line_number;
31 return DO;}
32 else {yylval.line_number = current_line_number;
33 return ELSE;}
34 end {yylval.line_number = current_line_number;
35 return END;}
36 false {yylval.line_number = current_line_number;
37 return FALSE;}
38 for {yylval.line_number = current_line_number;
39 return FOR;}
40 goto {yylval.line_number = current_line_number;
41 return GOTO;}
42 if {yylval.line_number = current_line_number;
43 return IF;]
44 imply {yylval.line_number = current_line_number;
45 return IMPLY;}
46 integer {yylval.line_number = current_line_number;
47 return INTEGER;}
48 label {yylval.line_number = current_line_number;
49 return LABEL;}
50 not {yylval.line_number = current_line_number;
51 return NOT;}
52 or {yylval.line_number = current_line_number;
53 return OR;}
54 own {yylval.line_number = current_line_number;
55 return OWN;}
56 procedure {yylval.line_number = current_line_number;
57 return PROCEDURE;}
58 real {yylval.line_number = current_line_number;
59 return REAL;}
60 step {yylval.line_number = current_line_number;
61 return STEP;}
62 string {yylval.line_number = current_line_number;
63 return STRING;}
64 then {yylval.line_number = current_line_number;
65 return THEN;}
66 true {yylval.line_number = current_line_number;
67 return TRUE;}
68 until {yylval.line_number = current_line_number;
69 return UNTIL;}
70 value {yylval.line_number = current_line_number;
71 return VALUE;}
72 while {yylval.line_number = current_line_number;
73 return WHILE;}
74 [a-zA-Z][a-zA-Z0-9]* {yylval.string_value.line_number = current_line_number;
75 yylval.string_value.value = malloc(sizeof(char) *(strlen (yytext)+1));
76 return IDENTIFIER;}
77 [0-9]+ {yylval.integer_value.line_number = current_line_number;
78 yylval.integer_value.value = atoi(yytext);
79 return INT;}
80 [0-9][0-9]*\.[0-9][0-9]* {yylval.real_value.line_number = current_line_number;
81 yylval.real_value.value = atof(yytext);
82 return REAL;}
83 "+" {yylval.line_number = current_line_number;
84 return PLUS;}
85 "-" {yylval.line_number = current_line_number;
86 return MINUS;}
87 "*" {yylval.line_number = current_line_number;
88 return MULT;}
89 "/" {yylval.line_number = current_line_number;
90 return DIV;}
91 "<" {yylval.line_number = current_line_number;
92 return LESS;}
93 "<=" {yylval.line_number = current_line_number;
94 return LESSEQ;}
95 ">" {yylval.line_number = current_line_number;
96 return GREAT;}
97 ">=" {yylval.line_number = current_line_number;
98 return GREATEQ;}
99 "=" {yylval.line_number = current_line_number;
100 return EQ;}
101 "!=" {yylval.line_number = current_line_number;
102 return NOTEQ;}
103 "," {yylval.line_number = current_line_number;
104 return COMMA;}
105 ":" {yylval.line_number = current_line_number;
106 return COLON;}
107 ";" {yylval.line_number = current_line_number;
108 return SEMI;}
109 "(" {yylval.line_number = current_line_number;
110 return LPARAN;}
111 ")" {yylval.line_number = current_line_number;
112 return RPARAN;}
113 "[" {yylval.line_number = current_line_number;
114 return LBRAK;}
115 "]" {yylval.line_number = current_line_number;
116 return RBRAK;}
117 ":=" {yylval.line_number = current_line_number;
118 return ASSIGN;}
119 . {printf("Found other data \"%s\"\n", yytext);
120 return 1;}
121
122 %%
Here is the actual error message:
cs368#admiral:~/cs4880$ lex scanner.lex
"scanner.lex":line 119: Error: Action does not terminate
Also, I would appreciate it something else does not seem right, suggestions are welcomed. Thank you everyone.

Found the error. On line 43 I had typed a "]" instead of "}" Still if you see anything that can be improved, I would appreciate it.

Related

Sort a collection of two integers in PowerShell

I have got a PowerShell script which adds items consisting of two items to a collection
$feedList = New-Object Collections.Generic.List[PSCustomObject]
foreach (...) {
$endpointId = ...
$messagehandler = ...
$feedItem = [Int]$endpointId,[Int]$messagehandler
$feedList.Add($feedItem)
}
$feedList = $feedlist | Sort -Unique
Unfortunately this seems to sort alphabetically rather than numerically. eg
219 20
221 59
222 59
225 67
240 78
246 90
46 34
47 31
49 96
51 47
52 103
52 113
52 18
52 20
52 26
52 74
52 76
52 81
55 10
58 18
59 64
60 17
61 52
69 63
70 30
75 12
89 14
90 28
93 1
Since you define $feedList as a generic list of custom objects I'd recommend actually creating custom objects and then sorting them by property.
foreach (...) {
...
$feedItem = [PSCustomObject]#{
'EndpointId' = [int]$endpointId
'MessageHandler' = [int]$messagehandler
}
$feedList.Add($feedItem)
}
$feedList = $feedList | Sort -Unique EndpointId, MessageHandler

Retrieve valid values for parameter PaperSize of Set-PrintConfiguration

We're trying to verify valid input for the parameter PaperSize of Set-PrintConfiguration.
We're trying to create an array with all possible accepted values for the argument:
$testCommand = Get-Command Set-PrintConfiguration
$testCommand.Parameters.PaperSize
$testPaperSie = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.PrinterConfiguration.PaperSizeEnum]
$testPaperSie.DeclaredFields.Name
This does return a list of options but it also includes a value like value__ which does not seem to be suggested by intellisense. This makes me think the query for valid values is incorrect.
To get the possible values from the PaperKind enum, you can do something like this:
function Get-Enum {
param (
[type]$Type
)
if ($Type.BaseType.FullName -ne 'System.Enum') {
Write-Error "Type '$Type' is not an enum"
}
else {
[enum]::GetNames($Type) | ForEach-Object {
$exp = "([$Type]::$($_)).value__"
[PSCustomObject] #{
'Name' = $_
'Value' = Invoke-Expression -Command $exp
}
}
}
}
Get-Enum System.Drawing.Printing.PaperKind
On my machine it returns:
Name Value
---- -----
Custom 0
Letter 1
LetterSmall 2
Tabloid 3
Ledger 4
Legal 5
Statement 6
Executive 7
A3 8
A4 9
A4Small 10
A5 11
B4 12
B5 13
Folio 14
Quarto 15
Standard10x14 16
Standard11x17 17
Note 18
Number9Envelope 19
Number10Envelope 20
Number11Envelope 21
Number12Envelope 22
Number14Envelope 23
CSheet 24
DSheet 25
ESheet 26
DLEnvelope 27
C5Envelope 28
C3Envelope 29
C4Envelope 30
C6Envelope 31
C65Envelope 32
B4Envelope 33
B5Envelope 34
B6Envelope 35
ItalyEnvelope 36
MonarchEnvelope 37
PersonalEnvelope 38
USStandardFanfold 39
GermanStandardFanfold 40
GermanLegalFanfold 41
IsoB4 42
JapanesePostcard 43
Standard9x11 44
Standard10x11 45
Standard15x11 46
InviteEnvelope 47
LetterExtra 50
LegalExtra 51
TabloidExtra 52
A4Extra 53
LetterTransverse 54
A4Transverse 55
LetterExtraTransverse 56
APlus 57
BPlus 58
LetterPlus 59
A4Plus 60
A5Transverse 61
B5Transverse 62
A3Extra 63
A5Extra 64
B5Extra 65
A2 66
A3Transverse 67
A3ExtraTransverse 68
JapaneseDoublePostcard 69
A6 70
JapaneseEnvelopeKakuNumber2 71
JapaneseEnvelopeKakuNumber3 72
JapaneseEnvelopeChouNumber3 73
JapaneseEnvelopeChouNumber4 74
LetterRotated 75
A3Rotated 76
A4Rotated 77
A5Rotated 78
B4JisRotated 79
B5JisRotated 80
JapanesePostcardRotated 81
JapaneseDoublePostcardRotated 82
A6Rotated 83
JapaneseEnvelopeKakuNumber2Rotated 84
JapaneseEnvelopeKakuNumber3Rotated 85
JapaneseEnvelopeChouNumber3Rotated 86
JapaneseEnvelopeChouNumber4Rotated 87
B6Jis 88
B6JisRotated 89
Standard12x11 90
JapaneseEnvelopeYouNumber4 91
JapaneseEnvelopeYouNumber4Rotated 92
Prc16K 93
Prc32K 94
Prc32KBig 95
PrcEnvelopeNumber1 96
PrcEnvelopeNumber2 97
PrcEnvelopeNumber3 98
PrcEnvelopeNumber4 99
PrcEnvelopeNumber5 100
PrcEnvelopeNumber6 101
PrcEnvelopeNumber7 102
PrcEnvelopeNumber8 103
PrcEnvelopeNumber9 104
PrcEnvelopeNumber10 105
Prc16KRotated 106
Prc32KRotated 107
Prc32KBigRotated 108
PrcEnvelopeNumber1Rotated 109
PrcEnvelopeNumber2Rotated 110
PrcEnvelopeNumber3Rotated 111
PrcEnvelopeNumber4Rotated 112
PrcEnvelopeNumber5Rotated 113
PrcEnvelopeNumber6Rotated 114
PrcEnvelopeNumber7Rotated 115
PrcEnvelopeNumber8Rotated 116
PrcEnvelopeNumber9Rotated 117
PrcEnvelopeNumber10Rotated 118
Hope that helps

MATLAB Serial incorrectly sending values

I am trying to communicate with a StepRocker motor controller/drive using MATLAB. I have figured out how to format their commands and have been able to get it to move to many of commands. Their commands require that the values be sent in a binary format over RS-232. I started running into some issues and started using an Arduino to echo my commands.
I am currently sending the values 1 - 255 just to test sending bytes over the serial channel. I am sending it to an Arduino and reading the bytes back out of the Arduino. All numbers work except for the numbers between 128 and 159. This is problematic since some of my commands require values in this range.
MATLAB Script:
obj = instrfind; delete(obj); % cleanup any lost objects
clear; close force all; clc; % clear the workspace
sM = serial('COM2','BaudRate',9600, 'Terminator', 'CR', 'Timeout', 10);
fopen(sM);
pause(2); % give port time to open
% make list of numbers 1-255, skip 10/13 since they terminate on the
% arduino
cmd = [1:9 11:12 14:255];
% Send command and get echo
fprintf(sM,cmd);
pause(0.5); % give time for echo
echo = fscanf(sM);
uint8(echo)
fclose(sM);
After executing this script I get the following output:
ans =
Columns 1 through 22
1 2 3 4 5 6 7 8 9 11 12 14 15 16 17 18 19 20 21 22 23 24
Columns 23 through 44
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
Columns 45 through 66
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
Columns 67 through 88
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
Columns 89 through 110
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
Columns 111 through 132
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 63 63 63 63 63 63 63
Columns 133 through 154
63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
Columns 155 through 176
63 63 63 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
Columns 177 through 198
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
Columns 199 through 220
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
Columns 221 through 242
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
Columns 243 through 254
245 246 247 248 249 250 251 252 253 254 255 13
Looking at the output, you can see that the numbers between 128 and 159 all come through as 63. I am at a loss for what is causing this issue. This is very repeatable, and the problem occurs anytime there is a number in this range, no matter its position in the string, no matter the length of the serial string.
Arduino Code:
bool stringComplete = false;
String inputString = "";
void setup() {
Serial.begin(9600);
}
void loop() {
if (stringComplete) {
Serial.print(inputString);
stringComplete = false;
inputString = "";
}
}
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\r') {
stringComplete = true;
}
}
}
Any suggestions or ideas on how to solve this problem?

Matlab lego nxt robot doesn’t turn but says it did

I am programming a Lego brick NXT in Matlab to go through a maze. The robot is supposed to drive forward until the touch sensor is activated by a wall.
The robot should
stop
backup
stop
read the ultraSonic (distance) sensor
display the result
If the sensor reads a large distance, the robot turns right and stops and if the sensor reads a small distance, the robot turns left and stops.
Then, the robot continues forward again until it runs into another wall.
Current code:
The robot will hit the wall, stop, back up, stop, and it will display that it’s turning, but it doesn’t turn.
Is there something I am typing incorrectly? Should I initialize the motors before the loop or inside of the loop? I am especially wary of my pauses.
1 %B = NXTMotor('B');
2 %C = NXTMotor('C');
3 OpenSwitch(SENSOR_1);
4 OpenUltrasonic(SENSOR_4);
5
6
7 while 1
8
9 B = NXTMotor('B');
10 C = NXTMotor('C');
11
12 %FORWARD 1
13 disp('move forward');
14 B.Power = 50;
15 C.Power = 50;
16
17 B.SendToNXT();
18 C.SendToNXT();
19 B.WaitFor();
20 C.WaitFor();
21 disp('before getswitch');
22
23 if GetSwitch(SENSOR_1)
24 pause(0.2);
25 B.Power = 0;
26 C.Power = 0;
27 B.SendToNXT();
28 C.SendToNXT();
29 B.WaitFor();
30 C.WaitFor();
31 disp('Hit a wall and stops');
32
33 disp('back up');
34 B.Power = -50;
35 C.Power = -50;
36
37 B.TachoLimit = 720;
38 C.TachoLimit = 720;
39
40 B.SendToNXT();
41 C.SendToNXT();
42 B.WaitFor();
43 C.WaitFor();
44
45 pause(0.5);
46 B.Power = 0;
47 C.Power = 0;
48 B.SendToNXT();
49 C.SendToNXT();
50 B.WaitFor();
51 C.WaitFor();
52 disp('finished back up');
53
54 %ultrasonic
55 distance = GetUltrasonic(SENSOR_4);
56 disp(distance);
57
58 if distance >100
59 %if GetUltrasonic(SENSOR_4) > 100
60
61 %TURN 1
62 disp('turn1 > 100');
63
64 B.Power = 0;
65 C.Power = 100;
66
67 B.TachoLimit = 720;
68 C.TachoLimit = 720;
69
70 B.SendToNXT();
71 C.SendToNXT();
72 B.WaitFor();
73 C.WaitFor();
74 disp('turn1 finished');
75
76 pause(0.2);
77 B.Power = 0;
78 C.Power = 0;
79 B.SendToNXT();
80 C.SendToNXT();
81 B.WaitFor();
82 C.WaitFor();
83
84 end
85
86 if distance <= 100
87
88 disp('turn2 < 100');
89
90 B.Power = 100;
91 C.Power = 0;
92 disp('turn 2');
93 B.TachoLimit = 720;
94 C.TachoLimit = 720;
95
96 B.SendToNXT();
97 C.SendToNXT();
98 B.WaitFor();
99 C.WaitFor();
100 disp('Finished turn 2');
101
102 pause(0.5);
103 B.Power = 0;
104 C.Power = 0;
105 B.SendToNXT();
106 C.SendToNXT();
107 B.WaitFor();
108 C.WaitFor();
109
110 disp('stopped turn2 and ready to go forward');
111
112 end
113
114 B.Stop('off');
115 C.Stop('off');
116 end
117
118 %B.Stop('off');
119 %C.Stop('off');
120 end
121
122 CloseSensor(SENSOR_4);
123 CloseSensor(SENSOR_1);

Calculate min/avg/max/std-dev for ICMP time stamp data from hping [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
What's the best way to calculate min/avg/max/std-dev for some random data in shell?
What if one has several columns per line, and needs to calculate the statistics for each one?
Sample input (based on processing of the hping output), with the columns 3, 4 and 5 being of interest:
0 145.5 146 = 75 + 71
1 142.7 142 = 72 + 70
2 140.7 140 = 70 + 70
3 146.7 146 = 76 + 70
4 148.3 148 = 77 + 71
5 157.5 157 = 87 + 70
6 167.1 167 = 96 + 71
7 166.3 166 = 95 + 71
8 167.7 167 = 97 + 70
9 159.0 159 = 88 + 71
10 156.7 156 = 86 + 70
11 154.9 155 = 84 + 71
12 151.9 152 = 81 + 71
13 157.3 157 = 86 + 71
14 155.0 155 = 84 + 71
15 157.7 158 = 87 + 71
16 156.6 156 = 86 + 70
(Note that this input is a live stream ad infinitum.)
I suggest you use Perl and keep a running total of N, Σx, and Σx², as well as the minimum and maximum x values. All of the values you need can be derived from those.
This example demonstrates. It dumps the current statistics after each line of the input is read.
use strict;
use warnings;
my ($n, #sum, #sumsq, #min, #max);
while (<DATA>) {
my #columns = /[0-9.]+/g;
my (#mean, #std_dev);
++$n;
for my $i (0 .. 2) {
my $x = $columns[$i + 2];
my $xsq = $x * $x;
$sum[$i] += $x;
$sumsq[$i] += $xsq;
$mean[$i] = $sum[$i] / $n;
$std_dev[$i] = sqrt($sumsq[$i]/$n - $mean[$i] * $mean[$i]);
$min[$i] = $x unless defined $min[$i] and $min[$i] <= $x;
$max[$i] = $x unless defined $max[$i] and $max[$i] >= $x;
}
print "min = #min\n";
print "max = #max\n";
print "mean = #mean\n";
print "std_dev = #std_dev\n";
print "---\n";
}
__DATA__
0 145.5 146 = 75 + 71
1 142.7 142 = 72 + 70
2 140.7 140 = 70 + 70
3 146.7 146 = 76 + 70
4 148.3 148 = 77 + 71
5 157.5 157 = 87 + 70
6 167.1 167 = 96 + 71
7 166.3 166 = 95 + 71
8 167.7 167 = 97 + 70
9 159.0 159 = 88 + 71
10 156.7 156 = 86 + 70
11 154.9 155 = 84 + 71
12 151.9 152 = 81 + 71
13 157.3 157 = 86 + 71
14 155.0 155 = 84 + 71
15 157.7 158 = 87 + 71
16 156.6 156 = 86 + 70
output
min = 146 75 71
max = 146 75 71
mean = 146 75 71
std_dev = 0 0 0
---
min = 142 72 70
max = 146 75 71
mean = 144 73.5 70.5
std_dev = 2 1.5 0.5
---
min = 140 70 70
max = 146 75 71
mean = 142.666666666667 72.3333333333333 70.3333333333333
std_dev = 2.4944382578501 2.05480466765642 0.47140452079146
---
min = 140 70 70
max = 146 76 71
mean = 143.5 73.25 70.25
std_dev = 2.59807621135332 2.38484800354236 0.433012701892219
---
min = 140 70 70
max = 148 77 71
mean = 144.4 74 70.4
std_dev = 2.93938769133971 2.60768096208109 0.489897948555485
---
min = 140 70 70
max = 157 87 71
mean = 146.5 76.1666666666667 70.3333333333333
std_dev = 5.40832691319598 5.39804491356711 0.47140452079146
---
min = 140 70 70
max = 167 96 71
mean = 149.428571428571 79 70.4285714285714
std_dev = 8.74817765279739 8.55235974119756 0.494871659305337
---
min = 140 70 70
max = 167 96 71
mean = 151.5 81 70.5
std_dev = 9.8488578017961 9.59166304662544 0.5
---
min = 140 70 70
max = 167 97 71
mean = 153.222222222222 82.7777777777778 70.4444444444444
std_dev = 10.4857339888036 10.3470637571759 0.496903995000609
---
min = 140 70 70
max = 167 97 71
mean = 153.8 83.3 70.5
std_dev = 10.0975244490914 9.94032192637645 0.5
---
min = 140 70 70
max = 167 97 71
mean = 154 83.5454545454545 70.4545454545455
std_dev = 9.64836302648838 9.50945592902742 0.497929597732158
---
min = 140 70 70
max = 167 97 71
mean = 154.083333333333 83.5833333333333 70.5
std_dev = 9.24173805202349 9.10547759440561 0.5
---
min = 140 70 70
max = 167 97 71
mean = 153.923076923077 83.3846153846154 70.5384615384615
std_dev = 8.89651218141581 8.77530154238378 0.498518515262866
---
min = 140 70 70
max = 167 97 71
mean = 154.142857142857 83.5714285714286 70.5714285714286
std_dev = 8.60943952761114 8.48287590817347 0.494871659305337
---
min = 140 70 70
max = 167 97 71
mean = 154.2 83.6 70.6
std_dev = 8.32025640630559 8.19593395125498 0.489897948558269
---
min = 140 70 70
max = 167 97 71
mean = 154.4375 83.8125 70.625
std_dev = 8.10839649684202 7.97824189593171 0.484122918275927
---
min = 140 70 70
max = 167 97 71
mean = 154.529411764706 83.9411764705882 70.5882352941177
std_dev = 7.874886718579 7.75712642546343 0.492152956783766
---