class EXPAND_EXPRESSION
Summary
That program shows the use of ABSTRACT_BACKTRACKING.
That program read expressions from the standard input and print the expansion of the read expression on the standard output. The expressions are composed of sequence and alternative of terms. The expansion is the list of all the sequences allowed when alternatives are removed.
For example the input expression "(0+1)(0+1)(0+1)" will give the following output:
  (1)   0 0 0
  (2)   0 0 1
  (3)   0 1 0
  (4)   0 1 1
  (5)   1 0 0
  (6)   1 0 1
  (7)   1 1 0
  (8)   1 1 1
The grammar of the input expressions is in ABNF like:
   expression  ::= alternative
   alternative ::= sequence [ '+' sequence ]...
   sequence    ::= term [ ['.'] term ]...
   term        ::= | '(' alternative ')' | "[^().+]*"
Direct parents
Inherit list: ABSTRACT_BACKTRACKING, EXPRESSION_ITEM_GLOBALS, MINI_PARSER_BUFFER
Insert list: EXCEPTIONS
Class invariant
Overview
Creation features
{ANY}
  • make
    read one line and treat it until end of input
{ANY}
Features
make
{ANY}
  • make
    read one line and treat it until end of input
  • initialise
    initialisation
enumeration of expansions
{ANY}
parsing
{ANY}
Common client features
{ANY}
Control of the exploration
{ANY}
Internal
{}
Specific to sequences
{ABSTRACT_BACKTRACKING_SEQUENCE}
Specific to alternatives
{ABSTRACT_BACKTRACKING_ALTERNATIVE}
internal: allocation and collection
{}
{ANY}
{ANY}
Memo
{ANY}
Queries
{ANY}
{}
{}
Various exceptions codes:
{ANY}
{ANY}
Status report:
{ANY}
Basic operations:
{ANY}
  • die (code: INTEGER_32)
    Terminate execution with exit status code, without triggering an exception.
  • raise (name: STRING)
    Raise a developer exception of name name.
  • throw (a_exception: EXCEPTION)
Non-Standard Extensions:
{ANY}
{}
make
effective procedure
{ANY}
read one line and treat it until end of input
initialise
effective procedure
{ANY}
initialisation
writable attribute
{ANY}
current_item: EXPRESSION_ITEM
writable attribute
{ANY}
goto_item (item: EXPRESSION_ITEM)
effective procedure
{ANY}
set the 'current_item' to 'item'
ensure
writable attribute
{ANY}
expand_all
effective procedure
{ANY}
print all the expansions of the root
evaluate_current_state
effective procedure
{ANY}
Here is how must be driven the and or explorer Only the basic features are called the evaluation of 'current_item' is made depending of its type.
context_clear
effective procedure
{ANY}
Clear any saved context.
Called by the features clear and search_first.
context_push
effective procedure
{ANY}
Push the current context.
Called each time that an alternative begins.
context_restore
effective procedure
{ANY}
Restore the context to the last saved one.
The saved context MUST remain available for future use. Called each time that a new alternative (of the previous alternative point) is starting.
context_restore_and_pop
effective procedure
{ANY}
Restore the context to the last saved one and drop it.
The saved context MUST be removed. Called each time that the last alternative (of the previous alternative point) is starting. Should be similar to context_restore followed by context_cut.
context_cut
effective procedure
{ANY}
Remove the last saved context.
Called by cut, cut_all or cut_until.
parse
effective procedure
{ANY}
initialise the mini_parser_buffer behavior then call parse and treat syntax errors with exceptions
ensure
parse_alternative: EXPRESSION_ITEM
effective function
{ANY}
parse an alternative recursively to construct tree balanced to the right because it is more efficient
parse_sequence: EXPRESSION_ITEM
effective function
{ANY}
parse a sequence recursively to construct tree balanced to the right because it is more efficient
parse_term: EXPRESSION_ITEM
effective function
{ANY}
parse a term
the_empty_item: EXPRESSION_ITEM
once function
{ANY}
the_failure_item: EXPRESSION_ITEM
once function
{ANY}
buffer: STRING
writable attribute
{ANY}
search_first
effective procedure
{ANY}
Resets all and searches the first solution.
The current state must be set. It is the first state, the root of the search. When the feature returns, 'search_is_success' must be checked to know if a solution was found. When search_is_success=False, it means that there is no solution at all. Conversely, if search_is_success=True, then the first solution is found and 'search_next' can be called to get the next solution if it exists.
ensure
search_next
effective procedure
{ANY}
Searches the next solution.
When the feature returns, 'search_is_success' must be checked to know if a solution was found. When search_is_success=False at the end, it means that there is no more solution. Conversely, if search_is_success=True, then a solution is found and 'search_next' can be called again to get the next solution.
require ensure
search_is_success: BOOLEAN
writable attribute
{ANY}
True when search is successful
is_off: BOOLEAN
effective function
{ANY}
True when search is finished
ensure
clear
effective procedure
{ANY}
Clears the current state to nothing.
ensure
is_cleared: BOOLEAN
effective function
{ANY}
True if no partial data remain in the current state
ensure
  • no_solution_when_cleared: Result implies is_off
