Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
sarah.grebing
ProofScriptParser
Commits
5d754ed2
Commit
5d754ed2
authored
Apr 30, 2017
by
Sarah Grebing
Browse files
variable assignment
parent
c2c8707a
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/edu/kit/formatl/proofscriptparser/TransformAst.java
View file @
5d754ed2
...
...
@@ -4,10 +4,14 @@ import edu.kit.formal.proofscriptparser.ScriptLanguageParser;
import
edu.kit.formal.proofscriptparser.ScriptLanguageVisitor
;
import
edu.kit.formatl.proofscriptparser.ast.*
;
import
org.antlr.v4.runtime.ParserRuleContext
;
import
org.antlr.v4.runtime.tree.*
;
import
sun.net.idn.Punycode
;
import
org.antlr.v4.runtime.tree.ErrorNode
;
import
org.antlr.v4.runtime.tree.ParseTree
;
import
org.antlr.v4.runtime.tree.RuleNode
;
import
org.antlr.v4.runtime.tree.TerminalNode
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author Alexander Weigl
...
...
@@ -39,8 +43,20 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
return
signature
;
}
private
Type
findType
(
String
n
)
{
for
(
Type
t
:
Type
.
values
())
{
if
(
t
.
symbol
().
equals
(
n
))
return
t
;
}
throw
new
IllegalStateException
(
"Type "
+
n
+
" not defined"
);
}
//TODO check
@Override
public
Object
visitVarDecl
(
ScriptLanguageParser
.
VarDeclContext
ctx
)
{
throw
new
IllegalStateException
(
"not implemented"
);
VariableDeclaration
varDecl
=
new
VariableDeclaration
();
varDecl
.
setIdentifier
(
new
Variable
(
ctx
.
name
));
varDecl
.
setType
(
findType
(
ctx
.
type
.
getText
()));
return
varDecl
;
}
@Override
public
Statements
visitStmtList
(
ScriptLanguageParser
.
StmtListContext
ctx
)
{
...
...
src/main/java/edu/kit/formatl/proofscriptparser/Visitor.java
View file @
5d754ed2
...
...
@@ -44,4 +44,6 @@ public interface Visitor<T> {
T
visit
(
Parameters
parameters
);
T
visit
(
UnaryExpression
unaryExpression
);
T
visit
(
VariableDeclaration
variableDeclaration
);
}
src/main/java/edu/kit/formatl/proofscriptparser/ast/Type.java
0 → 100644
View file @
5d754ed2
package
edu.kit.formatl.proofscriptparser.ast
;
/**
* Created by sarah on 4/30/17.
*/
public
enum
Type
{
INT
(
"int"
),
BOOL
(
"bool"
);
private
final
String
symbol
;
Type
(
String
symbol
)
{
this
.
symbol
=
symbol
;
}
public
String
symbol
()
{
return
symbol
;
}
}
src/main/java/edu/kit/formatl/proofscriptparser/ast/VariableDeclaration.java
0 → 100644
View file @
5d754ed2
package
edu.kit.formatl.proofscriptparser.ast
;
import
edu.kit.formal.proofscriptparser.ScriptLanguageParser
;
import
edu.kit.formatl.proofscriptparser.Visitor
;
/**
* Created by sarah on 4/30/17.
*/
public
class
VariableDeclaration
extends
ASTNode
<
ScriptLanguageParser
.
VarDeclContext
>
{
private
Variable
identifier
;
private
Type
type
;
public
VariableDeclaration
setType
(
Type
type
){
this
.
type
=
type
;
return
this
;
}
public
VariableDeclaration
setIdentifier
(
Variable
id
){
this
.
identifier
=
id
;
return
this
;
}
@Override
public
<
T
>
T
accept
(
Visitor
<
T
>
visitor
)
{
return
visitor
.
visit
(
this
);
}
@Override
public
ASTNode
<
ScriptLanguageParser
.
VarDeclContext
>
clone
()
{
return
null
;
}
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment