函式名:Parle\Parser::precedence()
適用版本:Parle 0.8.0 及以上版本
用法:Parle\Parser::precedence() 函式用於設定或獲取語法規則中運算子的優先順序。
語法:
public static int Parle\Parser::precedence(string $symbol [, int $precedence = NULL])
引數:
- $symbol:要設定或獲取優先順序的運算子的符號字串。
- $precedence(可選):要設定的優先順序值。如果未提供此引數,則函式將返回當前設定的優先順序值。
返回值:
- 如果提供了 $precedence 引數,則返回設定後的優先順序值。
- 如果未提供 $precedence 引數,則返回當前的優先順序值。
示例:
// 設定運算子 "+" 的優先順序為 10
Parle\Parser::precedence('+', 10);
// 獲取運算子 "+" 的當前優先順序
$precedence = Parle\Parser::precedence('+');
echo $precedence; // 輸出 10
注意事項:
- Parle\Parser::precedence() 函式必須在建立語法規則之前呼叫。
- 運算子的優先順序值越高,其優先順序越高。
- 預設情況下,所有運算子的優先順序都是 0。
熱門工具排行榜