Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SableCC STUPS
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
SableCC STUPS
Commits
25dc7c45
Commit
25dc7c45
authored
1 year ago
by
dgelessus
Browse files
Options
Downloads
Patches
Plain Diff
Continue refactoring type handling in alternative code generation
parent
97a6e956
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/sablecc/sablecc/GenerateAlternativeCodeForParser.java
+13
-12
13 additions, 12 deletions
...org/sablecc/sablecc/GenerateAlternativeCodeForParser.java
src/main/resources/org/sablecc/sablecc/parser.txt
+12
-16
12 additions, 16 deletions
src/main/resources/org/sablecc/sablecc/parser.txt
with
25 additions
and
28 deletions
src/main/java/org/sablecc/sablecc/GenerateAlternativeCodeForParser.java
+
13
−
12
View file @
25dc7c45
...
...
@@ -76,7 +76,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
}
}
private
static
String
v
ariable
PrefixFromInternalTyp
e
(
String
typeName
)
private
static
String
getV
ariable
Nam
e
(
String
typeName
,
int
position
)
{
if
(
"null"
.
equals
(
typeName
))
{
...
...
@@ -84,11 +84,11 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
}
else
if
(
typeName
.
startsWith
(
"L"
))
{
return
"list
"
;
return
"list
Node"
+
position
;
}
else
{
return
typeName
.
toLowerCase
();
return
typeName
.
toLowerCase
()
+
"Node"
+
position
;
}
}
...
...
@@ -114,7 +114,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
if
(
typeName
.
startsWith
(
"L"
))
{
macros
.
apply
(
file
,
"ParserListVariableDeclaration"
,
new
String
[]
{
""
+
position
});
macros
.
apply
(
file
,
"ParserListVariableDeclaration"
,
new
String
[]
{
getVariableName
(
typeName
,
position
)
});
}
else
if
(
typeName
.
equals
(
"null"
))
{
...
...
@@ -122,7 +122,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
}
else
{
macros
.
apply
(
file
,
"ParserSimpleVariableDeclaration"
,
new
String
[]
{
typeName
,
v
ariable
PrefixFromInternalTyp
e
(
typeName
)
,
""
+
position
});
macros
.
apply
(
file
,
"ParserSimpleVariableDeclaration"
,
new
String
[]
{
typeName
,
getV
ariable
Nam
e
(
typeName
,
position
)
});
}
}
...
...
@@ -162,7 +162,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
}
else
{
macros
.
apply
(
file
,
"ParserNewBodyListAdd"
,
new
String
[]
{
v
ariable
PrefixFromInternalTyp
e
(
type_name
)
,
""
+
position
});
macros
.
apply
(
file
,
"ParserNewBodyListAdd"
,
new
String
[]
{
getV
ariable
Nam
e
(
type_name
,
position
)
});
}
}
...
...
@@ -237,7 +237,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
macros
.
apply
(
file
,
"ParserSimpleTerm"
,
new
String
[]
{
v
ariable
PrefixFromInternalTyp
e
(
type_name
)
,
""
+
position
,
getV
ariable
Nam
e
(
type_name
,
position
)
,
variableTypeFromInternalType
(
type_name
),
""
+
elemPosition
,
""
+
positionMap
}
);
...
...
@@ -296,6 +296,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
{
try
{
String
listTypeName
=
lookupInternalTypeName
(
node
);
int
listPosition
=
CG
.
getTermNumbers
().
get
(
node
);
for
(
PListTerm
listTerm
:
node
.
getListTerms
())
...
...
@@ -307,11 +308,11 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
{
if
(
type_name
.
startsWith
(
"L"
))
{
macros
.
apply
(
file
,
"ParserTypedLinkedListAddAll"
,
new
String
[]
{
"list"
,
""
+
listPosition
,
"list"
,
""
+
position
});
macros
.
apply
(
file
,
"ParserTypedLinkedListAddAll"
,
new
String
[]
{
getVariableName
(
listTypeName
,
listPosition
)
,
getVariableName
(
type_name
,
position
)
});
}
else
{
macros
.
apply
(
file
,
"ParserTypedLinkedListAdd"
,
new
String
[]
{
"list"
,
""
+
listPosition
,
v
ariable
PrefixFromInternalTyp
e
(
type_name
)
,
""
+
position
});
macros
.
apply
(
file
,
"ParserTypedLinkedListAdd"
,
new
String
[]
{
getVariableName
(
listTypeName
,
listPosition
)
,
getV
ariable
Nam
e
(
type_name
,
position
)
});
}
}
}
...
...
@@ -332,7 +333,7 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
try
{
macros
.
apply
(
file
,
"ParserNewBodyNew"
,
new
String
[]
{
v
ariable
PrefixFromInternalTyp
e
(
type_name
)
,
""
+
position
,
newAltName
});
macros
.
apply
(
file
,
"ParserNewBodyNew"
,
new
String
[]
{
getV
ariable
Nam
e
(
type_name
,
position
)
,
newAltName
});
if
(!
params
.
isEmpty
())
{
...
...
@@ -345,11 +346,11 @@ public class GenerateAlternativeCodeForParser extends DepthFirstAdapter
if
(
type_name
.
equals
(
"null"
))
{
macros
.
apply
(
file
,
"ParserNew
&List
BodyParam
sNull
"
,
new
String
[]
{
isNotTheFirstParam
+
"null"
});
macros
.
apply
(
file
,
"ParserNewBodyParam"
,
new
String
[]
{
isNotTheFirstParam
+
"null"
});
}
else
{
macros
.
apply
(
file
,
"ParserNew
&List
BodyParam
s
"
,
new
String
[]
{
isNotTheFirstParam
+
v
ariable
PrefixFromInternalTyp
e
(
type_name
)
,
""
+
position
});
macros
.
apply
(
file
,
"ParserNewBodyParam"
,
new
String
[]
{
isNotTheFirstParam
+
getV
ariable
Nam
e
(
type_name
,
position
)
});
}
isNotTheFirstParam
=
", "
;
...
...
This diff is collapsed.
Click to expand it.
src/main/resources/org/sablecc/sablecc/parser.txt
+
12
−
16
View file @
25dc7c45
...
...
@@ -333,30 +333,26 @@ Macro:ParserBraceClosing
$
Macro:ParserSimpleVariableDeclaration
$0$ $1$
Node$2$
;
$0$ $1$;
$
Macro:ParserListVariableDeclaration
LinkedList
listNode
$0$ = new LinkedList();
LinkedList $0$ = new LinkedList();
$
Macro:ParserSimpleTerm
$0$
Node$1$
= ($
2
$)nodeArrayList$
3
$.get($
4
$);
$0$ = ($
1
$)nodeArrayList$
2
$.get($
3
$);
$
Macro:ParserNewBodyNew
$0$
Node$1$
= new $
2
$(
$0$ = new $
1
$(
$
Macro:ParserNew&ListBodyParams
$0$Node$1$
$
Macro:ParserNew&ListBodyParamsNull
Macro:ParserNewBodyParam
$0$
$
...
...
@@ -366,27 +362,27 @@ Macro:ParserNewBodyNewTail
$
Macro:ParserTypedLinkedListAdd
if($
2$Node$3
$ != null)
if($
1
$ != null)
{
$0$
Node$1$.add($2$Node$3
$);
$0$
.add($1
$);
}
$
Macro:ParserTypedLinkedListAddAll
if($
2$Node$3
$ != null)
if($
1
$ != null)
{
if(!$0$
Node$1$
.isEmpty()){
$0$
Node$1$
.addAll($
2$Node$3
$);
if(!$0$.isEmpty()){
$0$.addAll($
1
$);
}else{
$0$
Node$1$ = $2$Node$3
$;
$0$
= $1
$;
}
}
$
Macro:ParserNewBodyListAdd
nodeList.add($0$
Node$1$
);
nodeList.add($0$);
$
...
...
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