Hi Victor,
Yes, this is possible. SableCC is rejecting "NULL" because the id
element is not optional. You simply need to make it optional:
lib_elem =
{program} [name]:tk_identifier [id]:tk_identifier? ;
(Note the additional "?")
SableCC does check that CST->AST transformations match the
"multiplicity" of elements (not optional, "?", "*", and "+").
Have fun!
Etienne
Viktor Suvorov wrote:
> I want to add attribute into AST class, which have no
> relation to grammar. This attribute will be filled
> during semantic analyses stage.
>...
> I would like to add additional field "id" which can
> store "tk_identifier" to production lib_elem in AST:
>
> lib_elem = {program} [name]:tk_identifier
> [id]:tk_identifier
> ;
>
> Is it possible to modify CST production lib_elem in
> such way, that grammar would be valid ? Constructions
> like
>
> lib_elem {-> lib_elem} = tk_program
> [name]:tk_identifier tk_endprogram {-> New
> lib_elem.program(name, Null)}
> ;
>
--
Etienne M. Gagnon, Ph.D. http://www.info2.uqam.ca/~egagnon/
SableVM: http://www.sablevm.org/
SableCC: http://www.sablecc.org/
Attachment:
signature.asc
Description: OpenPGP digital signature