Skip to content
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

Use KeYParser.g4 for parsing proof scripts #3021

Open
wants to merge 30 commits into
base: main
Choose a base branch
from

Conversation

wadoon
Copy link
Member

@wadoon wadoon commented Feb 5, 2023

This PR removes the hand-written parser for proof scripts and uses a few rules in KeYParser.g4 instead.

Since the start of proof scripts, the KeYParser has changed and became an ANTLR4 grammar. This allows us to easily write a grammar for our proof scripts. (Or just copy the few rules from Sarah and mine proof script parser). This eliminates the handwritten proof script parser with the following benefits:

  1. Proof Scripts are a first-class citizen in KeY files. You do not need to put your proof script into a string literal:

    \proofscript {
        andLeft;
        andRight;  
        rule a ==> b;
    }
    

    Please note an ambiguity in the grammar: rule b ==> c could either be interpreted as a command with one or two arguments:

    1. a semi-sequent b ==> and a term c, or
    2. a sequent b ==> c.
    3. or a term b and a semi-sequent ==> c.

    Use quotes or better backticks to clarify these situations.

    Also, avoid using hyphens in identifiers. The grammar should follow the KeY grammar as best as possible. Backwards-compatiblity is tried to preserve.

  2. Earlier and better syntax errors. (during reading the KeY file)

  3. Better positioning information, as these are tucked to gather on the ParseContexts.

  4. Proper data structure: no triple of strings is pushed through KeY.

  5. You do not need to put your arguments in quotes. Literals, terms and sequents are parsed.

Tried to achieve backward-compatibility. If the proof script is given as a string, the parsing is delayed until the execution. The same is valid for arguments.

Note there is a difference between f(x) and "f(x)". The first one is parsed directly as a term and can only passed to term or string arguments. The second one is parsed as a string. By meta-information on commands, the string is lazily converted to a term if necessary.

The term f(x) might be parsed early with the input file, but the expression is evaluated (translated from parse tree to Term) on command-execution time, hence, the use of goal-local variables should be possible.

Additions to Proof Scripts

The interface of commands and the syntax received an extension to support commands like AllCommand in a uniform way. AllCommand (onAll hide \f(x)`) executes the sub-command specified by the arguments on all goals. In SaG scripts we used foreach { ... }` to achieve this behavior.

The extension adapts the command syntax to take a list of sub-commands in curly brackets.

proofScriptCommand: 
    name  args  (  '{'   <sub-command>  '}' ';'? | ';' )
    ; 

The new syntax for onAll is also onAll { hide \f(x)`; }. Commands receive the code block using the key #blockinside the map as a parse tree, that can be sent back to theScriptEngineusing#execute(state, statements)`. The new syntax allows to build new commands like

  • try {<sub>} -- executes <sub> ignoring errors
  • repeat { <sub> } -- executes <sub> as long as there are changes on the sequent.
  • matching <term> { <sub> } -- execute on all goals where <term> is prescense.

wadoon added 16 commits January 28, 2022 13:42
* master: (69 commits)
  [floats] optimising float termination rules
  [floats] reconducting a proof
  Move functionality for relevant Java files from NodeInfo to new class ProofJavaSourceCollection
  fix error in logging formatting strings
  fix the collection of JUnit tests on jenkins
  [floats] missing rules for double assignments
  [floats] re-implementing a Z3FP solver.
  also show message of the chained cause of the exception in IssueDialog
  [floats] added missing unary minus
  repairing cast to integer in JML translation.
  [floats] repairing float-cast rules
  [floats] repairing cast to float
  [floats] nasty method call missing
  [floats] introducing overloaded operator handler
  [floats] missing functions in LDT lookup
  Set the interactive flag for builtin rule applications coming from BuiltInRuleMenuItem correctly
  allowing [] after parameter names in JML model methods
  Fix potential stack overflow in ExplorationStepsList
  allow arrays and general types in JML. (KeYProject#1681)
  fixes KeYProject#1682
  ...
* master: (37 commits)
  missing NPE check in MasterHandlerTest
  Fix KeYProject#1696 (wrong hash for heapAtPre)
  a two-state method needs the invariant also at pre-state (try to fix KeYProject#1689)
  Fix KeYProject#1690
  Fix failing test case
  Fixed rule "wellFormedStoreObjectEQ"
  [floats] repairing JML interpretation of equality on floats and doubles.
  add comment to find AutoSuite
  fix NPE
  remove test filter
  fix, swap argument in assertEquals
  only recoder uses junit4
  translate the remaining Junit4 parts
  fix merge issues
  hopefully fixing gradle test filters
  new category "owntest" for tests with an own gradle task
  falsely marked as test
  migrate TestTacletEquality
  fix gradle settings, remove autosuite
  try to fix RAP
  ...

# Conflicts:
#	key/key.core/src/test/java/de/uka/ilkd/key/macros/scripts/TestProofScriptCommand.java
#	key/key.core/src/test/java/de/uka/ilkd/key/macros/scripts/meta/ValueInjectorTest.java
#	key/key.core/src/test/java/de/uka/ilkd/key/proof/proverules/ProveRulesTest.java
#	key/key.core/src/test/java/de/uka/ilkd/key/proof/runallproofs/performance/DataRecordingTestFile.java
* origin/master: (166 commits)
  Use generic method correctly
  avoid creating proof obligations in ProofManagementDialog It is unnecessary to create proof obligations in most cases there and creating some proof obligations changes state shared with a large part of KeY (see KeYProject#1715).
  use base directory for InfFlow tests
  partly revert 0eca94d to restore tests in automaticInfFlow.txt
  adding proofs for SMT lemmas.
  JavaDoc for changed methods + Doubles for timeout
  jdiv and jmod support in SMT translation via definitions.
  Checkstyle/SonarQube
  Avoid reopening popup menu when selection button is pressed
  Bug fixes from the IdentityHashMap case study
  Solve missing plugin in shadowJar by adding `mergeServiceFiles()`
  SonarQube
  Checkstyle
  mark JSpinner backgrounds correctly when an error occurs
  Deactivate SMT button when no proof is loaded
  Check formatting  with Spotless
  Add JavaDoc
  Modify problems using solver sockets
  Minor changes
  checkstyle
  ...
* master: (30 commits)
  Spotless: Don't join manually split lines
  Fixed two more files with broken comments (KeYProject#1710)
  manual formatting corrections (not for recoder, tests, and resources)
  applied spotless rules to .key files
  applied spotless rules to Java sources
  define KeY code style, remove options not supported by Eclipse formatter, enable spotless toggles, removed license header from spotless configuration, removed indentation config for .key files (did not really work)
  Fix Jenkins master script after !559
  Temporarily disable reloading sort.proof.gz because of KeYProject#1720
  ChoiceExpr: En-/Disabling taclets/goal templates using boolean expression
  Split `testRunAllProofs` into two tasks
  Fast fix: Do not run pipeline defined by the Jenkinsfile on "Master" worker
  Focus first cell in the taclet instantiation dialog on open
  Close more dialogs on escape press and code deduplication
  Allow ApplyTacletDialog to be closed by pressing Escape
  Fix getMainWindow infinite recursion
  Fix Exception when parsing "<unknown>" URL on Windows
  Disable exploration tree updates when disabled
  Remove space from taclet proof save file name
  Allows to have an expression on the lhs in a set statement. Hence,
  further logging commands fixed
  ...

# Conflicts:
#	key/key.core/src/main/java/de/uka/ilkd/key/api/ScriptApi.java
#	key/key.core/src/main/java/de/uka/ilkd/key/control/KeYEnvironment.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/AllCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/AssertCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/AssumeCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/AutoCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/AxiomCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/CutCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/EngineState.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/HideCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/InstantiateCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/JavascriptCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/LetCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/MacroCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/NoArgumentCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/ProofScriptCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/ProofScriptEngine.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/RewriteCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/RuleCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/SMTCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/SaveInstCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/SaveNewNameCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/SchemaVarCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/SelectCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/SetEchoCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/TryCloseCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/UnhideCommand.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/meta/Converter.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/meta/NoSpecifiedConverterException.java
#	key/key.core/src/main/java/de/uka/ilkd/key/macros/scripts/meta/ValueInjector.java
#	key/key.core/src/main/java/de/uka/ilkd/key/nparser/KeyAst.java
#	key/key.core/src/main/java/de/uka/ilkd/key/proof/io/AbstractProblemLoader.java
#	key/key.core/src/main/java/de/uka/ilkd/key/speclang/njml/JmlFacade.java
#	key/key.core/src/test/java/de/uka/ilkd/key/logic/TestLocalSymbols.java
#	key/key.core/src/test/java/de/uka/ilkd/key/macros/scripts/TestProofScriptCommand.java
#	key/key.core/src/test/java/de/uka/ilkd/key/proof/proverules/ProveRulesTest.java
#	key/key.core/src/test/java/de/uka/ilkd/key/proof/runallproofs/ProveTest.java
#	key/key.core/src/test/java/de/uka/ilkd/key/proof/runallproofs/performance/DataRecordingTestFile.java
#	key/key.core/src/test/java/de/uka/ilkd/key/proof/runallproofs/proofcollection/TestFile.java
#	key/key.ui/src/main/java/de/uka/ilkd/key/gui/ProofScriptWorker.java
#	key/key.ui/src/main/java/de/uka/ilkd/key/gui/WindowUserInterfaceControl.java
#	key/key.ui/src/main/java/de/uka/ilkd/key/gui/actions/ProofScriptInputAction.java
#	key/key.ui/src/main/java/de/uka/ilkd/key/ui/ConsoleUserInterfaceControl.java
* master: (160 commits)
  .git-blame-ignore-revs: ignore formatting commits
  Update checkstyle configuration to 10.6.0
  Move subprojects to top level
  Keep PositionInfo in ForToWhileTransformation
  log instead of disabling EditMostRecentFileAction on error
  Remove KeYDesktop interface, use java.awt.Desktop directly
  Logview open log file fallback: Browse dir
  Fixing a few typos in example files
  reducing the binary filesize by only including the necessary example files
  Fix typo in comment
  Checkstyle
  Immediately resize proof tree font
  Fix Z3 counterexample generation
  Recalculate all unique names on every change since the algorithm is incremental and does not change old names.
  SonarCube
  Add comments and move main method to tests
  Improve naming of recent files
  Keep entry class private, it's not used outside the class
  corrected the formatting
  Test for polarity check during replay
  ...
@mattulbrich
Copy link
Member

I agree that the current parser is more a proof-of-concept solution than future-proof.

However: With many ideas around proof scripts, which should possibly discuss how this should go now: The script debugger has its ways of communicating to the server, scripts can be in .key files, they were at a point interactively editable, and the plan is to have them in JML code. Do they all go to the same background linear script language or is the base language itself more than a sequence of commands?

@WolframPfeifer @jwiesler

@wadoon wadoon self-assigned this Feb 6, 2023
@wadoon wadoon closed this Oct 13, 2023
* refs/remotes/origin/main: (1809 commits)
  Bump the gradle-deps group across 1 directory with 5 updates
  Also depend on `checker-qual` artifact
  Bump the github-actions-deps group with 5 updates
  Minor refactoring to remove duplicate code
  fixing the broken automode
  resolve reviewer requests
  applied formatting style
  disable automatic formatting of Java code blocks in comments/JavaDoc
  removed formatter version lock and added new keys (via new styleMerge tool)
  added small utility to merge xml formatter style files
  add javadoc
  add javadoc
  reformat fix finalize() deprecation
  fix error in expecting proof script if there is none
  fix compile errors due to merging
  forgot ProofScriptEntry
  fix compile errors
  Removal of the Triple class
  Removal of Quadruple.java
  fix auto merger in github workflow
  ...

# Conflicts:
#	key.core/src/main/java/de/uka/ilkd/key/control/KeYEnvironment.java
#	key.core/src/main/java/de/uka/ilkd/key/macros/scripts/AllCommand.java
#	key.core/src/main/java/de/uka/ilkd/key/macros/scripts/AutoCommand.java
#	key.core/src/main/java/de/uka/ilkd/key/macros/scripts/EngineState.java
#	key.core/src/main/java/de/uka/ilkd/key/macros/scripts/HideCommand.java
#	key.core/src/main/java/de/uka/ilkd/key/macros/scripts/ProofScriptEngine.java
#	key.core/src/main/java/de/uka/ilkd/key/macros/scripts/SaveInstCommand.java
#	key.core/src/main/java/de/uka/ilkd/key/macros/scripts/UnhideCommand.java
#	key.core/src/main/java/de/uka/ilkd/key/macros/scripts/meta/ValueInjector.java
#	key.core/src/main/java/de/uka/ilkd/key/nparser/KeyAst.java
#	key.core/src/main/java/de/uka/ilkd/key/nparser/ParsingFacade.java
#	key.core/src/main/java/de/uka/ilkd/key/proof/init/KeYUserProblemFile.java
#	key.core/src/main/java/de/uka/ilkd/key/proof/io/AbstractProblemLoader.java
#	key.core/src/main/java/de/uka/ilkd/key/speclang/PositionedString.java
#	key.core/src/main/java/de/uka/ilkd/key/speclang/njml/JmlFacade.java
#	key.core/src/test/java/de/uka/ilkd/key/logic/TestLocalSymbols.java
#	key.core/src/test/java/de/uka/ilkd/key/macros/scripts/TestProofScriptCommand.java
#	key.core/src/test/java/de/uka/ilkd/key/proof/proverules/ProveRulesTest.java
#	key.core/src/test/java/de/uka/ilkd/key/proof/runallproofs/ProveTest.java
#	key.core/src/test/java/de/uka/ilkd/key/proof/runallproofs/performance/DataRecordingTestFile.java
#	key.core/src/test/java/de/uka/ilkd/key/proof/runallproofs/proofcollection/TestFile.java
#	key.core/tacletProofs/seqPerm2/Taclet_schiffl_lemma_2.proof
#	key.ui/src/main/java/de/uka/ilkd/key/gui/ProofScriptWorker.java
#	key.ui/src/main/java/de/uka/ilkd/key/gui/WindowUserInterfaceControl.java
#	key.ui/src/main/java/de/uka/ilkd/key/gui/actions/ProofScriptInputAction.java
#	key.ui/src/main/java/de/uka/ilkd/key/ui/ConsoleUserInterfaceControl.java
* adds script block commands arguments
Copy link
Member

@mattulbrich mattulbrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round of review. Some feedback. Could not review the whole thing.

| string_literal
| BACKTICK (term | seq) BACKTICK
| term
| seq;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really do not like the ambiguity.
Can we make this IDENTIFIER without ticks and any composed term/seq in ticks?
I would prefer single ticks compared to back ticks. I do not think we need single-character parameters (and if: Use strings ...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really do not like the ambiguity.

Not my language.

Can we make this IDENTIFIER without ticks and any composed term/seq in ticks?

What do you mean by this IDENTIFIER?

In macro tryclose, the tryclose is still evaluated as a string and not sent to the expression evaluation. This adds unnecessary complexity.

I would prefer single ticks compared to back ticks

  • single quotes ' are often used currently as string quotes in proof scripts
  • backticks are only necessary to avoid ambiguous situations: command p=2 could be a formula or the parameter p to be 2.

(and if: Use strings ...)

No. The advantage of separation is that the parser is eager to give feedback on syntactical correctness. Otherwise, these errors appears only on evaluation of commands.

@mattulbrich
Copy link
Member

mattulbrich commented Jan 20, 2025

Reply to me-from-the-past:

However: With many ideas around proof scripts, which should possibly discuss how this should go now: The script debugger has its ways of communicating to the server, scripts can be in .key files, they were at a point interactively editable, and the plan is to have them in JML code. Do they all go to the same background linear script language or is the base language itself more than a sequence of commands?

After implementing a/the script language for JML: This was compiled down to a linear script. So it seems that a list of individual proof commands looks like the right level of abstraction.

@wadoon wadoon marked this pull request as ready for review January 20, 2025 21:24
@wadoon wadoon added this to the v2.12.4 milestone Jan 25, 2025
@KeYProject KeYProject deleted a comment from codecov bot Jan 29, 2025
@wadoon
Copy link
Member Author

wadoon commented Jan 29, 2025

After implementing a/the script language for JML: This was compiled down to a linear script. So it seems that a list of individual proof commands looks like the right level of abstraction.

This PR gives the current state a proper syntax in alignment with the KeY grammar. So the list of proof commands are still preserved. Giving the commands the possibility to receive a block of sub-commands arises from your AllCommand and allows future extensions w/o needing syntax changes.

We need a quoting symbol for terms for the ambiguities, " is used for string values, and ' is also occupied (do we use it for char literals?). So backticks \`` are a possible option, but we can also go for parentheses, e.g., let @A=(f(x))` etc. I do not care.

@wadoon wadoon requested a review from mattulbrich January 30, 2025 01:50
@KeYProject KeYProject deleted a comment from codecov bot Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants