["03C0&"]如何匹配附件P中的"Ada参考手册"语法? [英] How ["03C0"] match <Ada Reference Manual>'s grammar in Annex P?

查看:117
本文介绍了["03C0&"]如何匹配附件P中的"Ada参考手册"语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一种工具,以使用2005年附录P中提供的语法来解析Ada源文件.

I'm writing a tool to parse Ada source file with the grammar provided in 2005 Annex P.

  1. 在下面的代码中,我知道 ["03C0"] 代表希腊字母Pi",但这是合法的变量名吗?

  1. With following piece of code, I know ["03C0"] stands for "greek letter Pi", but is it a legal 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;

  • 使用语法分析第03行时,我目前进入"basic_declaration".下一条规则是什么?接下来的下一条规则?下一个下一个下一条规则?直到可以成功解析["03C0"].最终,问题应该是:哪个规则解析为["03C0"]?

    Ada参考手册位于: http://www.adaic.org/resources/add_content/standards /05rm/RM-Final.pdf

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

    Ada参考手册PDF的第702页,位于页面右下角的页面676. 附件P/3.1

    Ada Reference Manual Page 702 in PDF, Page 676 at the right down 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
    

    我已根据 oenone 的答案进行了进一步调查.

    I've done further investigation based on oenone's answer.

    1. 如果我在代码中使用["03C0"],则字符集不必为"UTF-8",这很有意义. 编译时,我需要"gnatmake -gnatWb Hello.adb".
    2. 如果在代码中使用p,则必须将字符集更改为"UTF-8",否则GPS将无法识别该字符并提示消息. 将其更改为UTF-8后,需要使用"gnatmake -gnatW8 Hello.adb"进行编译.
    3. 我试图将["03C0"]更改为["abcd"] ,然后再次编译,它将失败,并显示标识符中的无效宽字符".
      我猜:如果仅通过语法分析["03C0"],则["abcd"]也将通过语法检查. 因此,从失败结果和消息中,我可以说,GNAT以这种方式工作: 在将源文件发送到语法分析器之前,需要进行预处理. 预处理将评估unicode值,检查其是否在有效的宽字符集中. 如果它在有效的宽字符集内,它将继续发送到语法解析器.否则,失败.
    1. If I use ["03C0"] in the code, the character set does not need to be "UTF-8", which makes sense. When compile, I need "gnatmake -gnatWb Hello.adb".
    2. If I use p in the code, I must change the character set to "UTF-8", otherwise the GPS will not recognize this character and prompt a message. After I change it to UTF-8, I need to use "gnatmake -gnatW8 Hello.adb" to compile.
    3. I tried to change ["03C0"] to ["abcd"] and compile again, it will fail, saying "invalid wide character in identifier".
      I GUESS: If ["03C0"] is parsed by grammar only, ["abcd"] will also pass the grammar check. So from the fail result and message, I can say, GNAT works in this way: there is a pre-process before send source file to the grammar parser. The pre-process will evaluate the unicode value, check whether or not it is in the valid wide character set. If it is inside the valid wide character set, it will continue send to the grammar parser. Otherwise, fail.

    推荐答案

    1:请参见 GNAT用户指南关于如何告诉GNAT应该使用哪种编码.

    1: see A.5 The Numerics Package - the RM uses the correct unicode character. Your quote seems to be from the GNAT package. For this, see the GNAT Users Guide about how to tell GNAT which encoding it should use.

    2:ARM没有规则.这是一个编码问题,由实现(GNAT)完成. ["03C0"](带有-gnatWb,默认设置)的处理方式与π(带有-gnatW8)或什至Pi作为变量名(或本例中的常量)的有效标识符一样.

    2: No rule from the ARM. It is an encoding question, which is done by the implementation (GNAT). ["03C0"] (with -gnatWb, which is default) is handled like π (with -gnatW8) or even Pi as valid identifier for a variable name (or in this case constant).

    这篇关于["03C0&"]如何匹配附件P中的"Ada参考手册"语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