package baguette_sharp

  1. Overview
  2. Docs

Parser module

Exceptions

class bag_exception : string -> object ... end
class outofbound : string -> object ... end
class arg : string -> object ... end
class type_error : string -> object ... end
class syntax_error : string -> object ... end
type 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

type 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

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

Type AST

Printing utility

val print_argument : arguments -> string

Transforms an argument into a string Type: value

val print_lit_argument : arguments -> string

Transforms only the value of an argument

val print_argument_for_repl : arguments -> string

Transform an argument into a string for the REPL

val print_parameter : ?fortbl:bool -> parameters -> string

Transforms a parameter into a string

  • parameter fortbl

    specify if we are printing an array to simplify the output

val print_pretty_arguments : parameters list -> string

Transform a list of parameters into a string representation

val print_pretty_node : parameters ast -> string

Pretty-print (transforms into a string) an AST

Parsing methods

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

Parse a string recursively until it encounters a closing quote

val ast_list_to_string_list : parameters ast list -> string list
val 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

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

Parse a file using parse line

Parameters/Arguments utility functions

val create_int_argument : int -> parameters

Creates an integer argument and wraps it into a parameter

val create_float_argument : float -> parameters

Creates a float argument and wraps it into a parameter

val create_bool_argument : bool -> parameters

Creates a boolean argument and wraps it into a parameter

val create_string_argument : string -> parameters

Creates a string argument and wraps it into a parameter

Parameters algebra function

val add_numbers : parameters -> parameters -> parameters

Adds two parameters

  • raises a

    baguette exception if the type are non-summable

val equality : parameters -> parameters -> parameters

Checks for equality between two parameters

val inferior_large : parameters -> parameters -> parameters

Checks for the <= between two parameters

val inferior : parameters -> parameters -> parameters

Checks for the < between two parameters

val superior_large : parameters -> parameters -> parameters

Checks for the >= between two parameters

val superior : parameters -> parameters -> parameters

Checks for the > between two parameters

val 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

val divide_numbers : parameters -> parameters -> parameters

Divide a/b

  • raises a

    baguette sharp type error if the arguments are not numbers

val substract_numbers : parameters -> parameters -> parameters

Subtract two number

  • raises a

    baguette sharp type error if the arguments are not numbers

val 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

val 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

OCaml

Innovation. Community. Security.