Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Proof Assistant with Solver
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zhang, Jenny
Proof Assistant with Solver
Commits
4ea66a3f
Commit
4ea66a3f
authored
9 months ago
by
Jenny Zhang
Browse files
Options
Downloads
Patches
Plain Diff
redefined Node by constructor function
parent
f8506705
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/utils/ast.js
+64
-53
64 additions, 53 deletions
src/utils/ast.js
with
64 additions
and
53 deletions
src/utils/ast.js
+
64
−
53
View file @
4ea66a3f
...
@@ -2,14 +2,13 @@
...
@@ -2,14 +2,13 @@
// Function to create a new AST node
// Function to create a new AST node
function
Node
(
type
,
value
,
left
,
right
)
{
function
Node
(
type
,
value
,
left
,
right
)
{
return
{
this
.
type
=
type
;
type
:
type
,
this
.
value
=
value
;
value
:
value
,
this
.
left
=
left
;
left
:
left
,
this
.
right
=
right
;
right
:
right
};
}
}
const
precedence
=
{
const
precedence
=
{
'
imply
'
:
1
,
'
imply
'
:
1
,
'
or
'
:
2
,
'
or
'
:
2
,
...
@@ -20,7 +19,12 @@ const precedence = {
...
@@ -20,7 +19,12 @@ const precedence = {
'
false
'
:
5
'
false
'
:
5
};
};
function
astsToString
(
nodes
){
function
astsToString
(
nodes
)
{
if
(
console
.
log
(
typeof
nodes
)
instanceof
Node
)
{
throw
new
Error
(
"
Invalid input. Only sequent is accepted, not expression.
"
);
}
const
leftList
=
nodes
[
0
];
const
leftList
=
nodes
[
0
];
const
rightList
=
nodes
[
1
];
const
rightList
=
nodes
[
1
];
...
@@ -36,49 +40,56 @@ function astsToString(nodes){
...
@@ -36,49 +40,56 @@ function astsToString(nodes){
}
}
function
astToString
(
node
,
parentPrecedence
=
0
)
{
function
astToString
(
node
,
parentPrecedence
=
0
)
{
if
(
!
node
)
return
""
;
if
(
!
(
console
.
log
(
typeof
nodes
)
instanceof
Node
))
{
let
currentPrecedence
=
precedence
[
node
.
type
];
throw
new
Error
(
"
Invalid input. Only expression is accepted.
"
);
}
let
left
=
astToString
(
node
.
left
,
currentPrecedence
);
let
right
=
astToString
(
node
.
right
,
currentPrecedence
);
if
(
!
node
)
return
""
;
let
result
;
let
currentPrecedence
=
precedence
[
node
.
type
];
switch
(
node
.
type
)
{
case
'
not
'
:
let
left
=
astToString
(
node
.
left
,
currentPrecedence
);
result
=
`!
${
left
}
`
;
let
right
=
astToString
(
node
.
right
,
currentPrecedence
);
break
;
case
'
and
'
:
let
result
;
result
=
`
${
left
}
&
${
right
}
`
;
switch
(
node
.
type
)
{
break
;
case
'
not
'
:
case
'
or
'
:
result
=
`!
${
left
}
`
;
result
=
`
${
left
}
||
${
right
}
`
;
break
;
break
;
case
'
and
'
:
case
'
imply
'
:
result
=
`
${
left
}
&
${
right
}
`
;
result
=
`
${
left
}
->
${
right
}
`
;
break
;
break
;
case
'
or
'
:
case
'
symbol
'
:
result
=
`
${
left
}
||
${
right
}
`
;
result
=
node
.
value
;
break
;
break
;
case
'
imply
'
:
case
'
true
'
:
result
=
`
${
left
}
->
${
right
}
`
;
result
=
'
true
'
;
break
;
break
;
case
'
symbol
'
:
case
'
false
'
:
result
=
node
.
value
;
result
=
'
false
'
;
break
;
break
;
case
'
true
'
:
default
:
result
=
'
true
'
;
throw
new
Error
(
`Unknown node type:
${
node
.
type
}
`
);
break
;
}
case
'
false
'
:
result
=
'
false
'
;
if
(
currentPrecedence
<
parentPrecedence
)
{
break
;
result
=
`(
${
result
}
)`
;
default
:
}
throw
new
Error
(
`Unknown node type:
${
node
.
type
}
`
);
}
return
result
;
if
(
currentPrecedence
<
parentPrecedence
)
{
result
=
`(
${
result
}
)`
;
}
return
result
;
}
}
// nodes are [[ast],[ast]]
// nodes are [[ast],[ast]]
function
astsToLateX
(
nodes
)
{
function
astsToLateX
(
nodes
)
{
const
leftList
=
nodes
[
0
];
const
leftList
=
nodes
[
0
];
const
rightList
=
nodes
[
1
];
const
rightList
=
nodes
[
1
];
...
@@ -139,13 +150,13 @@ function astToLaTeX(node, parentPrecedence = 0) {
...
@@ -139,13 +150,13 @@ function astToLaTeX(node, parentPrecedence = 0) {
var
ast
=
{};
var
ast
=
{};
ast
.
Not
=
Node
.
bind
(
null
,
'
not
'
)
;
ast
.
Not
=
function
(
value
,
left
,
right
)
{
return
new
Node
(
'
not
'
,
value
,
left
,
right
);
}
;
ast
.
And
=
Node
.
bind
(
null
,
'
and
'
)
;
ast
.
And
=
function
(
value
,
left
,
right
)
{
return
new
Node
(
'
and
'
,
value
,
left
,
right
);
}
;
ast
.
Or
=
Node
.
bind
(
null
,
'
or
'
)
;
ast
.
Or
=
function
(
value
,
left
,
right
)
{
return
new
Node
(
'
or
'
,
value
,
left
,
right
);
}
;
ast
.
Imply
=
Node
.
bind
(
null
,
'
imply
'
)
;
ast
.
Imply
=
function
(
value
,
left
,
right
)
{
return
new
Node
(
'
imply
'
,
value
,
left
,
right
);
}
;
ast
.
Symbol
=
Node
.
bind
(
null
,
'
symbol
'
)
;
ast
.
Symbol
=
function
(
value
,
left
,
right
)
{
return
new
Node
(
'
symbol
'
,
value
,
left
,
right
);
}
;
ast
.
True
=
Node
.
bind
(
null
,
'
true
'
);
ast
.
True
=
function
()
{
return
new
Node
(
'
true
'
);
};
ast
.
False
=
Node
.
bind
(
null
,
'
false
'
);
ast
.
False
=
function
()
{
return
new
Node
(
'
false
'
);
}
ast
.
astToString
=
astToString
;
ast
.
astToString
=
astToString
;
ast
.
astToLaTeX
=
astToLaTeX
;
ast
.
astToLaTeX
=
astToLaTeX
;
ast
.
astsToLateX
=
astsToLateX
;
ast
.
astsToLateX
=
astsToLateX
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment