-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coq lang #38
Open
lucaspena
wants to merge
44
commits into
master
Choose a base branch
from
coq-lang
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Coq lang #38
Changes from 23 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
cb093c7
begin support for coq in ML
lucaspena a721d74
more support for coq in ML. inductive defs parse
lucaspena 7bb9ed5
coq: Fix parsing of underscores
nishantjr 1a294cc
add more parsing rules and Logic examples
e9245c3
minor
13c1df5
coq-lang: parsing more logic, can parse exists and AndComm
lucaspena 7155865
coq-lang: format sentences (newline)
lucaspena 2413968
t/Logic.v: added eq inductive type
lucaspena 2d5da27
coq-driver: begin translating inductive defs to ml
lucaspena 40317e2
coq-driver: begin translating Definitions
lucaspena 2dd0fac
coq-driver: translating some definitions/terms
lucaspena 8e88b50
coq-driver: more translating coq term to pattern. AndComm mostly tran…
lucaspena 93bb94e
add mu, translating fix
lucaspena ba95017
coq-driver: translate binders from match clauses
lucaspena 54749f9
translating ind defs
lucaspena 12b53bc
parsing Logic.v
lucaspena 0c60745
kore-lang: for aml: application is Pattern(Patterns)
lucaspena 46b712b
cleanup
lucaspena b802ed3
remove coq tests besides Logic and nat_ind, add expeted output for those
lucaspena 8585a5d
coq tests in own directory
lucaspena 74f3c0b
use named axioms
lucaspena 968a224
set variables no longer sorted
lucaspena 5c2e2ce
create goals for typing coq defs. add result type to definitions
lucaspena b2bd250
change format for terms having type in v files
lucaspena 3090652
coq-driver: translate forall to pi
lucaspena 61881a2
change type-check to typecheck
lucaspena 85e8229
placeholder for typecheck strategy
lucaspena 33e7f10
encode output type in coq syntax rather than comment
lucaspena 2eb94c1
begin typecheck strategy
lucaspena 974aac4
typecheck works for simple examples
lucaspena 182db6b
typecheck: minor change
lucaspena 5b13db3
add coq rules
724644b
global environments, begin well-typing defs
lucaspena 7011393
add basic Coq typing rules
477dde5
add authors
895d236
wording of comment in W-Local-Assum
lucaspena 1de1820
parsing more terms in coq translation
lucaspena 07675a4
coq-lang, coq-driver: handling more constructs for generated verbose …
lucaspena 3deae83
more parsing
lucaspena 10c7863
coq rules: conversion rules
lucaspena 74f3359
coq_rules: more on conversion rules
lucaspena 7331f17
coq_rules: subtyping rules
lucaspena e93c40e
coq_rules: Inductive Definitions
lucaspena bff2495
coq_rules: correctness rules
lucaspena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
Coq Driver | ||
========== | ||
|
||
This file is responsible for loading definitions in the Coq format. | ||
|
||
```k | ||
module DRIVER-COQ-COMMON | ||
imports COQ | ||
imports STRATEGIES-EXPORTED-SYNTAX | ||
syntax Pgm ::= CoqSentences | ||
endmodule | ||
``` | ||
|
||
```k | ||
module DRIVER-COQ-SYNTAX | ||
imports DRIVER-BASE-SYNTAX | ||
imports DRIVER-COQ-COMMON | ||
imports COQ-SYNTAX | ||
endmodule | ||
``` | ||
|
||
```k | ||
module DRIVER-COQ | ||
imports DRIVER-KORE | ||
imports DRIVER-COQ-COMMON | ||
imports KORE | ||
imports PROVER-CONFIGURATION | ||
imports PROVER-CORE-SYNTAX | ||
imports STRATEGIES-EXPORTED-SYNTAX | ||
|
||
// Add sort "Term" to declarations | ||
rule <k> CS:CoqSentence CSs:CoqSentences => CS ~> CSs ... </k> | ||
<declarations> ( .Bag | ||
=> <declaration> sort StringToSort("Term") </declaration> | ||
) ... | ||
</declarations> | ||
|
||
// Add symbol (of sort Term) and equality axiom corresponding to each definition | ||
rule Definition ID BINDERs : TYPE1 := TERM hasType TYPE2 . => Definition ID := TERM hasType TYPE2 . | ||
rule <k> Definition ID := TERM hasType TYPE . | ||
=> .K | ||
... | ||
</k> | ||
<declarations> ( .Bag | ||
=> <declaration> symbol CoqIdentToSymbol(ID)(.Sorts) : StringToSort("Term") </declaration> | ||
<declaration> axiom getFreshGlobalAxiomName() : \equals(CoqIdentToSymbol(ID), CoqTermToPattern(TERM)) </declaration> | ||
) ... | ||
</declarations> | ||
<goals> | ||
( .Bag => | ||
<goal> | ||
<id> !N:ClaimName </id> | ||
<active> true:Bool </active> | ||
<parent> .K </parent> | ||
<claim> \type(CoqIdentToSymbol(ID), CoqTermToPattern(TYPE)) </claim> | ||
<strategy> type-check </strategy> | ||
<expected> success </expected> | ||
<local-context> .Bag </local-context> | ||
<trace> .K </trace> | ||
</goal> | ||
) | ||
... | ||
</goals> | ||
|
||
|
||
// Translate inductive cases | ||
rule <k> Inductive ID BINDERs : TERM := .CoqIndCases . | ||
=> .K | ||
... | ||
</k> | ||
<declarations> ( .Bag | ||
=> <declaration> symbol CoqIdentToSymbol(ID)(.Sorts) : StringToSort("Term") </declaration> | ||
) ... | ||
</declarations> | ||
|
||
rule <k> Inductive ID BINDERs : TERM := (IDC BINDERCs : TERMC) | CASEs . | ||
=> Inductive ID BINDERs : TERM := CASEs . | ||
... | ||
</k> | ||
<declarations> ( .Bag | ||
=> <declaration> symbol CoqIdentToSymbol(IDC)(.Sorts) : StringToSort("Term") </declaration> | ||
<declaration> axiom getFreshGlobalAxiomName() : \type(CoqIdentToSymbol(IDC)(.Patterns), CoqTermToPattern(TERMC)) </declaration> | ||
) ... | ||
</declarations> | ||
|
||
// Converting Term to Pattern | ||
syntax Pattern ::= CoqTermToPattern(CoqTerm) [function] | ||
rule CoqTermToPattern(UN:UpperName) => CoqIdentToSymbol(UN) | ||
rule CoqTermToPattern(LN:LowerName) => CoqIdentToSymbol(LN) | ||
rule CoqTermToPattern(#token("Prop", "CoqSort")) => StringToSort("Term") | ||
rule CoqTermToPattern(fun BINDERs => TERM) => \lambda { CoqBindersToPatterns(BINDERs) } CoqTermToPattern(TERM) | ||
rule CoqTermToPattern(forall BINDERs, TERM) => \forall { CoqBindersToPatterns(BINDERs) } CoqTermToPattern(TERM) | ||
rule CoqTermToPattern(match Ts with .CoqEquations end) => \bottom() | ||
rule CoqTermToPattern(match Ts with (MP:CoqMultPattern => TM:CoqTerm) | EQs end) => | ||
\or( #flattenOrs( | ||
\or( \exists { CoqMultPatternToBinders(MP) } | ||
\and( #equals(CoqMatchItemsToPatterns(Ts), CoqMultPatternToPatterns(MP)) | ||
++Patterns | ||
CoqTermToPattern(TM) | ||
) | ||
++Patterns | ||
CoqTermToPattern(match Ts with EQs end) | ||
), .Patterns)) | ||
rule CoqTermToPattern(TM:CoqTerm ARG) => CoqTermToPattern(TM)(CoqArgToPatterns(ARG)) | ||
rule CoqTermToPattern(fix ID BINDERs := TM) => \mu { # CoqNameToVariableName(ID) } CoqTermToPattern(fun BINDERs => TM) | ||
rule CoqTermToPattern(@ QID:CoqQualID TM:CoqTerm) => CoqIdentToSymbol(QID)(CoqTermToPattern(TM)) | ||
|
||
syntax Patterns ::= CoqArgToPatterns(CoqArg) [function] | ||
rule CoqArgToPatterns(ARG1 ARG2) => CoqArgToPatterns(ARG1) ++Patterns CoqArgToPatterns(ARG2) | ||
rule CoqArgToPatterns(TM:CoqTerm) => CoqTermToPattern(TM), .Patterns | ||
[owise] | ||
|
||
syntax Patterns ::= CoqMatchItemsToPatterns(CoqMatchItems) [function] | ||
syntax Pattern ::= CoqMatchItemToPattern(CoqMatchItem) [function] | ||
rule CoqMatchItemsToPatterns(.CoqMatchItems) => .Patterns | ||
rule CoqMatchItemsToPatterns(MI:CoqMatchItem, MIs) => CoqMatchItemToPattern(MI), .Patterns | ||
|
||
rule CoqMatchItemToPattern(MI:CoqTerm) => CoqTermToPattern(MI) | ||
|
||
syntax Patterns ::= #equals(Patterns, Patterns) [function] | ||
rule #equals(.Patterns, .Patterns) => .Patterns | ||
rule #equals((P1, Ps1), (P2, Ps2)) => \equals(P1, P2), #equals(Ps1, Ps2) | ||
|
||
syntax Pattern ::= CoqPatternToPattern(CoqPattern) [function] | ||
syntax Patterns ::= CoqPatternToPatterns(CoqPattern) [function] | ||
syntax Patterns ::= CoqMultPatternToPatterns(CoqMultPattern) [function] | ||
rule CoqMultPatternToPatterns(.CoqMultPattern) => .Patterns | ||
rule CoqMultPatternToPatterns(MP, MPs) => CoqPatternToPattern(MP), CoqMultPatternToPatterns(MPs) | ||
|
||
rule CoqPatternToPattern(ID:CoqQualID) => CoqIdentToSymbol(ID) | ||
rule CoqPatternToPattern(ID:CoqQualID P:CoqPattern) => CoqIdentToSymbol(ID)(CoqPatternToPatterns(P)) | ||
rule CoqPatternToPatterns(ID:CoqQualID) => CoqIdentToSymbol(ID), .Patterns | ||
rule CoqPatternToPatterns(ID:CoqQualID P:CoqPattern) => CoqIdentToSymbol(ID) ++Patterns CoqPatternToPatterns(P) | ||
|
||
// Get binders from MultPattern | ||
syntax Patterns ::= CoqMultPatternToBinders(CoqMultPattern) [function] | ||
syntax Patterns ::= CoqPatternToBinders(CoqMultPattern) [function] | ||
rule CoqMultPatternToBinders(ID:CoqQualID) => .Patterns | ||
rule CoqMultPatternToBinders(ID:CoqQualID P:CoqPattern) => CoqPatternToBinders(P) | ||
rule CoqPatternToBinders(ID:CoqQualID) => CoqIdentToSymbol(ID), .Patterns | ||
rule CoqPatternToBinders(ID:CoqQualID P:CoqPattern) => CoqIdentToSymbol(ID), CoqPatternToBinders(P) | ||
|
||
syntax Patterns ::= CoqBindersToPatterns(CoqBinders) [function] | ||
rule CoqBindersToPatterns(.CoqBinders) => .Patterns | ||
rule CoqBindersToPatterns(BINDER BINDERs:CoqBinders) => | ||
CoqBinderToPatterns(BINDER) ++Patterns CoqBindersToPatterns(BINDERs) | ||
|
||
syntax Patterns ::= CoqBinderToPatterns(CoqBinder) [function] | ||
rule CoqBinderToPatterns(NAME:CoqName) => CoqNameToVariableName(NAME) { StringToSort("Term") } | ||
rule CoqBinderToPatterns((.CoqNames : TYPE:CoqTerm)) => .Patterns | ||
rule CoqBinderToPatterns(((NAME:CoqName NAMES:CoqNames) : TYPE:CoqTerm)) => CoqNameToVariableName(NAME) { StringToSort("Term") }, CoqBinderToPatterns((NAMES : TYPE)) | ||
``` | ||
|
||
```k | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
```k | ||
module COQ-SYNTAX | ||
imports TOKENS-SYNTAX | ||
imports COQ | ||
endmodule | ||
|
||
module COQ | ||
imports INT-SYNTAX | ||
imports BOOL-SYNTAX | ||
imports STRING | ||
imports KORE-HELPERS | ||
|
||
// Identifiers | ||
syntax CoqIdent ::= LowerName | ||
| UpperName | ||
syntax CoqQualID ::= CoqIdent | ||
syntax CoqName ::= CoqIdent | ||
| Underscore | ||
syntax CoqNames ::= List{CoqName, ""} [klabel(CoqNames)] | ||
|
||
// Sorts | ||
syntax CoqSort ::= "SProp" [token] | ||
| "Prop" [token] | ||
| "Set" [token] | ||
| "Type" [token] | ||
|
||
// Seralize to String: | ||
syntax String ::= CoqNameToString(CoqName) [function, functional, hook(STRING.token2string)] | ||
|
||
// Sort conversions | ||
syntax Symbol ::= CoqIdentToSymbol(CoqIdent) [function] | ||
rule CoqIdentToSymbol(IDENT:UpperName) => IDENT | ||
rule CoqIdentToSymbol(IDENT:LowerName) => IDENT | ||
|
||
syntax Symbol ::= CoqQualIDToSymbol(CoqQualID) [function] | ||
rule CoqQualIDToSymbol(ID:CoqIdent) => CoqIdentToSymbol(ID) | ||
|
||
syntax VariableName ::= CoqNameToVariableName(CoqName) [function] | ||
rule CoqNameToVariableName(NAME) => StringToVariableName(CoqNameToString(NAME)) | ||
|
||
syntax Sorts ::= CoqNamesToSorts(CoqNames) [function] | ||
rule CoqNamesToSorts(.CoqNames) => .Sorts | ||
rule CoqNamesToSorts(NAME:CoqName NAMEs) => StringToSort("Term"), CoqNamesToSorts(NAMEs) | ||
|
||
// Terms | ||
syntax CoqTerm ::= "fun" CoqBinders "=>" CoqTerm | ||
| "fix" CoqFixBodies | ||
| "cofix" CoqCofixBodies | ||
| "let" CoqIdent ":=" CoqTerm "in" CoqTerm | ||
| "let" CoqIdent CoqBinders ":" CoqTerm ":=" CoqTerm "in" CoqTerm | ||
| "@" CoqQualID CoqTerm | ||
| "match" CoqMatchItems "with" CoqEquations "end" | ||
> CoqTerm CoqArg [right] | ||
| CoqQualID | ||
| CoqSort | ||
| Int | ||
| Underscore | ||
> "forall" CoqBinders "," CoqTerm | ||
> "(" CoqTerm ")" [bracket] | ||
|
||
syntax CoqBinder ::= CoqName | ||
| "(" CoqNames ":" CoqTerm ")" | ||
syntax CoqBinders ::= List{CoqBinder, ""} [klabel(CoqBinders)] | ||
|
||
syntax CoqArg ::= CoqArg CoqArg | ||
| "(" CoqIdent ":=" CoqTerm ")" | ||
> CoqTerm | ||
syntax CoqTerms ::= List{CoqTerm, ""} [klabel(CoqTerms)] | ||
|
||
syntax CoqFixBody ::= CoqIdent CoqBinders ":=" CoqTerm | ||
| CoqIdent CoqBinders ":" CoqTerm ":=" CoqTerm | ||
syntax CoqFixBodyList ::= List{CoqFixBody, "with"} | ||
syntax CoqFixBodies ::= CoqFixBody | ||
| CoqFixBody CoqFixBodyList "for" CoqIdent | ||
|
||
syntax CoqCofixBody ::= CoqIdent CoqBinders ":=" CoqTerm | ||
syntax CoqCofixBodyList ::= List{CoqCofixBody, "with"} | ||
syntax CoqCofixBodies ::= CoqCofixBody | ||
| CoqCofixBody CoqCofixBodyList "for" CoqIdent | ||
|
||
syntax CoqMatchItem ::= CoqTerm | ||
syntax CoqMatchItems ::= List{CoqMatchItem, ","} [klabel(CoqMatchItems)] | ||
|
||
syntax CoqEquation ::= CoqMultPattern "=>" CoqTerm | ||
syntax CoqEquations ::= List{CoqEquation, "|"} [klabel(CoqEquations)] | ||
|
||
syntax CoqPattern ::= CoqQualID CoqPattern | ||
| "@" CoqQualID CoqPattern | ||
// | CoqPattern CoqPattern | ||
| CoqPattern "as" CoqIdent | ||
| CoqPattern "%" CoqIdent | ||
| CoqQualID | ||
| Underscore | ||
| Int | ||
|
||
syntax CoqMultPattern ::= List{CoqPattern, ","} [klabel(CoqMultPattern)] | ||
syntax CoqPatterns ::= NeList{CoqPattern, ""} [klabel(CoqPatterns)] | ||
|
||
// Vernacular | ||
syntax CoqSentence ::= CoqDefinition | ||
| CoqInductive | ||
// | CoqCoInductive | ||
syntax CoqSentences ::= List{CoqSentence, ""} [klabel(CoqSentences), format(%1%n%2 %3)] | ||
syntax CoqDefinition ::= "Definition" CoqIdent ":=" CoqTerm "hasType" CoqTerm "." | ||
| "Definition" CoqIdent CoqBinders ":" CoqTerm ":=" CoqTerm "hasType" CoqTerm "." | ||
|
||
syntax CoqInductive ::= "Inductive" CoqIndBody "." | ||
syntax CoqIndBody ::= CoqIdent CoqBinders ":" CoqTerm ":=" CoqIndCases | ||
syntax CoqIndCase ::= CoqIdent CoqBinders ":" CoqTerm | ||
syntax CoqIndCases ::= List{CoqIndCase, "|"} [klabel(CoqIndCases)] | ||
|
||
``` | ||
|
||
```k | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to keep these commented lines?