Skip to content

Instantly share code, notes, and snippets.

@KiJeong-Lim
Last active May 18, 2024 11:10
Show Gist options
  • Save KiJeong-Lim/273011ff996f4962ededabc8fc87d16e to your computer and use it in GitHub Desktop.
Save KiJeong-Lim/273011ff996f4962ededabc8fc87d16e to your computer and use it in GitHub Desktop.
parsing typeclass
couldn't resolve conflict:
? REDUCE: <TypeConstructorName> ::= `largeid'; v.s. REDUCE: <TypeClassName> ::= `largeid'; at { state = 14, terminal = `smallid' }
? collection = {
getParserSInfo :: ParserS -> ParserSInfo
getParserSInfo 0 = ParserSInfo
{ myItems =
[ "<PiType> ::= . <TauType>"
, "<PiType> ::= . `lparen' <Sequence Contraint> `rparen' `fatarrow' <TauType>"
, "<TauType> ::= . <TauType1>"
, "<TauType> ::= . <TauType1> `arrow' <TauType>"
, "<TauType1> ::= . <TauType1> <TauType2>"
, "<TauType1> ::= . <TauType2>"
, "<TauType2> ::= . <TypeConstructorName>"
, "<TauType2> ::= . <TypeVariableName>"
, "<TauType2> ::= . `lparen' <TauType> `rparen'"
, "<TypeConstructorName> ::= . `largeid'"
, "<TypeVariableName> ::= . `smallid'"
, "<\\ACCEPT> ::= . <PiType> `\\$'"
]
, myNexts =
[ "<PiType> +-> 1"
, "<TauType> +-> 2"
, "<TauType1> +-> 3"
, "<TauType2> +-> 4"
, "<TypeConstructorName> +-> 5"
, "<TypeVariableName> +-> 6"
, "`largeid' +-> 7"
, "`lparen' +-> 8"
, "`smallid' +-> 9"
]
}
getParserSInfo 1 = ParserSInfo
{ myItems =
[ "<\\ACCEPT> ::= <PiType> . `\\$'"
]
, myNexts = []
}
getParserSInfo 2 = ParserSInfo
{ myItems =
[ "<PiType> ::= <TauType> ."
]
, myNexts = []
}
getParserSInfo 3 = ParserSInfo
{ myItems =
[ "<TauType> ::= <TauType1> ."
, "<TauType> ::= <TauType1> . `arrow' <TauType>"
, "<TauType1> ::= <TauType1> . <TauType2>"
, "<TauType2> ::= . <TypeConstructorName>"
, "<TauType2> ::= . <TypeVariableName>"
, "<TauType2> ::= . `lparen' <TauType> `rparen'"
, "<TypeConstructorName> ::= . `largeid'"
, "<TypeVariableName> ::= . `smallid'"
]
, myNexts =
[ "<TypeConstructorName> +-> 5"
, "<TypeVariableName> +-> 6"
, "`largeid' +-> 7"
, "`smallid' +-> 9"
, "`lparen' +-> 15"
, "<TauType2> +-> 16"
, "`arrow' +-> 17"
]
}
getParserSInfo 4 = ParserSInfo
{ myItems =
[ "<TauType1> ::= <TauType2> ."
]
, myNexts = []
}
getParserSInfo 5 = ParserSInfo
{ myItems =
[ "<TauType2> ::= <TypeConstructorName> ."
]
, myNexts = []
}
getParserSInfo 6 = ParserSInfo
{ myItems =
[ "<TauType2> ::= <TypeVariableName> ."
]
, myNexts = []
}
getParserSInfo 7 = ParserSInfo
{ myItems =
[ "<TypeConstructorName> ::= `largeid' ."
]
, myNexts = []
}
getParserSInfo 8 = ParserSInfo
{ myItems =
[ "<Contraint> ::= . <TypeClassName> <List TauType2>"
, "<PiType> ::= `lparen' . <Sequence Contraint> `rparen' `fatarrow' <TauType>"
, "<TauType> ::= . <TauType1>"
, "<TauType> ::= . <TauType1> `arrow' <TauType>"
, "<TauType1> ::= . <TauType1> <TauType2>"
, "<TauType1> ::= . <TauType2>"
, "<TauType2> ::= . <TypeConstructorName>"
, "<TauType2> ::= . <TypeVariableName>"
, "<TauType2> ::= . `lparen' <TauType> `rparen'"
, "<TauType2> ::= `lparen' . <TauType> `rparen'"
, "<TypeClassName> ::= . `largeid'"
, "<TypeConstructorName> ::= . `largeid'"
, "<TypeVariableName> ::= . `smallid'"
, "<Sequence Contraint> ::= ."
, "<Sequence Contraint> ::= . <Contraint> `comma' <Sequence Contraint>"
]
, myNexts =
[ "<TauType1> +-> 3"
, "<TauType2> +-> 4"
, "<TypeConstructorName> +-> 5"
, "<TypeVariableName> +-> 6"
, "`smallid' +-> 9"
, "<Contraint> +-> 10"
, "<TauType> +-> 11"
, "<TypeClassName> +-> 12"
, "<Sequence Contraint> +-> 13"
, "`largeid' +-> 14"
, "`lparen' +-> 15"
]
}
getParserSInfo 9 = ParserSInfo
{ myItems =
[ "<TypeVariableName> ::= `smallid' ."
]
, myNexts = []
}
getParserSInfo 10 = ParserSInfo
{ myItems =
[ "<Sequence Contraint> ::= <Contraint> . `comma' <Sequence Contraint>"
]
, myNexts =
[ "`comma' +-> 23"
]
}
getParserSInfo 11 = ParserSInfo
{ myItems =
[ "<TauType2> ::= `lparen' <TauType> . `rparen'"
]
, myNexts =
[ "`rparen' +-> 22"
]
}
getParserSInfo 12 = ParserSInfo
{ myItems =
[ "<Contraint> ::= <TypeClassName> . <List TauType2>"
, "<TauType2> ::= . <TypeConstructorName>"
, "<TauType2> ::= . <TypeVariableName>"
, "<TauType2> ::= . `lparen' <TauType> `rparen'"
, "<TypeConstructorName> ::= . `largeid'"
, "<TypeVariableName> ::= . `smallid'"
, "<List TauType2> ::= ."
, "<List TauType2> ::= . <TauType2> <List TauType2>"
]
, myNexts =
[ "<TypeConstructorName> +-> 5"
, "<TypeVariableName> +-> 6"
, "`largeid' +-> 7"
, "`smallid' +-> 9"
, "`lparen' +-> 15"
, "<TauType2> +-> 18"
, "<List TauType2> +-> 19"
]
}
getParserSInfo 13 = ParserSInfo
{ myItems =
[ "<PiType> ::= `lparen' <Sequence Contraint> . `rparen' `fatarrow' <TauType>"
]
, myNexts =
[ "`rparen' +-> 20"
]
}
getParserSInfo 14 = ParserSInfo
{ myItems =
[ "<TypeClassName> ::= `largeid' ."
, "<TypeConstructorName> ::= `largeid' ."
]
, myNexts = []
}
getParserSInfo 15 = ParserSInfo
{ myItems =
[ "<TauType> ::= . <TauType1>"
, "<TauType> ::= . <TauType1> `arrow' <TauType>"
, "<TauType1> ::= . <TauType1> <TauType2>"
, "<TauType1> ::= . <TauType2>"
, "<TauType2> ::= . <TypeConstructorName>"
, "<TauType2> ::= . <TypeVariableName>"
, "<TauType2> ::= . `lparen' <TauType> `rparen'"
, "<TauType2> ::= `lparen' . <TauType> `rparen'"
, "<TypeConstructorName> ::= . `largeid'"
, "<TypeVariableName> ::= . `smallid'"
]
, myNexts =
[ "<TauType1> +-> 3"
, "<TauType2> +-> 4"
, "<TypeConstructorName> +-> 5"
, "<TypeVariableName> +-> 6"
, "`largeid' +-> 7"
, "`smallid' +-> 9"
, "<TauType> +-> 11"
, "`lparen' +-> 15"
]
}
getParserSInfo 16 = ParserSInfo
{ myItems =
[ "<TauType1> ::= <TauType1> <TauType2> ."
]
, myNexts = []
}
getParserSInfo 17 = ParserSInfo
{ myItems =
[ "<TauType> ::= . <TauType1>"
, "<TauType> ::= . <TauType1> `arrow' <TauType>"
, "<TauType> ::= <TauType1> `arrow' . <TauType>"
, "<TauType1> ::= . <TauType1> <TauType2>"
, "<TauType1> ::= . <TauType2>"
, "<TauType2> ::= . <TypeConstructorName>"
, "<TauType2> ::= . <TypeVariableName>"
, "<TauType2> ::= . `lparen' <TauType> `rparen'"
, "<TypeConstructorName> ::= . `largeid'"
, "<TypeVariableName> ::= . `smallid'"
]
, myNexts =
[ "<TauType1> +-> 3"
, "<TauType2> +-> 4"
, "<TypeConstructorName> +-> 5"
, "<TypeVariableName> +-> 6"
, "`largeid' +-> 7"
, "`smallid' +-> 9"
, "`lparen' +-> 15"
, "<TauType> +-> 21"
]
}
getParserSInfo 18 = ParserSInfo
{ myItems =
[ "<TauType2> ::= . <TypeConstructorName>"
, "<TauType2> ::= . <TypeVariableName>"
, "<TauType2> ::= . `lparen' <TauType> `rparen'"
, "<TypeConstructorName> ::= . `largeid'"
, "<TypeVariableName> ::= . `smallid'"
, "<List TauType2> ::= ."
, "<List TauType2> ::= . <TauType2> <List TauType2>"
, "<List TauType2> ::= <TauType2> . <List TauType2>"
]
, myNexts =
[ "<TypeConstructorName> +-> 5"
, "<TypeVariableName> +-> 6"
, "`largeid' +-> 7"
, "`smallid' +-> 9"
, "`lparen' +-> 15"
, "<TauType2> +-> 18"
, "<List TauType2> +-> 27"
]
}
getParserSInfo 19 = ParserSInfo
{ myItems =
[ "<Contraint> ::= <TypeClassName> <List TauType2> ."
]
, myNexts = []
}
getParserSInfo 20 = ParserSInfo
{ myItems =
[ "<PiType> ::= `lparen' <Sequence Contraint> `rparen' . `fatarrow' <TauType>"
]
, myNexts =
[ "`fatarrow' +-> 26"
]
}
getParserSInfo 21 = ParserSInfo
{ myItems =
[ "<TauType> ::= <TauType1> `arrow' <TauType> ."
]
, myNexts = []
}
getParserSInfo 22 = ParserSInfo
{ myItems =
[ "<TauType2> ::= `lparen' <TauType> `rparen' ."
]
, myNexts = []
}
getParserSInfo 23 = ParserSInfo
{ myItems =
[ "<Contraint> ::= . <TypeClassName> <List TauType2>"
, "<TypeClassName> ::= . `largeid'"
, "<Sequence Contraint> ::= ."
, "<Sequence Contraint> ::= . <Contraint> `comma' <Sequence Contraint>"
, "<Sequence Contraint> ::= <Contraint> `comma' . <Sequence Contraint>"
]
, myNexts =
[ "<Contraint> +-> 10"
, "<TypeClassName> +-> 12"
, "<Sequence Contraint> +-> 24"
, "`largeid' +-> 25"
]
}
getParserSInfo 24 = ParserSInfo
{ myItems =
[ "<Sequence Contraint> ::= <Contraint> `comma' <Sequence Contraint> ."
]
, myNexts = []
}
getParserSInfo 25 = ParserSInfo
{ myItems =
[ "<TypeClassName> ::= `largeid' ."
]
, myNexts = []
}
getParserSInfo 26 = ParserSInfo
{ myItems =
[ "<PiType> ::= `lparen' <Sequence Contraint> `rparen' `fatarrow' . <TauType>"
, "<TauType> ::= . <TauType1>"
, "<TauType> ::= . <TauType1> `arrow' <TauType>"
, "<TauType1> ::= . <TauType1> <TauType2>"
, "<TauType1> ::= . <TauType2>"
, "<TauType2> ::= . <TypeConstructorName>"
, "<TauType2> ::= . <TypeVariableName>"
, "<TauType2> ::= . `lparen' <TauType> `rparen'"
, "<TypeConstructorName> ::= . `largeid'"
, "<TypeVariableName> ::= . `smallid'"
]
, myNexts =
[ "<TauType1> +-> 3"
, "<TauType2> +-> 4"
, "<TypeConstructorName> +-> 5"
, "<TypeVariableName> +-> 6"
, "`largeid' +-> 7"
, "`smallid' +-> 9"
, "`lparen' +-> 15"
, "<TauType> +-> 28"
]
}
getParserSInfo 27 = ParserSInfo
{ myItems =
[ "<List TauType2> ::= <TauType2> <List TauType2> ."
]
, myNexts = []
}
getParserSInfo 28 = ParserSInfo
{ myItems =
[ "<PiType> ::= `lparen' <Sequence Contraint> `rparen' `fatarrow' <TauType> ."
]
, myNexts = []
}
}
\hshead {
module Main where
}
\target {
token-type: "Token"
parser-name: "fooparser"
result-type: "PiType"
start: $PiType
terminals:
"T_arrow": $arrow 0 none
"T_lparen": $lparen 0 none
"T_rparen": $rparen 0 none
"T_fatarrow": $fatarrow 0 none
"T_comma": $comma 0 none
"T_largeid contents": $largeid 0 none
"T_smallid contents": $smallid 0 none
}
\define $TypeConstructorName : "TypeConstructorName" {
0 [$largeid]:
$1.contents
}
\define $TypeClassName : "TypeClassName" {
0 [$largeid]:
$1.contents
}
\define $TypeVariableName : "TypeVariableName" {
0 [$smallid]:
$1.contents
}
\define $PiType : "PiType" {
0 [$lparen, $Sequence $Contraint, $rparen, $fatarrow, $TauType]:
WithConstraints $2 $5
0 [$TauType]:
WithoutConstraints $1
}
\define $Contraint : "Contraint" {
0 [$TypeClassName, $List $TauType2]:
Contraint $1 $2
}
\define $TauType : "TauType" {
0 [$TauType1, $arrow, $TauType]:
TApp (TApp (TCon "Primitive.arrow") $1) $2
0 [$TauType1]:
$1
}
\define $TauType1 : "TauType" {
0 [$TauType1, $TauType2]:
TApp $1 $2
0 [$TauType2]:
$2
}
\define $TauType2 : "TauType" {
0 [$TypeConstructorName]:
TCon $1
0 [$TypeVariableName]:
TVar $1
0 [$lparen, $TauType, $rparen]:
$2
}
\define $Sequence ($Elem : "a") : "[a]" {
50 []:
[]
50 [$Elem, $comma, $Sequence $Elem]:
$1 : $2
}
\define $List ($Elem : "a") : "[a]" {
50 []:
[]
50 [$Elem, $List $Elem]:
$1 : $2
}
\hstail {
type TypeConstructorName = String
type TypeClassName = String
type TypeVariableName = String
data PiType
= WithConstraints [Contraint] TauType
| WithoutConstraints TauType
deriving (Eq, Show)
data Contraint
= Contraint TypeClassName [TauType]
deriving (Eq, Show)
data TauType
= TCon TypeConstructorName
| TVar TypeVariableName
| TApp TauType TauType
deriving (Eq, Show)
main :: IO ()
main = undefined
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment