• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • Vwsim
      • Isar
      • Wp-gen
      • Dimacs-reader
      • Pfcs
      • Legacy-defrstobj
      • Proof-checker-array
      • Soft
      • C
      • Farray
      • Rp-rewriter
      • Instant-runoff-voting
      • Imp-language
      • Sidekick
      • Leftist-trees
      • Java
      • Riscv
      • Taspi
      • Bitcoin
      • Des
      • Ethereum
      • X86isa
      • Sha-2
      • Yul
      • Zcash
      • Proof-checker-itp13
      • Regex
      • ACL2-programming-language
      • Json
      • Jfkr
      • Equational
      • Cryptography
      • Poseidon
      • Where-do-i-place-my-book
      • Axe
      • Aleo
        • Aleobft
        • Aleovm
        • Leo
          • Grammar
          • Early-version
            • Json2ast
            • Testing
            • Definition
              • Flattening
              • Abstract-syntax
              • Dynamic-semantics
              • Compilation
              • Static-semantics
              • Concrete-syntax
                • Pretty-printer
                • Grammar
                • Lexing-and-parsing
                  • Lexer
                  • Parser
                    • Parse-symbol-among
                    • Parse-keyword
                    • Parse-named-primitive-type
                    • Parse-rest-of-struct-component-expression
                    • Parse-rest-of-tuple-component-expression
                    • Parse-transition-declaration
                    • Parse-named-type-as-identifier-?-dot-record
                    • Parse-named-type-as-locator-?-dot-record
                    • Parse-assert-not-equal-call
                    • Parse-symbol
                    • Parse-struct-component-declarations
                    • Parse-assert-equal-call
                    • Parse-transition-or-function-declaration
                    • Parse-string-literal
                    • Parse-group-coordinate
                    • Parse-function-declaration
                    • Parse-finalizer
                    • Parse-*-comma-struct-component-declaration
                    • Parse-increment-statement
                    • Parse-function-parameter
                    • Parse-decrement-statement
                    • Parse-struct-component-declaration
                    • Parse-variable-declaration
                    • Parse-mapping-declaration
                    • Parse-function-parameters
                    • Parse-constant-declaration
                    • Parse-assert-call
                    • Parse-*-comma-function-parameter
                    • Parse-program-declaration
                    • Parse-affine-group-literal
                    • Parse-variable-or-free-constant
                    • Parse-struct-declaration
                    • Parse-record-declaration
                    • Parse-finalize-statement
                    • Parse-associated-constant
                    • Parse-numeral
                    • Parse-import-declaration
                    • Parse-identifier
                    • Parse-console-statement
                    • Parse-annotation
                    • Parse-return-statement
                    • Parse-program-item
                    • Parse-assignment-operator
                    • Parse-*-import-declaration
                    • Parse-unit-expression
                    • Parse-named-type
                    • Parse-console-call
                    • Parse-*-comma-natural
                    • Parse-program-id
                    • Parse-atomic-literal
                    • Parse-?-output-type
                    • Parse-unit-type
                    • Parse-*-program-item
                    • Parse-locator
                    • Parse-?-finalizer
                    • Parse-*-annotation
                    • Parse-primary-expression
                    • Parse-literal
                    • Parse-?-comma
                    • Parse-file
                    • Parsize
                    • Check-token-string
                    • Check-token-root
                    • Parse-postfix-expression-rest
                    • Parse-postfix-expression
                    • Parse-token
                    • Token-stringp
                    • Token-rootp
                    • Patbind-pok<
                    • Parse-rest-of-operator-call
                    • Parse-exclusive-disjunctive-expression-rest
                    • Parse-conditional-disjunctive-expression-rest
                    • Parse-conditional-conjunctive-expression-rest
                    • Parse-shift-expression-rest
                    • Parse-multiplicative-expression-rest
                    • Parse-disjunctive-expression-rest
                    • Parse-conjunctive-expression-rest
                    • Parse-additive-expression-rest
                    • Parse-*-statement
                    • Parse-*-comma-type
                    • Parse-*-comma-struct-component-initializer
                    • Parse-*-comma-expression
                    • Parse-unary-expression
                    • Parse-tuple-expression
                    • Parse-struct-expression
                    • Parse-struct-component-initializer
                    • Parse-static-function-call
                    • Parse-shift-expression
                    • Parse-ordering-expression
                    • Parse-multiplicative-expression
                    • Parse-function-arguments
                    • Parse-free-function-call
                    • Parse-exponential-expression
                    • Parse-exclusive-disjunctive-expression
                    • Parse-equality-expression
                    • Parse-disjunctive-expression
                    • Parse-conjunctive-expression
                    • Parse-conditional-ternary-expression
                    • Parse-conditional-statement
                    • Parse-conditional-disjunctive-expression
                    • Parse-conditional-conjunctive-expression
                    • Parse-binary-expression
                    • Parse-additive-expression
                    • Parse-type
                    • Parse-tuple-type
                    • Parse-statement
                    • Parse-loop-statement
                    • Parse-expression
                    • Parse-branch
                    • Parse-block
                    • Patbind-pok
                    • Perr
                  • Token-fringe
                  • Longest-lexp
                  • Parser-interface
                  • Grammar-lexp
                  • Identifier-lexp
                  • Output-file-parsep
                  • Input-file-parsep
                  • File-lex-parse-p
                  • Filter-tokens
                  • Lexp
                  • File-parsep
                  • Input-parser
                  • Output-file-lex-parse-p
                  • Input-file-lex-parse-p
                  • Parser-abstractor-interface
                  • Identifier-abnf-stringp
                  • Symbol-abnf-stringp
                  • Keyword-abnf-stringp
                  • Output-parser
                  • Tokenizer
                • Input-pretty-printer
                • Output-pretty-printer
                • Unicode-characters
                • Concrete-syntax-trees
                • Symbols
                • Keywords
      • Bigmems
      • Builtins
      • Execloader
      • Solidity
      • Paco
      • Concurrent-programs
      • Bls12-377-curves
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
    • Testing-utilities
  • Lexing-and-parsing

Parser

An executable parser of Leo.

If you are looking for API functions for calling the Leo parser, please see parser-interface. The following section describes the process of parsing a list of tokens into a CST.

This is a fairly simple parser for the Leo syntactic grammar. Efficiency is not the primary focus for now; correctness and simplicity are. In the future, we may optimize this parser, or we may use APT to do so.

The parser consists of a collection of parsing functions that operate on a sequence of tokens. Most parsing functions take a lookahead token (an optional ABNF tree) and a sequence of the remaining tokens (list of ABNF trees).

Each ABNF tree in the sequence of tokens (and the lookahead token) should have a rulename from the right hand side of the ABNF rule for token indicating the kind of token it is:

token = keyword
      / identifier
      / atomic-literal
      / numeral
      / annotation
      / symbol

All the parsing functions return, as first result, an ABNF tree or list of trees that represents the parsed input. This is called a CST (Concrete Syntax Tree).

Almost all the parsing functions also return the next unparsed token and the tokens that follow it. That is, they prefetch the token, so it is ready for the next function. If the end of the input is reached, the next token is nil (and so is the list of tokens after it).

Subtopics

Parse-symbol-among
Parse a symbol among the ones in a specified list.
Parse-keyword
Parse a specified keyword.
Parse-named-primitive-type
Parse a named-primitive-type.
Parse-rest-of-struct-component-expression
Parse the rest of a struct-component-expression.
Parse-rest-of-tuple-component-expression
Parse the rest of a tuple-component-expression.
Parse-transition-declaration
Parse a transition-declaration.
Parse-named-type-as-identifier-?-dot-record
Parse the named-type alternative identifier [ "." %s"record" ].
Parse-named-type-as-locator-?-dot-record
Parse the named-type alternative locator [ "." %s"record" ].
Parse-assert-not-equal-call
Parse an assert-not-equal-call.
Parse-symbol
Parse a specified symbol.
Parse-struct-component-declarations
Parse a struct-component-declarations.
Parse-assert-equal-call
Parse an assert-equal-call.
Parse-transition-or-function-declaration
Parse either a transition-declaration or a function-declaration.
Parse-string-literal
Parse a string-literal.
Parse-group-coordinate
Parse a group-coordinate.
Parse-function-declaration
Parse a function-declaration.
Parse-finalizer
Parse a finalize block.
Parse-*-comma-struct-component-declaration
Parse a *( "," struct-component-declaration ).
Parse-increment-statement
Parse a increment-statement.
Parse-function-parameter
Parse a function-parameter.
Parse-decrement-statement
Parse a decrement-statement.
Parse-struct-component-declaration
Parse a struct-component-declaration.
Parse-variable-declaration
Parse a variable-declaration.
Parse-mapping-declaration
Parse a mapping-declaration.
Parse-function-parameters
Parse a function-parameters.
Parse-constant-declaration
Parse a constant-declaration.
Parse-assert-call
Parse an assert-call.
Parse-*-comma-function-parameter
Parse a *( "," function-parameter ).
Parse-program-declaration
Parse an program-declaration.
Parse-affine-group-literal
Parse an affine-group-literal.
Parse-variable-or-free-constant
Parse a variable-or-free-constant.
Parse-struct-declaration
Parse a struct-declaration.
Parse-record-declaration
Parse a record-declaration.
Parse-finalize-statement
Parse a finalize-statement.
Parse-associated-constant
Parse a associated-constant.
Parse-numeral
Parse a numeral token.
Parse-import-declaration
Parse an import-declaration.
Parse-identifier
Parse an identifier.
Parse-console-statement
Parse a console-statement.
Parse-annotation
Parse an annotation.
Parse-return-statement
Parse a return-statement.
Parse-program-item
Parse a program-item.
Parse-assignment-operator
Parse an assignment-operator.
Parse-*-import-declaration
Parse a *import-declaration.
Parse-unit-expression
Parse a unit-expression.
Parse-named-type
Parse a named-type.
Parse-console-call
Parse a console-call.
Parse-*-comma-natural
Parse a *( "," natural ).
Parse-program-id
Parse an program-id.
Parse-atomic-literal
Parse an atomic-literal.
Parse-?-output-type
Parse [ "->" type ].
Parse-unit-type
Parse a unit-type.
Parse-*-program-item
Parse a *program-item.
Parse-locator
Parse a locator.
Parse-?-finalizer
Parse a [ finalizer ].
Parse-*-annotation
Parse a *annotation.
Parse-primary-expression
Parse a primary-expression.
Parse-literal
Parse a literal.
Parse-?-comma
Parse a [ "," ].
Parse-file
Parse a file.
Parsize
Size of the parser input.
Check-token-string
Check if the given token is present and has the given string as fringe.
Check-token-root
Check if the given token is present and has the given rule name as root.
Parse-postfix-expression-rest
Parse the rest of a postfix-expression.
Parse-postfix-expression
Parse a postfix-expression.
Parse-token
Parse a token.
Token-stringp
Check if the given token has the given string as fringe.
Token-rootp
Check if the given token has the given rule name as root.
Patbind-pok<
b* binder for checking and propagating error results of parsing functions and ensuring termination.
Parse-rest-of-operator-call
Parse the rest of an operator-call.
Parse-exclusive-disjunctive-expression-rest
Parse the rest of a exclusive-disjunctive-expression.
Parse-conditional-disjunctive-expression-rest
Parse the rest of a conditional-disjunctive-expression.
Parse-conditional-conjunctive-expression-rest
Parse the rest of a conditional-conjunctive-expression.
Parse-shift-expression-rest
Parse the rest of a shift-expression.
Parse-multiplicative-expression-rest
Parse the rest of a multiplicative-expression.
Parse-disjunctive-expression-rest
Parse the rest of a disjunctive-expression.
Parse-conjunctive-expression-rest
Parse the rest of a conjunctive-expression.
Parse-additive-expression-rest
Parse the rest of an additive-expression.
Parse-*-statement
Parse a *statement.
Parse-*-comma-type
Parse a *( "," type ).
Parse-*-comma-struct-component-initializer
Parse a *( "," struct-component-initializer ).
Parse-*-comma-expression
Parse a *( "," expression ).
Parse-unary-expression
Parse a unary-expression.
Parse-tuple-expression
Parse a tuple-expression.
Parse-struct-expression
Parse a struct-expression.
Parse-struct-component-initializer
Parse a struct-component-initializer.
Parse-static-function-call
Parse a static-function-call.
Parse-shift-expression
Parse a shift-expression.
Parse-ordering-expression
Parse an ordering-expression.
Parse-multiplicative-expression
Parse a multiplicative-expression.
Parse-function-arguments
Parse a function-arguments.
Parse-free-function-call
Parse a free-function-call.
Parse-exponential-expression
Parsen an exponential-expression.
Parse-exclusive-disjunctive-expression
Parse a exclusive-disjunctive-expression.
Parse-equality-expression
Parse an equality-expression.
Parse-disjunctive-expression
Parse a disjunctive-expression.
Parse-conjunctive-expression
Parse a conjunctive-expression.
Parse-conditional-ternary-expression
Parse a conditional-ternary-expression.
Parse-conditional-statement
Parse a conditional-statement.
Parse-conditional-disjunctive-expression
Parse a conditional-disjunctive-expression.
Parse-conditional-conjunctive-expression
Parse a conditional-conjunctive-expression.
Parse-binary-expression
Parse a binary-expression.
Parse-additive-expression
Parse an additive-expression.
Parse-type
Parse a type.
Parse-tuple-type
Parse a tuple-type.
Parse-statement
Parse a statement.
Parse-loop-statement
Parse a loop-statement.
Parse-expression
Parse an expression.
Parse-branch
Parse a branch.
Parse-block
Parse a block.
Patbind-pok
b* binder for checking and propagating error results of parsing functions.
Perr
Returning a parsing error.