Print

Narsese grammar

This is the Narsese syntax and grammar used by the nars.dll library. It was adapted from Wang’s NAL Specification documentation.

                         ⟨sentence⟩ ::=  ⟨judgment⟩ | ⟨goal⟩ | ⟨question⟩
                         ⟨judgment⟩ ::=  [⟨tense⟩] ⟨statement⟩. ⟨truth-value⟩
                             ⟨goal⟩ ::=  ⟨statement⟩! ⟨desire-value⟩
                         ⟨question⟩ ::=  (⟨term⟩ ⟨copula⟩ ⟨term⟩) | ⟨term⟩
		                      | (¬ ⟨statement⟩)
                                      | (∧ ⟨statement⟩ ⟨statement⟩⁺)
                                      | (∨ ⟨statement⟩ ⟨statement⟩⁺)
                                      | (∧/ ⟨statement⟩ ⟨statement⟩⁺)
                                      | (∧| ⟨statement⟩ ⟨statement⟩⁺)
                                      | (⇑ ⟨word⟩ ⟨term⟩*)
                          ⟨copula⟩ ::=   → | ↔ | ∘→ | →∘ | ∘→∘  
                                      | ⇒ | ⇔ | /⇒ |  \⇒ | |⇒ | /⇔ | |⇔
                           ⟨tense⟩ ::=   /⇒ |  \⇒ | |⇒
                            ⟨term⟩ ::=   ⟨word⟩ | ⟨variable⟩ | ⟨statement⟩
                                      | {⟨term⟩⁺} | [⟨term⟩⁺]
                                      | (∩ ⟨term⟩ ⟨term⟩⁺)
                                      | (∪ ⟨term⟩ ⟨term⟩⁺)
                                      | (- ⟨term⟩ ⟨term⟩)
                                      | (⊖ ⟨term⟩ ⟨term⟩)
                                      | (× ⟨term⟩ ⟨term⟩⁺)
                                      | (⊥ ⟨term⟩* ◊ ⟨term⟩*)
                                      | (⊤ ⟨term⟩* ◊ ⟨term⟩*)
                       ⟨variable⟩ ::=    ⟨independent-variable⟩
                                      | ⟨dependent-variable⟩
                                      | ⟨query-variable⟩
           ⟨independent-variable⟩ ::=    #⟨word⟩
             ⟨dependent-variable⟩ ::=    #[⟨word⟩(⟨independent-variable⟩*)]
                 ⟨query-variable⟩ ::=    ?[⟨word⟩]
                    ⟨truth-value⟩ ::=    <⟨real-number⟩, ⟨real-number⟩>
                   ⟨desire-value⟩ ::=    <⟨real-number⟩, ⟨real-number⟩>
                           ⟨word⟩ ::=    [_a-zA-Z0-9ɐ-ʯæ₀-₉]⁺

Special symbols of Narsese are not replaced by a combination of ASCII character but rather are encoded with UTF-8. Narsese code can be edited by any editor supporting UTF-8 encoding. NarsDevelop, provided on this website, is a simple GUI used togehter with the NARS library, which contains a simple editor of Narsese code with possibility to directly input special symbols used in Narsese by a keyboard shortcut. It has also syntaxhilighting and some debuging capability of Narsese code.

In case, compounds contain exactly two terms, operators ∧, ∨, ∩, ∪, -, ⊖, × can use both - prefix and infix form (e.g.: (∧, S1, S2) and (S1 ∧ s2) are equivalent).

Control and debug commands

The following is an extension of the grammar, used just during development and debugging and it is not part of the Narsese language.

                 space (ignored) ::= /\s\n\r\t+/
     multiline-comment (ignored) ::= '/*' .. '*/'
    singleline-comment (ignored) ::= /\#[^\n\r]*/

                          ⟨line⟩  ::=   ⟨sentence⟩ | ⟨control⟩
                        ⟨control⟩ ::=   ⋙ ⟨commands⟩
                       ⟨commands⟩ ::=   clear
                                      | sync						
                                      | test ⟨sentence⟩
                                      | words
                                      | compounds
                                      | statements
                                      | memory
                                      | question
                                      | inference
                                      | debug on | debug off
                                      | version

For performance reason, the answer from the system for these commands takes a mixture of text and binary form.

nars library uses C++ style single and multi-line comments.

Everything followed by a special symbol are processed as a command.

Direct input of special symbols

NarsDevelop has some special shortcuts to directly enter special symbols of Narsese using keyboard as it is shown in the following table.

Keyboard shortcutUTF-8 outputKeyboard shortcutUTF-8 output
Alt + 0"∘"Ctrl + 0"◊"
Alt + 1"→"Ctrl + 1"⇒"
Alt + 2"↔"Ctrl + 2"⇔"
Alt + 3"∩"Ctrl + 3"∧"
Alt + 4"∪"Ctrl + 4"∨"
Alt + 5"⊥"Ctrl + 5"⊤"
Alt + 6"¬"
Alt + 7"⇑"
Alt + 8"⋙"
Alt + *"×"
Alt + -"⊖"