push_sequence (sequence: ABSTRACT_BACKTRACKING_SEQUENCE)
effective procedure
{ANY}
Pushes the sequence in front of the continuation path.
require
  • sequence_not_void: sequence /= Void
ensure
push_alternative (alternative: ABSTRACT_BACKTRACKING_ALTERNATIVE)
effective procedure
{ANY}
Pushes the alternative before the continuation path.
require
  • alternative_not_void: alternative /= Void
ensure
continue
effective procedure
{ANY}
Continues the exploration of the current path.
backtrack
effective procedure
{ANY}
Stops the exploration of the current path and tries to explore the next alternative path.
push_cut_point
effective procedure
{ANY}
Inserts a cut point into the continuation path.
The inserted cut point records the current top of the alternatives.
cut
effective procedure
{ANY}
Removes the alternatives until the one recorded by the next cut point in the continuation path.
cut_all
effective procedure
{ANY}
Cuts all alternatives.
stop_search_loop: BOOLEAN
writable attribute
{}
True if at the end of a search.
This occurs if either a solution is found (and then search_is_success=True) or no solution is found (and then search_is_success=False). That feature should be modified only by continue and backtrack.
search
effective procedure
{}
Common search loop to search_first and search_next
cut_until (alternative: ABSTRACT_BACKTRACKING_ALTERNATIVE)
effective procedure
{}
Cut all alternatives until 'alternative'.
To cut an alternative is currently to remove it.
ensure
Stack of sequences represented by its top (can be Void)
current_continuation: ABSTRACT_BACKTRACKING_SEQUENCE
writable attribute
The current continuation path
pop_sequence
effective procedure
Removes the current sequence and replace it by the next sequence in the continuation path.
require
Stack of alternatives represented by its top (can be Void)
continue_alternative
effective procedure
Returns to the alternative on the top of the stack and put its saved continuation path as the current continuation path.
require ensure
pop_alternative
effective procedure
Returns to the alternative on the top of the stack and put its saved continuation path as the current continuation path.
Remove the alternative from the stack of alternatives. Same as continue_alternative but also removes the alternative.
require ensure
remove_top_sequence
effective procedure
{}
Removes the top sequence.
require ensure
remove_top_alternative
effective procedure
{}
Removes the top alternative.
require ensure
once function
{ANY}
Bank of cut points
initialize_with (string: ABSTRACT_STRING)
effective procedure
{ANY}
Initialize the Current buffer interning string.
require
  • string /= Void
ensure
next
effective procedure
{ANY}
Move the current_index forward by one.
require ensure
skip_separators
effective procedure
{ANY}
Skip all separators by using is_separator of class CHARACTER.
last_error: PARSE_ERROR
writable attribute
{ANY}
Can be used to memorize an error message.
set_last_error (error: PARSE_ERROR)
effective procedure
{ANY}
ensure
set_last_error_message (error_message: STRING)
effective procedure
{ANY}
ensure
set_current_index (new_index: INTEGER_32)
effective procedure
{ANY}
To be able to move (usually back) in the buffer
require ensure
print_position_on (stream: OUTPUT_STREAM)
effective procedure
{ANY}
require
  • stream.is_connected
set_memory (a_memory: MINI_PARSER_MEMORY)
effective procedure
{ANY}
require
  • a_memory /= Void
