Convert an existing chunk of c code into a perl module. The existing code takes a string like "source:pulse:width2 100 ns", and breaks it into a numeric function code (source:pulsE:width = function 36), a channel number (2), a parameter (100), units (ns), and a command type (command_param_units).
It can also loop through a "compound" command string, where multiple commands are separated by semi-colons. There are special "grammar" rules about processing compound commands.
The commands follow the SCPI standard ([login to view URL]). See chapter 6 and a bit of chapter 7. Also, see section 2.1 of my instrument programming manual ([login to view URL]). You'll need to read them to understand the grammar.
For example, "source:pulse:width2 100 ns" can also be written as "puls:widt2 100e-9".
Some other valid commands are:
pulse:width?
frequency 1.1MHz
freq 2000
freq 2.2 khz
diag:eprom:float 1000 9e-9
diag:eprom:float? 1000
diag:ampl:cal:point 2 go
*idn?
*rst
sour:pulse:width 1us;delay 2us;double off
sour:pulse:width 1us;:source:volt 10;delay 2us;double off
sour:pulse:width 1us;*rst;delay 2us;double off
These are not valid according to the rules:
width 100 ns
sour:pulse:width 1us;sour:pulse:delay 2us;sour:pulse:double off
This is a fairly direct translation with no change in basic functionality. The next code should be shorter, more elegant, and more robust, due to the use of a higher-level language like Perl and its string and regex functions.
You'll need to confirm that the end code actually meets the SCPI standard, even if the original code had bugs. The original code came from an odd embedded development system, and may have unused variables and other minor quirks.
Your will re-implement the "Parser_main" function in the attached zip file, and its support functions (Parser_*, String_trim*). You will only implement the parser, not any actual firmware functions (that set the pulse width, for example).