The Backus-Naur Form (BNF) & The Extended Backus-Naur Form (EBNF)

2023-11-13

The Backus-Naur Form (BNF)

The Backus-Naur Form (BNF) is a notation used for formal description of the syntax of programming languages. Developed by John Backus and Peter Naur in the late 1950s to early 1960s, BNF is designed to provide a clear, concise, and unambiguous way to describe the grammatical rules of languages.

Structure and Components

BNF consists of a set of production rules. A typical production rule looks like:

<non-terminal> ::= expression
  • Non-terminal: This represents an abstract syntactic structure and is usually enclosed in angle brackets < >.
  • Terminal: These are the actual symbols or tokens used in the language, such as keywords, operators, and punctuation marks.
  • Expression: Composed of terminals and/or non-terminals, this part describes how to generate or parse a specific non-terminal.

A non-terminal can be defined by multiple expressions, usually separated by a pipe | to signify alternative options. For instance:

<sentence> ::= <subject> <predicate> <object>
<subject> ::= "I" | "You" | "He"
<predicate> ::= "eat" | "drink" | "play"
<object> ::= "apple" | "water" | "ball"

Applications

BNF is widely used for the design and documentation of programming languages, data exchange formats, and protocols. It provides language designers with a precise, unambiguous method to describe language structure. It’s also commonly used in the development of compilers and interpreters.

Relation with EBNF

EBNF (Extended Backus-Naur Form) is an extension of BNF, offering more expressive power like repetition, optional elements, and grouping.

Advantages and Limitations

  • Advantages: BNF offers a clear, precise, and systematic way to describe the syntax of languages or data formats.
  • Limitations: BNF’s expressive power is relatively limited, making it less straightforward or easy to represent some complex syntactic structures.

In summary, BNF is a critical tool for formally defining the syntax of programming languages and data structures. While it has its limitations, many of these can often be overcome by using its extended forms, such as EBNF.

The Extended Backus-Naur Form (EBNF)

The Extended Backus-Naur Form (EBNF) is a formal notation used to describe the syntax of programming languages, document formats, or communication protocols. It serves as a way to formally specify the grammatical rules that make up the valid sentences (or expressions) in a particular language or format. EBFN is an extension of the original Backus-Naur Form (BNF), adding a few more expressive features to make it easier to specify complex rules.

Structure and Components

EBNF grammars are typically made up of a series of production rules, written as follows:

<non-terminal> ::= expression

Here, <non-terminal> is a placeholder that stands for a class of syntactic structures, and expression defines how those structures can be formed.

The expression can be a combination of:

  • Terminals: These are the actual symbols that appear in the language. For example, specific keywords like if, else, numbers, or other literal tokens.
  • Non-terminals: These are placeholders for patterns that will be defined elsewhere in the EBNF specification.
  • Operators: EBNF includes operators for sequence (,), choice (|), optional elements ([...]), repetition ({...}), and grouping ((...)).

For example, a simple EBNF rule for a conditional statement in a hypothetical programming language might look like:

<conditional-statement> ::= 'if' '(' <expression> ')' <statement> [ 'else' <statement> ]

Extended Features

Some of the features that set EBNF apart from BNF include:

  • Optional Elements: Square brackets [...] denote optional elements.

    ["else" <statement>]
    
  • Repetitions: Curly brackets {...} indicate zero or more repetitions of an element.

    {<statement>}
    
  • Grouping: Parentheses (...) are used for grouping elements together, often to resolve ambiguities or to apply repetition/optional markers to a group.

    ('a' | 'b') 'c'
    
  • Comments and Annotations: Some variants of EBNF allow for comments and annotations to describe rules in a more human-readable way.

Importance

EBNF is widely used in the development of compilers and interpreters, for auto-generating code, and for validating formats. By providing a formal way to describe language syntax, it helps eliminate ambiguities that might otherwise exist when trying to describe complex syntactical rules in natural language.

In summary, EBNF is a powerful tool for formally specifying the syntax of languages, extending the capabilities of the original BNF by adding expressive constructs that make it easier to define complex grammatical rules.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

