• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • Vwsim
      • Isar
      • Wp-gen
      • Dimacs-reader
      • Pfcs
      • Legacy-defrstobj
      • C
      • Proof-checker-array
      • Soft
      • Farray
      • Rp-rewriter
      • Instant-runoff-voting
      • Imp-language
      • Sidekick
      • Ethereum
      • Leftist-trees
      • Java
      • Riscv
      • Taspi
      • Bitcoin
      • Zcash
      • Des
      • X86isa
      • Sha-2
      • Yul
      • Proof-checker-itp13
      • Regex
      • ACL2-programming-language
      • Json
      • Jfkr
      • Equational
      • Cryptography
      • Axe
      • Poseidon
      • Where-do-i-place-my-book
      • 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
                  • Token-fringe
                  • Longest-lexp
                  • Parser-interface
                    • Parse-from-file-at-path+
                    • Tokens-to-cst
                      • Parse-fragment-to-cst+
                      • Lexemes-to-cst+
                      • Parse-from-string+
                      • Parse-from-codepoints+
                      • Parse-fragment-to-cst
                      • Parse-from-bytes+
                      • Parse-from-string
                      • Parse-from-file-at-path
                      • Token-parses?
                      • Statement-parses?
                      • Expression-parses?
                      • File-parses?
                      • Token-parses-same-fringe?
                      • Expression-parses-same-fringe?
                      • Statement-parses-same-fringe?
                      • Parse-from-codepoints
                      • File-parses-same-fringe?
                      • Parse-from-bytes
                    • 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
    • Parser-interface

    Tokens-to-cst

    Parse list of tokens for a supported grammar rule name.

    Signature
    (tokens-to-cst rule-name tokens) → tree
    Arguments
    rule-name — Guard (stringp rule-name).
    tokens — Guard (abnf::tree-listp tokens).
    Returns
    tree — Type (abnf::tree-resultp tree).

    Supported grammar rule names are file, statement, expression, and token (expressed as strings).

    Given a list of tokens resulting from lexing and tokenizing, this function attempts to parse the tokens into a CST for the the given grammar rule name.

    In the case of rule-name being "token", the rule names at the top of the trees in the tokens argument are actually the rule names on the right hand side of the rule for token, although that is not checked here.

    If the given rule cannot be parsed or if there are tokens left over, then a reserr is returned.

    Definitions and Theorems

    Function: tokens-to-cst

    (defun tokens-to-cst (rule-name tokens)
     (declare (xargs :guard (and (stringp rule-name)
                                 (abnf::tree-listp tokens))))
     (let ((__function__ 'tokens-to-cst))
      (declare (ignorable __function__))
      (b*
       (((unless
              (member-equal rule-name
                            '("file" "statement" "expression" "token")))
         (reserrf
              (cons :not-yet-supported-top-level-rule-name rule-name)))
        ((when (and (null tokens)
                    (not (equal rule-name "file"))))
         (reserrf (cons :not-enough-tokens rule-name)))
        ((mv cst next-token rest-input)
         (cond
          ((equal rule-name "file")
           (parse-file tokens))
          ((equal rule-name "statement")
           (parse-statement (first tokens)
                            (rest tokens)))
          ((equal rule-name "expression")
           (parse-expression (first tokens)
                             (rest tokens)))
          ((equal rule-name "token")
           (b* (((mv tree? rest-tokens)
                 (parse-token tokens))
                ((unless (abnf::treep tree?))
                 (mv (reserrf (cons :no-more-tokens tokens))
                     nil nil))
                ((when (null rest-tokens))
                 (mv tree? nil nil)))
             (mv tree? (car rest-tokens)
                 (cdr rest-tokens))))
          (t
           (mv
            (reserrf
                (cons :not-yet-supported-top-level-rule-name rule-name))
            nil nil))))
        ((when (reserrp cst)) cst)
        ((when (or next-token rest-input))
         (reserrf (list :not-all-tokens-parsed
                        cst next-token rest-input))))
       cst)))

    Theorem: tree-resultp-of-tokens-to-cst

    (defthm tree-resultp-of-tokens-to-cst
      (b* ((tree (tokens-to-cst rule-name tokens)))
        (abnf::tree-resultp tree))
      :rule-classes :rewrite)