diff --git a/Languages/Pascal/PascalABCParserNewSaushkin/ABCPascalParserTools.cs b/Languages/Pascal/PascalABCParserNewSaushkin/ABCPascalParserTools.cs index 43f45dded..670f78398 100644 --- a/Languages/Pascal/PascalABCParserNewSaushkin/ABCPascalParserTools.cs +++ b/Languages/Pascal/PascalABCParserNewSaushkin/ABCPascalParserTools.cs @@ -30,36 +30,36 @@ namespace Languages.Pascal.Frontend.Core tokenNum["tkIdentifier"] = StringResources.Get("TKIDENTIFIER"); tokenNum["tkStringLiteral"] = StringResources.Get("TKSTRINGLITERAL"); tokenNum["tkAmpersend"] = "'"; - tokenNum["tkColon"]="':'"; - tokenNum["tkDotDot"]="'..'"; - tokenNum["tkPoint"]="'.'"; - tokenNum["tkRoundOpen"]="'('"; - tokenNum["tkRoundClose"]="')'"; - tokenNum["tkSemiColon"]="';'"; - tokenNum["tkSquareOpen"]="'['"; - tokenNum["tkSquareClose"]="']'"; - tokenNum["tkQuestion"]="'?'"; - - tokenNum["tkComma"]="','"; - tokenNum["tkAssign"]="':='"; - tokenNum["tkPlusEqual"]="'+='"; - tokenNum["tkMinusEqual"]="'-='"; - tokenNum["tkMultEqual"]="'*='"; - tokenNum["tkDivEqual"]="'/='"; - tokenNum["tkMinus"]="'-'"; - tokenNum["tkPlus"]="'+'"; - tokenNum["tkSlash"]="'//'"; - tokenNum["tkStar"]="'*'"; - tokenNum["tkEqual"]="'='"; - tokenNum["tkGreater"]="'>'"; - tokenNum["tkGreaterEqual"]="'>='"; - tokenNum["tkLower"]="'<'"; - tokenNum["tkLowerEqual"]="'<='"; - tokenNum["tkNotEqual"]="'<>'"; - tokenNum["tkArrow"]="'->'"; - tokenNum["tkAddressOf"]="'@'"; - tokenNum["tkDeref"]="'^'"; - tokenNum["tkStarStar"]="'**'"; + tokenNum["tkColon"] = "':'"; + tokenNum["tkDotDot"] = "'..'"; + tokenNum["tkPoint"] = "'.'"; + tokenNum["tkRoundOpen"] = "'('"; + tokenNum["tkRoundClose"] = "')'"; + tokenNum["tkSemiColon"] = "';'"; + tokenNum["tkSquareOpen"] = "'['"; + tokenNum["tkSquareClose"] = "']'"; + tokenNum["tkQuestion"] = "'?'"; + + tokenNum["tkComma"] = "','"; + tokenNum["tkAssign"] = "':='"; + tokenNum["tkPlusEqual"] = "'+='"; + tokenNum["tkMinusEqual"] = "'-='"; + tokenNum["tkMultEqual"] = "'*='"; + tokenNum["tkDivEqual"] = "'/='"; + tokenNum["tkMinus"] = "'-'"; + tokenNum["tkPlus"] = "'+'"; + tokenNum["tkSlash"] = "'//'"; + tokenNum["tkStar"] = "'*'"; + tokenNum["tkEqual"] = "'='"; + tokenNum["tkGreater"] = "'>'"; + tokenNum["tkGreaterEqual"] = "'>='"; + tokenNum["tkLower"] = "'<'"; + tokenNum["tkLowerEqual"] = "'<='"; + tokenNum["tkNotEqual"] = "'<>'"; + tokenNum["tkArrow"] = "'->'"; + tokenNum["tkAddressOf"] = "'@'"; + tokenNum["tkDeref"] = "'^'"; + tokenNum["tkStarStar"] = "'**'"; } public PascalParserTools(IParser parserRef) : base(parserRef) @@ -115,6 +115,12 @@ namespace Languages.Pascal.Frontend.Core return 0; } + protected override string ReplaceSpecialSymbols(string text) + { + text = text.Replace("''", "'"); + return text; + } + public string CreateErrorString(string yytext, params object[] args) { string prefix = ""; @@ -128,7 +134,7 @@ namespace Languages.Pascal.Frontend.Core yytext = "}"; prefix = StringResources.Get("FOUND{0}"); } - + // Преобразовали в список строк - хорошо List tokens = new List(args.Skip(1).Cast()); @@ -178,7 +184,7 @@ namespace Languages.Pascal.Frontend.Core // string w = string.Join(" или ", tokens.Select(s => ConvertToHumanName((string)s))); - return string.Format(prefix + ExpectedString, "'" + yytext + "'", MaxTokHuman); + return string.Format(prefix + ExpectedString, "'" + yytext + "'", MaxTokHuman); } public string directive_parameter(string s) @@ -194,11 +200,19 @@ namespace Languages.Pascal.Frontend.Core } } - public ident create_directive_name(string text, SourceContext sc) + public override literal create_string_const(string text, SourceContext sc) { - ident dn = new ident(new string(text.ToCharArray(1, text.Length - 1))); - dn.source_context = sc; - return dn; + literal lt; + if (text.Length == 3 && text[0] == '\'' && text[2] == '\'') + { + lt = new char_const(text[1]); + lt.source_context = sc; + return lt; + } + text = ReplaceSpecialSymbols(text.Substring(1, text.Length - 2)); + lt = new string_const(text); + lt.source_context = sc; + return lt; } public function_lambda_definition find_pascalABC_lambda_name(string name) diff --git a/ParserTools/ParserTools/BaseParserTools.cs b/ParserTools/ParserTools/BaseParserTools.cs index 48858a95e..d2aee4196 100644 --- a/ParserTools/ParserTools/BaseParserTools.cs +++ b/ParserTools/ParserTools/BaseParserTools.cs @@ -27,7 +27,7 @@ namespace PascalABCCompiler.ParserTools // Класс глобальных описаний и статических методов // для использования различными подсистемами парсера и сканера - public abstract class BaseParserTools + public abstract class BaseParserTools { protected const int maxCharConst = 0xFFFF; // SSM: Errors инициализируется в другом месте - сюда только передается! @@ -93,11 +93,7 @@ namespace PascalABCCompiler.ParserTools warnings.Add(new CommonWarning(res, currentFileName, loc.begin_position.line_num, loc.begin_position.column_num)); } - protected string ReplaceSpecialSymbols(string text) - { - text = text.Replace("''", "'"); - return text; - } + protected abstract string ReplaceSpecialSymbols(string text); /// /// Удаление кавычек у параметра директивы @@ -106,7 +102,7 @@ namespace PascalABCCompiler.ParserTools { if (param.Length != 1 && param.StartsWith("'") && param.EndsWith("'")) return param.Substring(1, param.Length - 2); - + return param; } @@ -201,7 +197,7 @@ namespace PascalABCCompiler.ParserTools { string directiveText = ExtractDirectiveTextWithoutSpecialSymbols(directive); directiveName = GetDirectiveName(directiveText); - + ValidateDirectiveName(location, directiveName); // подстрока с параметрами @@ -294,7 +290,7 @@ namespace PascalABCCompiler.ParserTools { string paramsNumString = ""; int maxParamsNum = directiveInfo.paramsNums.Max(); - + if (directiveInfo.paramsNums.Length > 1) { if (directiveParams.Count > maxParamsNum) @@ -466,20 +462,7 @@ namespace PascalABCCompiler.ParserTools return proc_list; } - public literal create_string_const(string text, SourceContext sc) - { - literal lt; - if (text.Length == 3 && text[0] == '\'' && text[2] == '\'') - { - lt = new char_const(text[1]); - lt.source_context = sc; - return lt; - } - text = ReplaceSpecialSymbols(text.Substring(1, text.Length - 2)); - lt = new string_const(text); - lt.source_context = sc; - return lt; - } + public abstract literal create_string_const(string text, SourceContext sc); public literal create_multiline_string_const(string text, SourceContext sc) { diff --git a/SyntaxTree/tree/NodesBuilder.cs b/SyntaxTree/tree/NodesBuilder.cs index e4f8c1922..b0ba48b55 100644 --- a/SyntaxTree/tree/NodesBuilder.cs +++ b/SyntaxTree/tree/NodesBuilder.cs @@ -691,5 +691,17 @@ namespace PascalABCCompiler.SyntaxTree return BuildShortProcFuncDefinitionNoSC(ff, ass); } + + public static var_statement BuildVarStatementNodeFromAssignNode(assign _assign) + { + ident to = _assign.to as ident; + if (to == null) + throw new NotImplementedException(); + var _var_statement = SyntaxTreeNodesConstructor.CreateVarStatementNode(new ident_list(to.name), null, _assign.from); + _var_statement.source_context = _assign.source_context; + _var_statement.var_def.source_context = _assign.source_context; + _var_statement.var_def.vars.source_context = _assign.to.source_context; + return _var_statement; + } } } diff --git a/TreeConverter/TreeConversion/CompilationErrors.cs b/TreeConverter/TreeConversion/CompilationErrors.cs index 69d340d6d..aedc64243 100644 --- a/TreeConverter/TreeConversion/CompilationErrors.cs +++ b/TreeConverter/TreeConversion/CompilationErrors.cs @@ -133,8 +133,8 @@ namespace PascalABCCompiler.TreeConverter // SSM - 01.2014 - ужасно плодить много классов ошибок - достаточно сделать один общий для простых ошибок public class SimpleSemanticError : CompilationErrorWithLocation { - private string ErrResourceString; - private object[] values; + protected string ErrResourceString; + protected object[] values; public SimpleSemanticError(location loc, string ErrResourceString, params object[] values): base(loc) { diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index f8a0d4a3e..3c516006a 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -158,11 +158,6 @@ namespace PascalABCCompiler.TreeConverter SystemLibrary.SystemLibrary.syn_visitor = this; } - public void ProcessNode(T cd) where T : syntax_tree_node - { - base.ProcessNode(cd); - } - public List CompiledVariables => compiledVariables; public string UniqueNumStr()