ContentsIndex
Main
Contents
Main Monads
Merging Grammar Monads into Ours
Pattern Matching
Stage Driver
Grammar Changes
User Interaction
Synopsis
data St = St {
gr :: !Grammar
renamer :: !Renamer
lastLabel :: !Label
labelCount :: !Int
userLabs :: !Int
newLabels :: !Int
maxLabels :: !Int
joinCount :: !Int
maxJoin :: !Int
stage :: !Int
failure :: !Bool
batchOpt :: !Bool
quietOpt :: !Bool
inputFile :: !(Maybe String)
outputFile :: !(Maybe String)
anonymousOpt :: !Bool
outputRulesOpt :: !Bool
emptyMattersOpt :: !Bool
useHintsOpt :: !Bool
preferUserLabelsOpt :: !Bool
joinUserLabelsOpt :: !Bool
rules :: ![Rule]
rawRules :: ![Rule]
intersections :: ![Intersection]
}
type NonDetReader = ReaderT St []
type IOState = StateT St IO
doGr :: GrState a -> IOState a
readGr :: GrReader a -> IOState a
pickFromGr :: GrReader [a] -> NonDetReader a
matchTermWithGroundTerm :: Term -> Term -> NonDetReader Subst
matchSomewhere_c :: Variable -> Term -> NonDetReader Subst
matchSomewhere_hv :: Variable -> Head -> Variable -> NonDetReader Subst
matchSomewhere_hvv :: Variable -> Head -> Variable -> Variable -> NonDetReader Subst
matchSomewhere_hlv :: Variable -> Head -> Term -> Variable -> NonDetReader Subst
matchSomewhere_hvl :: Variable -> Head -> Variable -> Term -> NonDetReader Subst
matchClause :: Clause -> NonDetReader Subst
matchRule :: Rule -> NonDetReader (Label, Term)
matchRules :: [Rule] -> NonDetReader (Label, Term)
mayCreateLabels :: IOState Bool
mayJoinLabels :: IOState Bool
mayPromptUser :: IOState Bool
triedEverything :: IOState Bool
alreadyFailed :: IOState Bool
handleMatch :: Int -> (Label, Term) -> IOState Int
closeUnderRules :: IOState ()
newLabel :: IOState Label
addPlainTermToSet :: Label -> Term -> IOState ()
addGroundTermToSet :: Label -> Term -> IOState (Maybe ())
addGroundTermSomewhere :: Maybe Label -> Term -> IOState (Maybe Label)
addPlainTermSomewhere :: Maybe Label -> Term -> IOState (Maybe Label)
tryToJoinLabels :: IOState ()
displayGrammar :: IOState ()
displayUsedLabels :: IOState ()
displayStatistics :: IOState ()
promptUser :: Term -> IOState (Maybe Label)
pureExamples :: [Label] -> Term -> NonDetReader Term
parseFile :: IOState Bool
saveFixedPoint :: IOState ()
parseOptions :: [String] -> IOState ()
usageError :: IOState ()
initialState :: St
main :: IO ()
Main Monads
data St
The state used in the computation of the fixed point.
Constructors
St
gr :: !GrammarThe current term grammar.
renamer :: !RenamerThe Renamer.
lastLabel :: !LabelThe last generated label.
labelCount :: !IntIndex for the next label to be generated.
userLabs :: !IntNumber of user specified labels in the .rules file.
newLabels :: !IntNumber of generated labels, minus the number of joined labels.
maxLabels :: !IntBound on newLabels. Constant set by user.
joinCount :: !IntNumber of joined labels.
maxJoin :: !IntBound on joinCount. Constant set by user.
stage :: !IntCurrent stage in the computation of the fixed point.
failure :: !BoolWhether the analysis failed.
batchOpt :: !BoolTells whether we must avoid interacting with the user. Set by the user.
quietOpt :: !BoolVerbosity option set by user.
inputFile :: !(Maybe String)The name of the .rules file.
outputFile :: !(Maybe String)The name of the output file, if any.
anonymousOpt :: !BoolWhether the output file should record the name of the input file inside. Set by the user.
outputRulesOpt :: !BoolWhether to put the rewriting rules into the output file, in spite of the output grammar begin closed under such rules.
emptyMattersOpt :: !BoolWhether to allow for rewriting ground terms which can not be expanded into a pure term, but denote "empty" term sets.
useHintsOpt :: !BoolWhen rewriting T for @l:T, whether to prefer to use @l in the rewritten T, if possible. Used by addPlainTermSomewhere.
preferUserLabelsOpt :: !BoolWhether to prefer user @labels rather than $labels. Used by addPlainTermSomewhere.
joinUserLabelsOpt :: !Bool
rules :: ![Rule]The normalized rules we are closing under.
rawRules :: ![Rule]The (not yet normalized) rules from the input file. We store them here to eventually copy them into the output file.
intersections :: ![Intersection]The intersection rules.
type NonDetReader = ReaderT St []
Read-only (w.r.t. St) non-deterministic computation.
type IOState = StateT St IO
Read-write (w.r.t. St) deterministic IO-enabled computation.
Merging Grammar Monads into Ours
doGr :: GrState a -> IOState a
Perform a read-write actions on the Grammar.
readGr :: GrReader a -> IOState a
Perform a deterministic Grammar read.
pickFromGr :: GrReader [a] -> NonDetReader a
Perform a non-deterministic Grammar read.
Pattern Matching
matchTermWithGroundTerm :: Term -> Term -> NonDetReader Subst
Match a Term pattern with a ground Term, non-deterministically returning the unifying Substs.
matchSomewhere_c :: Variable -> Term -> NonDetReader Subst
Match a plain Term pattern somewhere in the grammar.
matchSomewhere_hv :: Variable -> Head -> Variable -> NonDetReader Subst
Match a Term pattern of the form h(X) somewhere in the grammar.
matchSomewhere_hvv :: Variable -> Head -> Variable -> Variable -> NonDetReader Subst
Match a Term pattern of the form h(X,Y) somewhere in the grammar.
matchSomewhere_hlv :: Variable -> Head -> Term -> Variable -> NonDetReader Subst
Match a Term pattern of the form h(@lab,Y) somewhere in the grammar.
matchSomewhere_hvl :: Variable -> Head -> Variable -> Term -> NonDetReader Subst
Match a Term pattern of the form h(X,@lab) somewhere in the grammar.
matchClause :: Clause -> NonDetReader Subst
Generic pattern matching for a Clause. Yields all matching substitutions, non-deterministically.
matchRule :: Rule -> NonDetReader (Label, Term)
matchRules :: [Rule] -> NonDetReader (Label, Term)
Apply all Rules and return (non-deterministically) all the ground Terms that would need to be added to Labels.
Stage Driver
mayCreateLabels :: IOState Bool
Check whether we can add a fresh Label to gr.
mayJoinLabels :: IOState Bool
Check whether the join bound has been reached.
mayPromptUser :: IOState Bool
Check whether we can ask the user at this stage.
triedEverything :: IOState Bool
Check whether we already tried all the strategies, including user interaction. In this case, we need to reuse a Label, hoping not to lose too much precision in the approximation.
alreadyFailed :: IOState Bool
Check whether the analisys has failed.
handleMatch :: Int -> (Label, Term) -> IOState Int
Insert a new Term into the Grammar, incrementing the Int if not possible now.
closeUnderRules :: IOState ()
Main driver for all stages. Loops until the state reaches a fixed point.
Grammar Changes
newLabel :: IOState Label
Return a fresh Label.
addPlainTermToSet :: Label -> Term -> IOState ()
Add a plain Term to the set of Label in the gr. Also, print a dot for every added Term.
addGroundTermToSet :: Label -> Term -> IOState (Maybe ())
Try to add a ground Term to the set of Label in the gr. If necessary, the production is changed into Chomsky Normal Form.
addGroundTermSomewhere
:: Maybe LabelHint: try this first.
-> Term
-> IOState (Maybe Label)
Try to find a place for a plain Term anywhere in the gr, choosing the 'best' Label. If possible, do not change gr.
addPlainTermSomewhere
:: Maybe LabelHint: try this first.
-> Term
-> IOState (Maybe Label)
Try to find a place for a plain Term anywhere in the gr, choosing the 'best' Label. If possible, do not change gr. On failure (e.g., early stage, so we want to try the alternatives first), return Nothing; otherwise return Just Label.
tryToJoinLabels :: IOState ()

Try to reclain some Label slots by joining two Labels if they have similar sets.

NOTE
In general, joining labels might lead to a non terminating algorithm, since joining makes the grammar size to decrease. Currently, we enforce termination by not allowing more than maxJoin joins.
User Interaction
displayGrammar :: IOState ()
Print the gr to the user.
displayUsedLabels :: IOState ()
Print information about available Label slots to the user.
displayStatistics :: IOState ()
promptUser :: Term -> IOState (Maybe Label)

Ask the user what to do, i.e. ask for a Label whose set is where to place the Term.

If Term is MinTerm, do not ask anything, but let the user explore the state.

pureExamples :: [Label] -> Term -> NonDetReader Term
Instantiate a ground Term into a pure Term in all the possible ways, in a non-deterministic fashion. Avoid infinite loops on the grammar reachability graph.
parseFile :: IOState Bool
Parse and type check a .rules file. If succeeds, returns the rules in Chomsky Normal Form, and stores the original ones in the St state.
saveFixedPoint :: IOState ()
Save the grammar in a file, if it was requested.
parseOptions :: [String] -> IOState ()
Parse command line options and update St accordingly.
usageError :: IOState ()
Display usage.
initialState :: St
main :: IO ()
Produced by Haddock version 0.6