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.

  • clear – clears system memory. Useful, if we want to test some test cases or examples, otherwise, previous experience of the system might affect results.
  • sync – waits till all inference threads are in waiting state. This is useful only for the test command (which implicitly uses it). All tasks run concurrently, and might happen, that incidentally a hint would be given before conclusion is found. It might be.
  • test ⟨sentence⟩ - test the last outcome from the system against the expected one (sentence) in terms of syntax and truth value.
  • debug on | debug off – with debug on, we get some additional information about the inference process. Some commands requires to be debug set on.
  • words – gets words from the memory.

    Output takes a mix of text and binary form:

    Length [Bytes]34termSize1n1...
    Content "<w>"termSizetermId02word03'\0'4...

    1termSize is a size of termId - internal representation of a term. termSize currently is represented by 8 bytes (64 bits).
    2A binary representation (identifier) of a term.
    3A text (string) representation of a term.
    4Null termination of a string.

  • compounds – gets compound terms from the memory.
    Length [Bytes]34termSizen1...
    Content "<c>"termSizetermId0compound0'\0'...
  • statements – gets statements from the memory.
    Length [Bytes]34termSizen1...
    Content "<s>"termSizetermId0statement0'\0'...
  • memory – print system memory in pure Narsese. Similar to 'statements', but every type of the same statement is printed separately. The output from this command can be used as input to the system for memory reloading.
    Length [Bytes]3n1...
    Content "<m>"statement0'\n'...
  • question – information about question derivation of the last question entering to the system. To able to use this command, debug must be on. If the question can’t be solved by any inference process, sub questions are generated during inference process which leads to the original question. This process is done recursively, until at least one question can be solved. Then tracking back we get the solution for the original question.
    Length [Bytes]34444
    Content "<q>"termSizenumberOfEdgesnumberOfNodesorderSize
    A list of edges
    Length [Bytes]termSizetermSize...
    Content node0node1...
    A list of nodes
    Length [Bytes]termSizetermSize1...
    Content termIdstatement'\0'...
    Processing sequence (order of processing sub questions)
    Length [Bytes]termSizetermSize...
    Content termIdattribute...

    NarsDevelop transforms these information into an SVG graph wich can be saved into a computer storage.

  • inference – Shows inference processes leading from a question to the final conclusion.
    Length [Bytes]3444
    Content "<n>"statementsOffsetstatementsNumopcodeNum
    Length [Bytes]4termSizetermSize...4...
    Content premiseNumpremise0premise1...opcode...
    Length [Bytes]termSizen1...
    Content termIdstatement0'\0'...
    Operation Code
    Length [Bytes]4n01n11...
    Content OpCodedescription0'\0'description1'\0'...
  • version – prints out the version of the nars library in form of a string.
    Length [Bytes]3n1
    Content <v>library version'\0'
  • Other outputs:
    • Output from internal questions
      Length [Bytes]3n1
      Content "<i>"Narsese statement'\0'
    • Time and elapsed cycles for the last external question.
      Length [Bytes]344
      Content "<t>"Elapsed time [μs]number of inference cycles
    • Error reporting.
      Length [Bytes]3444n1
      Content "<e>"rowcolumnerror type1description'\0'
    • 1Possible type of error:

      • 0x1 - syntax error
      • 0x2 - different answer from expected one (applies, when the test command is used)
      • 0x4 - different truth value (same as above)
      • 0x8 - different tense (same as above)

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 + -"⊖"


Background Image

Header Color


Content Color