antlr 3.5中的输入错误不匹配

时间:2014-10-20 06:05:31

标签: antlr3

我在antlr3.5中的语法代码有问题。我的输入文件是

` define tcpChannel  ChannelName
        define 
          listener  
       ListnerProperty  
        end  
 listener ;

       define  
         execution 
            request   with   format   RequestFormat,
            response   with   format  ResponseFormat,
            error  with  format   ErrorFormat ,
            call  servicename.executionname
    end define execution ;

 end  
define channel ;
      `

我的词法分析代码如下:

lexer grammar ChannelLexer;







// ***************** lexer rules:

Define
:
'define'
; 

Tcpchannel
:
'tcphannel'
;

Listener
:
'Listener'
;
End
:
'end'
;
Execution
:
' execution '
;
Request
:
' request '
;
With
:
' with '
;
Format
:
' format '
;
Response
:
' response '
;
Error
:
' error '
;
Call
:
' call '
;
Channel
:
' channel '
;

Dot
:
'.'
;

SColon
:
';'
;


Comma
:
','
;

Value
:
(
'a'..'z'
|'A'..'Z'
|'_'
)
(
'a'..'z'
|'A'..'Z'
|'_'
|Digit
)*
;




fragment
String
:
(
    '"'
    (
      ~(
        '"'
        | '\\'
       )
      | '\\'
      (
        '\\'
        | '"'
      )
    )*
    '"'
    | '\''
    (
      ~(
        '\''
        | '\\'
       )
      | '\\'
      (
        '\\'
        | '\''
      )
    )*
    '\''
  )
  {
  setText(getText().substring(1, getText().length() - 1).replaceAll("\\\\(.)",
      "$1"));

   }
   ;

   fragment
   Digit
   :
   '0'..'9'
;


Space
  :
  (
    ' '
    | '\t'
    | '\r'
    | '\n'
    | '\u000C'
  )

   {
    skip();
   }
  ;

我的解析器代码是:

parser grammar ChannelParser;

options
{
  // antlr will generate java lexer and parser
  language = Java;
  // generated parser should create abstract syntax tree
  output = AST;
}






// ***************** parser rules:
//our grammar accepts only salutation followed by an end symbol

expression
:

tcpChannelDefinition listenerDefinition  executionDefintion endchannel

;


tcpChannelDefinition
  :
  Define Tcpchannel channelName
  ;

channelName
  :
  i= Value
               {
                $i.setText("CHANNEL_NAME#" + $i.text);
               }
  ;

listenerDefinition
  :
  Define Listener listenerProperty endListener

  ;

listenerProperty
  :
  i=Value
            {
            $i.setText("PROPERTY_VALUE#" + $i.text);
            }

  ;

  endListener
  :
  End Listener SColon
  ;

executionDefintion
  :
     Define Execution execution 
  ;

execution
:
    Request With Format requestValue Comma
    Response With Format responseValue Comma
    Error With Format errorValue Comma
    Call servicename Dot executionname
;

requestValue
:
i=Value
  {
    $i.setText("REQUEST_FORMAT#" + $i.text);
    }

;  

responseValue
:
i=Value
 {
  $i.setText("RESPONSE_FORMAT#" + $i.text);
  }

; 

errorValue
:
i=Value
 {
   $i.setText("ERROR_FORMAT#" + $i.text);
  }

;

servicename
:
i=Value
  {
    $i.setText("SERVICE_NAME#" + $i.text);
     }

 ;

executionname
 :
 i=Value
  {
    $i.setText("OPERATION_NAME#" + $i.text);
    }

;

 endexecution
  :

 End Define Execution SColon
  ;

 endchannel
 :
 End Channel SColon

 ;

我在tcpChannel'中错过了丢失Tcpchannel的错误和无关的输入'频道名称'期待定义。如何纠正它们。请帮忙.ASAP

0 个答案:

没有答案