The Backus-Naur Form (BNF) & The Extended Backus-Naur Form (EBNF) 的相关文章

  • LLVM Language Reference Manual

    摘要 该文档是LLVM汇编语言的参考指南 LLVM是基于表示的静态单赋值 SSA 该表示提供类型安全 低层级操作 灵活性 及简洁表示所有高层级语言的能力 这是贯穿各方面LLVM编译策略的通用代码表示 简介 LLVM代码表示用于三个不同形式
  • 合肥工业大学编译原理实验二 LL1分析

    写在开头 当老师说这个实验最好写成图形界面时 我笑了 滑稽 心想终于可以用到python了 python真香 用python的数据结构可以很方便的表示LL1的某些东西 当然有利也有弊 方便的同时也会有一些坑 当然Java也牛逼 Java的图
  • 静态单赋值(二)—gcc中的SSA化算法

    版权声明 本文为CSDN博主 ashimida 的原创文章 遵循CC 4 0 BY SA版权协议 转载请附上原文出处链接及本声明 原文链接 https blog csdn net lidan113lidan article details
  • 将NFA变成最小化DFA的方法

    学习的时候总感觉这个遇到新的题目不会做 这里总结一下 整个流程是这样的 我们直接来看一个例子 使用上面的算法来实现我们最后的目标 a b ba ab 我们先来画NFA 明确 开始状态和接受状态 终结状态要画两个圈 值得注意的是 由于 也可以
  • 编译原理之first集,follow集,select集解析

    为了方便自顶向下语法分析 需要求文法对应的first集 follow集 以及select集 本文主要分为两部分 一个是求法解析 还有一个例子详解 第一部分是求法解析 将对first集 follow集 select集分为三种讲解方法 定义介绍
  • Code Block & Basic Block

    Code Block In a programming language a code block typically starts with certain syntactical constructs such as loops con
  • 编译原理------语法分析器C/C++代码实现

    一 实验目的 编制一个递归下降分析程序 实现对词法分析程序所提供的单词序列的语法检查和结构分析 二 实验内容 利用C语言编制递归下降分析程序 并对简单语言进行语法分析 2 1 待分析的简单语言的语法 用扩充的BNF表示如下 lt 程序 gt
  • 用 Rust 编写一个简单的词法分析器

    词法分析是编译器和解释器的第一个环节 相对而言也比较简单 词法分析器 有时也称为单元生成器 tokenizer 或者扫描器 scanner 将源代码转换为词法单元 这个过程称为词法分析 本文代码设计复刻自 用Go语言自制解释器 词法分析器一
  • 编译课设 (词法分析+LR1语法分析+语法制导翻译(四元式生成))

    代码已上传至 Github 完整的 VS2019 项目已上传至百度云 提取码 lql1 目录 源语言 语义动作 中间代码定义 整体框架 声明 语句 i f if if 语句
  • C++ 实现自动产生LR1分析器的产生器

    C 实现自动产生LR1分析器的产生器 1 介绍 2 总体思路 2 1 拓广文法 2 2 计算First集合 2 3 计算每个闭包的项目集以及GO函数 2 4 计算分析表的动作函数ACTION和状态转换函数GOTO 2 5 对语句进行语法分析
  • LLVM里的寄存器分配 - 准备工作(一)

    1 背景介绍 本文档是基于 LLVM 的寄存器分配系列科研笔记第一篇 以一个 C 语言程序为主干介绍 LLVM 在寄存器分配前做的一些主要工作 分析在寄存器分配前期可能的写操作来源 并记录了我在研究 LLVM 后端中 SSA 形式的中间表示
  • 简单的递归下降语法分析程序

    简单递归分析程序 其代码如下 include
  • 编译原理基础知识+笔记(1)

    一 编译原理概述 1 翻译程序 把某一种语言程序 称为源语言程序 等价地转换成另一种语言程序 称为目标语言程序 的程序 2 编译程序 把某一种高级语言程序等价地转换成另一种低级语言程序 如汇编语言或机器语言程序 的程序 又分为 诊断编译程序
  • 编译原理 CS-143(更新至week4)

    编译原理 CS 143 Pre Course Survey Navigation Your Course 01 01 Introduction 8m20s 01 02 Structure of a Compiler 13m53s 编译器结构
  • 编译原理——自顶向下分析中FOLLOW集的计算

    一 FOLLOW集的定义 对于非终结符号A FOLLOW A 被定义为 可能在某些句型中紧跟在A右边的终结符号的集合 为什么说是可能 因为在一些推导出来的文法符号串中 该非终结符号A可能在最右边 比如 A gt TA 如果存在S gt Aa
  • 正规表达式与有限自动机

    1 美图 2 概念 3 正规式和正规集 正规集可以用正规表达式 简称正规式 表示 正规表达式是表示正规集一种方法 一个字集合是正规集当且仅当它能用正规式表示 3 1 正规式和正规集的递归定义 4 确定有限自动机 DFA
  • 递归下降算法语法分析c语言

    递归下降算法 自上而下文法的递归下降的预测分析 从根节点出发逐步构造分析树 所以被称作自上而下文法 在文法中有递归的函数 例如 E gt TE 所以叫做递归下降算法 使用的文法如下 E gt TE E gt TE e T gt FT T g
  • Flex程序编译

    Makefile三要素 目标 依赖 命令 详解可见makefile 编写 周北 CSDN博客 makefile 编写 Makefile中常用函数和自动化变量 wildcard 扩展通配符 例 OBJECTS wildcard o 该找到目标
  • 编译原理_计算器_flex、bison实现(详细辅助理解)

    编译原理 计算器 flex bison实现 详细辅助理解 个人博客 https www yuque com ngp blog tuanh6 https www yuque com ngp blog tuanh6 P S 这篇文章只能助你理解
  • Compiler- 自增运算

    我们来看一下C语言中的前自增 i 和后自增 i 这个经典案例 大家在学习C的时候肯定学过前自增是先自增 然后将结果用于计算 后自增是先参与计算 再增加 好 看一下这段代码的结果 include

