Added some missing math operators
This commit is contained in:
parent
026949ae7e
commit
66fb77c84e
25 changed files with 728 additions and 427 deletions
11
Grammar.cf
11
Grammar.cf
|
|
@ -2,14 +2,17 @@
|
|||
|
||||
Program. Program ::= "main" "=" Exp ;
|
||||
|
||||
EId. Exp3 ::= Ident ;
|
||||
EInt. Exp3 ::= Integer ;
|
||||
EAbs. Exp ::= "\\" Ident "->" Exp ;
|
||||
EApp. Exp2 ::= Exp2 Exp3 ;
|
||||
EAdd. Exp1 ::= Exp1 "+" Exp2 ;
|
||||
ESub. Exp1 ::= Exp1 "-" Exp2 ;
|
||||
EAbs. Exp ::= "\\" Ident "->" Exp ;
|
||||
EMul. Exp2 ::= Exp2 "*" Exp3 ;
|
||||
EDiv. Exp2 ::= Exp2 "/" Exp3 ;
|
||||
EMod. Exp2 ::= Exp2 "%" Exp3 ;
|
||||
EId. Exp4 ::= Ident ;
|
||||
EInt. Exp4 ::= Integer ;
|
||||
|
||||
coercions Exp 3 ;
|
||||
coercions Exp 4 ;
|
||||
|
||||
comment "--" ;
|
||||
comment "{-" "-}" ;
|
||||
|
|
|
|||
2
language
2
language
|
|
@ -1 +1 @@
|
|||
/home/samuel/.cabal/store/ghc-9.4.4/language-0.1.0.0-e-language-80436b2c1d93bf52fad22442b35609fca17123af17fcd9d9251ea49ce5440bf0/bin/language
|
||||
/home/samuel/.cabal/store/ghc-9.4.4/language-0.1.0.0-e-language-8961629e3f2b94c68db8717be1683dcdcdc8fdba8bf535c043d14892383bd98b/bin/language
|
||||
|
|
@ -25,10 +25,11 @@ compileFile file = do
|
|||
exitFailure
|
||||
Right cor -> compile cor
|
||||
|
||||
data Type = I8 | I32 | I64 | Ptr | Ref Type | Array Integer Type
|
||||
data Type = I1 | I8 | I32 | I64 | Ptr | Ref Type | Array Integer Type
|
||||
instance Show Type where
|
||||
show :: Type -> String
|
||||
show t = case t of
|
||||
I1 -> "i1"
|
||||
I8 -> "i8"
|
||||
I32 -> "i32"
|
||||
I64 -> "i64"
|
||||
|
|
@ -66,6 +67,9 @@ data LLVMIr = Define Type Ident Params
|
|||
| Variable Ident
|
||||
| Add Type Value Value
|
||||
| Sub Type Value Value
|
||||
| Div Type Value Value
|
||||
| Mul Type Value Value
|
||||
| Srem Type Value Value
|
||||
| Call Type Ident Args
|
||||
| Alloca Type
|
||||
| Store Type Ident Type Ident
|
||||
|
|
@ -82,8 +86,11 @@ printLLVMIr (Declare t (Ident i) params) = undefined
|
|||
printLLVMIr (Variable (Ident i)) = concat ["%", i, " = "]
|
||||
printLLVMIr (Add t v1 v2) = concat ["add ", show t, " ", show v1, ", ", show v2, "\n"]
|
||||
printLLVMIr (Sub t v1 v2) = concat ["sub ", show t, " ", show v1, ", ", show v2, "\n"]
|
||||
printLLVMIr (Div t v1 v2) = concat ["sdiv ", show t, " ", show v1, ", ", show v2, "\n"]
|
||||
printLLVMIr (Mul t v1 v2) = concat ["mul ", show t, " ", show v1, ", ", show v2, "\n"]
|
||||
printLLVMIr (Srem t v1 v2) = concat ["srem ", show t, " ", show v1, ", ", show v2, "\n"]
|
||||
printLLVMIr (Call t (Ident i) arg) = concat ["call ", show t, " @", i, "("
|
||||
, concatMap (\(x,y) -> show x <> " " <> show y) arg
|
||||
, intercalate ", " $ Prelude.map (\(x,y) -> show x <> " " <> show y) arg
|
||||
, ")\n"]
|
||||
printLLVMIr (Alloca t) = unwords ["alloca", show t, "\n"]
|
||||
printLLVMIr (Store t1 (Ident id1) t2 (Ident id2)) = concat ["store ", show t1, " %", id1
|
||||
|
|
@ -129,6 +136,10 @@ compile (Program prgE) = do
|
|||
go (EInt int) = emitInt int
|
||||
go (EAdd e1 e2) = emitAdd e1 e2
|
||||
go (ESub e1 e2) = emitSub e1 e2
|
||||
go (EMul e1 e2) = emitMul e1 e2
|
||||
go (EDiv e1 e2) = emitDiv e1 e2
|
||||
go (EMod e1 e2) = emitMod e1 e2
|
||||
|
||||
go (EId id) = undefined
|
||||
go (EApp e1 e2) = undefined
|
||||
go (EAbs id e) = undefined
|
||||
|
|
@ -145,14 +156,49 @@ compile (Program prgE) = do
|
|||
|
||||
emitAdd :: Exp -> Exp -> CompilerState
|
||||
emitAdd e1 e2 = do
|
||||
-- instead of declaring variables for adding ints,
|
||||
-- we can directly pass them to add.
|
||||
(v1,v2) <- evalToValues e1 e2
|
||||
increaseVarCount
|
||||
v <- gets variableCount
|
||||
emit $ Variable $ Ident $ show v
|
||||
emit $ Add I64 v1 v2
|
||||
|
||||
emitMul :: Exp -> Exp -> CompilerState
|
||||
emitMul e1 e2 = do
|
||||
(v1,v2) <- evalToValues e1 e2
|
||||
increaseVarCount
|
||||
v <- gets variableCount
|
||||
emit $ Variable $ Ident $ show v
|
||||
emit $ Mul I64 v1 v2
|
||||
|
||||
emitMod :: Exp -> Exp -> CompilerState
|
||||
emitMod e1 e2 = do
|
||||
-- //TODO Replace with `let m a b = rem (abs $ b + a) b`
|
||||
(v1,v2) <- evalToValues e1 e2
|
||||
increaseVarCount
|
||||
vadd <- gets variableCount
|
||||
emit $ Variable $ Ident $ show vadd
|
||||
emit $ Add I64 v1 v2
|
||||
|
||||
increaseVarCount
|
||||
vabs <- gets variableCount
|
||||
emit $ Variable $ Ident $ show vabs
|
||||
emit $ Call I64 (Ident "llvm.abs.i64")
|
||||
[ (I64, VIdent (Ident $ show vadd))
|
||||
, (I1, VInteger 1)
|
||||
]
|
||||
increaseVarCount
|
||||
v <- gets variableCount
|
||||
emit $ Variable $ Ident $ show v
|
||||
emit $ Srem I64 (VIdent (Ident $ show vabs)) v2
|
||||
|
||||
emitDiv :: Exp -> Exp -> CompilerState
|
||||
emitDiv e1 e2 = do
|
||||
(v1,v2) <- evalToValues e1 e2
|
||||
increaseVarCount
|
||||
v <- gets variableCount
|
||||
emit $ Variable $ Ident $ show v
|
||||
emit $ Div I64 v1 v2
|
||||
|
||||
emitSub :: Exp -> Exp -> CompilerState
|
||||
emitSub e1 e2 = do
|
||||
(v1,v2) <- evalToValues e1 e2
|
||||
|
|
@ -163,6 +209,8 @@ compile (Program prgE) = do
|
|||
|
||||
evalToValues :: Exp -> Exp -> State CodeGenerator (Value, Value)
|
||||
evalToValues e1 e2 = case (e1, e2) of
|
||||
-- instead of declaring variables for working on ints,
|
||||
-- we can directly pass them to their functions.
|
||||
(EInt i1, EInt i2) -> return (VInteger i1, VInteger i2)
|
||||
(EInt i, e) -> do
|
||||
go e
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
declare i64 @llvm.abs.i64(i64, i1 immarg)
|
||||
declare i64 @llvm.powi.i64.i64(i64, i64)
|
||||
declare i32 @puts(i8* nocapture) nounwind
|
||||
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -19,6 +19,9 @@ data Exp
|
|||
| EApp Exp Exp
|
||||
| EAdd Exp Exp
|
||||
| ESub Exp Exp
|
||||
| EMul Exp Exp
|
||||
| EDiv Exp Exp
|
||||
| EMod Exp Exp
|
||||
| EAbs Ident Exp
|
||||
deriving (C.Eq, C.Ord, C.Show, C.Read)
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -28,8 +28,9 @@ The reserved words used in Grammar are the following:
|
|||
| ``main`` | | |
|
||||
|
||||
The symbols used in Grammar are the following:
|
||||
| = | + | - | \
|
||||
| -> | ( | ) |
|
||||
| = | + | - | *
|
||||
| / | % | \ | ->
|
||||
| ( | ) | |
|
||||
|
||||
===Comments===
|
||||
Single-line comments begin with --.Multiple-line comments are enclosed with {- and -}.
|
||||
|
|
@ -43,14 +44,18 @@ All other symbols are terminals.
|
|||
| //Program// | -> | ``main`` ``=`` //Exp//
|
||||
| //Exp3// | -> | //Ident//
|
||||
| | **|** | //Integer//
|
||||
| | **|** | ``(`` //Exp// ``)``
|
||||
| | **|** | //Exp3// ``%`` //Exp4//
|
||||
| | **|** | //Exp4//
|
||||
| //Exp2// | -> | //Exp2// //Exp3//
|
||||
| | **|** | //Exp2// ``*`` //Exp3//
|
||||
| | **|** | //Exp2// ``/`` //Exp3//
|
||||
| | **|** | //Exp3//
|
||||
| //Exp1// | -> | //Exp1// ``+`` //Exp2//
|
||||
| | **|** | //Exp1// ``-`` //Exp2//
|
||||
| | **|** | //Exp2//
|
||||
| //Exp// | -> | ``\`` //Ident// ``->`` //Exp//
|
||||
| | **|** | //Exp1//
|
||||
| //Exp4// | -> | ``(`` //Exp// ``)``
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
|
|
@ -14,6 +14,7 @@ module Grammar.Par
|
|||
, pExp2
|
||||
, pExp1
|
||||
, pExp
|
||||
, pExp4
|
||||
) where
|
||||
|
||||
import Prelude
|
||||
|
|
@ -34,29 +35,22 @@ type HappyAny = Happy_GHC_Exts.Any
|
|||
#else
|
||||
type HappyAny = forall a . a
|
||||
#endif
|
||||
newtype HappyWrap8 = HappyWrap8 (Grammar.Abs.Ident)
|
||||
happyIn8 :: (Grammar.Abs.Ident) -> (HappyAbsSyn )
|
||||
happyIn8 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap8 x)
|
||||
{-# INLINE happyIn8 #-}
|
||||
happyOut8 :: (HappyAbsSyn ) -> HappyWrap8
|
||||
happyOut8 x = Happy_GHC_Exts.unsafeCoerce# x
|
||||
{-# INLINE happyOut8 #-}
|
||||
newtype HappyWrap9 = HappyWrap9 (Integer)
|
||||
happyIn9 :: (Integer) -> (HappyAbsSyn )
|
||||
newtype HappyWrap9 = HappyWrap9 (Grammar.Abs.Ident)
|
||||
happyIn9 :: (Grammar.Abs.Ident) -> (HappyAbsSyn )
|
||||
happyIn9 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap9 x)
|
||||
{-# INLINE happyIn9 #-}
|
||||
happyOut9 :: (HappyAbsSyn ) -> HappyWrap9
|
||||
happyOut9 x = Happy_GHC_Exts.unsafeCoerce# x
|
||||
{-# INLINE happyOut9 #-}
|
||||
newtype HappyWrap10 = HappyWrap10 (Grammar.Abs.Program)
|
||||
happyIn10 :: (Grammar.Abs.Program) -> (HappyAbsSyn )
|
||||
newtype HappyWrap10 = HappyWrap10 (Integer)
|
||||
happyIn10 :: (Integer) -> (HappyAbsSyn )
|
||||
happyIn10 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap10 x)
|
||||
{-# INLINE happyIn10 #-}
|
||||
happyOut10 :: (HappyAbsSyn ) -> HappyWrap10
|
||||
happyOut10 x = Happy_GHC_Exts.unsafeCoerce# x
|
||||
{-# INLINE happyOut10 #-}
|
||||
newtype HappyWrap11 = HappyWrap11 (Grammar.Abs.Exp)
|
||||
happyIn11 :: (Grammar.Abs.Exp) -> (HappyAbsSyn )
|
||||
newtype HappyWrap11 = HappyWrap11 (Grammar.Abs.Program)
|
||||
happyIn11 :: (Grammar.Abs.Program) -> (HappyAbsSyn )
|
||||
happyIn11 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap11 x)
|
||||
{-# INLINE happyIn11 #-}
|
||||
happyOut11 :: (HappyAbsSyn ) -> HappyWrap11
|
||||
|
|
@ -83,6 +77,20 @@ happyIn14 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap14 x)
|
|||
happyOut14 :: (HappyAbsSyn ) -> HappyWrap14
|
||||
happyOut14 x = Happy_GHC_Exts.unsafeCoerce# x
|
||||
{-# INLINE happyOut14 #-}
|
||||
newtype HappyWrap15 = HappyWrap15 (Grammar.Abs.Exp)
|
||||
happyIn15 :: (Grammar.Abs.Exp) -> (HappyAbsSyn )
|
||||
happyIn15 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap15 x)
|
||||
{-# INLINE happyIn15 #-}
|
||||
happyOut15 :: (HappyAbsSyn ) -> HappyWrap15
|
||||
happyOut15 x = Happy_GHC_Exts.unsafeCoerce# x
|
||||
{-# INLINE happyOut15 #-}
|
||||
newtype HappyWrap16 = HappyWrap16 (Grammar.Abs.Exp)
|
||||
happyIn16 :: (Grammar.Abs.Exp) -> (HappyAbsSyn )
|
||||
happyIn16 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap16 x)
|
||||
{-# INLINE happyIn16 #-}
|
||||
happyOut16 :: (HappyAbsSyn ) -> HappyWrap16
|
||||
happyOut16 x = Happy_GHC_Exts.unsafeCoerce# x
|
||||
{-# INLINE happyOut16 #-}
|
||||
happyInTok :: (Token) -> (HappyAbsSyn )
|
||||
happyInTok x = Happy_GHC_Exts.unsafeCoerce# x
|
||||
{-# INLINE happyInTok #-}
|
||||
|
|
@ -92,41 +100,40 @@ happyOutTok x = Happy_GHC_Exts.unsafeCoerce# x
|
|||
|
||||
|
||||
happyExpList :: HappyAddr
|
||||
happyExpList = HappyA# "\x00\x00\x20\x00\x80\x80\x01\x00\x01\x03\x00\x02\x06\x00\x04\x0d\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x03\x00\x18\x00\x00\x00\x00\x00\x08\x1a\x00\x00\x10\x00\x00\x00\x00\x00\x03\x00\x80\x80\x01\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x08\x1a\x00\x00\x00\x00\x20\x60\x00\x40\xc0\x00\x00\x08\x00\x00\x02\x00\x00\x00\x00\x00\x04\x0d\x00\x08\x18\x00\x10\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00"#
|
||||
happyExpList = HappyA# "\x00\x00\x00\x04\x00\x80\x00\x06\x00\x20\x80\x01\x00\x08\x60\x00\x00\x02\x1a\x00\x80\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x80\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x80\x22\x06\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\xc0\x00\x00\x00\x8a\x18\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x02\x1a\x00\x80\x00\x00\x00\x10\x00\x00\x00\x08\x60\x00\x00\x02\x18\x00\x80\x00\x06\x00\x20\x80\x01\x00\x00\x01\x00\x00\x04\x00\x00\x00\x00\x00\x00\x20\xa0\x01\x00\x28\x62\x00\x00\x8a\x18\x00\x40\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"#
|
||||
|
||||
{-# NOINLINE happyExpListPerState #-}
|
||||
happyExpListPerState st =
|
||||
token_strs_expected
|
||||
where token_strs = ["error","%dummy","%start_pProgram","%start_pExp3","%start_pExp2","%start_pExp1","%start_pExp","Ident","Integer","Program","Exp3","Exp2","Exp1","Exp","'('","')'","'+'","'-'","'->'","'='","'\\\\'","'main'","L_Ident","L_integ","%eof"]
|
||||
bit_start = st Prelude.* 25
|
||||
bit_end = (st Prelude.+ 1) Prelude.* 25
|
||||
where token_strs = ["error","%dummy","%start_pProgram","%start_pExp3","%start_pExp2","%start_pExp1","%start_pExp","%start_pExp4","Ident","Integer","Program","Exp3","Exp2","Exp1","Exp","Exp4","'%'","'('","')'","'*'","'+'","'-'","'->'","'/'","'='","'\\\\'","'main'","L_Ident","L_integ","%eof"]
|
||||
bit_start = st Prelude.* 30
|
||||
bit_end = (st Prelude.+ 1) Prelude.* 30
|
||||
read_bit = readArrayBit happyExpList
|
||||
bits = Prelude.map read_bit [bit_start..bit_end Prelude.- 1]
|
||||
bits_indexed = Prelude.zip bits [0..24]
|
||||
bits_indexed = Prelude.zip bits [0..29]
|
||||
token_strs_expected = Prelude.concatMap f bits_indexed
|
||||
f (Prelude.False, _) = []
|
||||
f (Prelude.True, nr) = [token_strs Prelude.!! nr]
|
||||
|
||||
happyActOffsets :: HappyAddr
|
||||
happyActOffsets = HappyA# "\xf9\xff\x08\x00\x08\x00\x08\x00\x06\x00\xfc\xff\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x47\x00\xfd\xff\x06\x00\x05\x00\x00\x00\x10\x00\x01\x00\x0c\x00\x0c\x00\x1c\x00\x06\x00\x00\x00\x08\x00\x08\x00\x24\x00\x4a\x00\x00\x00\x06\x00\x08\x00\x08\x00\x00\x00\x00\x00\x00\x00"#
|
||||
happyActOffsets = HappyA# "\xf9\xff\x12\x00\x12\x00\x12\x00\x0e\x00\x03\x00\xfa\xff\x00\x00\xfb\xff\x0e\x00\x00\x00\x00\x00\x16\x00\x06\x00\x10\x00\x0b\x00\x00\x00\x05\x00\x00\x00\x17\x00\xff\xff\x01\x00\x13\x00\x19\x00\x0e\x00\x1e\x00\x2c\x00\x12\x00\x12\x00\x12\x00\x12\x00\x2e\x00\x3a\x00\x00\x00\x0e\x00\x06\x00\x06\x00\x44\x00\x44\x00\x00\x00\x00\x00\x00\x00\x00\x00"#
|
||||
|
||||
happyGotoOffsets :: HappyAddr
|
||||
happyGotoOffsets = HappyA# "\x4b\x00\x03\x00\x3b\x00\x35\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\x00\x00\x20\x00\x30\x00\x00\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x27\x00\x00\x00\x40\x00\x45\x00\x00\x00\x00\x00\x00\x00\x2e\x00\x15\x00\x15\x00\x00\x00\x00\x00\x00\x00"#
|
||||
happyGotoOffsets = HappyA# "\x47\x00\x5a\x00\x4b\x00\x43\x00\x23\x00\x46\x00\x00\x00\x00\x00\x00\x00\x2b\x00\x00\x00\x00\x00\x00\x00\x5f\x00\x00\x00\x00\x00\x00\x00\x5e\x00\x00\x00\x00\x00\x5f\x00\x00\x00\x00\x00\x00\x00\x33\x00\x5c\x00\x00\x00\x64\x00\x69\x00\x50\x00\x55\x00\x00\x00\x00\x00\x00\x00\x3b\x00\x6e\x00\x6e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"#
|
||||
|
||||
happyAdjustOffset :: Happy_GHC_Exts.Int# -> Happy_GHC_Exts.Int#
|
||||
happyAdjustOffset off = off
|
||||
|
||||
happyDefActions :: HappyAddr
|
||||
happyDefActions = HappyA# "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfa\xff\xf7\xff\xf6\xff\xf3\xff\xf0\xff\xee\xff\x00\x00\x00\x00\x00\x00\xf9\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf4\xff\x00\x00\x00\x00\x00\x00\x00\x00\xf5\xff\x00\x00\xf1\xff\xf2\xff\xf8\xff\xef\xff"#
|
||||
happyDefActions = HappyA# "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf9\xff\x00\x00\x00\x00\xf6\xff\xf5\xff\xef\xff\xec\xff\xea\xff\x00\x00\xf3\xff\x00\x00\xf8\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf2\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe9\xff\x00\x00\xed\xff\xee\xff\xf0\xff\xf1\xff\xf4\xff\xf7\xff\xeb\xff"#
|
||||
|
||||
happyCheck :: HappyAddr
|
||||
happyCheck = HappyA# "\xff\xff\x08\x00\x01\x00\x00\x00\x01\x00\x09\x00\x03\x00\x01\x00\x0b\x00\x01\x00\x09\x00\x0a\x00\x0b\x00\x07\x00\x09\x00\x09\x00\x0a\x00\x09\x00\x0a\x00\x03\x00\x04\x00\x00\x00\x01\x00\x0b\x00\x03\x00\x00\x00\x01\x00\x0b\x00\x03\x00\x04\x00\x05\x00\x06\x00\x00\x00\x01\x00\x06\x00\x03\x00\x04\x00\x05\x00\x06\x00\x00\x00\x01\x00\x05\x00\x03\x00\x04\x00\x05\x00\x06\x00\x00\x00\x01\x00\x00\x00\x03\x00\x04\x00\x05\x00\x06\x00\x00\x00\x01\x00\xff\xff\x03\x00\x04\x00\x05\x00\x00\x00\x01\x00\xff\xff\x03\x00\x04\x00\x00\x00\x01\x00\xff\xff\x03\x00\x04\x00\x00\x00\x01\x00\xff\xff\x03\x00\x04\x00\x03\x00\x04\x00\x02\x00\x02\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"#
|
||||
happyCheck = HappyA# "\xff\xff\x02\x00\x01\x00\x04\x00\x0b\x00\x02\x00\x0c\x00\x08\x00\x02\x00\x0e\x00\x04\x00\x0c\x00\x0d\x00\x0e\x00\x08\x00\x0e\x00\x02\x00\x0c\x00\x0c\x00\x0d\x00\x02\x00\x05\x00\x06\x00\x01\x00\x0a\x00\x0e\x00\x0c\x00\x0d\x00\x05\x00\x06\x00\x0c\x00\x0d\x00\x02\x00\x0e\x00\x09\x00\x00\x00\x01\x00\x0e\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x01\x00\x01\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x01\x00\x07\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x01\x00\x03\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x00\x00\x01\x00\x01\x00\x03\x00\x04\x00\x05\x00\x02\x00\x07\x00\x00\x00\x01\x00\x07\x00\x03\x00\x04\x00\x00\x00\x01\x00\x07\x00\x03\x00\x04\x00\x00\x00\x01\x00\x07\x00\x03\x00\x04\x00\x00\x00\x01\x00\x07\x00\x03\x00\x00\x00\x00\x00\x01\x00\x07\x00\x03\x00\x07\x00\x00\x00\x01\x00\x07\x00\x03\x00\xff\xff\x00\x00\x01\x00\x07\x00\x03\x00\xff\xff\x00\x00\x01\x00\x07\x00\x03\x00\xff\xff\xff\xff\xff\xff\x07\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"#
|
||||
|
||||
happyTable :: HappyAddr
|
||||
happyTable = HappyA# "\x00\x00\x15\x00\x0e\x00\x07\x00\x08\x00\x07\x00\x12\x00\x0e\x00\xff\xff\x0e\x00\x07\x00\x10\x00\xff\xff\x0f\x00\x07\x00\x07\x00\x10\x00\x07\x00\x10\x00\x18\x00\x19\x00\x07\x00\x08\x00\xff\xff\x16\x00\x07\x00\x08\x00\xff\xff\x09\x00\x0a\x00\x0b\x00\x0c\x00\x07\x00\x08\x00\x16\x00\x09\x00\x0a\x00\x0b\x00\x1a\x00\x07\x00\x08\x00\x1d\x00\x09\x00\x0a\x00\x0b\x00\x1f\x00\x07\x00\x08\x00\x19\x00\x09\x00\x0a\x00\x0b\x00\x20\x00\x07\x00\x08\x00\x00\x00\x09\x00\x0a\x00\x10\x00\x07\x00\x08\x00\x00\x00\x09\x00\x11\x00\x07\x00\x08\x00\x00\x00\x09\x00\x1e\x00\x07\x00\x08\x00\x00\x00\x09\x00\x1d\x00\x18\x00\x19\x00\x1c\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"#
|
||||
happyTable = HappyA# "\x00\x00\x0a\x00\x1a\x00\x1c\x00\x18\x00\x0a\x00\x08\x00\x1d\x00\x0a\x00\xff\xff\x1c\x00\x08\x00\x13\x00\xff\xff\x1d\x00\xff\xff\x0a\x00\x08\x00\x08\x00\x13\x00\x0a\x00\x1e\x00\x1f\x00\x1a\x00\x12\x00\xff\xff\x08\x00\x13\x00\x1e\x00\x1f\x00\x08\x00\x13\x00\x0a\x00\xff\xff\x19\x00\x0a\x00\x0b\x00\xff\xff\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x0a\x00\x0b\x00\x1a\x00\x0c\x00\x0d\x00\x0e\x00\x20\x00\x10\x00\x0a\x00\x0b\x00\x23\x00\x0c\x00\x0d\x00\x0e\x00\x28\x00\x10\x00\x0a\x00\x0b\x00\x22\x00\x0c\x00\x0d\x00\x0e\x00\x29\x00\x10\x00\x0a\x00\x0b\x00\x1a\x00\x0c\x00\x0d\x00\x13\x00\x16\x00\x10\x00\x0a\x00\x0b\x00\x08\x00\x0c\x00\x14\x00\x0a\x00\x0b\x00\x10\x00\x0c\x00\x24\x00\x0a\x00\x0b\x00\x10\x00\x0c\x00\x23\x00\x0a\x00\x0b\x00\x10\x00\x15\x00\x1f\x00\x0a\x00\x0b\x00\x10\x00\x1a\x00\x27\x00\x0a\x00\x0b\x00\x10\x00\x26\x00\x00\x00\x0a\x00\x0b\x00\x10\x00\x25\x00\x00\x00\x0a\x00\x0b\x00\x10\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"#
|
||||
|
||||
happyReduceArr = Happy_Data_Array.array (5, 17) [
|
||||
(5 , happyReduce_5),
|
||||
happyReduceArr = Happy_Data_Array.array (6, 22) [
|
||||
(6 , happyReduce_6),
|
||||
(7 , happyReduce_7),
|
||||
(8 , happyReduce_8),
|
||||
|
|
@ -138,122 +145,164 @@ happyReduceArr = Happy_Data_Array.array (5, 17) [
|
|||
(14 , happyReduce_14),
|
||||
(15 , happyReduce_15),
|
||||
(16 , happyReduce_16),
|
||||
(17 , happyReduce_17)
|
||||
(17 , happyReduce_17),
|
||||
(18 , happyReduce_18),
|
||||
(19 , happyReduce_19),
|
||||
(20 , happyReduce_20),
|
||||
(21 , happyReduce_21),
|
||||
(22 , happyReduce_22)
|
||||
]
|
||||
|
||||
happy_n_terms = 12 :: Prelude.Int
|
||||
happy_n_nonterms = 7 :: Prelude.Int
|
||||
happy_n_terms = 15 :: Prelude.Int
|
||||
happy_n_nonterms = 8 :: Prelude.Int
|
||||
|
||||
happyReduce_5 = happySpecReduce_1 0# happyReduction_5
|
||||
happyReduction_5 happy_x_1
|
||||
happyReduce_6 = happySpecReduce_1 0# happyReduction_6
|
||||
happyReduction_6 happy_x_1
|
||||
= case happyOutTok happy_x_1 of { (PT _ (TV happy_var_1)) ->
|
||||
happyIn8
|
||||
happyIn9
|
||||
(Grammar.Abs.Ident happy_var_1
|
||||
)}
|
||||
|
||||
happyReduce_6 = happySpecReduce_1 1# happyReduction_6
|
||||
happyReduction_6 happy_x_1
|
||||
happyReduce_7 = happySpecReduce_1 1# happyReduction_7
|
||||
happyReduction_7 happy_x_1
|
||||
= case happyOutTok happy_x_1 of { (PT _ (TI happy_var_1)) ->
|
||||
happyIn9
|
||||
happyIn10
|
||||
((read happy_var_1) :: Integer
|
||||
)}
|
||||
|
||||
happyReduce_7 = happySpecReduce_3 2# happyReduction_7
|
||||
happyReduction_7 happy_x_3
|
||||
happyReduce_8 = happySpecReduce_3 2# happyReduction_8
|
||||
happyReduction_8 happy_x_3
|
||||
happy_x_2
|
||||
happy_x_1
|
||||
= case happyOut14 happy_x_3 of { (HappyWrap14 happy_var_3) ->
|
||||
happyIn10
|
||||
(Grammar.Abs.Program happy_var_3
|
||||
)}
|
||||
|
||||
happyReduce_8 = happySpecReduce_1 3# happyReduction_8
|
||||
happyReduction_8 happy_x_1
|
||||
= case happyOut8 happy_x_1 of { (HappyWrap8 happy_var_1) ->
|
||||
= case happyOut15 happy_x_3 of { (HappyWrap15 happy_var_3) ->
|
||||
happyIn11
|
||||
(Grammar.Abs.EId happy_var_1
|
||||
(Grammar.Abs.Program happy_var_3
|
||||
)}
|
||||
|
||||
happyReduce_9 = happySpecReduce_1 3# happyReduction_9
|
||||
happyReduction_9 happy_x_1
|
||||
= case happyOut9 happy_x_1 of { (HappyWrap9 happy_var_1) ->
|
||||
happyIn11
|
||||
happyIn12
|
||||
(Grammar.Abs.EId happy_var_1
|
||||
)}
|
||||
|
||||
happyReduce_10 = happySpecReduce_1 3# happyReduction_10
|
||||
happyReduction_10 happy_x_1
|
||||
= case happyOut10 happy_x_1 of { (HappyWrap10 happy_var_1) ->
|
||||
happyIn12
|
||||
(Grammar.Abs.EInt happy_var_1
|
||||
)}
|
||||
|
||||
happyReduce_10 = happySpecReduce_3 3# happyReduction_10
|
||||
happyReduction_10 happy_x_3
|
||||
happyReduce_11 = happySpecReduce_3 3# happyReduction_11
|
||||
happyReduction_11 happy_x_3
|
||||
happy_x_2
|
||||
happy_x_1
|
||||
= case happyOut14 happy_x_2 of { (HappyWrap14 happy_var_2) ->
|
||||
happyIn11
|
||||
(happy_var_2
|
||||
)}
|
||||
|
||||
happyReduce_11 = happySpecReduce_2 4# happyReduction_11
|
||||
happyReduction_11 happy_x_2
|
||||
happy_x_1
|
||||
= case happyOut12 happy_x_1 of { (HappyWrap12 happy_var_1) ->
|
||||
case happyOut11 happy_x_2 of { (HappyWrap11 happy_var_2) ->
|
||||
case happyOut16 happy_x_3 of { (HappyWrap16 happy_var_3) ->
|
||||
happyIn12
|
||||
(Grammar.Abs.EApp happy_var_1 happy_var_2
|
||||
(Grammar.Abs.EMod happy_var_1 happy_var_3
|
||||
)}}
|
||||
|
||||
happyReduce_12 = happySpecReduce_1 4# happyReduction_12
|
||||
happyReduce_12 = happySpecReduce_1 3# happyReduction_12
|
||||
happyReduction_12 happy_x_1
|
||||
= case happyOut11 happy_x_1 of { (HappyWrap11 happy_var_1) ->
|
||||
= case happyOut16 happy_x_1 of { (HappyWrap16 happy_var_1) ->
|
||||
happyIn12
|
||||
(happy_var_1
|
||||
)}
|
||||
|
||||
happyReduce_13 = happySpecReduce_3 5# happyReduction_13
|
||||
happyReduction_13 happy_x_3
|
||||
happy_x_2
|
||||
happyReduce_13 = happySpecReduce_2 4# happyReduction_13
|
||||
happyReduction_13 happy_x_2
|
||||
happy_x_1
|
||||
= case happyOut13 happy_x_1 of { (HappyWrap13 happy_var_1) ->
|
||||
case happyOut12 happy_x_3 of { (HappyWrap12 happy_var_3) ->
|
||||
case happyOut12 happy_x_2 of { (HappyWrap12 happy_var_2) ->
|
||||
happyIn13
|
||||
(Grammar.Abs.EAdd happy_var_1 happy_var_3
|
||||
(Grammar.Abs.EApp happy_var_1 happy_var_2
|
||||
)}}
|
||||
|
||||
happyReduce_14 = happySpecReduce_3 5# happyReduction_14
|
||||
happyReduce_14 = happySpecReduce_3 4# happyReduction_14
|
||||
happyReduction_14 happy_x_3
|
||||
happy_x_2
|
||||
happy_x_1
|
||||
= case happyOut13 happy_x_1 of { (HappyWrap13 happy_var_1) ->
|
||||
case happyOut12 happy_x_3 of { (HappyWrap12 happy_var_3) ->
|
||||
happyIn13
|
||||
(Grammar.Abs.ESub happy_var_1 happy_var_3
|
||||
(Grammar.Abs.EMul happy_var_1 happy_var_3
|
||||
)}}
|
||||
|
||||
happyReduce_15 = happySpecReduce_1 5# happyReduction_15
|
||||
happyReduction_15 happy_x_1
|
||||
happyReduce_15 = happySpecReduce_3 4# happyReduction_15
|
||||
happyReduction_15 happy_x_3
|
||||
happy_x_2
|
||||
happy_x_1
|
||||
= case happyOut13 happy_x_1 of { (HappyWrap13 happy_var_1) ->
|
||||
case happyOut12 happy_x_3 of { (HappyWrap12 happy_var_3) ->
|
||||
happyIn13
|
||||
(Grammar.Abs.EDiv happy_var_1 happy_var_3
|
||||
)}}
|
||||
|
||||
happyReduce_16 = happySpecReduce_1 4# happyReduction_16
|
||||
happyReduction_16 happy_x_1
|
||||
= case happyOut12 happy_x_1 of { (HappyWrap12 happy_var_1) ->
|
||||
happyIn13
|
||||
(happy_var_1
|
||||
)}
|
||||
|
||||
happyReduce_16 = happyReduce 4# 6# happyReduction_16
|
||||
happyReduction_16 (happy_x_4 `HappyStk`
|
||||
happy_x_3 `HappyStk`
|
||||
happy_x_2 `HappyStk`
|
||||
happy_x_1 `HappyStk`
|
||||
happyRest)
|
||||
= case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) ->
|
||||
case happyOut14 happy_x_4 of { (HappyWrap14 happy_var_4) ->
|
||||
happyReduce_17 = happySpecReduce_3 5# happyReduction_17
|
||||
happyReduction_17 happy_x_3
|
||||
happy_x_2
|
||||
happy_x_1
|
||||
= case happyOut14 happy_x_1 of { (HappyWrap14 happy_var_1) ->
|
||||
case happyOut13 happy_x_3 of { (HappyWrap13 happy_var_3) ->
|
||||
happyIn14
|
||||
(Grammar.Abs.EAbs happy_var_2 happy_var_4
|
||||
) `HappyStk` happyRest}}
|
||||
(Grammar.Abs.EAdd happy_var_1 happy_var_3
|
||||
)}}
|
||||
|
||||
happyReduce_17 = happySpecReduce_1 6# happyReduction_17
|
||||
happyReduction_17 happy_x_1
|
||||
happyReduce_18 = happySpecReduce_3 5# happyReduction_18
|
||||
happyReduction_18 happy_x_3
|
||||
happy_x_2
|
||||
happy_x_1
|
||||
= case happyOut14 happy_x_1 of { (HappyWrap14 happy_var_1) ->
|
||||
case happyOut13 happy_x_3 of { (HappyWrap13 happy_var_3) ->
|
||||
happyIn14
|
||||
(Grammar.Abs.ESub happy_var_1 happy_var_3
|
||||
)}}
|
||||
|
||||
happyReduce_19 = happySpecReduce_1 5# happyReduction_19
|
||||
happyReduction_19 happy_x_1
|
||||
= case happyOut13 happy_x_1 of { (HappyWrap13 happy_var_1) ->
|
||||
happyIn14
|
||||
(happy_var_1
|
||||
)}
|
||||
|
||||
happyReduce_20 = happyReduce 4# 6# happyReduction_20
|
||||
happyReduction_20 (happy_x_4 `HappyStk`
|
||||
happy_x_3 `HappyStk`
|
||||
happy_x_2 `HappyStk`
|
||||
happy_x_1 `HappyStk`
|
||||
happyRest)
|
||||
= case happyOut9 happy_x_2 of { (HappyWrap9 happy_var_2) ->
|
||||
case happyOut15 happy_x_4 of { (HappyWrap15 happy_var_4) ->
|
||||
happyIn15
|
||||
(Grammar.Abs.EAbs happy_var_2 happy_var_4
|
||||
) `HappyStk` happyRest}}
|
||||
|
||||
happyReduce_21 = happySpecReduce_1 6# happyReduction_21
|
||||
happyReduction_21 happy_x_1
|
||||
= case happyOut14 happy_x_1 of { (HappyWrap14 happy_var_1) ->
|
||||
happyIn15
|
||||
(happy_var_1
|
||||
)}
|
||||
|
||||
happyReduce_22 = happySpecReduce_3 7# happyReduction_22
|
||||
happyReduction_22 happy_x_3
|
||||
happy_x_2
|
||||
happy_x_1
|
||||
= case happyOut15 happy_x_2 of { (HappyWrap15 happy_var_2) ->
|
||||
happyIn16
|
||||
(happy_var_2
|
||||
)}
|
||||
|
||||
happyNewToken action sts stk [] =
|
||||
happyDoAction 11# notHappyAtAll action sts stk []
|
||||
happyDoAction 14# notHappyAtAll action sts stk []
|
||||
|
||||
happyNewToken action sts stk (tk:tks) =
|
||||
let cont i = happyDoAction i tk action sts stk tks in
|
||||
|
|
@ -266,12 +315,15 @@ happyNewToken action sts stk (tk:tks) =
|
|||
PT _ (TS _ 6) -> cont 6#;
|
||||
PT _ (TS _ 7) -> cont 7#;
|
||||
PT _ (TS _ 8) -> cont 8#;
|
||||
PT _ (TV happy_dollar_dollar) -> cont 9#;
|
||||
PT _ (TI happy_dollar_dollar) -> cont 10#;
|
||||
PT _ (TS _ 9) -> cont 9#;
|
||||
PT _ (TS _ 10) -> cont 10#;
|
||||
PT _ (TS _ 11) -> cont 11#;
|
||||
PT _ (TV happy_dollar_dollar) -> cont 12#;
|
||||
PT _ (TI happy_dollar_dollar) -> cont 13#;
|
||||
_ -> happyError' ((tk:tks), [])
|
||||
}
|
||||
|
||||
happyError_ explist 11# tk tks = happyError' (tks, explist)
|
||||
happyError_ explist 14# tk tks = happyError' (tks, explist)
|
||||
happyError_ explist _ tk tks = happyError' ((tk:tks), explist)
|
||||
|
||||
happyThen :: () => Err a -> (a -> Err b) -> Err b
|
||||
|
|
@ -284,19 +336,22 @@ happyReturn1 = \a tks -> (return) a
|
|||
happyError' :: () => ([(Token)], [Prelude.String]) -> Err a
|
||||
happyError' = (\(tokens, _) -> happyError tokens)
|
||||
pProgram tks = happySomeParser where
|
||||
happySomeParser = happyThen (happyParse 0# tks) (\x -> happyReturn (let {(HappyWrap10 x') = happyOut10 x} in x'))
|
||||
happySomeParser = happyThen (happyParse 0# tks) (\x -> happyReturn (let {(HappyWrap11 x') = happyOut11 x} in x'))
|
||||
|
||||
pExp3 tks = happySomeParser where
|
||||
happySomeParser = happyThen (happyParse 1# tks) (\x -> happyReturn (let {(HappyWrap11 x') = happyOut11 x} in x'))
|
||||
happySomeParser = happyThen (happyParse 1# tks) (\x -> happyReturn (let {(HappyWrap12 x') = happyOut12 x} in x'))
|
||||
|
||||
pExp2 tks = happySomeParser where
|
||||
happySomeParser = happyThen (happyParse 2# tks) (\x -> happyReturn (let {(HappyWrap12 x') = happyOut12 x} in x'))
|
||||
happySomeParser = happyThen (happyParse 2# tks) (\x -> happyReturn (let {(HappyWrap13 x') = happyOut13 x} in x'))
|
||||
|
||||
pExp1 tks = happySomeParser where
|
||||
happySomeParser = happyThen (happyParse 3# tks) (\x -> happyReturn (let {(HappyWrap13 x') = happyOut13 x} in x'))
|
||||
happySomeParser = happyThen (happyParse 3# tks) (\x -> happyReturn (let {(HappyWrap14 x') = happyOut14 x} in x'))
|
||||
|
||||
pExp tks = happySomeParser where
|
||||
happySomeParser = happyThen (happyParse 4# tks) (\x -> happyReturn (let {(HappyWrap14 x') = happyOut14 x} in x'))
|
||||
happySomeParser = happyThen (happyParse 4# tks) (\x -> happyReturn (let {(HappyWrap15 x') = happyOut15 x} in x'))
|
||||
|
||||
pExp4 tks = happySomeParser where
|
||||
happySomeParser = happyThen (happyParse 5# tks) (\x -> happyReturn (let {(HappyWrap16 x') = happyOut16 x} in x'))
|
||||
|
||||
happySeq = happyDontSeq
|
||||
|
||||
|
|
|
|||
|
|
@ -11,31 +11,39 @@ Grammar
|
|||
%start_pExp2 -> Exp2 (2)
|
||||
%start_pExp1 -> Exp1 (3)
|
||||
%start_pExp -> Exp (4)
|
||||
Ident -> L_Ident (5)
|
||||
Integer -> L_integ (6)
|
||||
Program -> 'main' '=' Exp (7)
|
||||
Exp3 -> Ident (8)
|
||||
Exp3 -> Integer (9)
|
||||
Exp3 -> '(' Exp ')' (10)
|
||||
Exp2 -> Exp2 Exp3 (11)
|
||||
Exp2 -> Exp3 (12)
|
||||
Exp1 -> Exp1 '+' Exp2 (13)
|
||||
Exp1 -> Exp1 '-' Exp2 (14)
|
||||
Exp1 -> Exp2 (15)
|
||||
Exp -> '\\' Ident '->' Exp (16)
|
||||
Exp -> Exp1 (17)
|
||||
%start_pExp4 -> Exp4 (5)
|
||||
Ident -> L_Ident (6)
|
||||
Integer -> L_integ (7)
|
||||
Program -> 'main' '=' Exp (8)
|
||||
Exp3 -> Ident (9)
|
||||
Exp3 -> Integer (10)
|
||||
Exp3 -> Exp3 '%' Exp4 (11)
|
||||
Exp3 -> Exp4 (12)
|
||||
Exp2 -> Exp2 Exp3 (13)
|
||||
Exp2 -> Exp2 '*' Exp3 (14)
|
||||
Exp2 -> Exp2 '/' Exp3 (15)
|
||||
Exp2 -> Exp3 (16)
|
||||
Exp1 -> Exp1 '+' Exp2 (17)
|
||||
Exp1 -> Exp1 '-' Exp2 (18)
|
||||
Exp1 -> Exp2 (19)
|
||||
Exp -> '\\' Ident '->' Exp (20)
|
||||
Exp -> Exp1 (21)
|
||||
Exp4 -> '(' Exp ')' (22)
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
Terminals
|
||||
-----------------------------------------------------------------------------
|
||||
'(' { PT _ (TS _ 1) }
|
||||
')' { PT _ (TS _ 2) }
|
||||
'+' { PT _ (TS _ 3) }
|
||||
'-' { PT _ (TS _ 4) }
|
||||
'->' { PT _ (TS _ 5) }
|
||||
'=' { PT _ (TS _ 6) }
|
||||
'\\' { PT _ (TS _ 7) }
|
||||
'main' { PT _ (TS _ 8) }
|
||||
'%' { 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) }
|
||||
'main' { PT _ (TS _ 11) }
|
||||
L_Ident { PT _ (TV $$) }
|
||||
L_integ { PT _ (TI $$) }
|
||||
|
||||
|
|
@ -47,13 +55,15 @@ Non-terminals
|
|||
%start_pExp2 rule 2
|
||||
%start_pExp1 rule 3
|
||||
%start_pExp rule 4
|
||||
Ident rule 5
|
||||
Integer rule 6
|
||||
Program rule 7
|
||||
Exp3 rules 8, 9, 10
|
||||
Exp2 rules 11, 12
|
||||
Exp1 rules 13, 14, 15
|
||||
Exp rules 16, 17
|
||||
%start_pExp4 rule 5
|
||||
Ident rule 6
|
||||
Integer rule 7
|
||||
Program rule 8
|
||||
Exp3 rules 9, 10, 11, 12
|
||||
Exp2 rules 13, 14, 15, 16
|
||||
Exp1 rules 17, 18, 19
|
||||
Exp rules 20, 21
|
||||
Exp4 rule 22
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
States
|
||||
|
|
@ -62,395 +72,564 @@ State 0
|
|||
|
||||
%start_pProgram -> . Program (rule 0)
|
||||
|
||||
'main' shift, and enter state 20
|
||||
'main' shift, and enter state 23
|
||||
|
||||
Program goto state 19
|
||||
Program goto state 22
|
||||
|
||||
State 1
|
||||
|
||||
%start_pExp3 -> . Exp3 (rule 1)
|
||||
|
||||
'(' shift, and enter state 13
|
||||
L_Ident shift, and enter state 6
|
||||
L_integ shift, and enter state 15
|
||||
'(' shift, and enter state 9
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
|
||||
Ident goto state 7
|
||||
Integer goto state 8
|
||||
Exp3 goto state 18
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 21
|
||||
Exp4 goto state 16
|
||||
|
||||
State 2
|
||||
|
||||
%start_pExp2 -> . Exp2 (rule 2)
|
||||
|
||||
'(' shift, and enter state 13
|
||||
L_Ident shift, and enter state 6
|
||||
L_integ shift, and enter state 15
|
||||
'(' shift, and enter state 9
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
|
||||
Ident goto state 7
|
||||
Integer goto state 8
|
||||
Exp3 goto state 9
|
||||
Exp2 goto state 17
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 12
|
||||
Exp2 goto state 20
|
||||
Exp4 goto state 16
|
||||
|
||||
State 3
|
||||
|
||||
%start_pExp1 -> . Exp1 (rule 3)
|
||||
|
||||
'(' shift, and enter state 13
|
||||
L_Ident shift, and enter state 6
|
||||
L_integ shift, and enter state 15
|
||||
'(' shift, and enter state 9
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
|
||||
Ident goto state 7
|
||||
Integer goto state 8
|
||||
Exp3 goto state 9
|
||||
Exp2 goto state 10
|
||||
Exp1 goto state 16
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 12
|
||||
Exp2 goto state 13
|
||||
Exp1 goto state 19
|
||||
Exp4 goto state 16
|
||||
|
||||
State 4
|
||||
|
||||
%start_pExp -> . Exp (rule 4)
|
||||
|
||||
'(' shift, and enter state 13
|
||||
'\\' shift, and enter state 14
|
||||
L_Ident shift, and enter state 6
|
||||
L_integ shift, and enter state 15
|
||||
'(' shift, and enter state 9
|
||||
'\\' shift, and enter state 17
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
|
||||
Ident goto state 7
|
||||
Integer goto state 8
|
||||
Exp3 goto state 9
|
||||
Exp2 goto state 10
|
||||
Exp1 goto state 11
|
||||
Exp goto state 12
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 12
|
||||
Exp2 goto state 13
|
||||
Exp1 goto state 14
|
||||
Exp goto state 15
|
||||
Exp4 goto state 16
|
||||
|
||||
State 5
|
||||
|
||||
Ident -> . L_Ident (rule 5)
|
||||
%start_pExp4 -> . Exp4 (rule 5)
|
||||
|
||||
L_Ident shift, and enter state 6
|
||||
'(' shift, and enter state 9
|
||||
|
||||
Exp4 goto state 8
|
||||
|
||||
State 6
|
||||
|
||||
Ident -> L_Ident . (rule 5)
|
||||
Ident -> . L_Ident (rule 6)
|
||||
|
||||
'(' reduce using rule 5
|
||||
')' reduce using rule 5
|
||||
'+' reduce using rule 5
|
||||
'-' reduce using rule 5
|
||||
'->' reduce using rule 5
|
||||
L_Ident reduce using rule 5
|
||||
L_integ reduce using rule 5
|
||||
%eof reduce using rule 5
|
||||
L_Ident shift, and enter state 7
|
||||
|
||||
|
||||
State 7
|
||||
|
||||
Exp3 -> Ident . (rule 8)
|
||||
Ident -> L_Ident . (rule 6)
|
||||
|
||||
'(' reduce using rule 8
|
||||
')' reduce using rule 8
|
||||
'+' reduce using rule 8
|
||||
'-' reduce using rule 8
|
||||
L_Ident reduce using rule 8
|
||||
L_integ reduce using rule 8
|
||||
%eof reduce using rule 8
|
||||
'%' reduce using rule 6
|
||||
'(' reduce using rule 6
|
||||
')' reduce using rule 6
|
||||
'*' reduce using rule 6
|
||||
'+' reduce using rule 6
|
||||
'-' reduce using rule 6
|
||||
'->' reduce using rule 6
|
||||
'/' reduce using rule 6
|
||||
L_Ident reduce using rule 6
|
||||
L_integ reduce using rule 6
|
||||
%eof reduce using rule 6
|
||||
|
||||
|
||||
State 8
|
||||
|
||||
Exp3 -> Integer . (rule 9)
|
||||
%start_pExp4 -> Exp4 . (rule 5)
|
||||
|
||||
%eof accept
|
||||
|
||||
|
||||
State 9
|
||||
|
||||
Exp4 -> '(' . Exp ')' (rule 22)
|
||||
|
||||
'(' shift, and enter state 9
|
||||
'\\' shift, and enter state 17
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 12
|
||||
Exp2 goto state 13
|
||||
Exp1 goto state 14
|
||||
Exp goto state 32
|
||||
Exp4 goto state 16
|
||||
|
||||
State 10
|
||||
|
||||
Exp3 -> Ident . (rule 9)
|
||||
|
||||
'%' reduce using rule 9
|
||||
'(' reduce using rule 9
|
||||
')' reduce using rule 9
|
||||
'*' reduce using rule 9
|
||||
'+' reduce using rule 9
|
||||
'-' reduce using rule 9
|
||||
'/' reduce using rule 9
|
||||
L_Ident reduce using rule 9
|
||||
L_integ reduce using rule 9
|
||||
%eof reduce using rule 9
|
||||
|
||||
|
||||
State 9
|
||||
|
||||
Exp2 -> Exp3 . (rule 12)
|
||||
|
||||
'(' reduce using rule 12
|
||||
')' reduce using rule 12
|
||||
'+' reduce using rule 12
|
||||
'-' reduce using rule 12
|
||||
L_Ident reduce using rule 12
|
||||
L_integ reduce using rule 12
|
||||
%eof reduce using rule 12
|
||||
|
||||
|
||||
State 10
|
||||
|
||||
Exp2 -> Exp2 . Exp3 (rule 11)
|
||||
Exp1 -> Exp2 . (rule 15)
|
||||
|
||||
'(' shift, and enter state 13
|
||||
')' reduce using rule 15
|
||||
'+' reduce using rule 15
|
||||
'-' reduce using rule 15
|
||||
L_Ident shift, and enter state 6
|
||||
L_integ shift, and enter state 15
|
||||
%eof reduce using rule 15
|
||||
|
||||
Ident goto state 7
|
||||
Integer goto state 8
|
||||
Exp3 goto state 22
|
||||
|
||||
State 11
|
||||
|
||||
Exp1 -> Exp1 . '+' Exp2 (rule 13)
|
||||
Exp1 -> Exp1 . '-' Exp2 (rule 14)
|
||||
Exp -> Exp1 . (rule 17)
|
||||
Exp3 -> Integer . (rule 10)
|
||||
|
||||
')' reduce using rule 17
|
||||
'+' shift, and enter state 23
|
||||
'-' shift, and enter state 24
|
||||
%eof reduce using rule 17
|
||||
'%' reduce using rule 10
|
||||
'(' reduce using rule 10
|
||||
')' reduce using rule 10
|
||||
'*' reduce using rule 10
|
||||
'+' reduce using rule 10
|
||||
'-' reduce using rule 10
|
||||
'/' reduce using rule 10
|
||||
L_Ident reduce using rule 10
|
||||
L_integ reduce using rule 10
|
||||
%eof reduce using rule 10
|
||||
|
||||
|
||||
State 12
|
||||
|
||||
Exp3 -> Exp3 . '%' Exp4 (rule 11)
|
||||
Exp2 -> Exp3 . (rule 16)
|
||||
|
||||
'%' shift, and enter state 25
|
||||
'(' reduce using rule 16
|
||||
')' reduce using rule 16
|
||||
'*' reduce using rule 16
|
||||
'+' reduce using rule 16
|
||||
'-' reduce using rule 16
|
||||
'/' reduce using rule 16
|
||||
L_Ident reduce using rule 16
|
||||
L_integ reduce using rule 16
|
||||
%eof reduce using rule 16
|
||||
|
||||
|
||||
State 13
|
||||
|
||||
Exp2 -> Exp2 . Exp3 (rule 13)
|
||||
Exp2 -> Exp2 . '*' Exp3 (rule 14)
|
||||
Exp2 -> Exp2 . '/' Exp3 (rule 15)
|
||||
Exp1 -> Exp2 . (rule 19)
|
||||
|
||||
'(' shift, and enter state 9
|
||||
')' reduce using rule 19
|
||||
'*' shift, and enter state 27
|
||||
'+' reduce using rule 19
|
||||
'-' reduce using rule 19
|
||||
'/' shift, and enter state 28
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
%eof reduce using rule 19
|
||||
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 26
|
||||
Exp4 goto state 16
|
||||
|
||||
State 14
|
||||
|
||||
Exp1 -> Exp1 . '+' Exp2 (rule 17)
|
||||
Exp1 -> Exp1 . '-' Exp2 (rule 18)
|
||||
Exp -> Exp1 . (rule 21)
|
||||
|
||||
')' reduce using rule 21
|
||||
'+' shift, and enter state 29
|
||||
'-' shift, and enter state 30
|
||||
%eof reduce using rule 21
|
||||
|
||||
|
||||
State 15
|
||||
|
||||
%start_pExp -> Exp . (rule 4)
|
||||
|
||||
%eof accept
|
||||
|
||||
|
||||
State 13
|
||||
|
||||
Exp3 -> '(' . Exp ')' (rule 10)
|
||||
|
||||
'(' shift, and enter state 13
|
||||
'\\' shift, and enter state 14
|
||||
L_Ident shift, and enter state 6
|
||||
L_integ shift, and enter state 15
|
||||
|
||||
Ident goto state 7
|
||||
Integer goto state 8
|
||||
Exp3 goto state 9
|
||||
Exp2 goto state 10
|
||||
Exp1 goto state 11
|
||||
Exp goto state 26
|
||||
|
||||
State 14
|
||||
|
||||
Exp -> '\\' . Ident '->' Exp (rule 16)
|
||||
|
||||
L_Ident shift, and enter state 6
|
||||
|
||||
Ident goto state 25
|
||||
|
||||
State 15
|
||||
|
||||
Integer -> L_integ . (rule 6)
|
||||
|
||||
'(' reduce using rule 6
|
||||
')' reduce using rule 6
|
||||
'+' reduce using rule 6
|
||||
'-' reduce using rule 6
|
||||
L_Ident reduce using rule 6
|
||||
L_integ reduce using rule 6
|
||||
%eof reduce using rule 6
|
||||
|
||||
|
||||
State 16
|
||||
|
||||
%start_pExp1 -> Exp1 . (rule 3)
|
||||
Exp1 -> Exp1 . '+' Exp2 (rule 13)
|
||||
Exp1 -> Exp1 . '-' Exp2 (rule 14)
|
||||
Exp3 -> Exp4 . (rule 12)
|
||||
|
||||
'+' shift, and enter state 23
|
||||
'-' shift, and enter state 24
|
||||
%eof accept
|
||||
'%' reduce using rule 12
|
||||
'(' reduce using rule 12
|
||||
')' reduce using rule 12
|
||||
'*' reduce using rule 12
|
||||
'+' reduce using rule 12
|
||||
'-' reduce using rule 12
|
||||
'/' reduce using rule 12
|
||||
L_Ident reduce using rule 12
|
||||
L_integ reduce using rule 12
|
||||
%eof reduce using rule 12
|
||||
|
||||
|
||||
State 17
|
||||
|
||||
%start_pExp2 -> Exp2 . (rule 2)
|
||||
Exp2 -> Exp2 . Exp3 (rule 11)
|
||||
Exp -> '\\' . Ident '->' Exp (rule 20)
|
||||
|
||||
'(' shift, and enter state 13
|
||||
L_Ident shift, and enter state 6
|
||||
L_integ shift, and enter state 15
|
||||
%eof accept
|
||||
L_Ident shift, and enter state 7
|
||||
|
||||
Ident goto state 7
|
||||
Integer goto state 8
|
||||
Exp3 goto state 22
|
||||
Ident goto state 31
|
||||
|
||||
State 18
|
||||
|
||||
%start_pExp3 -> Exp3 . (rule 1)
|
||||
Integer -> L_integ . (rule 7)
|
||||
|
||||
%eof accept
|
||||
'%' reduce using rule 7
|
||||
'(' reduce using rule 7
|
||||
')' reduce using rule 7
|
||||
'*' reduce using rule 7
|
||||
'+' reduce using rule 7
|
||||
'-' reduce using rule 7
|
||||
'/' reduce using rule 7
|
||||
L_Ident reduce using rule 7
|
||||
L_integ reduce using rule 7
|
||||
%eof reduce using rule 7
|
||||
|
||||
|
||||
State 19
|
||||
|
||||
%start_pExp1 -> Exp1 . (rule 3)
|
||||
Exp1 -> Exp1 . '+' Exp2 (rule 17)
|
||||
Exp1 -> Exp1 . '-' Exp2 (rule 18)
|
||||
|
||||
'+' shift, and enter state 29
|
||||
'-' shift, and enter state 30
|
||||
%eof accept
|
||||
|
||||
|
||||
State 20
|
||||
|
||||
%start_pExp2 -> Exp2 . (rule 2)
|
||||
Exp2 -> Exp2 . Exp3 (rule 13)
|
||||
Exp2 -> Exp2 . '*' Exp3 (rule 14)
|
||||
Exp2 -> Exp2 . '/' Exp3 (rule 15)
|
||||
|
||||
'(' shift, and enter state 9
|
||||
'*' shift, and enter state 27
|
||||
'/' shift, and enter state 28
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
%eof accept
|
||||
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 26
|
||||
Exp4 goto state 16
|
||||
|
||||
State 21
|
||||
|
||||
%start_pExp3 -> Exp3 . (rule 1)
|
||||
Exp3 -> Exp3 . '%' Exp4 (rule 11)
|
||||
|
||||
'%' shift, and enter state 25
|
||||
%eof accept
|
||||
|
||||
|
||||
State 22
|
||||
|
||||
%start_pProgram -> Program . (rule 0)
|
||||
|
||||
%eof accept
|
||||
|
||||
|
||||
State 20
|
||||
State 23
|
||||
|
||||
Program -> 'main' . '=' Exp (rule 7)
|
||||
Program -> 'main' . '=' Exp (rule 8)
|
||||
|
||||
'=' shift, and enter state 21
|
||||
'=' shift, and enter state 24
|
||||
|
||||
|
||||
State 21
|
||||
State 24
|
||||
|
||||
Program -> 'main' '=' . Exp (rule 7)
|
||||
Program -> 'main' '=' . Exp (rule 8)
|
||||
|
||||
'(' shift, and enter state 13
|
||||
'\\' shift, and enter state 14
|
||||
L_Ident shift, and enter state 6
|
||||
L_integ shift, and enter state 15
|
||||
'(' shift, and enter state 9
|
||||
'\\' shift, and enter state 17
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
|
||||
Ident goto state 7
|
||||
Integer goto state 8
|
||||
Exp3 goto state 9
|
||||
Exp2 goto state 10
|
||||
Exp1 goto state 11
|
||||
Exp goto state 31
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 12
|
||||
Exp2 goto state 13
|
||||
Exp1 goto state 14
|
||||
Exp goto state 40
|
||||
Exp4 goto state 16
|
||||
|
||||
State 22
|
||||
State 25
|
||||
|
||||
Exp2 -> Exp2 Exp3 . (rule 11)
|
||||
Exp3 -> Exp3 '%' . Exp4 (rule 11)
|
||||
|
||||
'(' shift, and enter state 9
|
||||
|
||||
Exp4 goto state 39
|
||||
|
||||
State 26
|
||||
|
||||
Exp3 -> Exp3 . '%' Exp4 (rule 11)
|
||||
Exp2 -> Exp2 Exp3 . (rule 13)
|
||||
|
||||
'%' shift, and enter state 25
|
||||
'(' reduce using rule 13
|
||||
')' reduce using rule 13
|
||||
'*' reduce using rule 13
|
||||
'+' reduce using rule 13
|
||||
'-' reduce using rule 13
|
||||
'/' reduce using rule 13
|
||||
L_Ident reduce using rule 13
|
||||
L_integ reduce using rule 13
|
||||
%eof reduce using rule 13
|
||||
|
||||
|
||||
State 27
|
||||
|
||||
Exp2 -> Exp2 '*' . Exp3 (rule 14)
|
||||
|
||||
'(' shift, and enter state 9
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 38
|
||||
Exp4 goto state 16
|
||||
|
||||
State 28
|
||||
|
||||
Exp2 -> Exp2 '/' . Exp3 (rule 15)
|
||||
|
||||
'(' shift, and enter state 9
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 37
|
||||
Exp4 goto state 16
|
||||
|
||||
State 29
|
||||
|
||||
Exp1 -> Exp1 '+' . Exp2 (rule 17)
|
||||
|
||||
'(' shift, and enter state 9
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 12
|
||||
Exp2 goto state 36
|
||||
Exp4 goto state 16
|
||||
|
||||
State 30
|
||||
|
||||
Exp1 -> Exp1 '-' . Exp2 (rule 18)
|
||||
|
||||
'(' shift, and enter state 9
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 12
|
||||
Exp2 goto state 35
|
||||
Exp4 goto state 16
|
||||
|
||||
State 31
|
||||
|
||||
Exp -> '\\' Ident . '->' Exp (rule 20)
|
||||
|
||||
'->' shift, and enter state 34
|
||||
|
||||
|
||||
State 32
|
||||
|
||||
Exp4 -> '(' Exp . ')' (rule 22)
|
||||
|
||||
')' shift, and enter state 33
|
||||
|
||||
|
||||
State 33
|
||||
|
||||
Exp4 -> '(' Exp ')' . (rule 22)
|
||||
|
||||
'%' reduce using rule 22
|
||||
'(' reduce using rule 22
|
||||
')' reduce using rule 22
|
||||
'*' reduce using rule 22
|
||||
'+' reduce using rule 22
|
||||
'-' reduce using rule 22
|
||||
'/' reduce using rule 22
|
||||
L_Ident reduce using rule 22
|
||||
L_integ reduce using rule 22
|
||||
%eof reduce using rule 22
|
||||
|
||||
|
||||
State 34
|
||||
|
||||
Exp -> '\\' Ident '->' . Exp (rule 20)
|
||||
|
||||
'(' shift, and enter state 9
|
||||
'\\' shift, and enter state 17
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 12
|
||||
Exp2 goto state 13
|
||||
Exp1 goto state 14
|
||||
Exp goto state 41
|
||||
Exp4 goto state 16
|
||||
|
||||
State 35
|
||||
|
||||
Exp2 -> Exp2 . Exp3 (rule 13)
|
||||
Exp2 -> Exp2 . '*' Exp3 (rule 14)
|
||||
Exp2 -> Exp2 . '/' Exp3 (rule 15)
|
||||
Exp1 -> Exp1 '-' Exp2 . (rule 18)
|
||||
|
||||
'(' shift, and enter state 9
|
||||
')' reduce using rule 18
|
||||
'*' shift, and enter state 27
|
||||
'+' reduce using rule 18
|
||||
'-' reduce using rule 18
|
||||
'/' shift, and enter state 28
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
%eof reduce using rule 18
|
||||
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 26
|
||||
Exp4 goto state 16
|
||||
|
||||
State 36
|
||||
|
||||
Exp2 -> Exp2 . Exp3 (rule 13)
|
||||
Exp2 -> Exp2 . '*' Exp3 (rule 14)
|
||||
Exp2 -> Exp2 . '/' Exp3 (rule 15)
|
||||
Exp1 -> Exp1 '+' Exp2 . (rule 17)
|
||||
|
||||
'(' shift, and enter state 9
|
||||
')' reduce using rule 17
|
||||
'*' shift, and enter state 27
|
||||
'+' reduce using rule 17
|
||||
'-' reduce using rule 17
|
||||
'/' shift, and enter state 28
|
||||
L_Ident shift, and enter state 7
|
||||
L_integ shift, and enter state 18
|
||||
%eof reduce using rule 17
|
||||
|
||||
Ident goto state 10
|
||||
Integer goto state 11
|
||||
Exp3 goto state 26
|
||||
Exp4 goto state 16
|
||||
|
||||
State 37
|
||||
|
||||
Exp3 -> Exp3 . '%' Exp4 (rule 11)
|
||||
Exp2 -> Exp2 '/' Exp3 . (rule 15)
|
||||
|
||||
'%' shift, and enter state 25
|
||||
'(' reduce using rule 15
|
||||
')' reduce using rule 15
|
||||
'*' reduce using rule 15
|
||||
'+' reduce using rule 15
|
||||
'-' reduce using rule 15
|
||||
'/' reduce using rule 15
|
||||
L_Ident reduce using rule 15
|
||||
L_integ reduce using rule 15
|
||||
%eof reduce using rule 15
|
||||
|
||||
|
||||
State 38
|
||||
|
||||
Exp3 -> Exp3 . '%' Exp4 (rule 11)
|
||||
Exp2 -> Exp2 '*' Exp3 . (rule 14)
|
||||
|
||||
'%' shift, and enter state 25
|
||||
'(' reduce using rule 14
|
||||
')' reduce using rule 14
|
||||
'*' reduce using rule 14
|
||||
'+' reduce using rule 14
|
||||
'-' reduce using rule 14
|
||||
'/' reduce using rule 14
|
||||
L_Ident reduce using rule 14
|
||||
L_integ reduce using rule 14
|
||||
%eof reduce using rule 14
|
||||
|
||||
|
||||
State 39
|
||||
|
||||
Exp3 -> Exp3 '%' Exp4 . (rule 11)
|
||||
|
||||
'%' reduce using rule 11
|
||||
'(' reduce using rule 11
|
||||
')' reduce using rule 11
|
||||
'*' reduce using rule 11
|
||||
'+' reduce using rule 11
|
||||
'-' reduce using rule 11
|
||||
'/' reduce using rule 11
|
||||
L_Ident reduce using rule 11
|
||||
L_integ reduce using rule 11
|
||||
%eof reduce using rule 11
|
||||
|
||||
|
||||
State 23
|
||||
State 40
|
||||
|
||||
Exp1 -> Exp1 '+' . Exp2 (rule 13)
|
||||
Program -> 'main' '=' Exp . (rule 8)
|
||||
|
||||
'(' shift, and enter state 13
|
||||
L_Ident shift, and enter state 6
|
||||
L_integ shift, and enter state 15
|
||||
|
||||
Ident goto state 7
|
||||
Integer goto state 8
|
||||
Exp3 goto state 9
|
||||
Exp2 goto state 30
|
||||
|
||||
State 24
|
||||
|
||||
Exp1 -> Exp1 '-' . Exp2 (rule 14)
|
||||
|
||||
'(' shift, and enter state 13
|
||||
L_Ident shift, and enter state 6
|
||||
L_integ shift, and enter state 15
|
||||
|
||||
Ident goto state 7
|
||||
Integer goto state 8
|
||||
Exp3 goto state 9
|
||||
Exp2 goto state 29
|
||||
|
||||
State 25
|
||||
|
||||
Exp -> '\\' Ident . '->' Exp (rule 16)
|
||||
|
||||
'->' shift, and enter state 28
|
||||
%eof reduce using rule 8
|
||||
|
||||
|
||||
State 26
|
||||
State 41
|
||||
|
||||
Exp3 -> '(' Exp . ')' (rule 10)
|
||||
Exp -> '\\' Ident '->' Exp . (rule 20)
|
||||
|
||||
')' shift, and enter state 27
|
||||
|
||||
|
||||
State 27
|
||||
|
||||
Exp3 -> '(' Exp ')' . (rule 10)
|
||||
|
||||
'(' reduce using rule 10
|
||||
')' reduce using rule 10
|
||||
'+' reduce using rule 10
|
||||
'-' reduce using rule 10
|
||||
L_Ident reduce using rule 10
|
||||
L_integ reduce using rule 10
|
||||
%eof reduce using rule 10
|
||||
|
||||
|
||||
State 28
|
||||
|
||||
Exp -> '\\' Ident '->' . Exp (rule 16)
|
||||
|
||||
'(' shift, and enter state 13
|
||||
'\\' shift, and enter state 14
|
||||
L_Ident shift, and enter state 6
|
||||
L_integ shift, and enter state 15
|
||||
|
||||
Ident goto state 7
|
||||
Integer goto state 8
|
||||
Exp3 goto state 9
|
||||
Exp2 goto state 10
|
||||
Exp1 goto state 11
|
||||
Exp goto state 32
|
||||
|
||||
State 29
|
||||
|
||||
Exp2 -> Exp2 . Exp3 (rule 11)
|
||||
Exp1 -> Exp1 '-' Exp2 . (rule 14)
|
||||
|
||||
'(' shift, and enter state 13
|
||||
')' reduce using rule 14
|
||||
'+' reduce using rule 14
|
||||
'-' reduce using rule 14
|
||||
L_Ident shift, and enter state 6
|
||||
L_integ shift, and enter state 15
|
||||
%eof reduce using rule 14
|
||||
|
||||
Ident goto state 7
|
||||
Integer goto state 8
|
||||
Exp3 goto state 22
|
||||
|
||||
State 30
|
||||
|
||||
Exp2 -> Exp2 . Exp3 (rule 11)
|
||||
Exp1 -> Exp1 '+' Exp2 . (rule 13)
|
||||
|
||||
'(' shift, and enter state 13
|
||||
')' reduce using rule 13
|
||||
'+' reduce using rule 13
|
||||
'-' reduce using rule 13
|
||||
L_Ident shift, and enter state 6
|
||||
L_integ shift, and enter state 15
|
||||
%eof reduce using rule 13
|
||||
|
||||
Ident goto state 7
|
||||
Integer goto state 8
|
||||
Exp3 goto state 22
|
||||
|
||||
State 31
|
||||
|
||||
Program -> 'main' '=' Exp . (rule 7)
|
||||
|
||||
%eof reduce using rule 7
|
||||
|
||||
|
||||
State 32
|
||||
|
||||
Exp -> '\\' Ident '->' Exp . (rule 16)
|
||||
|
||||
')' reduce using rule 16
|
||||
%eof reduce using rule 16
|
||||
')' reduce using rule 20
|
||||
%eof reduce using rule 20
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
Grammar Totals
|
||||
-----------------------------------------------------------------------------
|
||||
Number of rules: 18
|
||||
Number of terminals: 10
|
||||
Number of non-terminals: 12
|
||||
Number of states: 33
|
||||
Number of rules: 23
|
||||
Number of terminals: 13
|
||||
Number of non-terminals: 14
|
||||
Number of states: 42
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -151,4 +151,7 @@ instance Print Grammar.Abs.Exp where
|
|||
Grammar.Abs.EApp exp1 exp2 -> prPrec i 2 (concatD [prt 2 exp1, prt 3 exp2])
|
||||
Grammar.Abs.EAdd exp1 exp2 -> prPrec i 1 (concatD [prt 1 exp1, doc (showString "+"), prt 2 exp2])
|
||||
Grammar.Abs.ESub exp1 exp2 -> prPrec i 1 (concatD [prt 1 exp1, doc (showString "-"), prt 2 exp2])
|
||||
Grammar.Abs.EMul exp1 exp2 -> prPrec i 2 (concatD [prt 2 exp1, doc (showString "*"), prt 3 exp2])
|
||||
Grammar.Abs.EDiv exp1 exp2 -> prPrec i 2 (concatD [prt 2 exp1, doc (showString "/"), prt 3 exp2])
|
||||
Grammar.Abs.EMod exp1 exp2 -> prPrec i 3 (concatD [prt 3 exp1, doc (showString "%"), prt 4 exp2])
|
||||
Grammar.Abs.EAbs id_ exp -> prPrec i 0 (concatD [doc (showString "\\"), prt 0 id_, doc (showString "->"), prt 0 exp])
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -30,4 +30,7 @@ transExp x = case x of
|
|||
Grammar.Abs.EApp exp1 exp2 -> failure x
|
||||
Grammar.Abs.EAdd exp1 exp2 -> failure x
|
||||
Grammar.Abs.ESub exp1 exp2 -> failure x
|
||||
Grammar.Abs.EMul exp1 exp2 -> failure x
|
||||
Grammar.Abs.EDiv exp1 exp2 -> failure x
|
||||
Grammar.Abs.EMod exp1 exp2 -> failure x
|
||||
Grammar.Abs.EAbs ident exp -> failure x
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
src/Grammar/test
BIN
src/Grammar/test
Binary file not shown.
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
|
||||
|
||||
main = 1 + (123 + 4214) - 1231 + 314
|
||||
main = (0-3) % (7) -- ((2 * (123 + 4214 % (1230)) - 1231) / 314)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue