首页 > 其他分享 >[code notes] ecpg precompiler 1

[code notes] ecpg precompiler 1

时间:2024-04-19 11:45:34浏览次数:28  
标签:code buffer notes rule precompiler into type symbol ecpg

This note will introduce the workflow of parse.pl of the ecpg precompiler. Run the precompiler:

perl parse.pl . ../../../backend/parser/gram.y

workflow

  • load ecpg.addons into an memory hash table. The key is composed of string literals from a production rule with no delimiter. The value is also a hash table which has two keys(type and lines). The type value could be of: block, rule and addon. The lines value is the code from below the addons definition. For more detail, see src/interfaces/ecpg/preproc/README.parser.
    • For block type, the attached code is completely written as the new semantic action.
    • For rule type, the attached new rules is directly appended to the original rule.
    • For addon type, the attached code is prepended to the original semantic action.
  • read the gram.y file line by line until end of file
    • split the line by space into an array
    • load ecpg.tokens file content into memory buffer with tag tokens if not yet
    • load ecpg.header file content into memory buffer with tag header if not yet
    • load ecpg.types file content into memory buffer with tag ecpgtype if not yet
    • for each token line without token type specified in gram.y(includes %token, %nonassoc, %left, etc), add each word to the tokens set. Also, reconcatenate the words with single space. For the token %nonassoc IDENT, add one more token %nonassoc CSTRING. Finally, add the reconcatenated token line into memory buffer with tag orig_tokens.
    • skip other lines until the bison grammar rules section reached
    • read each rule until rule delimiter ';'. In the process, we skip semantic action and only take care of the rule symbol.
    • if the rule symbol is in replace_token hash table, update the rule symbol.
    • if the rule symbol is a non-terminal symbol,
      • and is not defined in replace_types hash table, then set the rule symbol type to str and mark this rule as 'copymode'.
      • and is told being ignored, then go to read the next line.
      • populate the memory buffer tagging with 'rules' with this non-terminal symbol
      • if the non-terminal symbol is stmt, remember the state.
      • define the type of the non-terminal symbol, such as %type <str> stmt, and then populate the memory buffer with tag 'types'.
      • remember we're in a rule and going to process the remaining fields
    • if the rule symbol is '%prec', mark this state
    • if we're in 'copymode' and no '%prec' found and in processing the remaining fields,
      • if the following two conditions are met:
        • the symbol is not 'Op', and it is in the tokens set or it is a single quoted string
        • we'are in stmt rule,
          then, get the target string if this symbol is in replace_string hash table otherwise use this symbol string as target. Push the target string, lowcase it if we're not in stmt rule, into fields array.
      • else, push the $n into fields array where n is one plus the length of fields array.
  • dump the memory buffer as the following order:
    • header
    • tokens
    • types
    • ecpgtype
    • orig_tokens
    • rules
    • trailer
      The trailer buffer is loaded with ecpg.trailer file contents.

标签:code,buffer,notes,rule,precompiler,into,type,symbol,ecpg
From: https://www.cnblogs.com/lddcool/p/18145475

相关文章

  • vscode使用PasteImage插入图片
    vscode使用PasteImage插入图片需求在vscode中写Markdown文件,经常需要插入图片,使用插件PasteImage进行简单配置后,就可以方便插入图片并自动存放到相应路径的文件夹中安装及配置安装从扩展商店搜索PasteImage并安装即可配置vscode设置中搜索PasteImage,找到PasteImage:......
  • vscode自定义log快捷生成代码
    1、进入设置页面:文件>首选项>用户代码片段>选择设置的语言。2、自定义打印:3、关于代码段显示位置的调整设置文件>首选项>设置,搜索代码段或snippetSuggestions,修改为”top”;4、页面中使用:输入log看效果 ......
  • 《Pyramid Codes: Flexible Schemes to Trade Space for Access Efficiency in Reliab
    问题1:Introduction部分,第五段,[16,12]ERC和3-Copy达到了相同的可靠性,在每一个块独立失败概率为0.01的情况下,这个是怎么证明的。问题2:同上,第五段后半部分,那么多的IO次数是怎么计算出来的。在系统中,要分清各种性能指标,读和写是不一样的,第六段提到的是写性能,主要方法就是先用复制的方......
  • vscode使用jupyter
    vscode使用jupyter环境配置要在vscode中使用jupyter,需要先需要确认python环境已经安装,且pip源切换为国内源,否则可能会出现无法下载依赖包的情况。可以参考python安装及pip源切换安装扩展在vscode中,使用扩展管理器安装python扩展和jupyter扩展。配置jupyter内核一种可以直......
  • 在 VSCode 中使用正则表达式的示例
    下面是一些在VSCode中使用正则表达式的示例。在某个文件中查找相同的单词假设有一个名为sample.txt的文件,其内容如下:thequickbrownfoxjumpsoverthelazydog.thequickbrowncatjumpsoverthelazydog.thequickredhenjumpsoverthelazydog.我们想要查......
  • LeetCode三则
    三道动态规划62.不同路径一个机器人位于一个mxn网格的左上角(起始点在下图中标记为“Start”)。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为“Finish”)。问总共有多少条不同的路径?输入:m=3,n=7输出:28输入:m=3,n=2输出:3解释:......
  • 【VSCode】远程编码,ssh连接卡在downloading vscode server
    这是因为墙的原因导致下载失败。1、进入目录查看下载节点进入服务器目录~/.vscode-server/bin:97开头的这一串是commitid2、下载文件使用commitid拼接下载路径:https://update.code.visualstudio.com/commit:${commit_id}/server-linux-x64/stable在本地下载之后,上传服务器......
  • 根据微信code获取换取用户登录态信息
    1.根据微信code获取换取用户登录态信息点击查看代码/***根据code获取小程序用户openpid*/@OverridepublicR<Map<String,String>>getUnitCheckPersonOpenId(Stringcode){R<Map<String,String>>resMap=newR<>();//获取......
  • leedcode-判断子序列
    自己写的,有点麻烦classSolution:defisSubsequence(self,s:str,t:str)->bool:#第一步先验证s是t的无序子序列#使用字典记录t中每个字符的出现次数mydict=dict()foriint:ifnotmydict.get(i):......
  • LeetCode 面试经典150题---008
    ####151.反转字符串中的单词给你一个字符串s,请你反转字符串中单词的顺序。单词是由非空格字符组成的字符串。s中使用至少一个空格将字符串中的单词分隔开。返回单词顺序颠倒且单词之间用单个空格连接的结果字符串。注意:输入字符串s中可能会存在前导空格、尾随空格......