File: C:/Ruby27-x64/share/ri/2.7.0/system/lib/racc/rdoc/page-grammar_en_rdoc.ri
U:RDoc::TopLevel[ i I""lib/racc/rdoc/grammar.en.rdoc:ETcRDoc::Parser::Simpleo:RDoc::Markup::Document:@parts[vS:RDoc::Markup::Heading:
leveli: textI" Racc Grammar File Reference;To:RDoc::Markup::BlankLine S; ;
i;I"Global Structure;T@
S; ;
i;I"$Class Block and User Code Block;T@
o:RDoc::Markup::Paragraph;[I"bThere are two blocks on the toplevel. One is the 'class' block, the other is the 'user code' ;TI"Iblock. The 'user code' block MUST be placed after the 'class' block.;T@
S; ;
i;I"
Comments;T@
o;
;[I"}You can insert comments about all places. Two styles of comments can be used, Ruby style '#.....' and C style '/\*......*\/'.;T@
S; ;
i;I"Class Block;T@
o;
;[I")The class block is formed like this:;T@
o:RDoc::Markup::Verbatim;[I"class CLASS_NAME
;TI" [precedence table]
;TI" [token declarations]
;TI"* [expected number of S/R conflicts]
;TI" [options]
;TI"# [semantic value conversion]
;TI" [start rule]
;TI"
rule
;TI" GRAMMARS
;T:@format0o;
;[I"YCLASS_NAME is a name of the parser class. This is the name of the generating parser ;TI"class.;T@
o;
;[I"WIf CLASS_NAME includes '::', Racc outputs the module clause. For example, writing ;TI"6"class M::C" causes the code below to be created:;T@
o;;[I"module M
;TI" class C
;TI" :
;TI" :
;TI" end
;TI" end
;T;0S; ;
i;I"Grammar Block;T@
o;
;[I"WThe grammar block describes grammar which is able to be understood by the parser. ;TI"Syntax is:;T@
o;;[
I"3(token): (token) (token) (token).... (action)
;TI"
;TI"3(token): (token) (token) (token).... (action)
;TI"3 | (token) (token) (token).... (action)
;TI"3 | (token) (token) (token).... (action)
;T;0o;
;[I"J(action) is an action which is executed when its (token)s are found. ;TI"B(action) is a ruby code block, which is surrounded by braces:;T@
o;;[I"{ print val[0]
;TI" puts val[1] }
;T;0o;
;[I"ONote that you cannot use '%' string, here document, '%r' regexp in action.;T@
o;
;[I"KActions can be omitted. When it is omitted, '' (empty string) is used.;T@
o;
;[I"]A return value of action is a value of the left side value ($$). It is the value of the ;TI"9result, or the returned value by `return` statement.;T@
o;
;[I"3Here is an example of the whole grammar block.;T@
o;;[I"
rule
;TI"6 goal: definition rules source { result = val }
;TI"
;TI"0 definition: /* none */ { result = [] }
;TI"9 | definition startdesig { result[0] = val[1] }
;TI" | definition
;TI"C precrule # this line continues from upper line
;TI"
{
;TI" result[1] = val[1]
;TI"
}
;TI"
;TI" startdesig: START TOKEN
;T;0o;
;[I"AYou can use the following special local variables in action:;T@
o:RDoc::Markup::List:
@type:BULLET:@items[o:RDoc::Markup::ListItem:@label0;[o;
;[I"result ($$);T@
o;
;[I"FThe value of the left-hand side (lhs). A default value is val[0].;T@
o;;;;[o;;0;[o;
;[I"val ($1,$2,$3...);T@
o;
;[I"4An array of value of the right-hand side (rhs).;T@
o;;;;[o;;0;[o;
;[I"_values (...$-2,$-1,$0);T@
o;
;[I"TA stack of values. DO NOT MODIFY this stack unless you know what you are doing.;T@
S; ;
i;I"Operator Precedence;T@
o;
;[I"0This function is equal to '%prec' in yacc. ;TI"To designate this block:;T@
o;;[I"prechigh
;TI" nonassoc '++'
;TI" left '*' '/'
;TI" left '+' '-'
;TI" right '='
;TI"
preclow
;T;0o;
;[I"6`right` is yacc's %right, `left` is yacc's %left.;T@
o;
;[I"'`=` + (symbol) means yacc's %prec:;T@
o;;[I"prechigh
;TI" nonassoc UMINUS
;TI" left '*' '/'
;TI" left '+' '-'
;TI"
preclow
;TI"
;TI"
rule
;TI" exp: exp '*' exp
;TI" | exp '-' exp
;TI"? | '-' exp =UMINUS # equals to "%prec UMINUS"
;TI" :
;TI" :
;T;0S; ;
i;I"expect;T@
o;
;[I")Racc has bison's "expect" directive.;T@
o;;[I"# Example
;TI"
;TI"class MyParser
;TI"
rule
;TI" expect 3
;TI" :
;TI" :
;T;0o;
;[I"MThis directive declares "expected" number of shift/reduce conflicts. If ;TI"Q"expected" number is equal to real number of conflicts, Racc does not print ;TI"conflict warning message.;T@
S; ;
i;I"Declaring Tokens;T@
o;
;[I"QBy declaring tokens, you can avoid many meaningless bugs. If declared token ;TI"Pdoes not exist or existing token does not decleared, Racc output warnings. ;TI"Declaration syntax is:;T@
o;;[I""token TOKEN_NAME AND_IS_THIS
;TI"5 ALSO_THIS_IS AGAIN_AND_AGAIN THIS_IS_LAST
;T;0S; ;
i;I"Options;T@
o;
;[I">You can write options for Racc command in your Racc file.;T@
o;;[I"options OPTION OPTION ...
;T;0o;
;[I"Options are:;T@
o;;;;[o;;0;[o;
;[I"omit_action_call;T@
o;
;[I"$omits empty action call or not.;T@
o;;;;[o;;0;[o;
;[I"result_var;T@
o;
;[I")uses local variable "result" or not.;T@
o;
;[I"7You can use 'no_' prefix to invert their meanings.;T@
S; ;
i;I"Converting Token Symbol;T@
o;
;[I"#Token symbols are, as default,;T@
o;;[ I"H* naked token string in Racc file (TOK, XFILE, this_is_token, ...)
;TI"6 --> symbol (:TOK, :XFILE, :this_is_token, ...)
;TI"** quoted string (':', '.', '(', ...)
;TI", --> same string (':', '.', '(', ...)
;T;0o;
;[I"5You can change this default by "convert" block. ;TI"Here is an example:;T@
o;;[ I"
convert
;TI"E PLUS 'PlusClass' # We use PlusClass for symbol of `PLUS'
;TI"E MIN 'MinusClass' # We use MinusClass for symbol of `MIN'
;TI" end
;T;0o;
;[I"CWe can use almost all ruby value can be used by token symbol, ;TI"Cexcept 'false' and 'nil'. These cause unexpected parse error.;T@
o;
;[I"JIf you want to use String as token symbol, special care is required. ;TI"For example:;T@
o;;[
I"
convert
;TI"1 class '"cls"' # in code, "cls"
;TI"4 PLUS '"plus\n"' # in code, "plus\n"
;TI"; MIN "\"minus#{val}\"" # in code, \"minus#{val}\"
;TI" end
;T;0S; ;
i;I"Start Rule;T@
o;
;[I"/'%start' in yacc. This changes start rule.;T@
o;;[I"start real_target
;T;0S; ;
i;I"User Code Block;T@
o;
;[I"R"User Code Block" is a Ruby source code which is copied to output. There are ;TI";three user code blocks, "header" "inner" and "footer".;T@
o;
;[I"&Format of user code is like this:;T@
o;;[I"---- header
;TI" ruby statement
;TI" ruby statement
;TI" ruby statement
;TI"
;TI"---- inner
;TI" ruby statement
;TI" :
;TI" :
;T;0o;
;[I"PIf four '-' exist on the line head, Racc treats it as the beginning of the ;TI"Huser code block. The name of the user code block must be one word.;T:
@file@:0@omit_headings_from_table_of_contents_below0