-- This Happy file was machine-generated by the BNF converter
{
{-# OPTIONS_GHC -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns #-}
module ParRL where
import qualified AbsRL
import LexRL
}

%name pRL RL
%name pListRlblk ListRlblk
%name pRlblk Rlblk
%name pListStep ListStep
%name pFrom From
%name pJump Jump
%name pStep Step
%name pExp Exp
%name pExp2 Exp2
%name pExp3 Exp3
%name pExp4 Exp4
%name pExp5 Exp5
%name pExp6 Exp6
%name pExp7 Exp7
%name pExp8 Exp8
%name pExp9 Exp9
%name pExp1 Exp1
-- no lexer declaration
%monad { Either String } { (>>=) } { return }
%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) }
  '[' { PT _ (TS _ 16) }
  ']' { PT _ (TS _ 17) }
  '^' { PT _ (TS _ 18) }
  '^=' { PT _ (TS _ 19) }
  'else' { PT _ (TS _ 20) }
  'empty' { PT _ (TS _ 21) }
  'entry' { PT _ (TS _ 22) }
  'exit' { PT _ (TS _ 23) }
  'fi' { PT _ (TS _ 24) }
  'from' { PT _ (TS _ 25) }
  'goto' { PT _ (TS _ 26) }
  'if' { PT _ (TS _ 27) }
  'pop' { PT _ (TS _ 28) }
  'push' { PT _ (TS _ 29) }
  'skip' { PT _ (TS _ 30) }
  'top' { PT _ (TS _ 31) }
  L_Ident  { PT _ (TV $$) }
  L_integ  { PT _ (TI $$) }

%%

Ident :: { AbsRL.Ident}
Ident  : L_Ident { AbsRL.Ident $1 }

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

RL :: { AbsRL.RL }
RL : ListRlblk { AbsRL.ERL $1 }

ListRlblk :: { [AbsRL.Rlblk] }
ListRlblk : Rlblk { (:[]) $1 } | Rlblk ListRlblk { (:) $1 $2 }

Rlblk :: { AbsRL.Rlblk }
Rlblk : Ident ':' From ListStep Jump { AbsRL.Brlblk $1 $3 $4 $5 }

ListStep :: { [AbsRL.Step] }
ListStep : {- empty -} { [] } | Step ListStep { (:) $1 $2 }

From :: { AbsRL.From }
From : 'from' Ident { AbsRL.Ffrom $2 }
     | 'fi' Exp 'from' Ident 'else' Ident { AbsRL.Ffi $2 $4 $6 }
     | 'entry' { AbsRL.Fentry }

Jump :: { AbsRL.Jump }
Jump : 'goto' Ident { AbsRL.Jgoto $2 }
     | 'if' Exp 'goto' Ident 'else' Ident { AbsRL.Jif $2 $4 $6 }
     | 'exit' { AbsRL.Jexit }

Step :: { AbsRL.Step }
Step : Ident '+=' Exp { AbsRL.SasnAdd $1 $3 }
     | Ident '-=' Exp { AbsRL.SasnMin $1 $3 }
     | Ident '^=' Exp { AbsRL.SasnXor $1 $3 }
     | Ident '[' Exp ']' '+=' Exp { AbsRL.SasnArrAdd $1 $3 $6 }
     | Ident '[' Exp ']' '-=' Exp { AbsRL.SasnArrMin $1 $3 $6 }
     | Ident '[' Exp ']' '^=' Exp { AbsRL.SasnArrXor $1 $3 $6 }
     | 'push' Ident Ident { AbsRL.Spush $2 $3 }
     | 'pop' Ident Ident { AbsRL.Spop $2 $3 }
     | 'skip' { AbsRL.Sskip }

Exp :: { AbsRL.Exp }
Exp : 'top' Exp2 { AbsRL.Etop $2 } | Exp1 { $1 }

Exp2 :: { AbsRL.Exp }
Exp2 : 'empty' Exp3 { AbsRL.Eempty $2 } | Exp3 { $1 }

Exp3 :: { AbsRL.Exp }
Exp3 : Exp3 '^' Exp4 { AbsRL.Exor $1 $3 } | Exp4 { $1 }

Exp4 :: { AbsRL.Exp }
Exp4 : Exp4 '=' Exp5 { AbsRL.Eeq $1 $3 }
     | Exp4 '!=' Exp5 { AbsRL.Ene $1 $3 }
     | Exp5 { $1 }

Exp5 :: { AbsRL.Exp }
Exp5 : Exp5 '<' Exp6 { AbsRL.Elt $1 $3 }
     | Exp5 '>' Exp6 { AbsRL.Egt $1 $3 }
     | Exp5 '>=' Exp6 { AbsRL.Ele $1 $3 }
     | Exp5 '<=' Exp6 { AbsRL.Ege $1 $3 }
     | Exp6 { $1 }

Exp6 :: { AbsRL.Exp }
Exp6 : Exp6 '+' Exp7 { AbsRL.Eadd $1 $3 }
     | Exp6 '-' Exp7 { AbsRL.Emin $1 $3 }
     | Exp7 { $1 }

Exp7 :: { AbsRL.Exp }
Exp7 : Exp7 '*' Exp8 { AbsRL.Emul $1 $3 }
     | Exp7 '/' Exp8 { AbsRL.Ediv $1 $3 }
     | Exp8 { $1 }

Exp8 :: { AbsRL.Exp }
Exp8 : Exp9 '[' Exp ']' { AbsRL.Earr $1 $3 } | Exp9 { $1 }

Exp9 :: { AbsRL.Exp }
Exp9 : Integer { AbsRL.Econ $1 }
     | Ident { AbsRL.Evar $1 }
     | '(' Exp ')' { $2 }

Exp1 :: { AbsRL.Exp }
Exp1 : Exp2 { $1 }
{

happyError :: [Token] -> Either String a
happyError ts = Left $
  "syntax error at " ++ tokenPos ts ++
  case ts of
    []      -> []
    [Err _] -> " due to lexer error"
    t:_     -> " before `" ++ (prToken t) ++ "'"

myLexer = tokens
}

