U:RDoc::NormalModule[iI" Racc:ET@0o:RDoc::Markup::Document:@parts[o;;[ :
@fileI"ext/racc/cparse/cparse.c;T:0@omit_headings_from_table_of_contents_below0o;;[Io:RDoc::Markup::Paragraph;[I")Racc is a LALR(1) parser generator. ;TI"?It is written in Ruby itself, and generates Ruby programs.;To:RDoc::Markup::BlankLine S:RDoc::Markup::Heading:
leveli: textI"Command-line Reference;T@o:RDoc::Markup::Verbatim;[I"Fracc [-ofilename] [--output-file=filename]
;TI"C [-erubypath] [--embedded=rubypath]
;TI" [-v] [--verbose]
;TI"C [-Ofilename] [--log-file=filename]
;TI" [-g] [--debug]
;TI" [-E] [--embedded]
;TI"# [-l] [--no-line-convert]
;TI"$ [-c] [--line-convert-all]
;TI"# [-a] [--no-omit-actions]
;TI" [-C] [--check-only]
;TI"! [-S] [--output-status]
;TI"D [--version] [--copyright] [--help] grammarfile
;T:@format0o:RDoc::Markup::List:
@type:
LABEL:@items[o:RDoc::Markup::ListItem:@label[I"+filename+;T;[o;;[I"3Racc grammar file. Any extension is permitted.;To;;[I")-o+outfile+, --output-file=+outfile+;T;[o;;[I":A filename for output. default is <+filename+>.tab.rb;To;;[I"(-O+filename+, --log-file=+filename+;T;[o;;[I".Place logging output in file +filename+. ;TI"2Default log file name is <+filename+>.output.;To;;[I"*-e+rubypath+, --executable=+rubypath+;T;[o;;[I"Loutput executable file(mode 755). where +path+ is the Ruby interpreter.;To;;[I"-v, --verbose;T;[o;;[I"Lverbose mode. create +filename+.output file, like yacc's y.output file.;To;;[I"-g, --debug;T;[o;;[I"Gadd debug code to parser class. To display debugging information, ;TI"@use this '-g' option and set @yydebug true in parser class.;To;;[I"-E, --embedded;T;[o;;[I"EOutput parser which doesn't need runtime files (racc/parser.rb).;To;;[I"-C, --check-only;T;[o;;[I"0Check syntax of racc grammar file and quit.;To;;[I"-S, --output-status;T;[o;;[I"1Print messages time to time while compiling.;To;;[I"-l, --no-line-convert;T;[o;;[I"&turns off line number converting.;To;;[I"-c, --line-convert-all;T;[o;;[I">Convert line number of actions, inner, header and footer.;To;;[I"-a, --no-omit-actions;T;[o;;[I"2Call all actions, even if an action is empty.;To;;[I"--version;T;[o;;[I"!print Racc version and quit.;To;;[I"--copyright;T;[o;;[I"Print copyright and quit.;To;;[I"--help;T;[o;;[I"Print usage and quit.;T@S;
;i;I"!Generating Parser Using Racc;T@o;;[I"/To compile Racc grammar file, simply type:;T@o;;[I"$ racc parse.y
;T;0o;;[I"_This creates Ruby script file "parse.tab.y". The -o option can change the output filename.;T@S;
;i;I" Writing A Racc Grammar File;T@o;;[
I"DIf you want your own parser, you have to write a grammar file. ;TI"TA grammar file contains the name of your parser class, grammar for the parser, ;TI"#user code, and anything else. ;TI"?When writing a grammar file, yacc's knowledge is helpful. ;TI"AIf you have not used yacc before, Racc is not too difficult.;T@o;;[I")Here's an example Racc grammar file.;T@o;;[I"class Calcparser
;TI"
rule
;TI"$ target: exp { print val[0] }
;TI"
;TI" exp: exp '+' exp
;TI" | exp '*' exp
;TI" | '(' exp ')'
;TI" | NUMBER
;TI" end
;T;0o;;[ I"-Racc grammar files resemble yacc files. ;TI")But (of course), this is Ruby code. ;TI"-yacc's $$ is the 'result', $0, $1... is ;TI"Ian array called 'val', and $-1, $-2... is an array called '_values'.;T@o;;[I"RSee the {Grammar File Reference}[rdoc-ref:lib/racc/rdoc/grammar.en.rdoc] for ;TI"'more information on grammar files.;T@S;
;i;I"Parser;T@o;;[I"JThen you must prepare the parse entry method. There are two types of ;TI"Jparse methods in Racc, Racc::Parser#do_parse and Racc::Parser#yyparse;T@o;;[I"%Racc::Parser#do_parse is simple.;T@o;;[
I"EIt's yyparse() of yacc, and Racc::Parser#next_token is yylex(). ;TI"FThis method must returns an array like [TOKENSYMBOL, ITS_VALUE]. ;TI"EOF is [false, false]. ;TI"J(TOKENSYMBOL is a Ruby symbol (taken from String#intern) by default. ;TI";If you want to change this, see the grammar reference.;T@o;;[I"=Racc::Parser#yyparse is little complicated, but useful. ;TI"WIt does not use Racc::Parser#next_token, instead it gets tokens from any iterator.;T@o;;[I":For example, yyparse(obj, :scan)
causes ;TI"Tcalling +obj#scan+, and you can return tokens by yielding them from +obj#scan+.;T@S;
;i;I"Debugging;T@o;;[I"