* Add first comments
* Finish commenting for Compile and CompileUnit
* Write TODO sections
* Add a few clarifications
* splitted some functions from compile
* Written some methods from Compile to functions
* Update variable names
* Refactor - stage 1
Refactor GetUsesSection and IsPossibleNameSpace
* Refactor - stage 2
Rename a few functions and variables
* Correct an inaccuracy
* Added comments, look through CompileUnit
* Rename a few functions and add new comments
* Split CompileUnit to Subfunctions
Add IsUnitCompiled, IsUnitInPCU, InitializeNewUnit, GetSourceCode, GenSyntaxTree, GenUnitDocumentation, CheckDLLDirectiveOnlyForLibraries, MatchErrorsToBadNodes, CheckIfUnitModule, SetUseDLLForSystemUnits,
CompileInterfaceDependencies, CompileCurrentUnitInterface, GetImplementationUsesSection, CompileImplementationDependencies, CompileCurrentUnitImplementation
* Added some TODOs
* Return uses_unit_in original name
Renaming of syntax tree nodes leads to internal compiler errors
* Extract GenerateILCode method
* Add checking if recompilation needed method
Needs to be discussed and revised
* Add functions for catch blocks in Compile
* Extract building semantic tree method
Creating main function to be moved to another class
* Rename UnitsSortedList
* Edit CompileUnitsFromDelayedList method
* Change a few variable names, make CreateRCFile function and add comments
* Make code more "user-friendly"
* Add TODOs 31.11.23
* Create PrebuildSemanticTreeActionsMethod
* Refactor semantic checks section in initialize new unit method
* Refactor Adding standard units to uses method
* Return file_name and compiler_directives original names to avoid internal compilation errors
* Refactor GetReferences Method
* Initial refactoring of IncludeNamespaces function
* Create three more methods and wrap important code in regions
* Add TODO's
* Resolve merge conflicts
* Add returned value to ConstructSyntaxTree method
* Fix UnitsSortedList NotFoundError in PCUWriter
* Workaround commit
* Update PABCSystem after tests' changes
* Rename syntax trees in some methods
* Delete CurrentSyntaxUnit variable
* Revert unnecessary project files changes
* Squashed commit of the following:
commit f4d7599f1a39252feac97bd5391f46dfdc25f6f4
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:29 2023 +0300
added links to identarranger
commit 3bd5d33e2b2969884e61a3279ff9c353013b57fe
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:03 2023 +0300
Change extension for verybasic to yavb
commit 61294c6e7d405e1c68516cc81d3a109e8a1ee295
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:33:57 2023 +0300
Change Program Example
commit 86971488341ed6bf13c39e13a513d7ac0c51c285
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:28:59 2023 +0300
Add IndentArranger to Compile
commit 2ce50bbbf9db22c4243b247b870f6935ce206d26
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 17 10:00:31 2023 +0300
Add Semicolon After Each Statement
commit 796309d340e8d8ba730ff9418fa376f34fb7fd36
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Wed Nov 15 18:49:11 2023 +0300
Add Alpha Version of Python-style If-statement
commit 5eb88f946fe8254b4f5c5a56ed0a567b3be51227
Merge: ab4ce5b0 0162b637
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:54:26 2023 +0300
Merge branch 'IndentArranger' into VeryBasicLanguage
commit ab4ce5b0e32d42004726e3dc45cc0d8a65e53f56
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:53:51 2023 +0300
Fixes from seminar
commit af74012289d0d08517c13499a2a66cb543fc06d2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 18:57:29 2023 +0300
finally working!
fully implemented compatibility
commit 58a39c313324b468d1eec207ba3f5f6eddf74ef2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 11:58:16 2023 +0300
more compatibility with pabc
Now verybasic statements translate to pascal compiler
added .bat script for autobuilding verybasic
commit 0162b6376b8fe970704f26213bf9f0f670dfb12e
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:06:14 2023 +0300
Update test.txt
commit 1b759ab1cd7ee2ffeb14afff0418ddf0f30b0399
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:05:36 2023 +0300
Add Indent and Unindent Keywords to Generated File
commit cabda7f3985651cff2a8740f1a5bdea8fe7ac892
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 10 21:25:52 2023 +0300
Add Generation of Output File
commit 306f033d0176ab559e3622b8505427dbe2e0e203
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:42:18 2023 +0300
Update IndentArranger.sln
commit 60c0ceced1aa3a7d2e33de0facb1126e295f43b5
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:41:22 2023 +0300
Add IndentArranger
commit 1f4556c4573dae154fcc167b41ff6ab9e8122136
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Mon Nov 6 22:48:36 2023 +0300
Made my own VeryBasicParser project
Copied some code from SaushkinParser
Tried to compile it and implement into Pascal
Doesn't work due to grammatik issue
* Squashed commit of the following:
commit 4e73d9ac3ffef68312f06a74dc83afffcf3ccbee
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 15:08:10 2023 +0300
Fixed GPPG (i think so at least)
commit e5cfc220828b37fb2f35e565683019716ec3f0ce
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:44:27 2023 +0300
Update Compiler.cs
commit 4698e2e75a5f3b4f523a8bc7733a50e8abb4fca1
Merge: 22aaf2b2 f4d7599f
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:54 2023 +0300
Merge branch 'IndentArrangerTemp' into VeryBasicLanguage
commit f4d7599f1a39252feac97bd5391f46dfdc25f6f4
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:29 2023 +0300
added links to identarranger
commit 3bd5d33e2b2969884e61a3279ff9c353013b57fe
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:03 2023 +0300
Change extension for verybasic to yavb
commit 22aaf2b2508278a9ffce525ffed52419bf72c23f
Merge: c326174f 61294c6e
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:26:36 2023 +0300
Merge branch 'IndentArrangerTemp' into VeryBasicLanguage
commit 61294c6e7d405e1c68516cc81d3a109e8a1ee295
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:33:57 2023 +0300
Change Program Example
commit 86971488341ed6bf13c39e13a513d7ac0c51c285
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:28:59 2023 +0300
Add IndentArranger to Compile
commit c326174ff5ecccf9c4f76d58aea4653f047af049
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 19 15:03:19 2023 +0300
Added UniversalParserHelper and GPPG
ShiftReduceParser moved to another project
UniversalParserHelper project added, most of it copied from SaushkinParser
commit 2ce50bbbf9db22c4243b247b870f6935ce206d26
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 17 10:00:31 2023 +0300
Add Semicolon After Each Statement
commit 796309d340e8d8ba730ff9418fa376f34fb7fd36
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Wed Nov 15 18:49:11 2023 +0300
Add Alpha Version of Python-style If-statement
commit 5eb88f946fe8254b4f5c5a56ed0a567b3be51227
Merge: ab4ce5b0 0162b637
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:54:26 2023 +0300
Merge branch 'IndentArranger' into VeryBasicLanguage
commit ab4ce5b0e32d42004726e3dc45cc0d8a65e53f56
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:53:51 2023 +0300
Fixes from seminar
commit af74012289d0d08517c13499a2a66cb543fc06d2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 18:57:29 2023 +0300
finally working!
fully implemented compatibility
commit 58a39c313324b468d1eec207ba3f5f6eddf74ef2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 11:58:16 2023 +0300
more compatibility with pabc
Now verybasic statements translate to pascal compiler
added .bat script for autobuilding verybasic
commit 0162b6376b8fe970704f26213bf9f0f670dfb12e
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:06:14 2023 +0300
Update test.txt
commit 1b759ab1cd7ee2ffeb14afff0418ddf0f30b0399
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:05:36 2023 +0300
Add Indent and Unindent Keywords to Generated File
commit cabda7f3985651cff2a8740f1a5bdea8fe7ac892
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 10 21:25:52 2023 +0300
Add Generation of Output File
commit 306f033d0176ab559e3622b8505427dbe2e0e203
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:42:18 2023 +0300
Update IndentArranger.sln
commit 60c0ceced1aa3a7d2e33de0facb1126e295f43b5
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:41:22 2023 +0300
Add IndentArranger
commit 1f4556c4573dae154fcc167b41ff6ab9e8122136
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Mon Nov 6 22:48:36 2023 +0300
Made my own VeryBasicParser project
Copied some code from SaushkinParser
Tried to compile it and implement into Pascal
Doesn't work due to grammatik issue
* Changed GPPG project NET Framework version, added .dll to gitignore
* Adding UniversalParserHelper to project, trying to include VeryBasic
* Managed dependencies and got VeryBasicLanguage to work
* Change extension of a test program
* Rebuild changes
What should be added to .gitignore?
* Fix bug related to err0524_res_unit.pas
* Rebuild Parser
* Change Indent and Unindent tokens
* Add Symbol Table to ParserABC.y
* Change Indent Space Number to 2
* Add While Loop
* Add Some Operations to Parser
* Make Initialization Node at the Beginning of a program
* Create Grammar.txt
* Test program added
* Add ELIF and SyntaxHighlight
* Fix TableSymbol
* Add Division
* Add Method Call
* Add For Loop
* Rename SPython Parser Folder
* Add documented comments for CompileUnit method
* Added Errors to SPython
Added Errors.cs
Removed link to PABCSaushkinParser
Minor fixes
* Create default constructor for SourceContext
* Move null check of currentUnit to upper level in CompileUnit
* Move CreateMainFunction method from Compiler to TreeConverter class
* Add gppg and parserhelper to visualpascalabcnet dependencies
* Updated installer files to include GPPG and UniversalParserHelper
* Rename GPPG to ShiftReduceParser
* Fix ShiftReduceParser project dependencies
* Fix ShiftReduceParserDependencies second iteration
* Workaround commit
* Update PABCSystem after tests' changes
* Refactor ConvertDirectives method
* Get rid of legacy standard modules code
* Return varBeginOffset and beginOffset calculation to Compiler class
Размещение метода в SyntaxTreeToSemanticTreeConverter не целесообразно. В комментарии видимо имелось в виду что-то другое.
* Workaround commit
* Update PABCSystem after tests' changes
* Revert SPython changes
Оставляем только изменения связанные с рефакторингом.
* Update .gitignore
Co-authored-by: Sun Serega <sunserega2@gmail.com>
* Resolve a few Sun Serega treds
* Delete comments in ParsersController.cs
* Replace specific path with path variable in Studio.bat
* Add comment in Studio.bat file and return FileName in CompilerError.cs
* Fix TreeSubsidiary.cs encoding and sectCore.nsh indents
* Return old version of TestRunner.exe
* Rename some variables and polish a few methods
* Uncomment accidentally commented code
* Replace spaces with tabs
* Changed dll name from GPPG
* Revert "Changed dll name from GPPG"
This reverts commit c485cc8cb787809b7e9dfa8a361e75f17ed39893.
* Update .gitignore
* Delete Libraries/ShiftReduceParser.dll
* Delete bin\ShiftReduceParser.dll
* Replace tabs with spaces
* Update encoding in Studio.bat
* Fix bug with PABCrtl excluded files
* Refactor StandardModule class
* Add null checks to make debuging easier
* Delete unnecessary null checks in SymTable.cs
---------
Co-authored-by: Владислав Крылов <krylov@sfedu.ru>
Co-authored-by: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Co-authored-by: Sun Serega <sunserega2@gmail.com>
386 lines
14 KiB
C#
386 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
using QUT.Gppg;
|
|
|
|
using PascalABCCompiler.SyntaxTree;
|
|
using PascalABCCompiler.Errors;
|
|
|
|
namespace UniversalParserHelper
|
|
{
|
|
public static class StringResources
|
|
{
|
|
private static string prefix = "PASCALABCPARSER_";
|
|
public static string Get(string Id)
|
|
{
|
|
string ret = PascalABCCompiler.StringResources.Get(prefix + Id);
|
|
if (ret == prefix + Id)
|
|
return Id;
|
|
else
|
|
return ret;
|
|
}
|
|
}
|
|
public abstract class UniversalParserHelper
|
|
{
|
|
private const int max_char_const = 0xFFFF;
|
|
// SSM: Errors инициализируется в другом месте - сюда только передается!
|
|
public List<Error> errors;
|
|
public List<CompilerWarning> warnings;
|
|
public System.Collections.Stack NodesStack; // SSM: для каких-то вспомогательных целей в двух правилах
|
|
public bool build_tree_for_formatter = false;
|
|
public bool build_tree_for_format_strings = false;
|
|
public string CurrentFileName;
|
|
public List<compiler_directive> compilerDirectives;
|
|
|
|
public List<var_def_statement> pascalABC_var_statements;
|
|
public List<type_declaration> pascalABC_type_declarations;
|
|
public UniversalParserHelper()
|
|
{
|
|
NodesStack = new System.Collections.Stack();
|
|
pascalABC_var_statements = new List<var_def_statement>();
|
|
pascalABC_type_declarations = new List<type_declaration>();
|
|
}
|
|
public string directive_parameter(string s)
|
|
{
|
|
var ind = s.IndexOf(" ");
|
|
if (ind < 0)
|
|
return "";
|
|
else
|
|
{
|
|
s = s.Substring(ind + 1);
|
|
s = s.TrimEnd('}');
|
|
return s;
|
|
}
|
|
}
|
|
public ident create_directive_name(string text, SourceContext sc)
|
|
{
|
|
ident dn = new ident(new string(text.ToCharArray(1, text.Length - 1)));
|
|
dn.source_context = sc;
|
|
return dn;
|
|
}
|
|
|
|
public string RemoveThousandsDelimiter(string s, SourceContext sc)
|
|
{
|
|
if (s.EndsWith("_") || s.Contains("__"))
|
|
{
|
|
var errstr = ParserErrorsStringResources.Get("BAD_FORMED_NUM_CONST");
|
|
errors.Add(new SyntaxError(errstr, CurrentFileName, sc, null));
|
|
}
|
|
|
|
return s.Replace("_", "");
|
|
}
|
|
private const_node create_int_const(string text, SourceContext sc, System.Globalization.NumberStyles NumberStyles)
|
|
{
|
|
//таблица целых констант на уровне синтаксиса
|
|
// не может быть - 0 +
|
|
// 32--------16----8----|----8----16--------32----------------64(bits)
|
|
// [ int64 )[ int32 ]( int64 ]( uint64 ]
|
|
text = RemoveThousandsDelimiter(text, sc);
|
|
if (NumberStyles == System.Globalization.NumberStyles.HexNumber)
|
|
text = text.Substring(1);
|
|
const_node cn = new int32_const();
|
|
if (text.Length < 8)
|
|
(cn as int32_const).val = Int32.Parse(text, NumberStyles);
|
|
else
|
|
{
|
|
try
|
|
{
|
|
UInt64 uint64 = UInt64.Parse(text, NumberStyles);
|
|
if (uint64 <= Int32.MaxValue)
|
|
(cn as int32_const).val = (Int32)uint64;
|
|
else
|
|
if (uint64 <= Int64.MaxValue)
|
|
cn = new int64_const((Int64)uint64);
|
|
else
|
|
cn = new uint64_const(uint64);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
if (NumberStyles == System.Globalization.NumberStyles.HexNumber)
|
|
errors.Add(new BadHex(CurrentFileName, sc, null));
|
|
else
|
|
errors.Add(new BadInt(CurrentFileName, sc, null));
|
|
}
|
|
}
|
|
cn.source_context = sc;
|
|
return cn;
|
|
}
|
|
public const_node create_int_const(string text, SourceContext sc)
|
|
{
|
|
return create_int_const(text, sc, System.Globalization.NumberStyles.Integer);
|
|
}
|
|
public const_node create_double_const(string text, SourceContext sc)
|
|
{
|
|
const_node cn = null;
|
|
try
|
|
{
|
|
System.Globalization.NumberFormatInfo sgnfi = new System.Globalization.NumberFormatInfo();
|
|
sgnfi.NumberDecimalSeparator = ".";
|
|
|
|
text = RemoveThousandsDelimiter(text, sc);
|
|
|
|
double val = double.Parse(text, sgnfi);
|
|
cn = new double_const(val);
|
|
cn.source_context = sc;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
errors.Add(new BadFloat(CurrentFileName, sc, null));
|
|
}
|
|
return cn;
|
|
}
|
|
public const_node create_bigint_const(string text, SourceContext sc)
|
|
{
|
|
text = RemoveThousandsDelimiter(text, sc);
|
|
|
|
var txt = text.Substring(0, text.Length - 2);
|
|
var cn = new bigint_const();
|
|
try
|
|
{
|
|
cn.val = System.UInt64.Parse(txt);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
errors.Add(new BadInt(CurrentFileName, sc, null));
|
|
}
|
|
cn.source_context = sc;
|
|
return cn;
|
|
}
|
|
public ident create_ident(string text, SourceContext sc)
|
|
{
|
|
if (text[0] == '&')
|
|
text = text.Substring(1);
|
|
ident id = new ident(text);
|
|
id.source_context = sc;
|
|
return id;
|
|
}
|
|
|
|
public string ReplaceSpecialSymbols(string text)
|
|
{
|
|
text = text.Replace("''", "'");
|
|
return text;
|
|
}
|
|
|
|
public char_const create_char_const(string text, SourceContext sc)
|
|
{
|
|
string char_text = new string(text.ToCharArray(1, text.Length - 2));
|
|
char_text = ReplaceSpecialSymbols(char_text);
|
|
char_const ct = new char_const();
|
|
ct.source_context = sc;
|
|
if (char_text.Length == 1)
|
|
{
|
|
ct.cconst = char_text[0];
|
|
return ct;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public sharp_char_const create_sharp_char_const(string text, SourceContext sc)
|
|
{
|
|
string int_text = new string(text.ToCharArray(1, text.Length - 1));
|
|
sharp_char_const scc = null;
|
|
int val = 0;
|
|
if (int.TryParse(int_text, out val))
|
|
{
|
|
if (val > max_char_const)
|
|
{
|
|
scc = new sharp_char_const(0);
|
|
errors.Add(new TooBigCharNumberInSharpCharConstant(CurrentFileName, sc, scc));
|
|
}
|
|
else
|
|
scc = new sharp_char_const(val);
|
|
scc.source_context = sc;
|
|
}
|
|
else
|
|
{
|
|
errors.Add(new TooBigCharNumberInSharpCharConstant(CurrentFileName, sc, scc));
|
|
}
|
|
return scc;
|
|
}
|
|
|
|
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 literal create_format_string_const(string text, SourceContext sc)
|
|
{
|
|
literal lt;
|
|
text = ReplaceSpecialSymbols(text.Substring(2, text.Length - 3));
|
|
lt = new string_const(text);
|
|
(lt as string_const).IsInterpolated = true;
|
|
lt.source_context = sc;
|
|
return lt;
|
|
}
|
|
|
|
public void AddError(string message, LexLocation loc)
|
|
{
|
|
errors.Add(new SyntaxError(message, CurrentFileName, loc, null));
|
|
}
|
|
public string CreateErrorString(string yytext, LexLocation yyloc, params object[] args)
|
|
{
|
|
string prefix = "";
|
|
if (yytext != "")
|
|
prefix = StringResources.Get("FOUND{0}");
|
|
else
|
|
prefix = StringResources.Get("FOUNDEOF");
|
|
|
|
if (this.build_tree_for_format_strings && prefix == StringResources.Get("FOUNDEOF"))
|
|
{
|
|
yytext = "}";
|
|
prefix = StringResources.Get("FOUND{0}");
|
|
}
|
|
|
|
// Преобразовали в список строк - хорошо
|
|
string expected = String.Join(", ", args.Skip(1).Select(x => x.ToString()));
|
|
|
|
var ExpectedString = StringResources.Get("EXPECTED{1}");
|
|
|
|
// string w = string.Join(" или ", tokens.Select(s => ConvertToHumanName((string)s)));
|
|
|
|
return string.Format(prefix + ExpectedString, "'" + yytext + "'", expected);
|
|
}
|
|
/* public string CreateErrorString(string yytext, LexLocation yyloc, params object[] args)
|
|
{
|
|
string expected = String.Join(", ", args.Skip(1).Select(x => x.ToString()));
|
|
string err = $"PARSER ERROR \"{yytext}\" AT LINE #{yyloc.StartLine}: EXPECTED {expected}, FOUND {args[0]}";
|
|
return err;
|
|
}*/
|
|
public List<object> ident_list11(object lr1, object lr3)
|
|
{
|
|
List<object> ar = (List<object>)lr3;
|
|
ar.Insert(0, lr1);
|
|
return ar;
|
|
}
|
|
|
|
public List<object> ident_list12(object lr0)
|
|
{
|
|
List<object> ar = new List<object>();
|
|
ar.Add(lr0);
|
|
return ar;
|
|
}
|
|
|
|
public List<object> ident_list21(object lr0, object lr2)
|
|
{
|
|
List<object> ar = (List<object>)lr0;
|
|
ar.Add(lr2);
|
|
return ar;
|
|
}
|
|
|
|
public List<object> ident_list13(object lr1, object lr3, object lr5)
|
|
{
|
|
List<object> ar = (List<object>)lr5;
|
|
//named_type_reference n_t_r = (named_type_reference)lr3;
|
|
var_def_statement vds = new var_def_statement();
|
|
vds.vars = new ident_list();
|
|
vds.vars.idents.Add((ident)lr1);
|
|
vds.vars_type = (type_definition)lr3;//n_t_r;
|
|
ar.Insert(0, vds);
|
|
return ar;
|
|
}
|
|
|
|
public List<object> ident_list14(object lr1, object lr3)
|
|
{
|
|
List<object> ar = new List<object>();
|
|
//named_type_reference n_t_r = (named_type_reference)lr3;
|
|
var_def_statement vds = new var_def_statement();
|
|
vds.vars = new ident_list();
|
|
vds.vars.idents.Add((ident)lr1);
|
|
vds.vars_type = (type_definition)lr3;
|
|
ar.Add(vds);
|
|
return ar;
|
|
}
|
|
public void create_source_context(object to, object left, object right)
|
|
{
|
|
if (to != null)
|
|
((syntax_tree_node)to).source_context = get_source_context(left, right);
|
|
}
|
|
|
|
public SourceContext get_source_context(object left, object right)
|
|
{
|
|
//debug
|
|
/*if (left == null && right!=null)
|
|
{
|
|
Console.WriteLine("\n\rerror: left is null(create_source_context)!\n\r");
|
|
Console.WriteLine(((syntax_tree_node)right).source_context.ToString());
|
|
}
|
|
if (right == null && left!=null)
|
|
{
|
|
Console.WriteLine("\n\rerror: right is null(create_source_context)!\n\r");
|
|
Console.WriteLine(((syntax_tree_node)left).source_context.ToString());
|
|
}
|
|
if (((syntax_tree_node)left).source_context == null)
|
|
{
|
|
Console.WriteLine("\n\rerror: source_context is null!(left)\n\r");
|
|
return null;
|
|
}
|
|
if (((syntax_tree_node)right).source_context == null)
|
|
{
|
|
Console.WriteLine("\n\rerror: source_context is null!(right)\n\r");
|
|
return null;
|
|
}
|
|
*/
|
|
if ((left == null) || (right == null) || (((syntax_tree_node)left).source_context == null) || (((syntax_tree_node)right).source_context == null))
|
|
return null;
|
|
return new SourceContext(((syntax_tree_node)left).source_context, ((syntax_tree_node)right).source_context);
|
|
}
|
|
|
|
public void create_source_context_left(object to, object left)
|
|
{
|
|
file_position fp = ((syntax_tree_node)left).source_context.begin_position;
|
|
((syntax_tree_node)to).source_context = new SourceContext(fp.line_num, fp.column_num, fp.line_num, fp.column_num, 0, 0);
|
|
}
|
|
|
|
public void create_source_context_right(object to, object right)
|
|
{
|
|
file_position fp = ((syntax_tree_node)right).source_context.end_position;
|
|
((syntax_tree_node)to).source_context = new SourceContext(fp.line_num, fp.column_num, fp.line_num, fp.column_num, 0, 0);
|
|
}
|
|
|
|
public object sc_not_null(object o1, object o2)
|
|
{
|
|
if (o1 != null)
|
|
if (((syntax_tree_node)o1).source_context != null) return o1;
|
|
return o2;
|
|
}
|
|
|
|
public object sc_not_null(object o1, object o2, object o3)
|
|
{
|
|
if (o1 != null)
|
|
if (((syntax_tree_node)o1).source_context != null) return o1;
|
|
if (o2 != null)
|
|
if (((syntax_tree_node)o2).source_context != null) return o2;
|
|
return o3;
|
|
}
|
|
|
|
public object sc_not_null(params object[] arr)
|
|
{
|
|
foreach (object o in arr)
|
|
if (o != null)
|
|
if (((syntax_tree_node)o).source_context != null) return o;
|
|
return null;
|
|
}
|
|
|
|
public void assign_source_context(object to, object from)
|
|
{
|
|
//debug
|
|
//if (((tree_node)from).source_context==null) Console.WriteLine("\n\rerror: from sc is null(assign_source_context)!\n\r");
|
|
if (to != null && from != null)
|
|
((syntax_tree_node)to).source_context = ((syntax_tree_node)from).source_context;
|
|
}
|
|
}
|
|
}
|