packages feed

tip-lib-0.1: src/Tip/Parser/ParTIP.y

-- This Happy file was machine-generated by the BNF converter
{
{-# OPTIONS_GHC -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns #-}
module Tip.Parser.ParTIP where
import Tip.Parser.AbsTIP
import Tip.Parser.LexTIP
import Tip.Parser.ErrM

}

%name pStart Start
%name pListDecl ListDecl
%name pDecl Decl
%name pAssertion Assertion
%name pFunDef FunDef
%name pInnerFunDef InnerFunDef
%name pFunDecl FunDecl
%name pInnerFunDecl InnerFunDecl
%name pDatatype Datatype
%name pConstructor Constructor
%name pBinding Binding
%name pLetDecl LetDecl
%name pType Type
%name pExpr Expr
%name pBinder Binder
%name pCase Case
%name pPattern Pattern
%name pHead Head
%name pListLetDecl ListLetDecl
%name pListCase ListCase
%name pListExpr ListExpr
%name pListDatatype ListDatatype
%name pListConstructor ListConstructor
%name pListBinding ListBinding
%name pListSymbol ListSymbol
%name pListType ListType
%name pListFunDecl ListFunDecl
%name pListFunDef ListFunDef

-- no lexer declaration
%monad { Err } { thenM } { returnM }
%tokentype { Token }

%token
  '(' { PT _ (TS _ 1) }
  ')' { PT _ (TS _ 2) }
  '*' { PT _ (TS _ 3) }
  '+' { PT _ (TS _ 4) }
  '-' { PT _ (TS _ 5) }
  '<' { PT _ (TS _ 6) }
  '<=' { PT _ (TS _ 7) }
  '=' { PT _ (TS _ 8) }
  '=>' { PT _ (TS _ 9) }
  '>' { PT _ (TS _ 10) }
  '>=' { PT _ (TS _ 11) }
  '@' { PT _ (TS _ 12) }
  'Bool' { PT _ (TS _ 13) }
  'Int' { PT _ (TS _ 14) }
  'and' { PT _ (TS _ 15) }
  'as' { PT _ (TS _ 16) }
  'assert' { PT _ (TS _ 17) }
  'assert-not' { PT _ (TS _ 18) }
  'case' { PT _ (TS _ 19) }
  'check-sat' { PT _ (TS _ 20) }
  'declare-datatypes' { PT _ (TS _ 21) }
  'declare-fun' { PT _ (TS _ 22) }
  'declare-sort' { PT _ (TS _ 23) }
  'default' { PT _ (TS _ 24) }
  'define-funs-rec' { PT _ (TS _ 25) }
  'distinct' { PT _ (TS _ 26) }
  'div' { PT _ (TS _ 27) }
  'exists' { PT _ (TS _ 28) }
  'false' { PT _ (TS _ 29) }
  'forall' { PT _ (TS _ 30) }
  'ite' { PT _ (TS _ 31) }
  'lambda' { PT _ (TS _ 32) }
  'let' { PT _ (TS _ 33) }
  'match' { PT _ (TS _ 34) }
  'mod' { PT _ (TS _ 35) }
  'not' { PT _ (TS _ 36) }
  'or' { PT _ (TS _ 37) }
  'par' { PT _ (TS _ 38) }
  'true' { PT _ (TS _ 39) }

L_integ  { PT _ (TI $$) }
L_Symbol { PT _ (T_Symbol _) }


%%

Integer :: { Integer } : L_integ  { (read ( $1)) :: Integer }
Symbol    :: { Symbol} : L_Symbol { Symbol (mkPosToken $1)}

Start :: { Start }
Start : ListDecl { Start $1 } 


ListDecl :: { [Decl] }
ListDecl : '(' 'check-sat' ')' { [] } 
  | '(' Decl ')' ListDecl { (:) $2 $4 }


Decl :: { Decl }
Decl : 'declare-datatypes' '(' ListSymbol ')' '(' ListDatatype ')' { DeclareDatatypes (reverse $3) (reverse $6) } 
  | 'declare-sort' Symbol Integer { DeclareSort $2 $3 }
  | 'declare-fun' FunDecl { DeclareFun $2 }
  | 'define-funs-rec' '(' ListFunDef ')' '(' ListExpr ')' { DefineFunsRec (reverse $3) (reverse $6) }
  | Assertion Expr { MonoAssert $1 $2 }
  | Assertion '(' 'par' '(' ListSymbol ')' Expr ')' { ParAssert $1 (reverse $5) $7 }


Assertion :: { Assertion }
Assertion : 'assert' { AssertIt } 
  | 'assert-not' { AssertNot }


FunDef :: { FunDef }
FunDef : '(' 'par' '(' ListSymbol ')' InnerFunDef ')' { ParFunDef (reverse $4) $6 } 
  | InnerFunDef { MonoFunDef $1 }


InnerFunDef :: { InnerFunDef }
InnerFunDef : '(' Symbol '(' ListBinding ')' Type ')' { InnerFunDef $2 (reverse $4) $6 } 


FunDecl :: { FunDecl }
FunDecl : '(' 'par' '(' ListSymbol ')' '(' InnerFunDecl ')' ')' { ParFunDecl (reverse $4) $7 } 
  | InnerFunDecl { MonoFunDecl $1 }


InnerFunDecl :: { InnerFunDecl }
InnerFunDecl : Symbol '(' ListType ')' Type { InnerFunDecl $1 (reverse $3) $5 } 


Datatype :: { Datatype }
Datatype : '(' Symbol ListConstructor ')' { Datatype $2 (reverse $3) } 


Constructor :: { Constructor }
Constructor : '(' Symbol ListBinding ')' { Constructor $2 (reverse $3) } 


Binding :: { Binding }
Binding : '(' Symbol Type ')' { Binding $2 $3 } 


LetDecl :: { LetDecl }
LetDecl : '(' Binding Expr ')' { LetDecl $2 $3 } 


Type :: { Type }
Type : Symbol { TyVar $1 } 
  | '(' Symbol ListType ')' { TyApp $2 (reverse $3) }
  | '(' '=>' ListType ')' { ArrowTy (reverse $3) }
  | 'Int' { IntTy }
  | 'Bool' { BoolTy }


Expr :: { Expr }
Expr : Symbol { Var $1 } 
  | '(' 'as' Expr Type ')' { As $3 $4 }
  | '(' Head ListExpr ')' { App $2 (reverse $3) }
  | '(' 'match' Expr ListCase ')' { Match $3 (reverse $4) }
  | '(' 'let' '(' ListLetDecl ')' Expr ')' { Let (reverse $4) $6 }
  | '(' Binder '(' ListBinding ')' Expr ')' { Binder $2 (reverse $4) $6 }
  | Integer { LitInt $1 }
  | 'true' { LitTrue }
  | 'false' { LitFalse }


Binder :: { Binder }
Binder : 'lambda' { Lambda } 
  | 'forall' { Forall }
  | 'exists' { Exists }


Case :: { Case }
Case : '(' 'case' Pattern Expr ')' { Case $3 $4 } 


Pattern :: { Pattern }
Pattern : 'default' { Default } 
  | '(' Symbol ListSymbol ')' { ConPat $2 (reverse $3) }
  | Symbol { SimplePat $1 }


Head :: { Head }
Head : Symbol { Const $1 } 
  | '@' { At }
  | 'ite' { IfThenElse }
  | 'and' { And }
  | 'or' { Or }
  | 'not' { Not }
  | '=>' { Implies }
  | '=' { Equal }
  | 'distinct' { Distinct }
  | '+' { IntAdd }
  | '-' { IntSub }
  | '*' { IntMul }
  | 'div' { IntDiv }
  | 'mod' { IntMod }
  | '>' { IntGt }
  | '>=' { IntGe }
  | '<' { IntLt }
  | '<=' { IntLe }


ListLetDecl :: { [LetDecl] }
ListLetDecl : {- empty -} { [] } 
  | ListLetDecl LetDecl { flip (:) $1 $2 }


ListCase :: { [Case] }
ListCase : {- empty -} { [] } 
  | ListCase Case { flip (:) $1 $2 }


ListExpr :: { [Expr] }
ListExpr : {- empty -} { [] } 
  | ListExpr Expr { flip (:) $1 $2 }


ListDatatype :: { [Datatype] }
ListDatatype : {- empty -} { [] } 
  | ListDatatype Datatype { flip (:) $1 $2 }


ListConstructor :: { [Constructor] }
ListConstructor : {- empty -} { [] } 
  | ListConstructor Constructor { flip (:) $1 $2 }


ListBinding :: { [Binding] }
ListBinding : {- empty -} { [] } 
  | ListBinding Binding { flip (:) $1 $2 }


ListSymbol :: { [Symbol] }
ListSymbol : {- empty -} { [] } 
  | ListSymbol Symbol { flip (:) $1 $2 }


ListType :: { [Type] }
ListType : {- empty -} { [] } 
  | ListType Type { flip (:) $1 $2 }


ListFunDecl :: { [FunDecl] }
ListFunDecl : {- empty -} { [] } 
  | ListFunDecl FunDecl { flip (:) $1 $2 }


ListFunDef :: { [FunDef] }
ListFunDef : {- empty -} { [] } 
  | ListFunDef FunDef { flip (:) $1 $2 }



{

returnM :: a -> Err a
returnM = return

thenM :: Err a -> (a -> Err b) -> Err b
thenM = (>>=)

happyError :: [Token] -> Err a
happyError ts =
  Bad $ "syntax error at " ++ tokenPos ts ++ 
  case ts of
    [] -> []
    [Err _] -> " due to lexer error"
    _ -> " before " ++ unwords (map (id . prToken) (take 4 ts))

myLexer = tokens
}