Next: , Previous: , Up: Grammar methods   [Contents]


11.4 Symbols

Function: Marpa_Symbol_ID marpa_g_start_symbol (Marpa_Grammar g)

Returns current value of the start symbol of grammar g. The value is that specified in the marpa_g_start_symbol_set() call, if there has been one.

Return value: On failure, -2; -1 if there is no start symbol yet; otherwise the ID of the new start symbol.

Function: Marpa_Symbol_ID marpa_g_start_symbol_set ( Marpa_Grammar g, Marpa_Symbol_ID sym_id)

Sets the start symbol of grammar g to symbol id.

Return value: On success, the ID of the new start symbol. If sym_id is well-formed, but there is no such symbol, -1. On failure, -2.

Function: int marpa_g_highest_symbol_id (Marpa_Grammar g)

Return value: On success, the numerically largest symbol ID of g. On failure, -2.

Function: int marpa_g_symbol_is_accessible (Marpa_Grammar g, Marpa_Symbol_ID sym_id)

A symbol is accessible if it can be reached from the start symbol.

Return value: On success, 1 if symbol sym_id is accessible, 0 if not. If sym_id is well-formed, but there is no such symbol, -1. If the grammar is not precomputed, or on other failure, -2.

Function: int marpa_g_symbol_is_nullable ( Marpa_Grammar g, Marpa_Symbol_ID sym_id)

A symbol is nullable if it sometimes produces the empty string. A nulling symbol is always a nullable symbol, but not all nullable symbols are nulling symbols.

Return value: On success, 1 if symbol sym_id is nullable, 0 if not. If sym_id is well-formed, but there is no such symbol, -1. If the grammar is not precomputed, or on other failure, -2.

Function: int marpa_g_symbol_is_nulling (Marpa_Grammar g, Marpa_Symbol_ID sym_id)

A symbol is nulling if it always produces the empty string.

Return value: On success, 1 if symbol sym_id is nulling, 0 if not. If sym_id is well-formed, but there is no such symbol, -1. If the grammar is not precomputed, or on other failure, -2.

Function: int marpa_g_symbol_is_productive (Marpa_Grammar g, Marpa_Symbol_ID sym_id)

A symbol is productive if it can produce a string of terminals. All nullable symbols are considered productive.

Return value: On success, 1 if symbol sym_id is productive, 0 if not. If sym_id is well-formed, but there is no such symbol, -1. If the grammar is not precomputed, or on other failure, -2.

Function: int marpa_g_symbol_is_start ( Marpa_Grammar g, Marpa_Symbol_ID sym_id)

This return value of this call indicates whether sym_id is the start symbol.

Success value: Returns 1 if sym_id is the start symbol. Returns 0 if sym_id is not the start symbol, either because the start symbol is different from sym_id, or because the start symbol has not been set yet.

Failure values: If sym_id is well-formed, but there is no such symbol, -1. On other failure, -2.

Function: int marpa_g_symbol_is_terminal_set ( Marpa_Grammar g, Marpa_Symbol_ID sym_id, int value)
Function: int marpa_g_symbol_is_terminal ( Marpa_Grammar g, Marpa_Symbol_ID sym_id)

These methods, respectively, set and query the “terminal status” of a symbol. To be used as an input symbol in the marpa_r_alternative() method, a symbol must be a terminal. This function flags symbol sym_id as a terminal if value is 1, or flags it as a non-terminal if value is 0.

Once set to a value with the marpa_g_symbol_is_terminal_set() method, the terminal status of a symbol is “locked” at that value. A subsequent call to marpa_g_symbol_is_terminal_set() that attempts to change the terminal status of sym_id to a value different from its current one will fail. The error code will be MARPA_ERR_TERMINAL_IS_LOCKED.

By default, a symbol is a terminal if and only if it does not appear on the LHS of any rule. An attempt to flag a nulling symbol as a terminal will cause a failure, but this is not necessarily detected before precomputation.

Success returns: When successful, these methods return 1 if symbol sym_id is a terminal symbol after the call, 0 otherwise.

Failure returns: If sym_id is well-formed, but there is no such symbol, -1. On all other failures, -2. Other failures include when value is not 0 or 1; when the terminal status is locked and value is different from its current value; and, in the case of marpa_g_symbol_is_terminal_set(), when the grammar g is precomputed.

Function: Marpa_Symbol_ID marpa_g_symbol_new (Marpa_Grammar g)

Creates a new symbol. The symbol ID will be a non-negative integer.

Return value: On success, the ID of a new symbol; On failure, -2.


Next: , Previous: , Up: Grammar methods   [Contents]