* Implement first version of languages interfaces and classes ParsersController заменен на LanguageProvider. * Update ParserTools.csproj * Update RemoteCompiler.cs * Update TestRunner * Rename LanguageIntegrator project to Languages * Update TestRunner * Rename Parsers folder * Rename PascalABCParser.dll to PascalABCLanguage.dll * Reorganise LanguageIntegrator and rename DocTagsParser * Update Release Generators * Update language loading messages * Update linux version * Move BaseParser fields to ILanguage interface * Revert "Update Release Generators" This reverts commit 26a991c71b81e643d9fbd9a815ddca222768dda9. * Revert "Rename PascalABCParser.dll to PascalABCLanguage.dll" * Clean the mess in parser folders * Organize namespaces properly * Revert "Rename LanguageIntegrator project to Languages" * Add new enclosing folders for standard languages * Organize namespaces of LanguageIntegrator properly * Rename StandardLanguages to Languages * Comment the rest of Visual basic source code * Update OutputPath in pascal parser project * Move BaseParser methods to IParser * Restore Pascal parser project initial structure * Add PascalLanguage project * Move SyntaxTreeConverters project to Languages\Pascal folder * Rename SemanticRules in parser project * Rename Errors1 to Errors in parser project * Delete LambdaConverter dll from installer * Update language integrator to load *Language.dll files * Move lambda converter project to pascal lanuage dir * Revert "Delete LambdaConverter dll from installer" This reverts commit dd56f559ebe4f8c4c5c33752d44e6953001b96a5. * Switch off VBNETParser building * Delete syntax tree converters controller * Delete lambda converter dll from repository * Reorganize syntax tree to semantic tree conversion stage * Add BaseLanguage class to make language initialization more neat * Delete syntax tree post processors entity from ILanguage and refactor ABCStatistics calls * Add new IDocParser interface for documentation comments parser * Clean up folders * Add helper data structures to reduce parameters amount in CompileInterface and CompileImplementation * Add documentation to language classes * Move Union struct in global namespace and project (ParserTools) * Add more comments and a safe select language method * Rename SemanticRules class * Fix directives format null bug * Add System.Linq ref to LanguageIntegrator * Delete SyntaxToSemanticTreeConverter interface * Add BaseSyntaxTreeConverter * Call safe select language method in intellisence * Delete source files providers from parsers * Rename GetSyntaxTree method * Change Prebuild tree to be virtual - not abstract * Refresh documentation a bit * Add temporary language check for ABCHealth button * Add parser reference to parser tools * Move current compilation unit assigning higher to avoid bug with unit check * Delete null DirectiveInfo's and refactor directives' code * Add a few more comments
132 lines
6.3 KiB
C#
132 lines
6.3 KiB
C#
using System.Collections.Generic;
|
||
using PascalABCCompiler.SyntaxTree;
|
||
using PascalABCCompiler.Errors;
|
||
using QUT.Gppg;
|
||
using GPPGParserScanner;
|
||
|
||
namespace PascalABCCompiler.Oberon00Parser
|
||
{
|
||
// Класс глобальных описаний и статических методов
|
||
// для использования различными подсистемами парсера и сканера
|
||
public static class PT // PT - parser tools
|
||
{
|
||
public static List<Error> Errors;
|
||
/// Последний прочтенный идентификатор
|
||
public static string LastIdentificator = "";
|
||
//public static int max_errors;
|
||
public static string CurrentFileName;
|
||
/// Словарь стандартных типов с соответствующими внутренними именами
|
||
public static Dictionary<string, string> standartTypes = new Dictionary<string, string>();
|
||
|
||
/// Статический конструктор
|
||
static PT() {
|
||
standartTypes.Add("BOOLEAN", "boolean");
|
||
standartTypes.Add("INTEGER", "integer");
|
||
standartTypes.Add("SHORTINT", "byte");
|
||
standartTypes.Add("LONGINT", "int64");
|
||
standartTypes.Add("REAL", "real");
|
||
standartTypes.Add("LONGREAL", "double");
|
||
standartTypes.Add("CHAR", "char");
|
||
standartTypes.Add("STRING", "string");
|
||
}
|
||
|
||
public static SourceContext ToSourceContext(LexLocation loc)
|
||
{
|
||
if (loc != null)
|
||
return new SourceContext(loc.StartLine, loc.StartColumn + 1, loc.EndLine, loc.EndColumn);
|
||
return null;
|
||
}
|
||
|
||
public static string CreateErrorString(params object[] args)
|
||
{
|
||
string[] ww = new string[args.Length - 1];
|
||
for (int i = 1; i < args.Length; i++)
|
||
ww[i - 1] = GetStrByTokenName((string)args[i]);
|
||
string w = string.Join(" или ", ww);
|
||
|
||
string got = (string)args[0];
|
||
if (got.Equals("ID"))
|
||
got = "'" + LastIdentificator + "'";
|
||
else
|
||
got = GetStrByTokenName(got);
|
||
return string.Format("Синтаксическая ошибка: встречено {0}, а ожидалось {1}", got, w);
|
||
}
|
||
|
||
public static void AddError(string message, LexLocation loc)
|
||
{
|
||
Errors.Add(new SyntaxError(message, CurrentFileName, ToSourceContext(loc), null));
|
||
}
|
||
|
||
/// Определяет содержимое строки по ее представлению в тексте программы
|
||
/// <param name="sourceStr">Строка с кавычками</param>
|
||
/// <returns>Содержимое строки без кавычек</returns>
|
||
public static string GetStringContent(string sourceStr) {
|
||
bool hasStrType = (sourceStr.IndexOf('\'') != -1) ||
|
||
(sourceStr.IndexOf('"') != -1);
|
||
if (hasStrType)
|
||
return sourceStr.Substring(1, sourceStr.Length - 2);
|
||
else { // символ представлен 16ным кодом
|
||
string hexCode = sourceStr.Remove(sourceStr.Length - 1);
|
||
int tryParseHex;
|
||
if (int.TryParse(hexCode, System.Globalization.NumberStyles.AllowHexSpecifier, null, out tryParseHex))
|
||
return ((char)tryParseHex).ToString();
|
||
else
|
||
throw new System.ArgumentException("Некорректный шестнадцатеричный код символа");
|
||
}
|
||
}
|
||
|
||
/// Преобразует вещественный литерал, принятый в Обероне, к виду .NET
|
||
/// <param name="sourceDoubleStr">Исходная строка вещественного числа</param>
|
||
/// <returns>Корректную строку - вещественное число</returns>
|
||
public static string GetCorrectDoubleStr(string sourceDoubleStr) {
|
||
string correct = sourceDoubleStr.Replace(".",
|
||
System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator);
|
||
correct = correct.Replace('D', 'E');
|
||
return correct;
|
||
}
|
||
|
||
/// Определяет внутреннее имя типа по типу в программе
|
||
/// <param name="typeName">Имя типа в программе</param>
|
||
/// <returns>Корректное внутреннее имя типа</returns>
|
||
public static string InternalTypeName(string typeName) {
|
||
if (standartTypes.ContainsKey(typeName))
|
||
return standartTypes[typeName];
|
||
else
|
||
return typeName;
|
||
}
|
||
|
||
|
||
// -----------------------------------------------------------------------------
|
||
// Вспомогательные методы
|
||
// -----------------------------------------------------------------------------
|
||
/// Возвращает по имени токена представляющую его строку
|
||
private static string GetStrByTokenName(string tokenName) {
|
||
switch (tokenName) {
|
||
case "ASSIGN": return "':='";
|
||
case "SEMICOLUMN": return "';'";
|
||
case "COLON": return "':'";
|
||
case "COMMA": return "'.'";
|
||
case "COLUMN": return "','";
|
||
case "LPAREN": return "'('";
|
||
case "RPAREN": return "')'";
|
||
case "PLUS": return "'+'";
|
||
case "MINUS": return "'-'";
|
||
case "MULT": return "'*'";
|
||
case "DIVIDE": return "'/'";
|
||
case "LT": return "'<'";
|
||
case "GT": return "'>'";
|
||
case "LE": return "'<='";
|
||
case "GE": return "'>='";
|
||
case "EQ": return "'='";
|
||
case "NE": return "'#'";
|
||
case "NOT": return "'~'";
|
||
case "AND": return "'&'";
|
||
case "EXCLAMATION": return "'!'";
|
||
case "ID": return "идентификатор";
|
||
case "EOF": return "конец программы";
|
||
case "INTNUM": return "целое число";
|
||
default: return tokenName;
|
||
}
|
||
}
|
||
}
|
||
} |