-- File generated by the BNF Converter. -- Parser definition for use with Happy. { {-# OPTIONS_GHC -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns #-} {-# LANGUAGE PatternSynonyms #-} module ParFstStudio ( happyError , myLexer , pProgram , pDef , pExp , pExp1 , pExp2 , pExp3 , pExp4 , pListDef , pListExp , pListIdent ) where import Prelude import qualified AbsFstStudio import LexFstStudio } %name pProgram Program %name pDef Def %name pExp Exp %name pExp1 Exp1 %name pExp2 Exp2 %name pExp3 Exp3 %name pExp4 Exp4 %name pListDef ListDef %name pListExp ListExp %name pListIdent ListIdent %monad { Err } { (>>=) } { 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) } '.o.' { PT _ (TS _ 12) } '.x.' { PT _ (TS _ 13) } '//' { PT _ (TS _ 14) } '0' { PT _ (TS _ 15) } ':' { PT _ (TS _ 16) } '::=' { PT _ (TS _ 17) } ';' { PT _ (TS _ 18) } '<' { PT _ (TS _ 19) } '=>' { PT _ (TS _ 20) } '>' { PT _ (TS _ 21) } '?' { PT _ (TS _ 22) } '@->' { PT _ (TS _ 23) } '\\' { PT _ (TS _ 24) } '^' { PT _ (TS _ 25) } '_' { PT _ (TS _ 26) } 'import' { PT _ (TS _ 27) } 'main' { PT _ (TS _ 28) } '{' { PT _ (TS _ 29) } '|' { PT _ (TS _ 30) } '||' { PT _ (TS _ 31) } '}' { PT _ (TS _ 32) } '~' { PT _ (TS _ 33) } L_Ident { PT _ (TV $$) } L_integ { PT _ (TI $$) } L_quoted { PT _ (TL $$) } %% Ident :: { AbsFstStudio.Ident } Ident : L_Ident { AbsFstStudio.Ident $1 } Integer :: { Integer } Integer : L_integ { (read $1 ) :: Integer } String :: { String } String : L_quoted { $1 } Program :: { AbsFstStudio.Program } Program : ListDef { AbsFstStudio.Prog $1 } Def :: { AbsFstStudio.Def } Def : '<' 'main' '>' '::=' Exp { AbsFstStudio.Main $5 } | '<' Ident ListIdent '>' '::=' Exp { AbsFstStudio.Declaration $2 $3 $6 } | 'import' ListIdent { AbsFstStudio.Import $2 } Exp :: { AbsFstStudio.Exp } Exp : Exp '->' Exp1 { AbsFstStudio.Replacement $1 $3 } | Exp '->' Exp1 '//' Exp1 '_' Exp1 { AbsFstStudio.CSReplacement $1 $3 $5 $7 } | Exp '->' Exp1 '||' Exp1 '_' Exp1 { AbsFstStudio.CReplacement $1 $3 $5 $7 } | Exp '.o.' Exp1 { AbsFstStudio.Composition $1 $3 } | Exp '.x.' Exp1 { AbsFstStudio.CrossProduct $1 $3 } | Exp '=>' Exp1 '_' Exp1 { AbsFstStudio.Restriction $1 $3 $5 } | Exp '@->' Exp1 { AbsFstStudio.LongReplace $1 $3 } | Exp1 { $1 } Exp1 :: { AbsFstStudio.Exp } Exp1 : Exp1 '&' Exp2 { AbsFstStudio.Intersect $1 $3 } | Exp1 '-' Exp2 { AbsFstStudio.Minus $1 $3 } | Exp1 '|' Exp2 { AbsFstStudio.Union $1 $3 } | Exp2 { $1 } | Exp2 '...' Exp2 { AbsFstStudio.Markup $1 $3 } Exp2 :: { AbsFstStudio.Exp } Exp2 : Exp2 Exp3 { AbsFstStudio.Concat $1 $2 } | Exp3 { $1 } Exp3 :: { AbsFstStudio.Exp } Exp3 : '$' Exp4 { AbsFstStudio.Containment $2 } | '\\' Exp4 { AbsFstStudio.TComplement $2 } | '~' Exp4 { AbsFstStudio.Complement $2 } | Exp4 { $1 } Exp4 :: { AbsFstStudio.Exp } Exp4 : '(' Exp ')' { $2 } | '.#.' { AbsFstStudio.Boundary } | '0' { AbsFstStudio.Epsilon } | '<' Ident ListExp '>' { AbsFstStudio.AppDecl $2 $3 } | '?' { AbsFstStudio.Any } | '{' String '}' { AbsFstStudio.Concats $2 } | String { AbsFstStudio.Symbol $1 } | String ':' String { AbsFstStudio.Relation $1 $3 } | Ident { AbsFstStudio.Variable $1 } | Exp4 '*' { AbsFstStudio.Star $1 } | Exp4 '+' { AbsFstStudio.Plus $1 } | Exp4 '^' Integer { AbsFstStudio.NConcat $1 $3 } ListDef :: { [AbsFstStudio.Def] } ListDef : {- empty -} { [] } | Def ';' ListDef { (:) $1 $3 } ListExp :: { [AbsFstStudio.Exp] } ListExp : {- empty -} { [] } | ',' Exp ListExp { (:) $2 $3 } ListIdent :: { [AbsFstStudio.Ident] } ListIdent : {- empty -} { [] } | ',' Ident ListIdent { (:) $2 $3 } { type Err = Either String happyError :: [Token] -> Err a happyError ts = Left $ "syntax error at " ++ tokenPos ts ++ case ts of [] -> [] [Err _] -> " due to lexer error" t:_ -> " before `" ++ (prToken t) ++ "'" myLexer :: String -> [Token] myLexer = tokens }