随机推荐

  • 关于Linux/Ubuntu重置用户名密码

    Step1 重启 往死里按Esc或等启动后嗯Enter Step2 成功后会进入如下界面 这一步后如果你已经知道root密码 请直接跳到Step8 Step3 在菜单Ubuntu这摁 e 进入编辑模式 对标出行 做出如下修改 Step4 根
  • 零信任架构简介

    2021 年被誉为网络安全元年 种种因素极大的驱动了零信任成为安全新风口 零信任也无疑成为了整个安全圈包括网络安全领域最热门的词汇之一 什么是零信任 零信任既不是单一的产品 也不是单一的技术 它是一种安全理念以及安全架构 核心原则是持续验证
  • SV中program & module

    相同之处 1 和module相同 program也可以定义0个或多个输入 输出 双向端口 2 一个program块内部可以包含0个或多个initial块 generate块 specparam语句 连续赋值语句 并发断言 timeunit声
  • GPS 的PPS

    校准RTC时间的方法 首先需要一个准确的外部信号 比如GPS来的秒信号 或者其它很准确的信号 然后通过定时器来测量RTC的晶振误差 然后再对该误差进行校准 面接收机GPS的秒脉冲精度 也就是相邻两个秒脉冲上升沿的间隔精度能到100ns 授时
  • HTML+CSS+JS制作【飞机大战】小游戏(键盘版和鼠标版)

    文章目录 一 效果演示 设计思路 二 鼠标版飞机大战代码展示 1 HTML结构代码 2 CSS样式代码 3 JavaScript代码 js js文件 plane js文件 三 键盘版飞机大战代码展示 1 HTML结构代码 2 CSS样式代码
  • eclipse下maven打包失败(Please ensure you are using JDK 1.4 or above and not ......

    在eclipse下用maven编译时 可能会失败 报出以下提示 ERROR Unable to locate the Javac Compiler in ERROR C Program Files Java jre1 8 0 72 lib
  • 【ABviewer从零开始教学查看器篇①】3D查看器和3D剖面板

    ABViewer是一款高质量 高效率 低成本的多功能设计及工程文档管理工具 能为您提供全面的专业的浏览及编辑功能 同时支持30多种光栅和矢量图形格式 在小编看来 ABViewer是一款非常简单且实用的CAD文档查看与编辑器 对于使用小白可能
  • 华为云计算相关知识点

    云计算离不开网络基础设施 云计算中的网络分为不同的平面 管理平面 负责整个系统的监控 操作维护 系统配置 系统加载 告警上报 和虚拟机管理 创建 删除虚拟机 虚拟机调度 等 存储平面 主要为存储系统提供通信平面 并未虚拟机提供存储资源 用于
  • 你的数据隐私值多少钱?也许已有答案了

    全文共6032字 预计学习时长12分钟 图片来源 Timo Lenzen 对于一些大型科技公司来说 这一年侵犯用户隐私付出的代价变高了 未来还会更高吗 今年7月 脸书在受到有关泄露数亿用户数据隐私的指控后 同意缴纳50亿美元的罚金 同一周内
  • 【TOOLS】Python 3利用SMTP进行邮件Email自主发送

    作者 Che Hongshu 来源 AI蜗牛车 ID AI For Car 一 前言 利用Python进行邮件的发送 这个功能自我感觉主要应用于检测或者报告之类 我两次运用这个功能 第一次用在主要发送实时的数据给一个邮箱 第二次用是检测挂在
  • VS调试:函数断点与数据断点

    断点 是Debug过程中最常用的功能 关于断点VS还有很多高级功能 本文使用的是VS2017 介绍函数断点与数据断点的使用场景以及使用方法 1 普通断点 普通断点是最常接触的断点 VS中 在代码行左边栏灰色区域点击 或者把光标放在某代码行按
  • 使用Python编写Maya脚本插件批量导入Obj文件

    最近开发中遇到需要使用Python语言编写Maya脚本 要求使用脚本选择某一磁盘路径 脚本根据路径自动导入路径与子目录下的所有OBJ文件 并重命名它们 在Maya中 有自带的脚本编辑器供我们使用 这使得我们编写代码非常轻松 打开脚本编辑器
  • Installation did not succeed. The application could not be installed: INSTALL_FAILED_USER_RESTRICTED

    当我们第一次在我们的手机上 也就是物理设备上 运行我们的写好的安卓应用程序时可能会报以下错误 Session app Installation did not succeed The application could not be ins
  • 互斥锁的实现细节

    首先 一个互斥锁要实现什么功能 一个互斥锁需要有阻塞和唤醒功能 实现阻塞和唤醒功能需要哪些要素 需要有一个标记锁状态的state变量 需要记录哪个线程持有了锁 需要有一个队列维护所有的线程 另外 state和队列中为了实现线程安全都用到了C
  • Java - 将base64编码解码成图片

    为了方便测试 我们可以使用一个图片编码网站 将图片进行base64编码 解密的代码如下 public static String generateImage String base64 String path 解密 try String s
  • 计算机视觉(十六):目标检测概述

    1 什么是目标检测 目标检测 Object Detection 的任务是找出图像中所有感兴趣的目标 物体 确定它们的类别和位置 例子 确定某张给定图像中是否存在给定类别 比如人 车 自行车 狗和猫 的目标实例 如果存在 就返回每个目标实例的
  • 配置哨兵监控Redis运行情况

    Redis的主从架构 如果master发现故障了 还得手动将slave切换成master继续服务 手动的方式容易造成失误 导致数据丢失 那Redis有没有一种机制可以在master和slave进行监控 并在master发送故障的时候 能自动
  • 动态链接库(二)--动态链接库的创建

    开发环境 系统 Win10企业版 64位 vs版本 Microsoft Visual Studio 2010 版本10 0 Dll项目创建 为从头了解dll项目中各文件的来源 这里暂不使用vs新建项目列表中的动态链接库 DLL 向导 选择创
  • OJDBC8 12.2.0.1下载

    一 进入oracle官网 注册oracle账户 登入oracle官网 二 在oracle官网找到ojdbc8的下载地址 地址如下 https www oracle com database technologies jdbc ucp 122
  • The Backus-Naur Form (BNF) & The Extended Backus-Naur Form (EBNF)

    The Backus Naur Form BNF The Backus Naur Form BNF is a notation used for formal description of the syntax of programming