To compile racc grammer file, simply type:
$ racc parse.yThis create 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 [TOKENSIMBOL, ITS_VALUE]. EOF is [false, false]. (token simbol is ruby simbol (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 output file (.output).
"-g" causes creating "Verbose Parser".
Verbose Parser prints internal status when parsing.
But, attention please! it is not automatic.
You must use -g option and be @yydebug true to get output.
-g option only create verbose parser.