1

私は bison プログラムを開発しており、何かを認識できるようにする最後のオプションが必要です。他の場合と同じように...

ありがとう

commands: F{
            t[top++] = 'F';
            }
      |PLUS{
            t[top++] = '+';
            }
      |MINUS{
            t[topo++] = '-';
            }
      |ACOL { 
            t[top++] = '[';
            }
      |FCOL{
            t[top++] = ']';
            }
      |POINT{
             t[top++] = '.';
            }
      |EQUAL {
            t[top++] = '=';
            }
      | {  
           /* generic command should be here
           if any of the commands above were found it should run whatever is here*/
      }
4

1 に答える 1

1

以下のように、任意のコマンド トークンが認識された後に実行するロジックをマーカーの非終端記号にアタッチします。の生成の右側がmarkerどのトークンとも一致しないことに注意してください。

command_and_marker: command marker;

command:  F
            {
            t[top++] = 'F';
            }
        | PLUS
            {
            t[top++] = '+';
            }
        | MINUS
            {
            t[topo++] = '-';
            }
        | ACOL
            { 
            t[top++] = '[';
            }
        | FCOL
            {
            t[top++] = ']';
            }
        | POINT
            {
            t[top++] = '.';
            }
        | EQUAL
            {
            t[top++] = '=';
            } 
marker:     {  
            /* generic command should be here
            if any of the commands above were found it should run whatever is here*/
            }

コード内のコメントと一致するように回答を作成しましたが、これは質問のテキストと多少矛盾しています。、 などだけでcommandなく、何かと一致させたい場合は、レクサーが. いくつかの理由から、これは必ずしも良い考えではありません。FPLUScommand

于 2012-11-16T14:45:14.787 に答える