This is temporary specification.
There's two block on toplevel. one is 'class' block, another is 'user code' block. 'user code' block MUST places after 'class' block.
You can insert comment about all places. Two style comment can be used, Ruby style (#.....) and C style (/*......*/) .
class block is like this:
class class_name [precedance] [start] [token] rule RULES endclass_name is a name of parser class. This is equal to name of generating parser class.
'rule block' discripts grammer which is able to be understood by parser. For example:
(token): (token) (token) (token).... (action) ; (token): (token) (token) (token).... (action) | (token) (token) (token).... (action) | (token) (token) (token).... (action)(action) is an action which is executed when its (token)s are found. (action) is like this:
{ print val[0] puts val[1] }In (action), you cannot use '%' string, here document, '%r' regexp. Actions can be omitted. When it is omitted, ''(empty string) is used.
A return value of action is a value of left side value ($$). It is value of result, or returned value by "return" statement.
Then, here's a sample of whole 'rule block'.
rule goal: definition ruls source { result = val } definition: /* none */ { result = [] } | definition startdesig { result[0] = val[1] } | definition precrule # this line continue from upper line { result[1] = val[1] } startdesig: START TOKEN endYou can use these spetial local variables in action.
This function is equal to '%prec' in yacc. To designate this block:
prechigh nonassoc '++' left '*' '/' left '+' '-' right '=' preclow'right' is '%right', 'left' is '%left'. While this example is written 'prechigh' upper and 'preclow' lower, but another format 'preclow...prechigh' is also premitted.
'%prec' can be used. format is like this:
prechigh nonassoc UMINUS left '*' '/' left '+' '-' preclow rule exp: exp '*' exp | exp '-' exp | '-' exp = UMINUS # this!!! :
'%start' in yacc. This changes start rule.
start real_target
this statement won't be used forever, I think.
token simbol is, as default,
You can change this by 'token' block. This is example:
token PLUS 'PlusClass' # not use :PLUS but PlusClass MIN 'MinusClass' # not use :MIN but MinusClass endAlmost all ruby value can be used by token simbol, but 'false' and 'nil' are NOT. These are causes unexpected parse error.
If you want to use String as token simbol, special care is required. For example:
token class '"cls"' # in code, "cls" PLUS '"plus\n"' # in code, "plus\n" MIN "\"minus#{val}\"" # in code, \"minus#{val}\" endThese are not BUG, but FEATURE.
'user block' is Ruby source code which is copied to output.
In racc command, Three spetial user code
'header' 'inner' 'footer' are used.
Until version 0.10.2, they are called prepare/inner/driver.
It is also OK, but they will be eliminated in future.
format of user code is like this:
---- header ruby statement ruby statement ruby statement ---- inner ruby statement :If 4 '-' exist on line head, racc treat it as beginning of user code. A name of user code must be one word.
You can include other file as user code like this:
---- footer = init.rb run.rb print "these code is used as driver, too!!"This statement makes racc to use "init.rb" "run.rb" as 'footer' user code.
Copyright (c) 1999,2000 Minero Aoki <aamine@dp.u-netsurf.ne.jp>