ensure
memo: INTEGER_32
effective function
{ANY}
restore (a_memo: INTEGER_32)
effective procedure
{ANY}
writable attribute
{ANY}
lower: INTEGER_32
effective function
{ANY}
upper: INTEGER_32
effective function
{ANY}
Maximum valid index in storage.
count: INTEGER_32
effective function
{ANY}
The length of the Current buffer which is also the maximum valid index.
capacity: INTEGER_32
effective function
{ANY}
Of storage.
current_index: INTEGER_32
writable attribute
{ANY}
Index of the current character.
current_character: CHARACTER
effective function
{ANY}
The current character (the one at current_index).
require
end_reached: BOOLEAN
effective function
{ANY}
Is the end of the buffer reached?
ensure
marked: BOOLEAN
writable attribute
{ANY}
clear_mark
effective procedure
{ANY}
ensure
storage: FIXED_STRING
writable attribute
{}
The storage area to be parsed.
default_create
effective procedure
{}
Default creation method.
It is used when no creation method is specified if allowed. Note it may be renamed.
once function
{}
Failure_item: INTEGER_32
is 1
constant attribute
{}
Value_item: INTEGER_32
is 2
constant attribute
{}
Or_item: INTEGER_32
is 3
constant attribute
{}
And_item: INTEGER_32
is 4
constant attribute
{}
Empty_item: INTEGER_32
is 5
constant attribute
{}
Success_item: INTEGER_32
is 6
constant attribute
{}
Iterate: BOOLEAN
is True
constant attribute
{}
alternative_pool: POOL_ALTERNATIVE
once function
{}
sequence_pool: POOL_SEQUENCE
once function
{}
Check_instruction: INTEGER_32
is 1
constant attribute
{ANY}
Exception code for violated check.
Class_invariant: INTEGER_32
is 2
constant attribute
{ANY}
Exception code for violated class invariant.
Developer_exception: INTEGER_32
is 3
constant attribute
{ANY}
Exception code for developer exception.
See also: raise, throw
Incorrect_inspect_value: INTEGER_32
is 4
constant attribute
{ANY}
Exception code for inspect statement.
This exception occurs when Void is passed as the expression to inspect ("inspect on STRING only). This exception also occurs when the inspected value selects no branch (when the keyword "else" not used, one "when" branch _must_ be selected). Some value which is not one of the inspect constants, if there is no Else_part r
Loop_invariant: INTEGER_32
is 5
constant attribute
{ANY}
Exception code for violated loop invariant
Loop_variant: INTEGER_32
is 6
constant attribute
{ANY}
Exception code for non-decreased loop variant
No_more_memory: INTEGER_32
is 7
constant attribute
{ANY}
Exception code for failed memory allocation
Postcondition: INTEGER_32
is 8
constant attribute
{ANY}
Exception code for violated postcondition.
Precondition: INTEGER_32
is 9
constant attribute
{ANY}
Exception code for violated precondition.
Routine_failure: INTEGER_32
is 10
constant attribute
{ANY}
Exception code for failed routine.
Os_signal: INTEGER_32
is 11
constant attribute
{ANY}
Exception code for a signal received from the OS.
Void_attached_to_expanded: INTEGER_32
is 12
constant attribute
{ANY}
Exception code for attachment of Void value to expanded entity.
Void_call_target: INTEGER_32
is 13
constant attribute
{ANY}
Exception code for feature applied to Void reference
System_level_type_error: INTEGER_32
is 14
constant attribute
{ANY}
Exception code for the system-level type error (this kind of error mostly arise with covariant redefinition).
exception_name: STRING
effective function
{ANY}
name_of_exception (a_exception: INTEGER_32): STRING
effective function
{ANY}
developer_exception: EXCEPTION
effective function
{ANY}
The last developer-thrown exception.
require
developer_exception_name: STRING
effective function
{ANY}
Name of last developer-raised exception.
require
is_developer_exception: BOOLEAN
effective function
{ANY}
Is the last exception originally due to a developer exception?
is_developer_named_exception: BOOLEAN
effective function
{ANY}
Is the last exception originally due to a developer exception?
is_developer_exception_of_name (name: STRING): BOOLEAN
effective function
{ANY}
Is the last exception originally due to a developer exception of name name?
assertion_violation: BOOLEAN
effective function
{ANY}
Is last exception originally due to a violated assertion or non-decreasing variant?
exception: INTEGER_32
{ANY}
Code of last exception that occurred.
is_signal: BOOLEAN
effective function
{ANY}
Is last exception originally due to an external event (operating system signal) ?
die (code: INTEGER_32)
effective procedure
{ANY}
Terminate execution with exit status code, without triggering an exception.
raise (name: STRING)
effective procedure
{ANY}
Raise a developer exception of name name.
require
  • name /= Void
throw (a_exception: EXCEPTION)
effective procedure
{ANY}
require
  • a_exception /= Void
signal_number: INTEGER_32
{ANY}
Signal Number received from OS.
 Zero if exception is not an OS signal.
named_exception: NAMED_EXCEPTION
once function
{}
developer_exception_memory: REFERENCE[EXCEPTION]
once function
{}
raise_exception (code: INTEGER_32)
{}