Loading ...
Sorry, an error occurred while loading the content.

Re: Rules for STRING, CHAR, DIGIT

Expand Messages
  • gita roy
    Hi, I am new to Antlr and using C++ to parse some file having Identifiers as digits, Strings (starting with alphabets), char (starting with digits) Add an
    Message 1 of 2 , Apr 3, 2003
    • 0 Attachment
      Hi, 
      I am new to Antlr and using C++ to parse some file having Identifiers as digits, Strings (starting with alphabets), char (starting with digits)

      Add an IDENTIFIER rule and ANTLR can then check the text against the literals table.

      In my case I want the one IDENTIFIER rule, lets say rule for DIGIT:

      .

       

      DIGIT : (‘0’..’9’)+

      ;

       

      And in another IDENTIFIER like STRING I define the rule:

       

      STRING : ((‘A’..’Z’) (“%”)? (‘0’..’9’))+

      ;

       

      My purpose will be to parse some token “Circuit12” as STRING and at the same time some token may checked as DIGIT.  In third case I need to verify some token as CHAR whose first position may or may not be digits.

       

      So lexer class is as follows:

       

       class MyLexer extends Lexer;

      options {

      k=10;

      filter=true;

      }

       

      DIGIT

                  : (('0'..'9')+

                  ;

       

      STRING : ((‘A’..’Z’) (“%”)? (‘0’..’9’))+

      ;

       

      CHAR

                  : ((DIGIT)? STRING)+

                  ;

       

      Add all IDENTIFIER rules and ANTLR can then check the text against the literals table, but for the case of char antlr is giving error.

       

      • The rule methods like mDIGIT are missing in MyLexer.cpp.

       

       

      • How can I check the identifier Circuit12, 12, 12Circuit, using the abovedefined rules.

       

      Please help.

       

      Thanks in advance.

       

      Gita 



      Yahoo! Mail - For a better Internet experience
    • gita roy
      Hi, I am new to Antlr and using C++ to parse some file having Identifiers as digits, Strings (starting with alphabets), char (starting with digits) Add an
      Message 2 of 2 , Apr 3, 2003
      • 0 Attachment
        Hi, 
        I am new to Antlr and using C++ to parse some file having Identifiers as digits, Strings (starting with alphabets), char (starting with digits)

        Add an IDENTIFIER rule and ANTLR can then check the text against the literals table.

        In my case I want the one IDENTIFIER rule, lets say rule for DIGIT:

        .

         

        DIGIT : (‘0’..’9’)+

        ;

         

        And in another IDENTIFIER like STRING I define the rule:

         

        STRING : ((‘A’..’Z’) (“%”)? (‘0’..’9’))+

        ;

         

        My purpose will be to parse some token “Circuit12” as STRING and at the same time some token may checked as DIGIT.  In third case I need to verify some token as CHAR whose first position may or may not be digits.

         

        So lexer class is as follows:

         

         class MyLexer extends Lexer;

        options {

        k=10;

        filter=true;

        }

         

        DIGIT

                    : (('0'..'9')+

                    ;

         

        STRING : ((‘A’..’Z’) (“%”)? (‘0’..’9’))+

        ;

         

        CHAR

                    : ((DIGIT)? STRING)+

                    ;

         

        Add all IDENTIFIER rules and ANTLR can then check the text against the literals table, but for the case of char antlr is giving error.

         

        • The rule methods like mDIGIT are missing in MyLexer.cpp.

         

         

        • How can I check the identifier Circuit12, 12, 12Circuit, using the abovedefined rules.

         

        Please help.

         

        Thanks in advance.

         

        Gita 



        Yahoo! Mail - For a better Internet experience
      Your message has been successfully submitted and would be delivered to recipients shortly.