BISON

1.2 From Formal Rules to Bison Input

  • Terminal
  • Nonterminal

1.3 Semantic Values A formal grammar selects tokens only by their classifications each token in a Bison grammar has both a token kind and a semantic value 强类型,有类型和值的区别

1.4 Semantic Actions The action says how to produce the semantic value

1.5 Writing GLR Parsers 略,默认是LR文法,但是有RR和SR冲突,所以为了不那么严格限制语法,在一定程度上允许冲突。这里不做了解

1.6 Locations produce verbose and useful error messages

1.7 Bison Output: the Parser Implementation File The tokens come from a function called the lexical analyzer. The Bison parser calls the lexical analyzer each time it wants a new token supply some additional functions. One is the lexical analyzer. Another is an error-reporting function

1.8 Stages in Using Bison The actual language-design process using Bison, from grammar specification to a working compiler or interpreter, has these parts:

Formally specify the grammar in a form recognized by Bison (see Bison Grammar Files). For each grammatical rule in the language, describe the action that is to be taken when an instance of that rule is recognized. The action is described by a sequence of C statements. Write a lexical analyzer to process input and pass tokens to the parser. The lexical analyzer may be written by hand in C (see The Lexical Analyzer Function yylex). It could also be produced using Lex, but the use of Lex is not discussed in this manual. Write a controlling function that calls the Bison-produced parser. Write error-reporting routines. To turn this source code as written into a runnable program, you must follow these steps:

Run Bison on the grammar to produce the parser. Compile the code output by Bison, as well as any other source files. Link the object files to produce the finished product.

1.9 The Overall Layout of a Bison Grammar

%{
Prologue
 define types and variables used in the actions.
 include header files
 declare the lexical analyzer yylex and the error printer yyerror

%}

Bison declarations
  declare the names of the terminal and nonterminal symbols
%%
Grammar rules
%%
Epilogue

stop here Mon Nov 14 23:04:18 CST 2022

https://www.gnu.org/software/bison/manual/bison.html#Semantic-Values

2 example You don’t have to give an action for every rule. When a rule has no action, Bison by default copies the value of $1 into $$

3.3 Grammar Rules

  • Syntax of Grammar Rules

  • Empty Rules

  • Recursive Rules

  • Reduce/Reduce Conflicts

  • Shift/Reduce Conflicts