[cedet-semantic] Re: Moving to Semantic 2.0 & %start nonterminal that generate multiple tags.
Brought to you by:
zappo
From: Joseph K. <ki...@ac...> - 2004-02-16 15:30:00
|
Hello again Eric, "Eric M. Ludlam" <er...@si...> writes: >>>> Joseph Kiniry <ki...@ac...> seems to think that: > [ ... ] >>I've begun testing my grammar with CVS HEAD today and things look >>good so far. > > Yay! Right-on. >>I'm now generating good looking sets of tags, but my current problem >>is one of structure. It is just the standard loosly-typed Lispisms; >>things like something should be a list of lists, but I only have a >>list, etc. >> >>Here is a problem that has come up though that I must ask about. >> >>I have top-level constructs that have multiple meanings. For example, >>a PVS datatype is a datatype, a type, and a function. Unfortunately, >>a top-level %start rule can only return a *single* tag, whereas I >>would like to return a list of tags. > > I had identified that if I iterate in code over the same rule to > generate the tags, it was more robust that using typical looping via > recursive grammar rules. This is how I can identify unmatched syntax. I understand this choice. > The assumption was that a give call into the parser would then return > only one tag. > >>E.g., >>datatype : id theoryformals_opt COLON datatype_or_codatatype with_subtypes_ids_opt >> BEGIN >> importing_semicolon_opt >> assumingpart_opt >> datatypepart >> END id >> (list >> (TYPE-TAG $1 $4 (append $7 $8 $9) nil) >> (when $2 >> (FUNCTION-TAG $1 $1 $2)) >> (TAG $1 'datatype (append $7 $8 $9))) >> ; >> >>Any ideas on how to handle this problem? > [ ... ] > > I think I would return a tag of a new class. Give it a name specific > to your language. > > Then implement a function for `semantic-tag-expand-function'. When > it sees a tag of that new class, it will replace it with two or more > new tags. > > If the function part of your declaration is a constructor, don't > forget to set the attribute :constructor to non-nil. > > Hmmm. I think it is the symbol `constructor' without the :. I should > fix that. > > Anyway, that is the official way to do that, and is used in C and > Java for statements like this: > > int a, b; Must (sub)functions of -expand-tag be written for all non-core semantics tags, or only ones that are returned by %start denoted rules? In other words, were I to use custom tags on other, non-expand(full) related production rules, would they would be expanded with my semantic-tag-expand-function as well? (I'm deep in refactor mode so I cannot even compile my grammar at the moment, thus the silly question.) I don't see any discussion of semantic-tag-expand-function in the current CVS head documentation (beyond an extremely brief mention in the Semantic Tags chapter's Misc Tag Internals subsection), FWIW. I've been updating the docs a bit in my local sandbox, fixing typos, spelling errors, grammar, and clarifying issues. Shall I send a diff eventually to someone? Joe -- Joseph R. Kiniry ID 78860581 ICQ 4344804 SOS Group, University of Nijmegen http://www.cs.kun.nl/~kiniry/ KindSoftware, LLC http://www.kindsoftware.com/ Board Chair: NICE http://www.eiffel-nice.org/ |