views:

42

answers:

0

I want to convert 4Test scripts to Perl. I have been using the Parse::RecDescent in Perl, but am still overwhelmed at the task. Here is an example.

An example of 4Test is something like:

ParseSMSPlans (STRING sDir)
{
STRING sFile;
STRING sDirSMSPlan = sDir + "sms_plans\";
STRING sDirPlan = sDir + "plan\";
STRING sDirDeal = sDir + "deal\";
STRING sDirProduct = sDir + "product\";
STRING sLine, sType, sName;
HFILE hIn;
FILEINFO fiFile;
LIST OF FILEINFO lfInfo = SYS_GetDirContents (sDirSMSPlan);
       ...
}

... This is my Parse::RecDescent grammar

my $grammar = q{

#-----------------identifiers and datatypes-------------------#

    identifier : /[a-z]\w+/
    binops : '+' | '-' | '/' | '*' | '%' | '**'
    lbinops: '!' | '<' | '>' | '>='| '<='| '&&'| '||' | '=='
    integer: /\d+/ {print "hello $item[-1]" if $::debugging;}
    number : /(\d+|\d*\.\d+)/ {print "hello $item[-1]" if $::debugging;}
    string : /"(([^"]*)(\\")?)*"/
    operation : number binops number operation(s?)
    datatype : /[a-zA-Z]\w*/
    definition : datatype expression(s) #{print "hello $item[-1]" if $::debugging;}
                |datatype expression(s) "=" expression(s) #{print "hello $item[-1] = $item[-2]" if $::debugging;}
    statement : ifexp | elsexp | elseifexp |forexp | feachexp | whexp | swcexp


#------------------Expressed Values-----------------------------#
    program : expression
    expression :  number {print $item[1] if $::debugging}
                | integer
                | assignment
                | operation
                | identifier binops expression
                | number binops expression

#------------------Conditionals---------------------------------------#

    ifexp  : 'if' '(' expression(s) ')' '{' expression(s) '}' elsexp(?)
    elsexp : 'else' '{' expression(s) '}'
    elseifexp: 'else' 'if' '(' expression(s) ')' '{' expression(s) '}'
    forexp : 'for' '(' expression ';' expression ';' expression ')' '{' expression(s)  }'
           | 'for' assignment 'to' number expression(s) | 'for' assignment 'to' number '{' expression(s) '}'
    feachexp : 'for each' expression 'in' expression '{' expression(s) '}'
    whexp  : 'while' '(' expression ')' '{' expression(s) '}'
    casest : 'case' expression(s /,/) ':'
    swcexp : 'switch' identifier '{' casest(s) '}' expression(s) 'default'
    assignment : identifier(s) '=' expression
};

So, I'm looking at adding "$" to every variable name, and chopping datatypes. For the most part my grammar works, though I have fully tested it yet, but only because Parse::RecDescent has been a bit tricky for me to understand and, I'm not really sure if it's the best way to complete my task...or the fastest, for that matter.

My main concern is whether or not anyone feels that PRD can handle what I'm asking it to do or will simple(complex) regex(s) suffice? I would appreciate any help anyone could offer on this.