To compile Racc grammer file, simply type:
$ racc parse.yThis creates ruby script file "parse.tab.y". -o option changes this.
If you want your own parser, you have to write grammer file.
A grammer file contains name of parser class, grammer the parser can parse,
user code, and any.
When writing grammer file, yacc's knowledge is helpful.
If you have not use yacc, also racc is too difficult.
Here's example of Racc grammer file.
class Calcparser rule target: exp { print val[0] } exp: exp '+' exp | exp '*' exp | '(' exp ')' | NUMBER endRacc grammer file is resembles to yacc file. But (of cource), action is Ruby code. yacc's $$ is 'result', $0, $1... is an array 'val', $-1, $-2... is an array '_values'.
yylex() is method "next_token()". This method must returns an array like [TOKENSYMBOL, ITS_VALUE]. EOF is [false, false]. (token symbol is ruby symbol (got by String#intern) as default. If you want to change this, see grammer reference.
yyparse() is method "do_parse()".
When debug, "-v" or/and "-g" option is helpful. "-v" causes creating verbose log file (.output). "-g" causes creating "Verbose Parser". Verbose Parser prints internal status when parsing. But it is not automatic. You must use -g option and set @yydebug true to get output. -g option only creates verbose parser.
A parser, which is created by Racc, requires Racc runtime. You should re-distribute Racc runtime with your parser, or users need to install Racc. Racc package is easy to re-distribute.
/usr/src/racc-xxx/ $ cp -r setup.rb bin lib ext TARGET/This copies Racc runtime under directory TARGET/ . You can use Racc's installation process.
cd TARGET/ ruby setup.rb config ruby setup.rb setup ruby setup.rb install
Copyright (c) 1999,2000 Minero Aoki <aamine@dp.u-netsurf.ne.jp>