in Appendix P? I am writing a tool to analyze the Ada source file with the grammar in App...">

How does ["03C0"] correspond to the <Ada Reference Guide> in Appendix P?

I am writing a tool to analyze the Ada source file with the grammar in Appendix 2005 of the document.

  • Using the following code snippet, I know that ["03C0"] means "Greek letter Pi", but is this a variable name?

     01 package Ada.Numerics is 02 Pi : constant := 3.14159_26535_89793_23846_26433_83279_50288_41971_69399_37511; 03 ["03C0"] : constant := Pi; 04 e : constant := 2.71828_18284_59045_23536_02874_71352_66249_77572_47093_69996; 05 end Ada.Numerics; 
  • When using grammar to parse line 03, I am currently moving to "basic_declaration". What is the following rule? And the following next rule? Next next next rule? Until ["03C0"] is successfully analyzed. In the end, the question should be: Which rule has been analyzed ["03C0"]?

The Ada Reference Guide is located at: http://www.adaic.org/resources/add_content/standards/05rm/RM-Final.pdf

Ada Reference Guide Page 702 in PDF , p. 676 in the lower right corner of the page. Annex P / 3.1

  3.1 basic_declaration ::= type_declaration | subtype_declaration | object_declaration | number_declaration | subprogram_declaration | abstract_subprogram_declaration | null_procedure_declaration | package_declaration | renaming_declaration | exception_declaration | generic_declaration | generic_instantiation 

I conducted a further investigation based on oenone's answer.

  • If I use ["03C0"] in the code, the character set does not have to be "UTF-8", which makes sense. When compiled, I need "gnatmake -gnatWb Hello.adb".
  • If I use p in the code, I have to change the character set to "UTF-8", otherwise the GPS will not recognize this character and will not ask for a message. After I changed it to UTF-8, I need to use the "gnatmake -gnatW8 Hello.adb" command to compile.
  • I tried to change ["03C0"] to ["abcd"] and compile it again, it will fail by indicating "invalid wide character in identifier".
    I GUESS: If ["03C0"] is parsed only by grammar, ["abcd"] will also pass a grammar check. Therefore, from the result of the failure and the message, I can say that GNAT works this way: there is a pre-process source file in front of the grammar parser. The preliminary process will evaluate the value of Unicode, check whether it is in an acceptable wide character set. If it is inside a valid wide character set, it will continue to send to the parser. Otherwise, a failure.
+4
source share
1 answer

1: see A.5 Numerics Package - RM uses the correct Unicode character. Your quote seems to be from the GNAT package. To do this, see the GNAT User Guide on how to tell GNAT which encoding it should use.

2: There is no rule from ARM. This is a coding issue that is implemented by the implementation (GNAT). ["03C0"] (with -gnatWb, which by default) is treated as π (with -gnatW8) or even Pi as a valid identifier for a variable name (or in this case a constant).

+4
source

All Articles