Avoiding state variables
Alberto Luaces <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
Suppose that I am parsing a language with similar semantics with regards
to public/private than C++: if "PRIVATE" is found, every declaration
after it is considered private; else "public" is the default state, or
if it is ensured with the "PUBLIC" keyword.
At first I thought about a state variable set when PUBLIC or PRIVATE is
found, but I did not know how to bind that state to the declarations
found afterwards without resorting to semantic actions.
Then I thought about a scheme like this:
dec_list =
*(
lexeme["PRIVATE"] >> +(decls) |
-lexeme["PUBLIC"] >> +(decls)
)
It is surely cleaner, but the problem is that it can be overrided inside
the declaration:
PRIVATE
INTEGER, PUBLIC :: a
INTEGER :: b
I can check later in the AST if "a" is public besides being initially in
the private "bin", but I wonder if there is a nicer solution.
Thanks!
--
Alberto
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot