Skip to content

Commit

Permalink
#5 への対応(仮)&演算子の優先順位修正、配列の添え字チェックの実装
Browse files Browse the repository at this point in the history
  • Loading branch information
r-koubou committed Mar 27, 2018
1 parent 91a85c1 commit 5759005
Show file tree
Hide file tree
Showing 12 changed files with 774 additions and 681 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"./classes/"
],
"mainClass": "net.rkoubou.kspparser.KSPSyntaxParser",
"args": "--source ./.temp/test.ksp"
"args": "./.temp/test.ksp"
},
{
"type": "java",
Expand All @@ -32,7 +32,7 @@
"./classes/"
],
"mainClass": "net.rkoubou.kspparser.KSPSyntaxParser",
"args": "--source ./.temp/test.ksp --obfuscate"
"args": "./.temp/test.ksp --obfuscate"
},
{
"type": "java",
Expand Down
3 changes: 3 additions & 0 deletions data/lang/message.properties
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ error.semantic.variable.invalid.maxarraysize = ${level} ${line} ${symbolname} :
# Array variable declaration : Invalid array element type
error.semantic.variable.invalid.arrayinitilizer = ${level} ${line} ${symbolname} : Array initializer : element[${ext1}] is not compatible type

# Array variable : Missing array subscript
error.semantic.variable.invalid.arraysubscript = ${level} ${line} ${symbolname} : Missing Subscript

# UI variable declaration : Not compatible type
error.semantic.variable.invalid.uitype = ${level} ${line} ${symbolname} : ${ext2} is required variable type : ${ext1}

Expand Down
3 changes: 3 additions & 0 deletions data/lang/message_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ error.semantic.variable.invalid.maxarraysize = ${level} ${line} ${symbolname} :
# Array variable declaration : Invalid array element type
error.semantic.variable.invalid.arrayinitilizer = ${level} ${line} ${symbolname} : 配列初期化 : 要素[${ext1}] のデータ型が異なっています

# Array variable : Missing array subscript
error.semantic.variable.invalid.arraysubscript = ${level} ${line} ${symbolname} : 添字がありません

# UI variable declaration : Not compatible type
error.semantic.variable.invalid.uitype = ${level} ${line} ${symbolname} : ${ext2} が要求する変数型は ${ext1} です

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import net.rkoubou.kspparser.javacc.generated.ASTStrAdd;
import net.rkoubou.kspparser.javacc.generated.ASTSub;
import net.rkoubou.kspparser.javacc.generated.ASTUserFunctionDeclaration;
import net.rkoubou.kspparser.javacc.generated.Node;
import net.rkoubou.kspparser.javacc.generated.SimpleNode;

/**
* 基本的な四則演算の評価処理を実装したテンプレートクラス
Expand Down Expand Up @@ -197,58 +195,7 @@ public Object visit( ASTSub node, Object data )
@Override
public Object visit( ASTStrAdd node, Object data )
{
// 上位ノードの型評価式用
SimpleNode ret = EvaluationUtility.createEvalNode( node, node.getId() );

//--------------------------------------------------------------------------
// *初期値代入式では使用できない
//--------------------------------------------------------------------------
{
Node p = node.jjtGetParent();
while( p != null )
{
if( p.getId() == JJTVARIABLEINITIALIZER )
{
MessageManager.printlnE( MessageManager.PROPERTY_ERROR_SEMANTIC_VARIABLE_INVALID_INITIALIZER_STRINGADD, node.symbol );
AnalyzeErrorCounter.e();
ret.symbol.type = TYPE_VOID;
ret.symbol.setName( Variable.toKSPTypeCharacter( TYPE_VOID ) );
return ret;
}
p = p.jjtGetParent();
}
}

final SimpleNode exprL = (SimpleNode)node.jjtGetChild( 0 ).jjtAccept( this, data );
final SimpleNode exprR = (SimpleNode)node.jjtGetChild( 1 ).jjtAccept( this, data );
final SymbolDefinition symL = exprL.symbol;
final SymbolDefinition symR = exprR.symbol;

// 左辺、右辺どちらか一方が文字列である必要がある(KONTAKT内で暗黙の型変換が作動する)
if( !symL.isString() && !symR.isString() )
{
MessageManager.printlnE( MessageManager.PROPERTY_ERROR_SEMANTIC_BINOPR_DIFFERENT, node.symbol );
AnalyzeErrorCounter.e();
ret.symbol.type = TYPE_VOID;
ret.symbol.setName( Variable.toKSPTypeCharacter( TYPE_VOID ) );
}
else
{
ret.symbol.setName( Variable.toKSPTypeCharacter( TYPE_STRING ) );
ret.symbol.type = TYPE_STRING;
if( symL.isConstant() && symR.isConstant() )
{
// 定数、リテラル文字列同士の連結:結合
String v = symL.value.toString() + symR.value.toString();
v = v.replaceAll( "\\\"", "" );
v = '"' + v + '"';
ret.symbol.addTypeFlag( TYPE_NONE, ACCESS_ATTR_CONST );
ret.symbol.value = v;
node.symbol.setValue( ret.symbol.value );
SymbolDefinition.setTypeFlag( ret.symbol, node.symbol );
}
}
return ret;
return EvaluationUtility.evalStringAddOperator( node, this, data );
}

/**
Expand Down
Loading

0 comments on commit 5759005

Please sign in to comment.