package baguette_sharp

  1. Overview
  2. Docs

Module Baguette_sharp.ParserSource

Parser module

Exceptions

Sourceclass bag_exception : string -> object ... end
Sourceclass outofbound : string -> object ... end
Sourceclass arg : string -> object ... end
Sourceclass type_error : string -> object ... end
Sourceclass syntax_error : string -> object ... end
Sourcetype arguments =
  1. | Str of string
  2. | I of int
  3. | Nul of unit
  4. | D of float
  5. | Bool of bool

Type argument: every primitive type the language recognize

Sourcetype parameters =
  1. | CallExpression of string
  2. | Argument of arguments
  3. | GOTO of string
  4. | LOAD of string
  5. | Exception of bag_exception
  6. | Label of string
  7. | IF
  8. | COND
  9. | Array
  10. | TBL of parameters array
  11. | Function of string * string list

Type parameters: every structure the language recognize

Sourcetype 'a ast =
  1. | Nil
  2. | Node of 'a * 'a ast list

Type AST

Printing utility

Sourceval print_argument : arguments -> string

Transforms an argument into a string Type: value

Sourceval print_lit_argument : arguments -> string

Transforms only the value of an argument

Sourceval print_argument_for_repl : arguments -> string

Transform an argument into a string for the REPL

Sourceval print_parameter : ?fortbl:??? -> parameters -> string

Transforms a parameter into a string

  • parameter fortbl

    specify if we are printing an array to simplify the output

Sourceval print_pretty_arguments : parameters list -> string

Transform a list of parameters into a string representation

Sourceval print_pretty_node : parameters ast -> string

Pretty-print (transforms into a string) an AST

Parsing methods

Sourceval parse_string_rec : Token.token_type list -> string * Token.token_type list

Parse a string recursively until it encounters a closing quote

Sourceval ast_list_to_string_list : parameters ast list -> string list
Sourceval parse_line : Token.token_type list -> Token.token_type list * parameters ast list

Parse a line (a list of tokens) into a a list of ASTs

Sourceval parse_file : Token.token_type list -> parameters ast list

Parse a file using parse line

Parameters/Arguments utility functions

Sourceval create_int_argument : int -> parameters

Creates an integer argument and wraps it into a parameter

Sourceval create_float_argument : float -> parameters

Creates a float argument and wraps it into a parameter

Sourceval create_bool_argument : bool -> parameters

Creates a boolean argument and wraps it into a parameter

Sourceval create_string_argument : string -> parameters

Creates a string argument and wraps it into a parameter

Parameters algebra function

Sourceval add_numbers : parameters -> parameters -> parameters

Adds two parameters

  • raises a

    baguette exception if the type are non-summable

Checks for equality between two parameters

Sourceval inferior_large : parameters -> parameters -> parameters

Checks for the <= between two parameters

Checks for the < between two parameters

Sourceval superior_large : parameters -> parameters -> parameters

Checks for the >= between two parameters

Checks for the > between two parameters

Sourceval mult_numbers : parameters -> parameters -> parameters

Multiply two numbers

  • raises a

    baguette sharp type error if the arguments are not numbers

Exponentiate a^b

  • raises a

    baguette sharp type error if the arguments are not numbers

Sourceval divide_numbers : parameters -> parameters -> parameters

Divide a/b

  • raises a

    baguette sharp type error if the arguments are not numbers

Sourceval substract_numbers : parameters -> parameters -> parameters

Subtract two number

  • raises a

    baguette sharp type error if the arguments are not numbers

Sourceval apply_binary_operator : (bool -> bool -> bool) -> parameters -> parameters -> parameters

Apply a binary operator for two booleans

  • raises a

    baguette sharp type error if the arguments are not booleans

Sourceval apply_unary_operator : (bool -> bool) -> parameters -> parameters

Apply an unary operator on a boolean

  • raises a

    baguette sharp type error if the argument is not a boolean