MaintainerCS 131, Programming Languages (Melissa O'Neill, Chris Stone, Ben Wiedermann)
Safe HaskellSafe

MosesParser

Description

You do not need to edit this file, nor do you need to even read it, if you don't want. But you might find it interesting anyway.

Synopsis

Documentation

rwords :: [String] #

Reserved words in Moses

vname :: Parser String #

Variable names A valid variable name starts with a lowercase letter and is not a reserved word.

variable :: Parser Expr #

Parse a variable

literal :: Parser Expr #

Parse a literal value (float, int, string, or boolean)

float :: Parser Double #

Parse a floating-point number (ignoring preceding whitespace)

stringcontent :: Parser String #

Parse the contents of a string literal

numb :: Parser Integer #

Parse a positive integer (ignoring preceding whitespace)

expr :: Parser Expr #

Parse a Moses expression * Relational operators are left-associative and have least precedence * List operators are right-associative and have next-highest precedence * Addition & subtraction are left-associative and have next-highest precedence * Multiplication & division are left-associative and have next-highest precedence * Unary negation has highest precedence

relop :: Parser (Expr -> Expr -> Expr) #

Parse a single relational operator

cterm :: Parser Expr #

Handle list operators

listop :: Parser (Expr -> Expr -> Expr) #

Parse a single list operator

pterm :: Parser Expr #

Handle addition & subtraction

plusminus :: Parser (Expr -> Expr -> Expr) #

Parse a single addition or subtraction operator

mterm :: Parser Expr #

Handle multiplication & division

timesdivide :: Parser (Expr -> Expr -> Expr) #

Parse a single multiplication or division operator

aterm :: Parser Expr #

Parse a negated number or a factor

factor :: Parser Expr #

A factor is one of:

  • a variable
  • a literal value (int, real, string, or boolean)
  • a parenthetical expression
  • a tuple
  • a list
  • an if expression
  • a recursive let expression
  • a let expression
  • a case expression on a list
  • a function

tuple_or_parenthetical :: Parser Expr #

Parse a tuple-creating expression or a parenthetical expression

list :: Parser Expr #

Parse a list-creating expression

ifExpression :: Parser Expr #

Parse an if expression

recursiveLet :: Parser Expr #

Parse a recursive letrec expression

letExpression :: Parser Expr #

Parse a let expression

vdecl :: Parser (String, Ty) #

Parse a variable declaration (i.e., a variable name or a variable name + type)

ty :: Parser Ty #

Parse a type declaration Our grammar for Moses is somewhat ambiguous, it allows you to write fn x : INT -> x+1 and fn x : INT -> INT -> x+1 which means that we have to use a slightly more careful version of chainr1 which isn't so quick to think it's found a syntax error. Note that fn x : INT => x+1 is the preferred syntax.

bty :: Parser Ty #

Parse a non-function type

caseExpression :: Parser Expr #

Parse a case expression

function :: Parser Expr #

Parse a function

data PreludeDecl #

Instances

Eq PreludeDecl # 

Methods

(==) :: PreludeDecl -> PreludeDecl -> Bool

(/=) :: PreludeDecl -> PreludeDecl -> Bool

Ord PreludeDecl # 
Show PreludeDecl # 

Methods

showsPrec :: Int -> PreludeDecl -> ShowS

show :: PreludeDecl -> String

showList :: [PreludeDecl] -> ShowS

parse :: Parser a -> String -> a #

parseNamed :: Parser a -> String -> String -> a #

parseFile :: Parser a -> String -> IO a #