Yacc 与 Lex 快速入门

yyparse() returns a value of 0 if the input it parses is valid according to the given grammar rules.

It returns a 1 if the input is incorrect and error recovery is impossible.

yyparse() does not do its own lexical analysis. In other words, it does not pull the input apart into tokens ready for parsing.

Instead, it calls a routine called yylex() everytime it wants to obtain a token from the input.

yylex() returns a value indicating the type of token that has been obtained.

If the token has an actual value, this value (or some representation of the value, for example, a pointer to a string containing the value) is returned in an external variable named yylval.

It is up to the user to write a yylex() routine that breaks the input into tokens and returns the tokens one by one to yyparse().

See Function section for more information on the lexical analyzer.

How yacc works

The input to yacc describes the rules of a grammar. yacc uses these rules to produce the source code for a program that parses the grammar.

You can then compile this source code to obtain a program that reads input, parses it according to the grammar, and takes action based on the result.

The source code produced by yacc is written in the C programming language. It consists of a number of data tables that represent the grammar, plus a C function named yyparse().

By default, yacc symbol names used begin with yy. This is an historical convention, dating back to yacc's predecessor, UNIX yacc.

You can avoid conflicts with yacc names by avoiding symbols that start with yy.

If you want to use a different prefix, indicate this with a line of the form:

%prefix prefix

at the beginning of the yacc input. For example:

%prefix ww

asks for a prefix of ww instead of yy. Alternatively, you could specify -p ww on the lex command line.

The prefix chosen should be 1 or 2 characters long; longer prefixes lead to name conflicts on systems that truncate external names to 6 characters during the loading process.
In addition, at least 1 of the characters in the prefix should be a lowercase letter
(because yacc uses an all-uppercase version of the prefix for some special names, and this has to be different from the specified prefix).

Note

Different prefixes are useful when two yacc-produced parsers are to be merged into a single program.
For the sake of convenience, however, the yy convention is used throughout this manual.
 

yyparse() and yylex()的更多相关文章

  1. Compiler Theory(编译原理)、词法/语法/AST/中间代码优化在Webshell检测上的应用

    catalog . 引论 . 构建一个编译器的相关科学 . 程序设计语言基础 . 一个简单的语法制导翻译器 . 简单表达式的翻译器(源代码示例) . 词法分析 . 生成中间代码 . 词法分析器的实现 ...

  2. [转载] 如何使用Lex/YACC

    原文: http://segmentfault.com/a/1190000000396608?hmsr=toutiao.io&utm_medium=toutiao.io&utm_sou ...

  3. php 词法分析,语法分析

    php的词法分析 可以理解为 通过一定的规则,把输入的代码 区分出哪些是 是$开头的变量, 哪些是 以两个单引号括起来的字符串,哪些是以两个双引号括起来的字符串 等等, 这些区分出来的东西 称为tok ...

  4. check fasta format

    reference: https://www.biostars.org/p/42126/ fasta.y %{ #include <stdio.h> #include <stdlib ...

  5. Android编译环境折腾记

    题记:感觉是时候写点什么了=_=! 第一次安装了ubuntu14.04.5,官网下载的iso,官网下的jar,编译android4.x需要安装jdk6,更高的版本会有问题,baidu到很多搭建环境的步 ...

  6. 更改make/bison的版本

    一.make版本 1.下载make的压缩包 ftp://ftp.gnu.org/gnu/make/ 2.解压,安装 cd make-x.x ./configuration sh build.sh su ...

  7. Lex&Yacc Parser错误发生后再次parser之前恢复初始状态

    使用lex yacc 对文件进行parser时,如果文件内容有错,parser报错,然后你修改了文件,再次读入文件进行parser,如果你不是重启程序进行parser,那就需要对做些处理了. &quo ...

  8. lex中yyrestart()的使用

    使用lex&yacc时,如果文件有错,parse停止. "每次调用yyparse(),语法分析器会忘记上次分析可能拥有的任何状态而重新开始分析.这不像lex产生的词法分析器的yyle ...

  9. [转载]Bison-Flex 笔记

    FLEX 什么是FLEX?它是一个自动化工具,可以按照定义好的规则自动生成一个C函数yylex(),也成为扫描器(Scanner).这个C函数把文本串作为输入,按照定义好的规则分析文本串中的字符,找到 ...

随机推荐

  1. 在IDEA中使用gradle配置打可执行jar包[可执行jar与其所依赖的jar分离]

    下面是我的项目的build.gradle文件的所有内容,注意高亮部分是关键: group 'com.xbs' version '1.0-SNAPSHOT' apply plugin: 'java' a ...

  2. Linux系统声卡问题

    问题:Linux系统中有声卡设备,但是听不到声音 一.声卡驱动没有安装 1.通过插拔声卡查出声卡驱动 2.在相应的kernel中编译内核 修改保存.config文件,然后进行编译 make -j ma ...

  3. TableView中Label自适应高度

    //Xcode6.3以后label自适应需要添加两个属性 _tableView.rowHeight = UITableViewAutomaticDimension; //给予预计行高 _tableVi ...

  4. 29-jsp中用js进行时间格式转化

    CST可以为如下4个不同的时区的缩写: 美国中部时间:Central Standard Time (USA) UT-6:00 澳大利亚中部时间:Central Standard Time (Austr ...

  5. will not be exported or published. Runtime ClassNotFoundExceptions may result.

    在eclipse中加入某个jar包时,会出现Classpath entry XXX.jar will not be exported or published. Runtime ClassNotFou ...

  6. MVC中的七层架构

    工厂模式的七层架构 1.创建Model,实现业务实体. 2.创建IDAL,实现接口. 3.创建DAL,实现接口里的方法. 4.创建DBUtility,数据库操作类5.创建DALFactory,抽象工程 ...

  7. python之virtualenv

    一 virtualenv简介 virtualenv------用来建立一个虚拟的python环境,一个专属于项目的python环境.用virtualenv 来保持一个干净的环境非常有用 在开发Pyth ...

  8. 在BCH硬分叉后防止重放攻击-1

    导致新加密货币的硬分叉为加密交换运营商带来了独特的机遇和挑战.Poloniex在最近的Bitcoin Cash硬叉之后面临的一个挑战是保护我们的客户免受重播攻击.由于SV链后面的开发团队选择在分叉后近 ...

  9. ajax 之POST请求,参数序列化

    比如,,我们在没有使用jquery的时候,没有$.post来让我们使用,那我们像下面这样直接发送: var params1 = { username: username, passwrod: pass ...

  10. PyQt5速成教程

    博客地址 https://www.jianshu.com/nb/26159952