PreviousUpNext

15.4.136  src/app/yacc/lib/make-complete-yacc-parser-g.pkg

## make-complete-yacc-parser-g.pkg

# Compiled by:
#     src/lib/std/standard.lib

# See also:
#     src/app/yacc/lib/make-complete-yacc-parser-with-custom-argument-g.pkg
#
# (A practical parser almost always needs a customized argument,
# so the above file is much more frequently used than this one.)

# generic make_complete_yacc_parser_g creates a user parser by putting together a Lexer package,
# an LrValues package, and a typeagnostic parser package.  Note that
# the Lexer and LrValues package must share the type Source_Position (i.e. the type
# of line numbers), the type Semantic_Value, and the type of tokens.



generic package make_complete_yacc_parser_g (

    package lex:         Lexer;                         # Lexer         is from   src/app/yacc/lib/base.api
    package parser_data: Parser_Data;                   # Parser_Data   is from   src/app/yacc/lib/base.api
    package lr_parser:   Lr_Parser;                     # Lr_Parser     is from   src/app/yacc/lib/base.api

    sharing parser_data::lr_table ==  lr_parser::lr_table;
    sharing parser_data::token    ==  lr_parser::token;

    sharing lex::user_declarations::Semantic_Value  ==  parser_data::Semantic_Value;
    sharing lex::user_declarations::Source_Position ==  parser_data::Source_Position;
    sharing lex::user_declarations::Token           ==  parser_data::token::Token;
)

: (weak)  Parser                                        # Parser        is from   src/app/yacc/lib/base.api

{
    package token  =  parser_data::token;
    package stream =  lr_parser::stream;                # lr_parser     is from   src/app/yacc/lib/parser2.pkg
 
    exception PARSE_ERROR = lr_parser::PARSE_ERROR;

    Arg             =  parser_data::Arg;
    Source_Position =  parser_data::Source_Position;
    Result          =  parser_data::Result;
    Semantic_Value  =  parser_data::Semantic_Value;

                                                        # streamify     def in    src/app/yacc/lib/stream.pkg

    # Given a read-input-string fn, construct and
    # return a lazy token stream function.
    # In more detail:
    #  o Accepts a (Int -> String) function which reads and returns a string <= given length.
    #  o Returns a (Void -> (token, next)) function where 'token' is next input token and
    #                                                 and 'next()' returns another such (token,\\) pair.
    #
    make_lexer      = lr_parser::stream::streamify      # Make lazy stream from imperative read function.
                      o
                      lex::make_lexer;
                        #
                        # Accepts a (Int -> String) function which reads and returns a string <= given length.
                        # Returns a (Void -> Token) function reading and returning tokens.
    parse
        =
        \\ (lookahead, lexer, error, arg) =
        (\\ (a, b) =  (parser_data::actions::extract a, b))
        (lr_parser::parse
            { lexer,
              lookahead,
              arg,
              table          =>  parser_data::table,
              saction        =>  parser_data::actions::actions,
              void           =>  parser_data::actions::void,
              error_recovery =>  { error,
                                   is_keyword       =>  parser_data::error_recovery::is_keyword,
                                   no_shift         =>  parser_data::error_recovery::no_shift,
                                   preferred_change =>  parser_data::error_recovery::preferred_change,
                                   errtermvalue     =>  parser_data::error_recovery::errtermvalue,
                                   show_terminal    =>  parser_data::error_recovery::show_terminal,
                                   terms            =>  parser_data::error_recovery::terms
                                 }
            }
      );

     same_token = token::same_token;
};






## Mythryl-Yacc Parser Generator (c) 1989 Andrew W. Appel, David R. Tarditi 
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext