yyparse() and yylex()
Posted cpsmile
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了yyparse() and yylex()相关的知识,希望对你有一定的参考价值。
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.
%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. 以上是关于yyparse() and yylex()的主要内容,如果未能解决你的问题,请参考以下文章
环境初始化 Build and Install the Apache Thrift IDL Compiler Install the Platform Development Tools(代码片段
项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde(代码片段
Operator '||' cannot be applied to operands of type 'bool?' and 'bool?'(代码片段
Operator '||' cannot be applied to operands of type 'bool?' and 'bool?'(代码片段
[TIA PORTAL][CONVERT] Convert Char Array to DInt...DInt to Char Array..Useful and easy function(代码片段
[Grid Layout] Use auto-fill and auto-fit if the number of repeated grid tracks is not to be def(代码片段