NuSMV开发:修改case语句中TRUE关键字的功能
TRUE Branch in case...esac Reuse the Previous Action? Short Answer
Absolutely—this is totally feasible! NuSMV is open-source, so you can tweak its core expression-handling logic to change how the TRUE branch behaves to inherit the prior state of your variable.
Background on Default TRUE Branch Behavior
By default, the TRUE branch in case...esac acts as a catch-all: it triggers when none of the preceding conditional branches match. Under the hood, NuSMV parses case statements into nested ITE (if-then-else) expressions. Your example:
next(a) := case a>0 : -10; a<0 : 10; TRUE : (do the last time actions); esac;
gets converted to something like:
ITE(a > 0, -10, ITE(a < 0, 10, <TRUE_BRANCH_EXPR>))
Right now, <TRUE_BRANCH_EXPR> uses whatever you explicitly write, or a default value if omitted. Your goal is to make this automatically reference the previous value of a (i.e., prev(a)) when the TRUE branch runs.
Key C Files to Modify
To implement this behavior, you’ll need to adjust NuSMV’s expression parsing and conversion logic. Here are the critical files to focus on:
src/compile/expr/Expr.c: This is the core file for handling expression semantics. It’s wherecasestatements are converted into nested ITE expressions. You’ll add logic here to detect when the final branch of acaseusesTRUEas its condition, then replace its expression withprev(<target_variable>).src/compile/parser/parser.y: This YACC parser defines NuSMV’s syntax rules. You may need to tweak how theTRUEbranch is recognized during parsing to flag it for special handling later.src/compile/flat/Flat.c: This file handles "flattening" complex expressions into simpler forms. You’ll want to ensure your modifiedTRUEbranch logic is preserved during this step.
High-Level Modification Steps
- Detect the
TRUEcatch-all branch: When parsing acasestatement into an abstract syntax tree (AST), check if the final branch’s condition is theTRUEconstant. - Replace the branch expression: For that final
TRUEbranch, instead of using the user-provided expression (or default), construct aprev()expression targeting the variable on the left side of thenext()assignment (in your example, that’sa). - Validate semantics: Ensure the
prev()expression is correctly handled in subsequent compilation steps (like model flattening and BDD generation) so it properly references the variable’s prior state.
Quick Notes
- Test your changes incrementally! Start with a small model like your
avariable example to verify theTRUEbranch correctly inherits the previous value whena=0. - NuSMV’s codebase includes helpful comments, so you’ll find context about how expressions are processed in the files listed above.
内容的提问来源于stack exchange,提问作者Alvin

