解析4Test并将其转换为Perl

解析4Test并将其转换为Perl,perl,parsing,interpreter,Perl,Parsing,Interpreter,我想将4Test脚本转换为Perl。我一直在Perl中使用Parse::RecDescent,但仍然无法胜任这项任务。这里有一个例子 4Test的一个示例如下: ParseSMSPlans (STRING sDir) { STRING sFile; STRING sDirSMSPlan = sDir + "sms_plans\"; STRING sDirPlan = sDir + "plan\"; STRING sDirDeal = sDir + "deal\"; STRING sDirProd

我想将4Test脚本转换为Perl。我一直在Perl中使用Parse::RecDescent,但仍然无法胜任这项任务。这里有一个例子

4Test的一个示例如下:

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);
       ...
}
。。。 这是我的Parse::RecDescent语法

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
};
my$grammar=q{
#-----------------标识符和数据类型-------------------#
标识符:/[a-z]\w+/
副词:“+”|“-“|”/“|”*“|”%“|”**”

lbinops:“!”|“|”>=“|”我建议您简化4Test脚本,用子例程调用替换所有运算符表达式。然后您仍然可以将它们作为4Test脚本运行,从而证明它们是有效的,但您将大大简化解析问题-运算符表达式比str更难解析aight过程调用。到了极限,此过程将生成几乎可以由Perl直接运行的4Test脚本+4Test函数的一些替换例程。

您看过Regexp::Grammars吗?4Test需要完整的解释器还是只需要转换几个脚本?