Search code examples
rubycompiler-constructionyacc

yacc: What does %{} mean in yacc?


Does it mean just copy the C code? This is excerpted from ruby source code parse.y

%{

#ifndef PARSER_DEBUG
#define PARSER_DEBUG 0
#endif
#define YYDEBUG 1
#define YYERROR_VERBOSE 1
#define YYSTACK_USE_ALLOCA 0

#include "ruby/ruby.h"
#include "ruby/st.h"
#include "ruby/encoding.h"

Solution

  • The definition section is to be put within the %{ and %}

    The definitions section consists of token declarations and C code bracketed by "%{" and "%}".

    DOC