-- This Happy file was machine-generated by the BNF converter
{
{-# OPTIONS_GHC -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns #-}
module ParSRLRL where
import AbsSRLRL
import LexSRLRL
import ErrM

}

%name pVar Var
%name pOplus Oplus
%name pOtime Otime
%name pConst Const
%name pExp Exp
%name pStep Step
%name pBlk Blk
%name pSRL SRL
%name pLabel Label
%name pJump Jump
%name pFrom From
%name pRlblk Rlblk
%name pRl Rl
-- 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) }
  '[' { PT _ (TS _ 13) }
  ']' { PT _ (TS _ 14) }
  '^' { PT _ (TS _ 15) }
  'do' { PT _ (TS _ 16) }
  'else' { PT _ (TS _ 17) }
  'empty' { PT _ (TS _ 18) }
  'entry' { PT _ (TS _ 19) }
  'exit' { PT _ (TS _ 20) }
  'fi' { PT _ (TS _ 21) }
  'from' { PT _ (TS _ 22) }
  'goto' { PT _ (TS _ 23) }
  'if' { PT _ (TS _ 24) }
  'l' { PT _ (TS _ 25) }
  'loop' { PT _ (TS _ 26) }
  'pop' { PT _ (TS _ 27) }
  'push' { PT _ (TS _ 28) }
  'skip' { PT _ (TS _ 29) }
  'then' { PT _ (TS _ 30) }
  'top' { PT _ (TS _ 31) }
  'until' { PT _ (TS _ 32) }

L_ident  { PT _ (TV $$) }
L_integ  { PT _ (TI $$) }


%%

Ident   :: { Ident }   : L_ident  { Ident $1 }
Integer :: { Integer } : L_integ  { (read ( $1)) :: Integer }

Var :: { Var }
Var : Ident { AbsSRLRL.IVar $1 }
Oplus :: { Oplus }
Oplus : '+' { AbsSRLRL.Plus }
      | '-' { AbsSRLRL.Minus }
      | '^' { AbsSRLRL.Index }
Otime :: { Otime }
Otime : Oplus { AbsSRLRL.Calc $1 }
      | '*' { AbsSRLRL.Time }
      | '/' { AbsSRLRL.Div }
      | '=' { AbsSRLRL.Eq }
      | '<' { AbsSRLRL.Less }
      | '>' { AbsSRLRL.Greater }
      | '<=' { AbsSRLRL.Less_Eq }
      | '>=' { AbsSRLRL.Greater_Eq }
      | '!=' { AbsSRLRL.Not_Eq }
Const :: { Const }
Const : Integer { AbsSRLRL.IConst $1 }
Exp :: { Exp }
Exp : Const { AbsSRLRL.EConst $1 }
    | Ident { AbsSRLRL.EVar $1 }
    | Var '[' Exp ']' { AbsSRLRL.EVar_List $1 $3 }
    | Exp Otime Exp { AbsSRLRL.EExp $1 $2 $3 }
    | 'top' Var { AbsSRLRL.ETop $2 }
    | 'empty' Var { AbsSRLRL.EEmpty $2 }
Step :: { Step }
Step : Var Oplus '=' Exp { AbsSRLRL.Oplus_Eq $1 $2 $4 }
     | Var '[' Exp ']' Oplus '=' Exp { AbsSRLRL.OPlus_Eq_List $1 $3 $5 $7 }
     | 'push' Var Var { AbsSRLRL.Push $2 $3 }
     | 'pop' Var Var { AbsSRLRL.Pop $2 $3 }
     | 'skip' { AbsSRLRL.Skip }
Blk :: { Blk }
Blk : Step { AbsSRLRL.Sstep $1 }
    | 'if' Exp 'then' Blk 'else' Blk 'fi' Exp { AbsSRLRL.Sif $2 $4 $6 $8 }
    | Blk Blk { AbsSRLRL.Sblk $1 $2 }
    | 'from' Exp 'do' Blk 'loop' Blk 'until' Exp { AbsSRLRL.Sfrom $2 $4 $6 $8 }
SRL :: { SRL }
SRL : Blk { AbsSRLRL.ESRL $1 }
Label :: { Label }
Label : 'l' Integer { AbsSRLRL.ELabel $2 }
Jump :: { Jump }
Jump : 'goto' Label { AbsSRLRL.Rgoto $2 }
     | 'if' Exp 'goto' Label 'else' Label { AbsSRLRL.Rif $2 $4 $6 }
     | 'exit' { AbsSRLRL.Rexit }
From :: { From }
From : 'from' Label { AbsSRLRL.Rfrom $2 }
     | 'fi' Exp 'from' Label 'else' Label { AbsSRLRL.Rfi $2 $4 $6 }
     | 'entry' { AbsSRLRL.Rentry }
Rlblk :: { Rlblk }
Rlblk : Label ':' From Jump { AbsSRLRL.Rblk1 $1 $3 $4 }
      | Label ':' From Step Jump { AbsSRLRL.Rblk2 $1 $3 $4 $5 }
Rl :: { Rl }
Rl : {- empty -} { AbsSRLRL.Rl1 }
   | Rlblk ';' Rl { AbsSRLRL.Rl2 $1 $3 }
{

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
}

