{
    "mode": "ri",
    "parameter": "Racc",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/ri/Racc/json",
    "generated": "2026-06-02T15:49:31Z",
    "sections": {
        "Racc": {
            "content": "(from gem rdoc-7.2.0)\n------------------------------------------------------------------------\n\n\nRacc is an LALR(1) parser generator. It is written in Ruby itself, and\ngenerates Ruby programs.\n",
            "subsections": [
                {
                    "name": "Command-line Reference",
                    "content": "racc [-o<var>filename</var>] [--output-file=<var>filename</var>]\n[-e<var>rubypath</var>] [--executable=<var>rubypath</var>]\n[-v] [--verbose]\n[-O<var>filename</var>] [--log-file=<var>filename</var>]\n[-g] [--debug]\n[-E] [--embedded]\n[-l] [--no-line-convert]\n[-c] [--line-convert-all]\n[-a] [--no-omit-actions]\n[-C] [--check-only]\n[-S] [--output-status]\n[--version] [--copyright] [--help] <var>grammarfile</var>\n\ngrammarfile:\nRacc grammar file. Any extension is permitted.\n\n-o+outfile+, --output-file=outfile:\nA filename for output. default is <filename>.tab.rb\n\n-O+filename+, --log-file=filename:\nPlace logging output in file filename. Default log file name is\n<filename>.output.\n\n-e+rubypath+, --executable=rubypath:\noutput executable file(mode 755). where path is the Ruby interpreter.\n\n-v, --verbose:\nverbose mode. create filename.output file, like yacc's y.output file.\n\n-g, --debug:\nadd debug code to parser class. To display debugging information, use\nthis '-g' option and set @yydebug true in parser class.\n\n-E, --embedded:\nOutput parser which doesn't need runtime files (racc/parser.rb).\n\n-F, --frozen:\nOutput parser which declares frozenstringliterals: true\n\n-C, --check-only:\nCheck syntax of racc grammar file and quit.\n\n-S, --output-status:\nPrint messages time to time while compiling.\n\n-l, --no-line-convert:\nturns off line number converting.\n\n-c, --line-convert-all:\nConvert line number of actions, inner, header and footer.\n\n-a, --no-omit-actions:\nCall all actions, even if an action is empty.\n\n--version:\nprint Racc version and quit.\n\n--copyright:\nPrint copyright and quit.\n\n--help:\nPrint usage and quit.\n\n"
                },
                {
                    "name": "Generating Parser Using Racc",
                    "content": "To compile Racc grammar file, simply type:\n\n$ racc parse.y\n\nThis creates Ruby script file \"parse.tab.y\". The -o option can change\nthe output filename.\n"
                },
                {
                    "name": "Writing A Racc Grammar File",
                    "content": "If you want your own parser, you have to write a grammar file. A grammar\nfile contains the name of your parser class, grammar for the parser,\nuser code, and anything else. When writing a grammar file, yacc's\nknowledge is helpful. If you have not used yacc before, Racc is not too\ndifficult.\n\nHere's an example Racc grammar file.\n\nclass Calcparser\nrule\ntarget: exp { print val[0] }\n\nexp: exp '+' exp\n| exp '*' exp\n| '(' exp ')'\n| NUMBER\nend\n\nRacc grammar files resemble yacc files. But (of course), this is Ruby\ncode. yacc's $$ is the 'result', $0, $1... is an array called 'val', and\n$-1, $-2... is an array called 'values'.\n\nSee the Grammar File Reference( rdoc-ref:lib/racc/rdoc/grammar.en.rdoc )\nfor more information on grammar files.\n"
                },
                {
                    "name": "Parser",
                    "content": "Then you must prepare the parse entry method. There are two types of\nparse methods in Racc, Racc::Parser#doparse and Racc::Parser#yyparse\n\nRacc::Parser#doparse is simple.\n\nIt's yyparse() of yacc, and Racc::Parser#nexttoken is yylex(). This\nmethod must returns an array like [TOKENSYMBOL, ITSVALUE]. EOF is\n[false, false]. (TOKENSYMBOL is a Ruby symbol (taken from String#intern)\nby default. If you want to change this, see the grammar reference.\n\nRacc::Parser#yyparse is little complicated, but useful. It does not use\nRacc::Parser#nexttoken, instead it gets tokens from any iterator.\n\nFor example, yyparse(obj, :scan) causes calling +obj#scan+, and you can\nreturn tokens by yielding them from +obj#scan+.\n"
                },
                {
                    "name": "Debugging",
                    "content": "When debugging, \"-v\" or/and the \"-g\" option is helpful.\n\n\"-v\" creates verbose log file (.output). \"-g\" creates a \"Verbose\nParser\". Verbose Parser prints the internal status when parsing. But\nit's not automatic. You must use -g option and set +@yydebug+ to\ntrue in order to get output. -g option only creates the verbose parser.\n\n=== Racc reported syntax error.\n\nIsn't there too many \"end\"? grammar of racc file is changed in v0.10.\n\nRacc does not use '%' mark, while yacc uses huge number of '%' marks..\n\n=== Racc reported \"XXXX conflicts\".\n\nTry \"racc -v xxxx.y\". It causes producing racc's internal log file,\nxxxx.output.\n\n=== Generated parsers does not work correctly\n\nTry \"racc -g xxxx.y\". This command let racc generate \"debugging parser\".\nThen set @yydebug=true in your parser. It produces a working log of your\nparser.\n"
                },
                {
                    "name": "Re-distributing Racc runtime",
                    "content": "A parser, which is created by Racc, requires the Racc runtime module;\nracc/parser.rb.\n\nRuby 1.8.x comes with Racc runtime module, you need NOT distribute Racc\nruntime files.\n\nIf you want to include the Racc runtime module with your parser. This\ncan be done by using '-E' option:\n\n$ racc -E -omyparser.rb myparser.y\n\nThis command creates myparser.rb which `includes' Racc runtime. Only you\nmust do is to distribute your parser file (myparser.rb).\n\nNote: parser.rb is ruby license, but your parser is not. Your own parser\nis completely yours.\n\n\n\nRacc is an LALR(1) parser generator. It is written in Ruby itself, and\ngenerates Ruby programs.\n"
                },
                {
                    "name": "Command-line Reference",
                    "content": "racc [-o<var>filename</var>] [--output-file=<var>filename</var>]\n[-e<var>rubypath</var>] [--executable=<var>rubypath</var>]\n[-v] [--verbose]\n[-O<var>filename</var>] [--log-file=<var>filename</var>]\n[-g] [--debug]\n[-E] [--embedded]\n[-l] [--no-line-convert]\n[-c] [--line-convert-all]\n[-a] [--no-omit-actions]\n[-C] [--check-only]\n[-S] [--output-status]\n[--version] [--copyright] [--help] <var>grammarfile</var>\n\ngrammarfile:\nRacc grammar file. Any extension is permitted.\n\n-o+outfile+, --output-file=outfile:\nA filename for output. default is <filename>.tab.rb\n\n-O+filename+, --log-file=filename:\nPlace logging output in file filename. Default log file name is\n<filename>.output.\n\n-e+rubypath+, --executable=rubypath:\noutput executable file(mode 755). where path is the Ruby interpreter.\n\n-v, --verbose:\nverbose mode. create filename.output file, like yacc's y.output file.\n\n-g, --debug:\nadd debug code to parser class. To display debugging information, use\nthis '-g' option and set @yydebug true in parser class.\n\n-E, --embedded:\nOutput parser which doesn't need runtime files (racc/parser.rb).\n\n-F, --frozen:\nOutput parser which declares frozenstringliterals: true\n\n-C, --check-only:\nCheck syntax of racc grammar file and quit.\n\n-S, --output-status:\nPrint messages time to time while compiling.\n\n-l, --no-line-convert:\nturns off line number converting.\n\n-c, --line-convert-all:\nConvert line number of actions, inner, header and footer.\n\n-a, --no-omit-actions:\nCall all actions, even if an action is empty.\n\n--version:\nprint Racc version and quit.\n\n--copyright:\nPrint copyright and quit.\n\n--help:\nPrint usage and quit.\n\n"
                },
                {
                    "name": "Generating Parser Using Racc",
                    "content": "To compile Racc grammar file, simply type:\n\n$ racc parse.y\n\nThis creates Ruby script file \"parse.tab.y\". The -o option can change\nthe output filename.\n"
                },
                {
                    "name": "Writing A Racc Grammar File",
                    "content": "If you want your own parser, you have to write a grammar file. A grammar\nfile contains the name of your parser class, grammar for the parser,\nuser code, and anything else. When writing a grammar file, yacc's\nknowledge is helpful. If you have not used yacc before, Racc is not too\ndifficult.\n\nHere's an example Racc grammar file.\n\nclass Calcparser\nrule\ntarget: exp { print val[0] }\n\nexp: exp '+' exp\n| exp '*' exp\n| '(' exp ')'\n| NUMBER\nend\n\nRacc grammar files resemble yacc files. But (of course), this is Ruby\ncode. yacc's $$ is the 'result', $0, $1... is an array called 'val', and\n$-1, $-2... is an array called 'values'.\n\nSee the Grammar File Reference( rdoc-ref:lib/racc/rdoc/grammar.en.rdoc )\nfor more information on grammar files.\n"
                },
                {
                    "name": "Parser",
                    "content": "Then you must prepare the parse entry method. There are two types of\nparse methods in Racc, Racc::Parser#doparse and Racc::Parser#yyparse\n\nRacc::Parser#doparse is simple.\n\nIt's yyparse() of yacc, and Racc::Parser#nexttoken is yylex(). This\nmethod must returns an array like [TOKENSYMBOL, ITSVALUE]. EOF is\n[false, false]. (TOKENSYMBOL is a Ruby symbol (taken from String#intern)\nby default. If you want to change this, see the grammar reference.\n\nRacc::Parser#yyparse is little complicated, but useful. It does not use\nRacc::Parser#nexttoken, instead it gets tokens from any iterator.\n\nFor example, yyparse(obj, :scan) causes calling +obj#scan+, and you can\nreturn tokens by yielding them from +obj#scan+.\n"
                },
                {
                    "name": "Debugging",
                    "content": "When debugging, \"-v\" or/and the \"-g\" option is helpful.\n\n\"-v\" creates verbose log file (.output). \"-g\" creates a \"Verbose\nParser\". Verbose Parser prints the internal status when parsing. But\nit's not automatic. You must use -g option and set +@yydebug+ to\ntrue in order to get output. -g option only creates the verbose parser.\n\n=== Racc reported syntax error.\n\nIsn't there too many \"end\"? grammar of racc file is changed in v0.10.\n\nRacc does not use '%' mark, while yacc uses huge number of '%' marks..\n\n=== Racc reported \"XXXX conflicts\".\n\nTry \"racc -v xxxx.y\". It causes producing racc's internal log file,\nxxxx.output.\n\n=== Generated parsers does not work correctly\n\nTry \"racc -g xxxx.y\". This command let racc generate \"debugging parser\".\nThen set @yydebug=true in your parser. It produces a working log of your\nparser.\n"
                },
                {
                    "name": "Re-distributing Racc runtime",
                    "content": "A parser, which is created by Racc, requires the Racc runtime module;\nracc/parser.rb.\n\nRuby 1.8.x comes with Racc runtime module, you need NOT distribute Racc\nruntime files.\n\nIf you want to include the Racc runtime module with your parser. This\ncan be done by using '-E' option:\n\n$ racc -E -omyparser.rb myparser.y\n\nThis command creates myparser.rb which `includes' Racc runtime. Only you\nmust do is to distribute your parser file (myparser.rb).\n\nNote: parser.rb is ruby license, but your parser is not. Your own parser\nis completely yours.\n------------------------------------------------------------------------"
                }
            ]
        },
        "Constants:": {
            "content": "Copyright:\n[not documented]\n\nVERSION:\n[not documented]\n\nVersion:\n[not documented]\n\n",
            "subsections": []
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}