用 flex和bison 解析配置文件

flex和bison是常用的词法分析和语法分析工具, flex可以将源文本以指定个规则识别为单词, bison可以将这些识别出来的单词进行结构化处理。下面可以通过一个bind9 config 解析程序进行说明。 词法分析,语法分析编译过程也是两个过程,通过词法分析, 语法分析, 语义分析前端工作完成输入源代码的识别, 通过中间语言,优化方式完成实现代码可扩展和优化(中端工作), 最终通过生成目标码, 一般也成为后端工作, 实现把源代码变成目标代码的过程。 使用flex和bison可以方便的解析配置文件。就是把字符串分解为token,再将这些token解析到配置文件对应的结构。为之后提供查询修改。 仅简单分析一下包含zone block的bind9配置 识别token bind9.l 标识出要是别的关键字, 也可以过滤掉一些注释和空白字符 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 %{ #include <stdio.h> #include <stdlib.h> #include "y.tab.h" #include "tree.h" %} %% [ \t\r\n]+ /* ignore whitespace*/ "//"(.)*"\n" /* ignore single-line comments */ "/*"(.)*"*/" /* ignore multi-line comments */ "{" { return LBRACE; } "}" { return RBRACE; } ";" { return SEMICOLON; } "=" { return EQUALS; } "zone" { return ZONE; } [a-zA-Z0-9\._/\-]+ { yylval.value = strdup(yytext); return NAME; } \"[^"]*\" { yylval.value = strdup(yytext); return STRING; } %% int yywrap() { return 1; } ...

2023-04-24 · 8 min · 1635 words · Garlic Space

SSL证书与私钥的编码格式和文件扩展名

...

2023-04-09 · 4 min · 712 words · Garlic Space

Emiller’s Advanced Topics In Nginx Module Development

原文链接

2023-03-30 · 10 min · 2008 words · Garlic Space

X.509 certificates

 X.509是定义的一个公钥证书格式标准。 RFC 5280 详细描述公钥证书,包括它们的字段和扩展名。 ...

2023-03-09 · 2 min · 222 words · Garlic Space

Emiller’s Guide To Nginx Module Development

原文链接:https://www.evanmiller.org/nginx-modules-guide.html 要充分理解网络服务器 Nginx,有助于理解漫画人物蝙蝠侠。 蝙蝠侠很快。 Nginx 很快。蝙蝠侠打击犯罪。 Nginx 与浪费的 CPU 周期和内存泄漏作斗争。蝙蝠侠在压力下表现出色。就 Nginx 而言,它在服务器负载很重的情况下表现出色。 但如果没有蝙蝠侠实用腰带,蝙蝠侠几乎什么都不是。 ...

2023-03-05 · 17 min · 3508 words · Garlic Space

Why does calloc exist?

 原文链接:https://vorpus.org/blog/why-does-calloc-exist/ ...

2023-01-29 · 4 min · 687 words · Garlic Space

leetcode - Monotonic Array

问题: An array is monotonic if it is either monotone increasing or monotone decreasing. An array nums is monotone increasing if for all i <= j, nums[i] <= nums[j]. An array nums is monotone decreasing if for all i <= j, nums[i] >= nums[j]. Given an integer array nums, return true if the given array is monotonic, or false otherwise. 解答: 单调数组,当数组个数大于2时, 遍历数组, 通过比较当当前值与前一个值的,确定其是递增还是递减, 遍历过程中,如果有变化那么则不满足单调性。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 def isMonotonic(array): if len(array) <= 2: return True direction = array[1] - array[0] for i in range(2, len(array)): if direction == 0: direction = array[i] - array[i-1] continue if breakDirection(direction , array[i], array[i-1]): return False; return True; def breakDirection (direction, val, preval): diff = val - preval if direction > 0: return diff < 0 else: return diff > 0 ...

2023-01-23 · 1 min · 189 words · Garlic Space

Linux sed 中的&

一次使用sed 替换操作,替换后的字符串包含 &,替换文本如下

2022-12-03 · 1 min · 65 words · Garlic Space

ubuntu 忘记密码

...

2022-12-03 · 1 min · 43 words · Garlic Space

Nginx Development guide

这篇文章来自nginx document /http://nginx.org/en/docs/dev/development_guide.html nginx的开发指南 ...

2022-11-15 · 77 min · 16248 words · Garlic Space