удалены старые парсеры на базе GoldParser

обновлен год в копирайтах
This commit is contained in:
Бондарев Иван 2016-01-07 22:01:36 +01:00
parent 034b96253d
commit 321d8a48fe
64 changed files with 6 additions and 33507 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,31 +0,0 @@
cls
@echo off
echo [Haskell] GRM to CS,RES compiler.
echo.
echo Delete old files...
del Haskell_lrparser_rules.cs
del haskell_parser.cgt
del HaskellLang.resources
del haskell_parser.tmpl
del haskell_parser.log
echo Compile: GRM to CGT...
start /wait ..\..\Utils\gpbcmd\goldbuilder_main haskell_parser.grm haskell_parser.cgt
copy haskell_parser.log con
echo.
echo Compile: CGT,PGT to TEMPLATE...
start /wait ..\..\Utils\gpbcmd\createskelprog_main haskell_parser.cgt haskell_parser.pgt haskell_parser.tmpl
echo.
echo Compile: GRM,TEMPLATE to CS...
..\..\Utils\grmCommentCompiler\bin\Debug\grmCommentCompiler.exe haskell_parser.grm haskell_parser.tmpl Haskell_lrparser_rules.cs
echo.
echo Compile: CGT to RES...
start /wait ..\..\Utils\ResXMaker\ResXMaker.exe haskell_parser.CGT HaskellLanguage HaskellLang.resources
echo.
copy HaskellLang.resources ..\..\Parsers\HaskellParser\HaskellLang.resources
copy Haskell_lrparser_rules.cs ..\..\Parsers\HaskellParser\Haskell_lrparser_rules.cs

View file

@ -1,31 +0,0 @@
cls
@echo off
echo [Haskell] GRM to CS,RES compiler.
echo.
echo Delete old files...
del Haskell_lrparser_rules.cs
del haskell_parser.cgt
del HaskellLang.resources
del haskell_parser.tmpl
del haskell_parser.log
echo Compile: GRM to CGT...
start /wait ..\..\Utils\gpbcmd\goldbuilder_main haskell_parser.grm haskell_parser.cgt
copy haskell_parser.log con
echo.
echo Compile: CGT,PGT to TEMPLATE...
start /wait ..\..\Utils\gpbcmd\createskelprog_main haskell_parser.cgt haskell_parser.pgt haskell_parser.tmpl
echo.
echo Compile: GRM,TEMPLATE to CS...
..\..\Utils\grmCommentCompiler\bin\Debug\grmCommentCompiler.exe haskell_parser.grm haskell_parser.tmpl Haskell_lrparser_rules.cs
echo.
echo Compile: CGT to RES...
start /wait ..\..\Utils\ResXMaker\ResXMaker.exe haskell_parser.CGT HaskellLanguage HaskellLang.resources
echo.
copy HaskellLang.resources ..\..\Parsers\HaskellParser\HaskellLang.resources
copy Haskell_lrparser_rules.cs ..\..\Parsers\HaskellParser\Haskell_lrparser_rules.cs

Binary file not shown.

View file

@ -1,394 +0,0 @@
!=========================================================================
!
! This is a version of programming language Haskell
!
!=========================================================================
"Name" = 'Haskell'
"Author" = 'Tasha'
"About" = 'A version of the Haskell language.'
"Case Sensitive" = True
"Start Symbol" = <module>
!<%NAME%> %CODE%
!*
[TERMINALTEMPLATE]
{
%NAME% _%NAME%=new %NAME%(%PARAMS%);
_%NAME%.source_context=parsertools.GetTokenSourceContext();
%CODE%
return _%NAME%;
}
*!
!%NAME%<%PARAMS%> %CODE%
!%PARAMS%=$1,$2,...
!*
[NONTERMINALTEMPLATE0]
{
%NAME% _%NAME%=new %NAME%(%PARAMS%);
parsertools.create_source_context(_%NAME%,%LEFTTOKEN%,%RIGHTTOKEN%);
%CODE%
return _%NAME%;
}
*!
!add to list
!*
[NONTERMINALTEMPLATE1]
{
%NAME% _%NAME%=(%NAME%)%CODE%
return _%NAME%;
}
*!
!*
[NONTERMINALTEMPLATE2]
{
%NAME% _%NAME%;
%CODE%
return _%NAME%;
}
*!
!*
[NONTERMINALTEMPLATE3]
{
%NAME% _%NAME%=new %NAME%(%PARAMS%);
%CODE%
return _%NAME%;
}
*!
!for list:
!<el>
!<list> token <el>
!*
[NONTERMINALTEMPLATE6]
//TemplateList for %NAME% (create)
{
%NAME% _%NAME%=new %NAME%();
_%NAME%.source_context=((%CODE%)$1).source_context;
_%NAME%.%PARAMS%.Add((%CODE%)$1);
return _%NAME%;
}
*!
!*
[NONTERMINALTEMPLATE7]
//TemplateList for %NAME% (add)
{
%NAME% _%NAME%=(%NAME%)$1;
parsertools.create_source_context(_%NAME%,$$,$3);
_%NAME%.%PARAMS%.Add($3 as %CODE%);
return _%NAME%;
}
*!
!*
[NONTERMINALTEMPLATE8]
{
procedure_call pc = new procedure_call();
expression_list expr = new expression_list();
expr.expressions.Add((expression)$2);
method_call mc = new method_call(expr);
mc.dereferencing_value = new ident("%NAME%");
pc.func_name = mc;
parsertools.create_source_context(mc.dereferencing_value,$2,$2);
parsertools.create_source_context(expr,$2,$2);
parsertools.create_source_context(mc,$1,$2);
parsertools.create_source_context(pc,$1,$2);
return pc;
}
*!
{Chars} = {ANSI Printable} + {HT} + {Cyrillic}
{String Chars} = {ANSI Printable} + {HT} + {Cyrillic} - ["]
Comment Start = '{-'
Comment End = '-}'
Comment Line = '--'
tkIdent = {Letter}{Alphanumeric}* !*$$=parsertools.create_ident(this);*!
tkInt = {digit}+ !*$$=parsertools.create_int_const(this);*!
tkDouble = {Digit}+[.]{Digit}+ !*$$=parsertools.create_double_const(this);*!
tkChar = ''{Chars}'' !*$$=parsertools.create_char_const(this);*!
tkString = '"'{String Chars}* '"' !*$$=parsertools.create_string_const(this);*!
tkBool = (True) | (False) | (true) | (false) !*{
ident _ident = null;
string s = LRParser.TokenText;
if (s == "True" || s == "true")
s = "true";
else
s = "false";
_ident =new ident(s);
_ident.source_context = parsertools.GetTokenSourceContext();
return _ident;
}*!
tkModule = 'module' !*<token_info>*!
tkWhere = 'where' !*{
token_where = 1;
token_where_count++;
token_info _token_info=new token_info(LRParser.TokenText);
_token_info.source_context=parsertools.GetTokenSourceContext();
return _token_info;
}*!
tkDo = 'do' !*<token_info>*!
tkIf = 'if' !*<token_info>*!
tkThen = 'then' !*<token_info>*!
tkElse = 'else' !*<token_info>*!
tkCase = 'case' !*<token_info>*!
tkOf = 'of' !*<token_info>*!
tkLet = 'let' !*<token_info>*!
tkIn = 'in' !*<token_info>*!
tkReturn = 'return' !*<token_info>*!
tkMinus = '-' !*<op_type_node(Operators.Minus)>*!
tkPlus = '+' !*<op_type_node(Operators.Plus)>*!
tkSlash = '/' !*<op_type_node(Operators.IntegerDivision)>*!
tkStar = '*' !*<op_type_node(Operators.Multiplication)>*!
tkSemiColon = ';' !*<token_info>*!
tkDot = '.' !*<token_info>*!
tkAssign = '=' !*{
if (token_where == 2 || token_where == 1)
{
token_where = 0;
//if (let_where_funcs_main.Count > 1)
//for (int i = 0; i let_where_funcs.Count; i++)
//if (let_funcs.Count > 0)
//let_funcs.RemoveAt(let_funcs.Count - 1);
let_where_funcs_main.Add(let_where_funcs.Clone());
let_where_funcs.Clear();
}
token_info _token_info=new token_info(LRParser.TokenText);
_token_info.source_context=parsertools.GetTokenSourceContext();
return _token_info;
}*!
tkRoundOpen = '(' !*<token_info>*!
tkRoundClose = ')' !*<token_info>*!
tkFigureOpen = '{' !*<token_info>*!
tkFigureClose = '}' !*<token_info>*!
tkSquareOpen = '[' !*<token_info>*!
tkSquareClose = ']' !*<token_info>*!
tkMainIdent = 'Main' !*<token_info>*!
tkMainIdent1 = 'main' !*<token_info>*!
tkArrow = '->' !*<token_info>*!
tkMore = '>' !*<op_type_node(Operators.Greater)>*!
tkLess = '<' !*<op_type_node(Operators.Less)>*!
tkMoreEq = '>=' !*<op_type_node(Operators.GreaterEqual)>*!
tkLessEq = '<=' !*<op_type_node(Operators.LessEqual)>*!
tkEqual = '==' !*<op_type_node(Operators.Equal)>*!
tkNotEqual = '/=' !*<op_type_node(Operators.NotEqual)>*!
tkOr = 'or' !*<op_type_node(Operators.LogicalOR)>*!
tkAnd = 'and' !*<op_type_node(Operators.LogicalAND)>*!
tkNot = 'not' !*<op_type_node(Operators.LogicalNOT)>*!
tkImport = 'import' !*<token_info>*!
tkRef = '#reference' !*$$=parsertools.create_directive_name(this);*!
tkSplit = '|' !*<token_info>*!
tkComma = ',' !*<token_info>*!
tkColon = ':' !*<token_info>*!
tkLeftSlash = '\' !*<token_info>*!
tkOtherwise = 'otherwise' !*<token_info>*!
tkArrowGen = '<-' !*<token_info>*!
tkQuote = '`' !*<token_info>*!
tkBottomMinus = '_' !*<token_info>*!
<module>::= tkModule tkMainIdent tkWhere <reference> <imports> <body> <empty>
| <reference> <imports> <body> <empty>
| tkModule tkIdent tkWhere <reference> <imports> <funcs> <empty>
<reference>::=
| tkRef tkString
<imports>::=
| <import> <empty>
| <imports> <empty> <import>
<import>::= tkImport tkIdent
<body>::= <main_func>
| <funcs> <main_func>
<funcs>::= <funcs_variants> <empty>
<funcs_variants>::= <variants> <empty>
<variants>::= <variant> <empty>
| <variants> <variant>
<variant>::= tkIdent <params> <guard_body_list> <where_var>
| <list_param1> tkQuote tkIdent tkQuote <list_param1> <guard_body_list> <where_var>
<list_param1>::= <list_param><empty>
<body_where>::= <body_func> <where_var>
<where_var>::=
| tkWhere <inits>
<inits>::= <init> <empty>
| <inits> tkSemiColon <init>
<init>::= tkIdent <params_where> <guard_body_list> <where_var>
<params_where>::=
| <param> <empty>
| <params_where> <param>
<params>::=
| <param> <empty>
| <params> <param>
<param>::= <list_param>
<list_param> ::= tkIdent <empty>
| <simple_type_expr> <empty>
| tkSquareOpen tkSquareClose
| tkBottomMinus
| tkIdent tkColon <list_param>
| tkBottomMinus tkColon <list_param>
| tkRoundOpen <list_param> tkRoundClose
<guard>::=
| tkSplit <expr>
| tkSplit tkOtherwise
<main_func>::= tkMainIdent1 tkAssign <body_func>
<body_func>::= <stmt>
<stmts>::= <stmt> <empty><empty>
| <stmts> tkSemiColon <stmt>
<stmts1>::= <stmt><empty><empty>
| <stmts1> <stmt>
<expr>::= <expr> tkEqual <add_expr>
| <expr> tkNotEqual <add_expr>
| <expr> tkMore <add_expr>
| <expr> tkLess <add_expr>
| <expr> tkMoreEq <add_expr>
| <expr> tkLessEq <add_expr>
| <add_expr>
<list>::= tkSquareOpen <list_elements> tkSquareClose
| tkSquareOpen <list_elements> tkDot tkDot <simple_expr> tkSquareClose
| tkSquareOpen <list_elements> tkDot tkDot tkSquareClose
| <list_constructor>
| <simple_expr> tkColon <empty> <simple_expr>
<list_constructor>::= tkSquareOpen <simple_expr> tkSplit <generators> <conditions_comma> tkSquareClose
<generators>::= <generator> <empty>
| <generators> tkComma <generator>
<generator>::= <simple_expr> tkArrowGen <simple_expr>
<conditions_comma>::= <empty>
| tkComma <conditions>
<conditions>::= <condition> <empty>
| <conditions> tkComma <condition>
<condition>::= <expr>
<corteg>::= tkRoundOpen <simple_expr> tkComma <list_elements> tkRoundClose
<list_elements>::= <empty>
| <simple_expr> <empty>
| <list_elements> tkComma <simple_expr>
<add_expr>::= <add_expr> tkAnd <mult_expr>
| <add_expr> <addop> <mult_expr>
| <mult_expr>
<mult_expr>::= <mult_expr> tkOr <negate_expr>
| <mult_expr> <multop> <negate_expr>
| <negate_expr>
<negate_expr>::= tkMinus <simple_expr>
| tkNot <simple_expr>
| <simple_expr>
<simple_expr>::= <simple_type_expr>
| tkRoundOpen <expr> tkRoundClose
| <infix_expr><empty>
| <variable>
| tkLet <def_vars> tkIn <body_func>
| <list>
| <corteg>
| <lambda_func> <empty>
| tkRoundOpen tkRoundOpen <lambda_func> tkRoundClose <params_value> tkRoundClose
<simple_type_expr>::=tkInt
| tkDouble
| tkBool
| tkChar
| tkString
<variable_expr>::= <simple_expr>
<def_vars>::= <def_var> <empty>
| <def_vars> tkSemiColon <def_var>
<def_var>::= tkIdent <params> <guard_body_list> <where_var>
<guard_body_list>::= <guard_body><empty>
| <guard_body_list><guard_body>
<guard_body>::= <guard> tkAssign <body_func>
<variable>::= tkIdent
| tkRoundOpen tkIdent <params_value> tkRoundClose
| tkRoundOpen <variable> <params_value> tkRoundClose
| tkRoundOpen tkQuote tkIdent tkQuote <params_value> tkRoundClose
<infix_expr>::= tkRoundOpen <simple_expr> tkQuote tkIdent tkQuote <simple_expr> tkRoundClose
| tkRoundOpen <simple_expr> tkQuote tkIdent tkQuote tkRoundClose
| tkRoundOpen tkRoundOpen <simple_expr> tkQuote tkIdent tkQuote tkRoundClose <params_value> tkRoundClose
<multop>::= tkStar
| tkSlash
<addop>::= tkPlus
| tkMinus
<stmt>::= tkIdent tkArrowGen tkIdent
| tkIf <expr> tkThen <body_func> tkElse <body_func>
| tkCase tkRoundOpen <params1> tkRoundClose tkOf <case_variants>
| tkDo tkFigureOpen <stmts> tkSemiColon tkFigureClose
| tkDo <stmts1>
| tkReturn <expr>
| <func_call>
<case_variants>::= <case_variant> <empty>
| <case_variants> tkSplit <case_variant>
<case_variant>::= tkRoundOpen <params1> tkRoundClose tkArrow <body_func>
<params1>::= <param> <empty>
| <params1> tkComma <param>
<func_call>::= <expr><empty>
<params_value>::=<param_value> <empty>
| <params_value> <param_value>
<param_value>::= <expr><empty>
<lambda_func>::= tkLeftSlash <params> tkArrow <body_func>
<empty>::= ! for rule code call

View file

@ -1,61 +0,0 @@
============================================================
GOLD Parser Builder
Version 3.2.3
============================================================
========================================
Log
========================================
Grammar Details Whitespace was implicitly defined
Grammar Details The grammar contains a total of 52 formal terminals.
Grammar Warning Unreachable rule: <body_where>
Grammar Warning Unreachable rule: <variable_expr>
Grammar Success The grammar was successfully analyzed
LALR States Details The temporary First and Nullable tables were successfully created
LALR States Warning 4 A Shift-Reduce Conflict was fixed
LALR States Warning 19 A Shift-Reduce Conflict was fixed
LALR States Warning 35 A Shift-Reduce Conflict was fixed
LALR States Warning 36 A Shift-Reduce Conflict was fixed
LALR States Warning 69 A Shift-Reduce Conflict was fixed
LALR States Warning 71 A Shift-Reduce Conflict was fixed
LALR States Warning 78 A Shift-Reduce Conflict was fixed
LALR States Warning 81 A Shift-Reduce Conflict was fixed
LALR States Warning 87 A Shift-Reduce Conflict was fixed
LALR States Warning 89 A Shift-Reduce Conflict was fixed
LALR States Warning 108 A Shift-Reduce Conflict was fixed
LALR States Warning 112 A Shift-Reduce Conflict was fixed
LALR States Warning 115 A Shift-Reduce Conflict was fixed
LALR States Warning 116 A Shift-Reduce Conflict was fixed
LALR States Warning 117 A Shift-Reduce Conflict was fixed
LALR States Warning 118 A Shift-Reduce Conflict was fixed
LALR States Warning 123 A Shift-Reduce Conflict was fixed
LALR States Warning 149 A Shift-Reduce Conflict was fixed
LALR States Warning 151 A Shift-Reduce Conflict was fixed
LALR States Warning 169 A Shift-Reduce Conflict was fixed
LALR States Warning 180 A Shift-Reduce Conflict was fixed
LALR States Warning 181 A Shift-Reduce Conflict was fixed
LALR States Warning 182 A Shift-Reduce Conflict was fixed
LALR States Warning 183 A Shift-Reduce Conflict was fixed
LALR States Warning 184 A Shift-Reduce Conflict was fixed
LALR States Warning 185 A Shift-Reduce Conflict was fixed
LALR States Warning 186 A Shift-Reduce Conflict was fixed
LALR States Warning 187 A Shift-Reduce Conflict was fixed
LALR States Warning 223 A Shift-Reduce Conflict was fixed
LALR States Warning 252 A Shift-Reduce Conflict was fixed
LALR States Warning 270 A Shift-Reduce Conflict was fixed
LALR States Details LALR computation took: 0 Hours 0 Minutes 3 Seconds
LALR States Success The LALR Table was succesfully created
LALR States Details Total actions: 968 Shifts, 3725 Reduces, 754 Gotos, 1 Accepts.
DFA States Details The terminal 'Whitespace' is variable length.
DFA States Details The terminal 'tkDouble' is variable length.
DFA States Details The terminal 'tkIdent' is variable length.
DFA States Details The terminal 'tkInt' is variable length.
DFA States Details The terminal 'tkString' is variable length.
DFA States Details The initial Nondeterministic Finite Automata has 338 states
DFA States Success The DFA State Table was successfully created
DFA States Details DFA computation took: 0 Hours 0 Minutes 1 Second
System Complete The grammar was successfully analyzed and the CGT file was created.

View file

@ -1,488 +0,0 @@
##TEMPLATE-NAME 'PascalABC.NET'
##LANGUAGE 'Haskell'
##ENGINE-NAME 'PascalABCNET GOLD Parser Engine'
##AUTHOR 'Tasha'
##FILE-EXTENSION 'cs'
##NOTES
Haskell parser template.
Version 1.0
##END-NOTES
##ID-CASE UPPERCASE
##ID-SEPARATOR '_'
##ID-SYMBOL-PREFIX 'Symbol'
##ID-RULE-PREFIX 'Rule'
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Collections;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.Errors;
using PascalABCCompiler.HaskellParser.Errors;
using PascalABCCompiler.ParserTools;
using GoldParser;
namespace PascalABCCompiler.HaskellParser
{
public partial class GPBParser_Haskell : GPBParser
{
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//SymbolConstants
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
public enum SymbolConstants : int
{
##SYMBOLS
##DELIMITER ','
%ID.Padded% = %Value.Padded%%Delimiter% // %Description%
##END-SYMBOLS
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//RuleConstants
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
public enum RuleConstants : int
{
##RULES
##DELIMITER ','
%ID.Padded% = %Value.Padded%%Delimiter% // %Description%
##END-RULES
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//CreateTerminalObject
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
private Object CreateTerminalObject(int TokenSymbolIndex)
{
switch (TokenSymbolIndex)
{
##SYMBOLS
case (int)SymbolConstants.%ID% :
//%Description%
//TERMINAL:%Name%
return null;
//ENDTERMINAL
##END-SYMBOLS
}
throw new SymbolException("Unknown symbol");
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//CreateNonTerminalObject
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
public ArrayList param_value_list = new ArrayList();
public ArrayList body_variant_list = new ArrayList();
public ArrayList param_value_list_main = new ArrayList();
public ArrayList body_variant_list_main = new ArrayList();
public ArrayList guard_list = new ArrayList();
public ArrayList guard_list_main = new ArrayList();
public ArrayList where_list_var = new ArrayList();
public ArrayList where_list_assign = new ArrayList();
public ArrayList where_list_var_main = new ArrayList();
public ArrayList where_list_assign_main = new ArrayList();
public ArrayList func_name = new ArrayList();
public ArrayList where_list_counts=new ArrayList();
public ArrayList where_list_counts_main = new ArrayList();
public int decls_counts = 0;
public bool where_flag = false;
public ArrayList list_param = new ArrayList();
public ArrayList list_params = new ArrayList();
public ArrayList list_params_temp = new ArrayList();
public ArrayList list_params_main = new ArrayList();
public ArrayList _function_lambda_definitions = new ArrayList();
public ArrayList _function_lambda_definitions_after = new ArrayList();
public int lambda_num = 0;
public ArrayList _functions = new ArrayList();
public ArrayList list_method_calls = new ArrayList();
public ArrayList list_method_calls_main = new ArrayList();
public ArrayList list_return_funcs = new ArrayList();
public ArrayList list_return_funcs_main = new ArrayList();
public ArrayList list_params1 = new ArrayList();
public ArrayList last_function_lambda_definitions = new ArrayList();
public ArrayList last_list_method_calls = new ArrayList();
public ArrayList last_list_method_calls_lambda = new ArrayList();
public ArrayList let_fact_params = new ArrayList();
public ArrayList let_funcs = new ArrayList();
public ArrayList let_funcs_funcs = new ArrayList();
public ArrayList let_func_last = new ArrayList();
public ArrayList let_funcs1 = new ArrayList();
public ArrayList let_flag = new ArrayList();
public struct types_param_lampda
{
public string name;
public ArrayList types;
}
public ArrayList list_method_calls_lambda = new ArrayList();
public Object CreateNonTerminalObject(int ReductionRuleIndex)
{
switch (ReductionRuleIndex)
{
##RULES
case (int)RuleConstants.%ID% :
//%Description%
//NONTERMINAL:%Description%
return null;
//ENDNONTERMINAL
##END-RULES
}
throw new RuleException("Unknown rule");
}
public method_call _ob(object dt)
{
token_info _token_info = new token_info(".");
_token_info.source_context = parsertools.GetTokenSourceContext();
///////////
ident id = new ident("ob");
dot_node _dot_node = new dot_node(null, (addressed_value)id);
parsertools.create_source_context(_dot_node, _token_info, id);
_dot_node.left = (addressed_value)dt;
parsertools.create_source_context(_dot_node, dt, _dot_node.right);
/////////////////////////
expression_list el = new expression_list();
el.expressions.Add(_dot_node);
method_call _method_call = new method_call(el);
parsertools.create_source_context(_method_call, null, null);
/////////////////////////
ident id1 = new ident("boolean");
/////////////////////////
if (_method_call is dereference)
{
((dereference)_method_call).dereferencing_value = (addressed_value)id1;
parsertools.create_source_context(_method_call, id1, _method_call);
}
return _method_call;
}
public procedure_definition lambda(function_lambda_definition _function_lambda_definition)
{
SyntaxTree.procedure_definition _func_def = new PascalABCCompiler.SyntaxTree.procedure_definition();
SyntaxTree.method_name _method_name1 = new SyntaxTree.method_name(null, new SyntaxTree.ident(_function_lambda_definition.lambda_name), null);
SyntaxTree.function_header _function_header1 = new SyntaxTree.function_header();
object rt1 = new object();
_function_header1.name = _method_name1;
SyntaxTree.formal_parametres fps = new PascalABCCompiler.SyntaxTree.formal_parametres();
_function_header1.parametres = _function_lambda_definition.formal_parametres;//fps;
SyntaxTree.named_type_reference _named_type_reference = new SyntaxTree.named_type_reference();
SyntaxTree.ident idtype = new SyntaxTree.ident("datatype");
_named_type_reference.source_context = idtype.source_context;
_named_type_reference.names.Add(idtype);
rt1 = _named_type_reference;
_function_header1.return_type = (SyntaxTree.type_definition)_named_type_reference;
_function_header1.of_object = false;
_function_header1.class_keyword = false;
SyntaxTree.block _block1 = new SyntaxTree.block(null, null);
SyntaxTree.statement_list sl1 = new SyntaxTree.statement_list();
sl1.subnodes.Add(_function_lambda_definition.proc_body);
_block1.program_code = sl1;
_func_def.proc_header = _function_header1;
_func_def.proc_body = (SyntaxTree.proc_block)_block1;
_function_lambda_definition.proc_definition = _func_def;
return _func_def;
}
public procedure_definition find_function1(string name)
{
int i = 0;
while (i < _functions.Count && ((procedure_definition)_functions[i]).proc_header.name.meth_name.name != name)
i++;
if (i < _functions.Count)
return (procedure_definition)_functions[i];
else
return null;
}
public int find_count_params(string name)
{
if (param_value_list_main.Count == 0 && param_value_list.Count == 0)
{
int i = 0;
while (i < _functions.Count && ((procedure_definition)_functions[i]).proc_header.name.meth_name.name != name)
i++;
if (i < _functions.Count)
{
if (((procedure_definition)_functions[i]).proc_header.parametres == null)
return 0;
else
return ((procedure_definition)_functions[i]).proc_header.parametres.params_list.Count;
}
else
return 0;
}
else
{
int i = 0;
while (i < func_name.Count && ((ident)func_name[i]).name != name)
i++;
if (i < func_name.Count)
{
if (i >= param_value_list_main.Count)
{
if (i >= param_value_list_main.Count)
//if (param_value_list_main.Count==0)
{
if (param_value_list[param_value_list.Count - 1] == null)
return 0;
else
return ((expression_list)param_value_list[param_value_list.Count - 1]).expressions.Count;
}
else
return 0;
}
else
{
if (((ArrayList)param_value_list_main[i])[((ArrayList)param_value_list_main[i]).Count - 1] == null)
return 0;
else
return ((expression_list)((ArrayList)param_value_list_main[i])[((ArrayList)param_value_list_main[i]).Count - 1]).expressions.Count;
}
}
else
return 0;
}
}
public int find_count_params_lambda(string name)
{
int i = 0;
while (i < _function_lambda_definitions_after.Count && ((function_lambda_definition)_function_lambda_definitions_after[i]).lambda_name != name)
i += 2;
if (i < _function_lambda_definitions_after.Count)
return ((function_lambda_definition)_function_lambda_definitions_after[i]).formal_parametres.params_list.Count;
else
return -1;
}
public string find_name_params_lambda(string name, int ind)
{
int i = 0;
while (i < _function_lambda_definitions_after.Count && ((function_lambda_definition)_function_lambda_definitions_after[i]).lambda_name != name)
i += 2;
if (i < _function_lambda_definitions_after.Count)
{
formal_parametres fp = ((function_lambda_definition)_function_lambda_definitions_after[i]).formal_parametres;
if (ind < fp.params_list.Count)
return fp.params_list[ind].idents.idents[0].name;
else
return "";
}
else
return "";
}
public bool find_func_name(string name)
{
int i = 0;
while (i < func_name.Count && ((ident)func_name[i]).name != name)
i++;
if (i < func_name.Count)
return true;
else
return false;
}
public function_lambda_definition find_func_lambda_name(string name)
{
int i = 0;
while (i < _function_lambda_definitions.Count && ((function_lambda_definition)_function_lambda_definitions[i]).lambda_name != name)
i++;
if (i < _function_lambda_definitions.Count)
return (function_lambda_definition)_function_lambda_definitions[i];
else
return null;
}
public type_definition func_type(int count)
{
//int count = mc.parametres.expressions.Count;
formal_parametres _formal_parametres = new formal_parametres();
for (int i = 0; i < count; i++)
{
ident_list _ident_list = new ident_list();
ident id = new ident("$a" + i.ToString());
_ident_list.idents.Add(id);
named_type_reference _named_type_reference1 = new named_type_reference();
ident idtype1 = new ident("datatype");
_named_type_reference1.names.Add(idtype1);
typed_parametres _typed_parametres = new typed_parametres(_ident_list, (type_definition)_named_type_reference1, parametr_kind.none, null);
_formal_parametres.params_list.Add(_typed_parametres);
}
named_type_reference _named_type_reference = new named_type_reference();
ident idtype = new ident("datatype");
_named_type_reference.names.Add(idtype);
function_header _function_header = new function_header();
_function_header.parametres = _formal_parametres;
_function_header.return_type = (type_definition)_named_type_reference;
_function_header.of_object = false;
_function_header.class_keyword = false;
return (type_definition)_function_header;
}
public var_statement var_st(string name, type_definition td)
{
ident_list il = new ident_list();
il.idents.Add(new ident(name));
var_def_statement _var_def_statement = new var_def_statement(il, td, null, definition_attribute.None, false);
return new var_statement(_var_def_statement);
}
public method_call find_method_call(string name, int k)
{
int i = 0;
while (i < ((ArrayList)list_method_calls_main[k]).Count &&
((ident)((method_call)((ArrayList)list_method_calls_main[k])[i]).dereferencing_value).name != name)
i++;
if (i < ((ArrayList)list_method_calls_main[k]).Count)
return (method_call)((ArrayList)list_method_calls_main[k])[i];
else
return null;
}
public method_call find_method_call_lambda(string name)
{
int i = 0;
while (i < list_method_calls_lambda.Count &&
((ident)((method_call)list_method_calls_lambda[i]).dereferencing_value).name != name)
i++;
if (i < list_method_calls_lambda.Count)
return (method_call)list_method_calls_lambda[i];
else
return null;
}
public function_lambda_definition find_func_lambda_after(string name)
{
int i = 0;
while (i < _function_lambda_definitions_after.Count &&
((function_lambda_definition)_function_lambda_definitions_after[i]).lambda_name != name)
i += 2;
if (i < _function_lambda_definitions_after.Count)
return _function_lambda_definitions_after[i] as function_lambda_definition;
else
return null;
}
public ArrayList find_params(string name)
{
ArrayList _params = new ArrayList();
if (param_value_list_main.Count == 0 && param_value_list.Count == 0)
{
int i = 0;
while (i < _functions.Count && ((procedure_definition)_functions[i]).proc_header.name.meth_name.name != name)
i++;
if (i < _functions.Count)
{
if (((procedure_definition)_functions[i]).proc_header.parametres == null)
return _params;
else
{
for (int j = 0; j < ((procedure_definition)_functions[i]).proc_header.parametres.params_list.Count; j++)
_params.Add(((procedure_definition)_functions[i]).proc_header.parametres.params_list[j]);
return _params;
}
}
else
return _params;
}
else
{
int i = 0;
while (i < func_name.Count && ((ident)func_name[i]).name != name)
i++;
if (i < func_name.Count)
{
if (i >= param_value_list_main.Count)
{
if (i >= param_value_list_main.Count)
//if (param_value_list_main.Count==0)
{
if (param_value_list[param_value_list.Count - 1] == null)
return _params;
else
{
for (int j = 0; j < ((expression_list)param_value_list[param_value_list.Count - 1]).expressions.Count; j++)
_params.Add(((expression_list)param_value_list[param_value_list.Count - 1]).expressions[j]);
return _params;
}
}
else
return _params;
}
else
{
if (((ArrayList)param_value_list_main[i])[((ArrayList)param_value_list_main[i]).Count - 1] == null)
return _params;
else
{
for (int j = 0; j < ((expression_list)((ArrayList)param_value_list_main[i])[((ArrayList)param_value_list_main[i]).Count - 1]).expressions.Count; j++)
_params.Add(((expression_list)((ArrayList)param_value_list_main[i])[((ArrayList)param_value_list_main[i]).Count - 1]).expressions[j]);
return _params;
}
}
}
else
return _params;
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,445 +0,0 @@
{
//////////////////////////head
method_name _method_name = new method_name(null, (ident)LRParser.GetReductionSyntaxNode(0), null);
parsertools.create_source_context(_method_name, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
function_header _function_header = new function_header();
object rt = LRParser.GetReductionSyntaxNode(2);
_function_header.name = _method_name;
if (_function_header.name.meth_name is template_type_name)
{
_function_header.template_args = (_function_header.name.meth_name as template_type_name).template_args;
ident id = new ident(_function_header.name.meth_name.name);
parsertools.create_source_context(id, _function_header.name.meth_name, _function_header.name.meth_name);
_function_header.name.meth_name = id;
}
if (LRParser.GetReductionSyntaxNode(1)!=null) {
rt=LRParser.GetReductionSyntaxNode(1);
_function_header.parametres=(formal_parametres)LRParser.GetReductionSyntaxNode(1);
}
named_type_reference _named_type_reference = new named_type_reference();
ident idtype = new ident("integer");
_named_type_reference.source_context = idtype.source_context;
_named_type_reference.names.Add(idtype);
rt=_named_type_reference;
_function_header.return_type=(type_definition)_named_type_reference;
_function_header.of_object = false;
_function_header.class_keyword = false;
token_info _token_info = new token_info("function");
_token_info.source_context = parsertools.GetTokenSourceContext();
parsertools.create_source_context(_function_header, _token_info, rt);
//////////////////////////////////////block
block _block = new block(null, null);
statement_list sl = null;
if (LRParser.GetReductionSyntaxNode(3) is statement_list)
sl = LRParser.GetReductionSyntaxNode(3) as statement_list;
else
{
sl = new statement_list();
sl.subnodes.Add(LRParser.GetReductionSyntaxNode(3) as statement);
if (!(LRParser.GetReductionSyntaxNode(3) is empty_statement))
parsertools.assign_source_context(sl, LRParser.GetReductionSyntaxNode(3));
}
_block.program_code = sl;
//////////////////
procedure_definition _procedure_definition = new procedure_definition(_function_header, null);
rt = _function_header;
if (_block != null)
{
rt = _block;
if (_block is proc_block)
_procedure_definition.proc_body = (proc_block)_block;
}
parsertools.create_source_context(_procedure_definition, _function_header, rt);
return _procedure_definition;
}
/////////////////////////////////////////////////////////////////////////////////
{
//////////////////////////head
method_name _method_name = new method_name(null, func_name, null);
parsertools.create_source_context(_method_name, func_name, func_name);
function_header _function_header = new function_header();
object rt = new object();
_function_header.name = _method_name;
if (_function_header.name.meth_name is template_type_name)
{
_function_header.template_args = (_function_header.name.meth_name as template_type_name).template_args;
ident id = new ident(_function_header.name.meth_name.name);
parsertools.create_source_context(id, _function_header.name.meth_name, _function_header.name.meth_name);
_function_header.name.meth_name = id;
}
////////////////////////////////params
formal_parametres _formal_parametres = new formal_parametres();
expression_list f = (expression_list)param_value_list[param_value_list.Count-1];
for (int i = 0; i < f.expressions.Count; i++)
{
ident_list _ident_list = new ident_list();
_ident_list.source_context = ((ident)f.expressions[i]).source_context;
_ident_list.idents.Add((ident)f.expressions[i]);
named_type_reference _named_type_reference1 = new named_type_reference();
ident idtype1 = new ident("integer");
_named_type_reference1.source_context = idtype1.source_context;
_named_type_reference1.names.Add(idtype1);
typed_parametres _typed_parametres = new typed_parametres(_ident_list, (type_definition)_named_type_reference1, parametr_kind.none, null);
parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference1);
_formal_parametres.params_list.Add(_typed_parametres);
}
_function_header.parametres = _formal_parametres;
//////////////////////////type
named_type_reference _named_type_reference = new named_type_reference();
ident idtype = new ident("integer");
_named_type_reference.source_context = idtype.source_context;
_named_type_reference.names.Add(idtype);
rt=_named_type_reference;
_function_header.return_type=(type_definition)_named_type_reference;
_function_header.of_object = false;
_function_header.class_keyword = false;
token_info _token_info = new token_info("function");
_token_info.source_context = parsertools.GetTokenSourceContext();
parsertools.create_source_context(_function_header, _token_info, rt);
//////////////////////////////////////block
statement_list stmt_l = new statement_list();
for (int i=0;i<param_value_list.Count;i++)
{
expression_list pv = (expression_list)param_value_list[i];
statement body_part = (statement)body_variant_list[i];
for (int j=0;j<pv.expressions.Count;j++)
{
typed_parametres tp = (typed_parametres)_function_header.parametres.params_list[j];
if (!(pv.expressions[j] is ident))//vstavka if (vyhod iz rekursii)
{
if_node _if_node = new if_node(null, body_part, null);
parsertools.create_source_context(_if_node, null, parsertools.sc_not_null(body_part, null));
op_type_node _op_type_node = new op_type_node(Operators.Equal);
_op_type_node.source_context = parsertools.GetTokenSourceContext();
bin_expr _bin_expr = new bin_expr(tp.idents.idents[0] as expression, (expression)pv.expressions[j], _op_type_node.type);
parsertools.create_source_context(_bin_expr, tp.idents.idents[0], pv.expressions[j]);
_if_node.condition = (expression)_bin_expr;
parsertools.create_source_context(_if_node, null, _if_node);
body_part = (statement)_if_node;
}
}
stmt_l.subnodes.Add(body_part);
}
block _block = new block(null, null);
statement_list sl = null;
if (stmt_l is statement_list)
sl = stmt_l as statement_list;
else
{
sl = new statement_list();
sl.subnodes.Add(stmt_l as statement);
if (!(stmt_l is empty_statement))
parsertools.assign_source_context(sl, stmt_l);
}
_block.program_code = sl;
//////////////////
procedure_definition _procedure_definition = new procedure_definition(_function_header, null);
rt = _function_header;
if (_block != null)
{
rt = _block;
if (_block is proc_block)
_procedure_definition.proc_body = (proc_block)_block;
}
parsertools.create_source_context(_procedure_definition, _function_header, rt);
return _procedure_definition;
}
////////////////////////////////////////////////////////////////////////////
{
//////////////////////////head
method_name _method_name = new method_name(null, func_name, null);
parsertools.create_source_context(_method_name, func_name, func_name);
function_header _function_header = new function_header();
object rt = new object();
_function_header.name = _method_name;
if (_function_header.name.meth_name is template_type_name)
{
_function_header.template_args = (_function_header.name.meth_name as template_type_name).template_args;
ident id = new ident(_function_header.name.meth_name.name);
parsertools.create_source_context(id, _function_header.name.meth_name, _function_header.name.meth_name);
_function_header.name.meth_name = id;
}
////////////////////////////////params
formal_parametres _formal_parametres = new formal_parametres();
expression_list f = (expression_list)param_value_list[param_value_list.Count-1];
if (f != null)
{
for (int i = 0; i < f.expressions.Count; i++)
{
ident_list _ident_list = new ident_list();
_ident_list.source_context = ((ident)f.expressions[i]).source_context;
_ident_list.idents.Add((ident)f.expressions[i]);
named_type_reference _named_type_reference1 = new named_type_reference();
ident idtype1 = new ident("integer");
_named_type_reference1.source_context = idtype1.source_context;
_named_type_reference1.names.Add(idtype1);
typed_parametres _typed_parametres = new typed_parametres(_ident_list, (type_definition)_named_type_reference1, parametr_kind.none, null);
parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference1);
_formal_parametres.params_list.Add(_typed_parametres);
}
_function_header.parametres = _formal_parametres;
}
//////////////////////////type
named_type_reference _named_type_reference = new named_type_reference();
ident idtype = new ident("integer");
_named_type_reference.source_context = idtype.source_context;
_named_type_reference.names.Add(idtype);
rt=_named_type_reference;
_function_header.return_type=(type_definition)_named_type_reference;
_function_header.of_object = false;
_function_header.class_keyword = false;
token_info _token_info = new token_info("function");
_token_info.source_context = parsertools.GetTokenSourceContext();
parsertools.create_source_context(_function_header, _token_info, rt);
//////////////////////////////////////block
statement_list stmt_l = new statement_list();
statement last_if = (statement)body_variant_list[body_variant_list.Count-1];
for (int i = param_value_list.Count-2; i >= 0; i--)
{
expression_list pv = (expression_list)param_value_list[i];
statement body_part = (statement)body_variant_list[i];
if_node _if_node = new if_node(null, body_part, last_if);
parsertools.create_source_context(_if_node, null, parsertools.sc_not_null(body_part, last_if));
ident id_true = new ident("true");
expression last_expr = id_true as expression;
for (int j = 0; j < pv.expressions.Count; j++)
{
typed_parametres tp = (typed_parametres)_function_header.parametres.params_list[j];
if (!(pv.expressions[j] is ident))//vstavka if (vyhod iz rekursii)
{
op_type_node _op_type_node = new op_type_node(Operators.Equal);
_op_type_node.source_context = parsertools.GetTokenSourceContext();
bin_expr _bin_expr = new bin_expr(tp.idents.idents[0] as expression, (expression)pv.expressions[j], _op_type_node.type);
parsertools.create_source_context(_bin_expr, tp.idents.idents[0], pv.expressions[j]);
op_type_node _op_type_node1 = new op_type_node(Operators.LogicalAND);
_op_type_node1.source_context = parsertools.GetTokenSourceContext();
bin_expr _bin_expr1 = new bin_expr(_bin_expr, last_expr, _op_type_node1.type);
parsertools.create_source_context(_bin_expr1, _bin_expr, last_expr);
last_expr = _bin_expr1;
}
}
_if_node.condition = last_expr;
parsertools.create_source_context(_if_node, null, _if_node);
last_if = _if_node;
}
stmt_l.subnodes.Add(last_if);
block _block = new block(null, null);
statement_list sl = null;
if (stmt_l is statement_list)
sl = stmt_l as statement_list;
else
{
sl = new statement_list();
sl.subnodes.Add(stmt_l as statement);
if (!(stmt_l is empty_statement))
parsertools.assign_source_context(sl, stmt_l);
}
_block.program_code = sl;
//////////////////
procedure_definition _procedure_definition = new procedure_definition(_function_header, null);
rt = _function_header;
if (_block != null)
{
rt = _block;
if (_block is proc_block)
_procedure_definition.proc_body = (proc_block)_block;
}
parsertools.create_source_context(_procedure_definition, _function_header, rt);
param_value_list.Clear();
body_variant_list.Clear();
return _procedure_definition;
}
/////////////////////////////////////////////////////////////////////
{
//////////////////////////head
/*ident_list il = new ident_list();
il.idents.Add(new ident("T"));
template_type_name _template_type_name = new template_type_name(il);
_template_type_name.name = func_name.name;
parsertools.create_source_context(_template_type_name, func_name, il);*/
method_name _method_name = new method_name(null, func_name, null);
parsertools.create_source_context(_method_name, func_name, func_name);
function_header _function_header = new function_header();
object rt = new object();
_function_header.name = _method_name;
if (_function_header.name.meth_name is template_type_name)
{
_function_header.template_args = (_function_header.name.meth_name as template_type_name).template_args;
ident id = new ident(_function_header.name.meth_name.name);
parsertools.create_source_context(id, _function_header.name.meth_name, _function_header.name.meth_name);
_function_header.name.meth_name = id;
}
////////////////////////////////params
formal_parametres _formal_parametres = new formal_parametres();
expression_list f = (expression_list)param_value_list[param_value_list.Count - 1];
if (f != null)
{
for (int i = 0; i < f.expressions.Count; i++)
{
ident_list _ident_list = new ident_list();
if (f.expressions[i] is ident)
{
_ident_list.source_context = ((ident)f.expressions[i]).source_context;
_ident_list.idents.Add((ident)f.expressions[i]);
}
else
{
int i1=0;
expression_list el = (expression_list)param_value_list[0];
while (i1 < param_value_list.Count && !(el.expressions[i] is ident))
{
i1++;
el = (expression_list)param_value_list[i1];
}
if (i1 < param_value_list.Count)
{
_ident_list.source_context = (el.expressions[i]).source_context;
_ident_list.idents.Add(el.expressions[i] as ident);
}
}
named_type_reference _named_type_reference1 = new named_type_reference();
ident idtype1 = new ident("integer");
_named_type_reference1.source_context = idtype1.source_context;
_named_type_reference1.names.Add(idtype1);
typed_parametres _typed_parametres = new typed_parametres(_ident_list, (type_definition)_named_type_reference1, parametr_kind.none, null);
parsertools.create_source_context(_typed_parametres, _ident_list, _named_type_reference1);
_formal_parametres.params_list.Add(_typed_parametres);
}
_function_header.parametres = _formal_parametres;
}
//////////////////////////type
named_type_reference _named_type_reference = new named_type_reference();
ident idtype = new ident("integer");
_named_type_reference.source_context = idtype.source_context;
_named_type_reference.names.Add(idtype);
rt = _named_type_reference;
_function_header.return_type = (type_definition)_named_type_reference;
_function_header.of_object = false;
_function_header.class_keyword = false;
token_info _token_info = new token_info("function");
_token_info.source_context = parsertools.GetTokenSourceContext();
parsertools.create_source_context(_function_header, _token_info, rt);
//////////////////////////////////////block
statement_list stmt_l = new statement_list();
statement last_if = (statement)body_variant_list[body_variant_list.Count - 1];
for (int i = param_value_list.Count - 2; i >= 0; i--)
{
expression_list pv = (expression_list)param_value_list[i];
statement body_part = (statement)body_variant_list[i];
if_node _if_node = new if_node(null, body_part, last_if);
parsertools.create_source_context(_if_node, null, parsertools.sc_not_null(body_part, last_if));
ident id_true = new ident("true");
expression last_expr = id_true as expression;
for (int j = 0; j < pv.expressions.Count; j++)
{
typed_parametres tp = (typed_parametres)_function_header.parametres.params_list[j];
if (!(pv.expressions[j] is ident))//vstavka if (vyhod iz rekursii)
{
op_type_node _op_type_node = new op_type_node(Operators.Equal);
_op_type_node.source_context = parsertools.GetTokenSourceContext();
bin_expr _bin_expr = new bin_expr(tp.idents.idents[0] as expression, (expression)pv.expressions[j], _op_type_node.type);
parsertools.create_source_context(_bin_expr, tp.idents.idents[0], pv.expressions[j]);
op_type_node _op_type_node1 = new op_type_node(Operators.LogicalAND);
_op_type_node1.source_context = parsertools.GetTokenSourceContext();
bin_expr _bin_expr1 = new bin_expr(_bin_expr, last_expr, _op_type_node1.type);
parsertools.create_source_context(_bin_expr1, _bin_expr, last_expr);
last_expr = _bin_expr1;
}
}
_if_node.condition = last_expr;
////ââîä íîâûõ ïåðåìåííûõ
/*for (int j = 0; j < pv.expressions.Count; j++)
{
if (pv.expressions[j] is ident && ((ident)pv.expressions[j]).name!=_function_header.parametres.params_list[j].idents.idents[0].name)
{
ident_list il = new ident_list();
il.idents.Add(new ident(((ident)pv.expressions[j]).name));
named_type_reference _named_type_reference1 = new named_type_reference();
ident idtype1 = new ident("integer");
_named_type_reference1.source_context = idtype1.source_context;
_named_type_reference1.names.Add(idtype1);
var_def_statement _var_def_statement = new var_def_statement(il, (type_definition)_named_type_reference1, null, definition_attribute.None, false);
parsertools.create_source_context(_var_def_statement, il, _named_type_reference1);
var_statement _var_statement = new var_statement(_var_def_statement);
parsertools.create_source_context(_var_statement, null, _var_def_statement);
((statement_list)_if_node.then_body).subnodes.Insert(0, _var_statement);//obyavlenie peremennoy
op_type_node _op_type_node2 = new op_type_node(Operators.Assignment);
_op_type_node2.source_context = parsertools.GetTokenSourceContext();
assign _assign = new assign(il.idents[0] as addressed_value, _function_header.parametres.params_list[j].idents.idents[0] as expression, _op_type_node2.type);
parsertools.create_source_context(_assign, il.idents[0], _function_header.parametres.params_list[j].idents.idents[0]);
((statement_list)_if_node.then_body).subnodes.Insert(1, _assign);
}
}*/
////
parsertools.create_source_context(_if_node, null, _if_node);
last_if = _if_node;
}
stmt_l.subnodes.Add(last_if);
block _block = new block(null, null);
statement_list sl = null;
if (stmt_l is statement_list)
sl = stmt_l as statement_list;
else
{
sl = new statement_list();
sl.subnodes.Add(stmt_l as statement);
if (!(stmt_l is empty_statement))
parsertools.assign_source_context(sl, stmt_l);
}
_block.program_code = sl;
//////////////////
procedure_definition _procedure_definition = new procedure_definition(_function_header, null);
rt = _function_header;
if (_block != null)
{
rt = _block;
if (_block is proc_block)
_procedure_definition.proc_body = (proc_block)_block;
}
parsertools.create_source_context(_procedure_definition, _function_header, rt);
param_value_list.Clear();
body_variant_list.Clear();
return _procedure_definition;
}

Binary file not shown.

View file

@ -1,108 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{35F1E213-0BEA-4C12-B004-129EA088CD75}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BFParser</RootNamespace>
<AssemblyName>BFParser</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>4.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="SyntaxTree, Version=1.0.2518.2974, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\bin\SyntaxTree.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BF_lrparser.cs" />
<Compile Include="BFParserTools.cs" />
<Compile Include="Parser.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="BFLang.resources" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Errors\Errors.csproj">
<Project>{44A01F9E-DCE7-470C-AAE5-C3DE0CCBEE3B}</Project>
<Name>Errors</Name>
</ProjectReference>
<ProjectReference Include="..\..\ParserTools\ParserTools.csproj">
<Project>{AF2EFD7B-69DD-4B43-AF65-B59B29349C23}</Project>
<Name>ParserTools</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>Клиентский профиль .NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Установщик Windows 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -1,21 +0,0 @@
using System;
using System.Text;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.ParserTools;
using GoldParser;
namespace PascalABCCompiler.BFParser
{
public class BF_parsertools:parser_tools
{
public override string symbol_to_string(Symbol symbol)
{
return null;
}
public override int symbol_priority(Symbol symbol)
{
return 0;
}
}
}

View file

@ -1,492 +0,0 @@
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Collections;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.Errors;
using PascalABCCompiler.ParserTools;
using GoldParser;
namespace PascalABCCompiler.BFParser
{
public class GPBParser_BF:GPBParser
{
private Stack NodesStack;
private int operation_value=0;
private object left_node,right_node;
public GPBParser_BF(Stream stream)
:base(stream)
{
parsertools = new BF_parsertools();
}
public object Parse(string source)
{
NodesStack = new Stack();
LRParser = new Parser(new StringReader(source), LanguageGrammar);
parsertools.parser = LRParser;
LRParser.TrimReductions = false;
while (true)
{
switch (LRParser.Parse())
{
case ParseMessage.LexicalError:
errors.Add(new TokenReadError(this));
LRParser.PopInputToken();
if (errors.Count > max_errors)
return null;
break;
case ParseMessage.SyntaxError:
prev_node = LRParser.TokenSyntaxNode;
Error er = new UnexpectedToken(this,parsertools.symbol_collection_to_string(this.LRParser.GetExpectedTokens()));
Symbol sym = LRParser.PopInputToken();
if (sym.SymbolType == SymbolType.End && errors.Count > 0)
return null;
errors.Add(er);
if (errors.Count > max_errors)
return null;
break;
case ParseMessage.Reduction:
LRParser.TokenSyntaxNode = CreateNonTerminalObject();
break;
case ParseMessage.Accept:
return LRParser.TokenSyntaxNode;
case ParseMessage.TokenRead:
LRParser.TokenSyntaxNode = CreateTerminalObject();
break;
case ParseMessage.InternalError:
errors.Add(new CompilerInternalError("PascalABCParser", new Exception("ParseMessage.InternalError")));
return null;
case ParseMessage.NotLoadedError:
errors.Add(new CompilerInternalError("PascalABCParser", new Exception("ParseMessage.NotLoadedError")));
return null;
case ParseMessage.CommentError:
errors.Add(new UnexpectedToken(this,"(EOF)"));
return null;
/*case ParseMessage.CommentBlockRead:
break;
case ParseMessage.CommentLineRead:
break;*/
}
}
}
public enum SymbolConstants : int
{
SYMBOL_EOF = 0, // (EOF)
SYMBOL_ERROR = 1, // (Error)
SYMBOL_WHITESPACE = 2, // (Whitespace)
SYMBOL_TKDEC = 3, // 'tkDec'
SYMBOL_TKDECVALUE = 4, // 'tkDecValue'
SYMBOL_TKINC = 5, // 'tkInc'
SYMBOL_TKINCVALUE = 6, // 'tkIncValue'
SYMBOL_TKJMPPAST = 7, // 'tkJMPPast'
SYMBOL_TKJMPRET = 8, // 'tkJMPRet'
SYMBOL_TKREAD = 9, // 'tkRead'
SYMBOL_TKWRITE = 10, // 'tkWrite'
SYMBOL_BF = 11, // <BF>
SYMBOL_BF_EMPTY_INSTRUCTION = 12, // <bf_empty_instruction>
SYMBOL_BF_INSTRUCTION = 13, // <bf_instruction>
SYMBOL_BF_INSTRUCTIONS = 14, // <bf_instructions>
SYMBOL_BF_INSTRUCTIONS_LIST = 15, // <bf_instructions_list>
SYMBOL_CHANGE_POS = 16, // <change_pos>
SYMBOL_CHANGE_POS_LIST = 17, // <change_pos_list>
SYMBOL_CHANGE_VALUE = 18, // <change_value>
SYMBOL_CHANGE_VALUE_LIST = 19 // <change_value_list>
};
public enum RuleConstants : int
{
RULE_BF = 0, // <BF> ::= <bf_instructions>
RULE_BF_EMPTY_INSTRUCTION = 1, // <bf_empty_instruction> ::=
RULE_BF_INSTRUCTIONS = 2, // <bf_instructions> ::= <bf_instructions_list>
RULE_BF_INSTRUCTIONS2 = 3, // <bf_instructions> ::= <bf_empty_instruction>
RULE_BF_INSTRUCTIONS_LIST = 4, // <bf_instructions_list> ::= <bf_instruction>
RULE_BF_INSTRUCTIONS_LIST2 = 5, // <bf_instructions_list> ::= <bf_instructions_list> <bf_instruction>
RULE_CHANGE_POS_LIST = 6, // <change_pos_list> ::= <change_pos>
RULE_CHANGE_POS_LIST2 = 7, // <change_pos_list> ::= <change_pos_list> <change_pos>
RULE_CHANGE_VALUE_LIST = 8, // <change_value_list> ::= <change_value>
RULE_CHANGE_VALUE_LIST2 = 9, // <change_value_list> ::= <change_value_list> <change_value>
RULE_CHANGE_POS_TKINC = 10, // <change_pos> ::= 'tkInc'
RULE_CHANGE_POS_TKDEC = 11, // <change_pos> ::= 'tkDec'
RULE_CHANGE_VALUE_TKINCVALUE = 12, // <change_value> ::= 'tkIncValue'
RULE_CHANGE_VALUE_TKDECVALUE = 13, // <change_value> ::= 'tkDecValue'
RULE_BF_INSTRUCTION_TKJMPPAST_TKJMPRET = 14, // <bf_instruction> ::= 'tkJMPPast' <bf_instructions> 'tkJMPRet'
RULE_BF_INSTRUCTION = 15, // <bf_instruction> ::= <change_pos_list>
RULE_BF_INSTRUCTION2 = 16, // <bf_instruction> ::= <change_value_list>
RULE_BF_INSTRUCTION_TKWRITE = 17, // <bf_instruction> ::= 'tkWrite'
RULE_BF_INSTRUCTION_TKREAD = 18 // <bf_instruction> ::= 'tkRead'
};
private Object CreateTerminalObject()
{
switch ((SymbolConstants) LRParser.TokenSymbol.Index)
{
case SymbolConstants.SYMBOL_EOF :
//(EOF)
//TERMINAL:EOF
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_ERROR :
//(Error)
//TERMINAL:Error
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_WHITESPACE :
//(Whitespace)
/*Console.Error.WriteLine("\n\rwarning: TerminalToken 'Whitespace' return NULL! \n\r");*/return null;
case SymbolConstants.SYMBOL_TKDEC :
//'tkDec'
{
token_info _token_info=new token_info(LRParser.TokenText);
_token_info.source_context=parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_TKDECVALUE :
//'tkDecValue'
{
token_info _token_info=new token_info(LRParser.TokenText);
_token_info.source_context=parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_TKINC :
//'tkInc'
{
token_info _token_info=new token_info(LRParser.TokenText);
_token_info.source_context=parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_TKINCVALUE :
//'tkIncValue'
{
token_info _token_info=new token_info(LRParser.TokenText);
_token_info.source_context=parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_TKJMPPAST :
//'tkJMPPast'
{
token_info _token_info=new token_info(LRParser.TokenText);
_token_info.source_context=parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_TKJMPRET :
//'tkJMPRet'
{
token_info _token_info=new token_info(LRParser.TokenText);
_token_info.source_context=parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_TKREAD :
//'tkRead'
{
token_info _token_info=new token_info(LRParser.TokenText);
_token_info.source_context=parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_TKWRITE :
//'tkWrite'
{
token_info _token_info=new token_info(LRParser.TokenText);
_token_info.source_context=parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_BF :
//<BF>
//TERMINAL:BF
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_BF_EMPTY_INSTRUCTION :
//<bf_empty_instruction>
//TERMINAL:bf_empty_instruction
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_BF_INSTRUCTION :
//<bf_instruction>
//TERMINAL:bf_instruction
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_BF_INSTRUCTIONS :
//<bf_instructions>
//TERMINAL:bf_instructions
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_BF_INSTRUCTIONS_LIST :
//<bf_instructions_list>
//TERMINAL:bf_instructions_list
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_CHANGE_POS :
//<change_pos>
//TERMINAL:change_pos
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_CHANGE_POS_LIST :
//<change_pos_list>
//TERMINAL:change_pos_list
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_CHANGE_VALUE :
//<change_value>
//TERMINAL:change_value
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_CHANGE_VALUE_LIST :
//<change_value_list>
//TERMINAL:change_value_list
return null;
//ENDTERMINAL
}
throw new SymbolException("Unknown symbol");
}
public Object CreateNonTerminalObject()
{
switch ((RuleConstants) LRParser.ReductionRule.Index)
{
case RuleConstants.RULE_BF :
//<BF> ::= <bf_instructions>
{
program_module _program_module=new program_module();
_program_module.Language = LanguageId.PascalABCNET;
ident BFSystem=new ident("BFSystem");
unit_or_namespace unit=new unit_or_namespace();
unit.name = new ident_list();
unit.name.idents.Add(BFSystem);
uses_list used_units=new uses_list();
used_units.units.Add(unit);
block program_block=new block(null,(statement_list)LRParser.GetReductionSyntaxNode(0));
_program_module.used_units=used_units;
_program_module.program_block=program_block;
used_units.source_context=unit.source_context=BFSystem.source_context=new SourceContext(1,1,1,1,1,1);
parsertools.create_source_context(program_block,LRParser.GetReductionSyntaxNode(0),LRParser.GetReductionSyntaxNode(0));
parsertools.create_source_context(_program_module,LRParser.GetReductionSyntaxNode(0),LRParser.GetReductionSyntaxNode(0));
operation_value=0;
return _program_module;
}
case RuleConstants.RULE_BF_EMPTY_INSTRUCTION :
//<bf_empty_instruction> ::=
//NONTERMINAL:<bf_empty_instruction> ::=
return null;
//ENDNONTERMINAL
case RuleConstants.RULE_BF_INSTRUCTIONS :
//<bf_instructions> ::= <bf_instructions_list>
return LRParser.GetReductionSyntaxNode(0);
case RuleConstants.RULE_BF_INSTRUCTIONS2 :
//<bf_instructions> ::= <bf_empty_instruction>
{
statement_list _statement_list=new statement_list();
_statement_list.subnodes.Add(new empty_statement());
return _statement_list;
}
case RuleConstants.RULE_BF_INSTRUCTIONS_LIST :
//<bf_instructions_list> ::= <bf_instruction>
//TemplateList for statement_list (create)
{
statement_list _statement_list=new statement_list();
_statement_list.source_context=((statement)LRParser.GetReductionSyntaxNode(0)).source_context;
_statement_list.subnodes.Add((statement)LRParser.GetReductionSyntaxNode(0));
return _statement_list;
}
case RuleConstants.RULE_BF_INSTRUCTIONS_LIST2 :
//<bf_instructions_list> ::= <bf_instructions_list> <bf_instruction>
//TemplateList for statement_list (add)
{
statement_list _statement_list=(statement_list)LRParser.GetReductionSyntaxNode(0);
parsertools.create_source_context(_statement_list,_statement_list,LRParser.GetReductionSyntaxNode(1));
_statement_list.subnodes.Add((statement)LRParser.GetReductionSyntaxNode(1));
return _statement_list;
}
case RuleConstants.RULE_CHANGE_POS_LIST :
//<change_pos_list> ::= <change_pos>
left_node=right_node=LRParser.GetReductionSyntaxNode(0); return null;
case RuleConstants.RULE_CHANGE_POS_LIST2 :
//<change_pos_list> ::= <change_pos_list> <change_pos>
right_node=LRParser.GetReductionSyntaxNode(1); return null;
case RuleConstants.RULE_CHANGE_VALUE_LIST :
//<change_value_list> ::= <change_value>
left_node=right_node=LRParser.GetReductionSyntaxNode(0); return null;
case RuleConstants.RULE_CHANGE_VALUE_LIST2 :
//<change_value_list> ::= <change_value_list> <change_value>
right_node=LRParser.GetReductionSyntaxNode(1); return null;
case RuleConstants.RULE_CHANGE_POS_TKINC :
//<change_pos> ::= 'tkInc'
operation_value++; return LRParser.GetReductionSyntaxNode(0);
case RuleConstants.RULE_CHANGE_POS_TKDEC :
//<change_pos> ::= 'tkDec'
operation_value--; return LRParser.GetReductionSyntaxNode(0);
case RuleConstants.RULE_CHANGE_VALUE_TKINCVALUE :
//<change_value> ::= 'tkIncValue'
operation_value++; return LRParser.GetReductionSyntaxNode(0);
case RuleConstants.RULE_CHANGE_VALUE_TKDECVALUE :
//<change_value> ::= 'tkDecValue'
operation_value--; return LRParser.GetReductionSyntaxNode(0);
case RuleConstants.RULE_BF_INSTRUCTION_TKJMPPAST_TKJMPRET :
//<bf_instruction> ::= 'tkJMPPast' <bf_instructions> 'tkJMPRet'
{
indexer indx=new indexer(new expression_list());
indx.indexes.expressions.Add(new ident("BFCaretPos"));
indx.dereferencing_value=new ident("BFField");
bin_expr be=new bin_expr(indx,new int32_const(0),Operators.NotEqual);
while_node wn=new while_node();
wn.expr=be;
wn.statements=(statement_list)LRParser.GetReductionSyntaxNode(1);
parsertools.create_source_context(wn,LRParser.GetReductionSyntaxNode(0),LRParser.GetReductionSyntaxNode(2));
be.right.source_context=indx.dereferencing_value.source_context=indx.source_context=indx.indexes.expressions[0].source_context=be.source_context=wn.source_context;
return wn;
}
case RuleConstants.RULE_BF_INSTRUCTION :
//<bf_instruction> ::= <change_pos_list>
{
if (operation_value!=0)
{
ident caret=new ident("BFCaretPos");
int32_const caret_n=new int32_const(operation_value);
operation_value=0;
bin_expr expr=new bin_expr(caret,caret_n,Operators.Plus);
assign _assign=new assign(caret,expr,Operators.Assignment);
parsertools.create_source_context(caret,left_node,right_node);
caret_n.source_context=expr.source_context=_assign.source_context=caret.source_context;
return _assign;
}
syntax_tree_node tn=new empty_statement();
parsertools.create_source_context(tn,left_node,right_node);
return tn;
}
case RuleConstants.RULE_BF_INSTRUCTION2 :
//<bf_instruction> ::= <change_value_list>
{
if (operation_value!=0)
{
indexer indx=new indexer(new expression_list());
indx.indexes.expressions.Add(new ident("BFCaretPos"));
indx.dereferencing_value=new ident("BFField");
bin_expr be=new bin_expr(indx,new int32_const(operation_value),Operators.Plus);
assign assg=new assign(indx,be,Operators.Assignment);
operation_value=0;
parsertools.create_source_context(assg,left_node,right_node);
indx.dereferencing_value.source_context=indx.source_context=indx.indexes.expressions[0].source_context=be.right.source_context=be.source_context=assg.source_context;
return assg;
}
syntax_tree_node tn=new empty_statement();
parsertools.create_source_context(tn,left_node,right_node);
return tn;
}
case RuleConstants.RULE_BF_INSTRUCTION_TKWRITE :
//<bf_instruction> ::= 'tkWrite'
{
ident _ident=new ident("WriteCaretValue");
procedure_call _procedure_call=new procedure_call(_ident);
parsertools.create_source_context(_ident,LRParser.GetReductionSyntaxNode(0),LRParser.GetReductionSyntaxNode(0));
parsertools.create_source_context(_procedure_call,LRParser.GetReductionSyntaxNode(0),LRParser.GetReductionSyntaxNode(0));
return _procedure_call;
}
case RuleConstants.RULE_BF_INSTRUCTION_TKREAD :
//<bf_instruction> ::= 'tkRead'
{
ident _ident=new ident("ReadCaretValue");
procedure_call _procedure_call=new procedure_call(_ident);
parsertools.create_source_context(_ident,LRParser.GetReductionSyntaxNode(0),LRParser.GetReductionSyntaxNode(0));
parsertools.create_source_context(_procedure_call,LRParser.GetReductionSyntaxNode(0),LRParser.GetReductionSyntaxNode(0));
return _procedure_call;
}
}
throw new RuleException("Unknown rule");
}
}
}

View file

@ -1,154 +0,0 @@
using System;
using System.IO;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.Parsers;
using System.Resources;
using System.Reflection;
using System.Collections.Generic;
using PascalABCCompiler.Errors;
namespace PascalABCCompiler.BFParser
{
public class BFLanguageParser: IParser
{
private GPBParser_BF parser;
public BFLanguageParser()
{
filesExtensions = new string[1];
filesExtensions[0] = ".bf";
parser = null;
}
string[] filesExtensions;
public string[] FilesExtensions
{
get
{
return filesExtensions;
}
}
public ILanguageInformation LanguageInformation {
get {
return null;
}
}
public bool CaseSensitive
{
get
{
return parser.LanguageGrammar.CaseSensitive;
}
}
public Keyword[] Keywords
{
get
{
return new Keyword[0];
}
}
public List<compiler_directive> CompilerDirectives
{
get
{
return new List<compiler_directive>();
}
}
List<Error> errors = new List<Error>();
public List<Error> Errors
{
get
{
return errors;
}
set
{
errors = value;
}
}
SourceFilesProviderDelegate sourceFilesProvider = null;
public SourceFilesProviderDelegate SourceFilesProvider
{
get
{
return sourceFilesProvider;
}
set
{
sourceFilesProvider = value;
}
}
public string Name
{
get
{
return "BF";
}
}
public string Version
{
get
{
return "1.1";
}
}
public string Copyright
{
get
{
return "(c) Òêà÷óê À.Â. 2006";
}
}
public void Reset()
{
parser = new GPBParser_BF(CGTResourceExtractor.Extract(new ResourceManager("BFParser.BFLang", Assembly.GetExecutingAssembly()), "BFLanguage"));
//parser.Parse("+[.,]");
parser.max_errors = 5;
}
public syntax_tree_node BuildTree(string FileName, string Text,string[] SearchPatchs, ParseMode ParseMode)
{
if (parser == null)
Reset();
parser.errors = Errors;
parser.current_file_name = FileName;
switch (ParseMode)
{
case ParseMode.Expression:
case ParseMode.Statement:
return null;
}
syntax_tree_node cu = (syntax_tree_node)parser.Parse(Text);
if (cu != null && cu is compilation_unit)
(cu as compilation_unit).file_name = FileName;
return cu;
}
public override string ToString()
{
return "BF Language Parser v1.1";
}
public IPreprocessor Preprocessor
{
get
{
return null;
}
}
}
}

View file

@ -1,35 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("BF Language Parser")]
[assembly: AssemblyDescription("BF Language Parser for PascalABC.NET")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("PascalABCNETCompiler Team")]
[assembly: AssemblyProduct("BFParser")]
[assembly: AssemblyCopyright("Copyright © DarkStar 2006, 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("92be8996-4d69-46fa-a243-85b2a459a603")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

View file

@ -1,42 +0,0 @@
using System;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.HaskellParser;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.Errors;
using System.Collections.Generic;
namespace PascalABCCompiler.HaskellParser.Errors
{
public class UnexpectedToken : SyntaxError
{
private string _message;
public UnexpectedToken(PascalABCCompiler.ParserTools.GPBParser parser)
: base("", parser.current_file_name, parser.parsertools.GetTokenSourceContext(parser.LRParser), (syntax_tree_node)parser.prev_node)
{
List<GoldParser.Symbol> Symbols = parser.parsertools.GetPrioritySymbols(parser.LRParser.GetExpectedTokens());
if (Symbols.Count == 1)
{
string OneSybmolText = "ONE_" + Symbols[0].Name.ToUpper();
string LocOneSybmolText = StringResources.Get(OneSybmolText);
if (LocOneSybmolText != OneSybmolText)
{
_message = string.Format(LocOneSybmolText);
return;
}
}
_message = string.Format(StringResources.Get("EXPECTED{0}"), PascalABCCompiler.FormatTools.ObjectsToString(parser.parsertools.SymbolsToStrings(Symbols.ToArray()), ","));
}
public UnexpectedToken(string _file_name, string expected, SourceContext _source_context, syntax_tree_node _node)
: base("", _file_name, _source_context, _node)
{
_message = string.Format(StringResources.Get("EXPECTED{0}"), expected);
}
public override string Message
{
get
{
return _message;
}
}
}
}

View file

@ -1,83 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{760E7113-85AE-430F-A3E5-84A20F294356}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HaskellParser</RootNamespace>
<AssemblyName>HaskellParser</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>4.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Errors.cs" />
<Compile Include="HaskellParserTools.cs" />
<Compile Include="Haskell_lrparser.cs" />
<Compile Include="Haskell_lrparser_rules.cs">
</Compile>
<Compile Include="Parser.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Errors\Errors.csproj">
<Project>{44A01F9E-DCE7-470C-AAE5-C3DE0CCBEE3B}</Project>
<Name>Errors</Name>
</ProjectReference>
<ProjectReference Include="..\..\Localization\Localization.csproj">
<Project>{2DE2842F-0912-4251-BC0F-480854C44A13}</Project>
<Name>Localization</Name>
</ProjectReference>
<ProjectReference Include="..\..\ParserTools\ParserTools.csproj">
<Project>{AF2EFD7B-69DD-4B43-AF65-B59B29349C23}</Project>
<Name>ParserTools</Name>
</ProjectReference>
<ProjectReference Include="..\..\SyntaxTree\SyntaxTree.csproj">
<Project>{C2CAC65A-B2AE-4CCC-B067-E6B8E75DF73A}</Project>
<Name>SyntaxTree</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="HaskellLang.resources" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -1,77 +0,0 @@
using System;
using System.Text;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.ParserTools;
using GoldParser;
namespace PascalABCCompiler.HaskellParser
{
public static class StringResources
{
private static string prefix = "HaskellPARSER_";
public static string Get(string Id)
{
string ret = PascalABCCompiler.StringResources.Get(prefix + Id);
if (ret == prefix + Id)
return Id;
else
return ret;
}
}
public class Haskell_parsertools : parser_tools
{
public override string symbol_to_string(Symbol symbol)
{
/*switch (symbol.Index)
{
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKMINUS:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKSLASH:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKSTAR:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKGREATER:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKGREATEREQUAL:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKLOWER:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKLOWEREQUAL:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKNOTEQUAL:
return StringResources.Get("OPERATOR");
}*/
string res = StringResources.Get(symbol.Name.ToUpper());
if (res.IndexOf("TK") == 0)
return res.Remove(0, 2).ToLower();
return res;
}
public override int symbol_priority(Symbol symbol)
{
/*switch (symbol.Index)
{
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKEND:
return 8;
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKBEGIN:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKNUMBER:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKROUNDCLOSE:
return 9;
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKIDENT:
return 10;
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKASSIGN:
return 25;
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKEQUAL:
return 25;
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKSEMICOLON:
return 30;
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_EXPRESSION:
return 100;
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_STATEMENT:
return 110;
}*/
if (symbol.SymbolType == SymbolType.Terminal)
return 1;
return 0;
}
}
}

View file

@ -1,100 +0,0 @@
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Collections;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.Errors;
using PascalABCCompiler.HaskellParser.Errors;
using PascalABCCompiler.ParserTools;
namespace PascalABCCompiler.HaskellParser
{
public partial class GPBParser_Haskell : GPBParser
{
private Stack NodesStack;
private SyntaxError error;
Stream GrammarStream;
public GPBParser_Haskell(Stream stream)
: base(stream)
{
GrammarStream = stream;
parsertools = new Haskell_parsertools();
}
public object Parse(string source)
{
NodesStack = new Stack();
LRParser = new GoldParser.Parser(new StringReader(source), LanguageGrammar);
parsertools.parser = LRParser;
LRParser.TrimReductions = true;
try
{
while (true)
{
switch (LRParser.Parse())
{
case GoldParser.ParseMessage.LexicalError:
errors.Add(new TokenReadError(this));
LRParser.PopInputToken();
if (errors.Count >= max_errors)
return null;
break;
//sdes nugno vesti chtoto vrode steka poslednix oshibok. podumat
case GoldParser.ParseMessage.SyntaxError:
GoldParser.Symbol sym = LRParser.PopInputToken();
error = new HaskellParser.Errors.UnexpectedToken(this);
//error = new UnexpectedToken(this, parsertools.symbol_collection_to_string(this.LRParser.GetExpectedTokens()));
if (sym.SymbolType == GoldParser.SymbolType.End && errors.Count > 0)
return null;
errors.Add(error);
if (errors.Count >= max_errors)
return null;
break;
case GoldParser.ParseMessage.Reduction:
LRParser.TokenSyntaxNode = CreateNonTerminalObject(LRParser.ReductionRule.Index);
if ((LRParser.TokenSyntaxNode as syntax_tree_node) != null)
prev_node = LRParser.TokenSyntaxNode;
break;
case GoldParser.ParseMessage.Accept:
return LRParser.TokenSyntaxNode;
case GoldParser.ParseMessage.TokenRead:
LRParser.TokenSyntaxNode = CreateTerminalObject(LRParser.TokenSymbol.Index);
break;
case GoldParser.ParseMessage.InternalError:
errors.Add(new CompilerInternalError("HaskellParser", new Exception("ParseMessage.InternalError")));
return null;
case GoldParser.ParseMessage.NotLoadedError:
errors.Add(new CompilerInternalError("HaskellParser", new Exception("ParseMessage.NotLoadedError")));
return null;
case GoldParser.ParseMessage.CommentError:
errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "(EOF)"));
return null;
/*case ParseMessage.CommentBlockRead:
break;
case ParseMessage.CommentLineRead:
break;*/
}
}
}
catch (Exception e)
{
Error_Clear();
if (errors.Count > 0)
return null;
else
throw;
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,171 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.Parsers;
using System.Resources;
using System.Reflection;
using PascalABCCompiler.Errors;
using System.IO;
namespace PascalABCCompiler.HaskellParser
{
public class HaskellLanguageParser : IParser
{
GPBParser_Haskell parser;
public HaskellLanguageParser()
{
filesExtensions = new string[1];
filesExtensions[0] = ".hs";
}
string[] filesExtensions;
public string[] FilesExtensions
{
get
{
return filesExtensions;
}
}
ILanguageInformation languageInformation;
public ILanguageInformation LanguageInformation
{
get
{
if (languageInformation == null)
languageInformation = new DefaultLanguageInformation(this);
return languageInformation;
}
}
Keyword[] _keywords;
void initKeywords()
{
List<Keyword> key_words = new List<Keyword>();
key_words.Add(new Keyword("module"));
key_words.Add(new Keyword("where"));
_keywords = key_words.ToArray();
}
public Keyword[] Keywords
{
get
{
return _keywords;
}
}
public void Reset()
{
ResourceManager rm = new ResourceManager("HaskellParser.HaskellLang", Assembly.GetExecutingAssembly());
parser = new GPBParser_Haskell(CGTResourceExtractor.Extract(rm, "HaskellLanguage"));
parser.max_errors = 30;
}
public bool CaseSensitive
{
get
{
return parser.LanguageGrammar.CaseSensitive;
}
}
SourceFilesProviderDelegate sourceFilesProvider = null;
public SourceFilesProviderDelegate SourceFilesProvider
{
get
{
return sourceFilesProvider;
}
set
{
sourceFilesProvider = value;
}
}
public List<compiler_directive> compilerDirectives = new List<compiler_directive>();
public List<compiler_directive> CompilerDirectives
{
get
{
return new List<compiler_directive>();
}
}
List<Error> errors = new List<Error>();
public List<Error> Errors
{
get
{
return errors;
}
set
{
errors = value;
}
}
public syntax_tree_node BuildTree(string FileName, string Text, string[] SearchPatchs, ParseMode ParseMode)
{
if (parser == null)
Reset();
compilerDirectives = new System.Collections.Generic.List<compiler_directive>();
parser.CompilerDirectives = compilerDirectives;
parser.errors = Errors;
parser.current_file_name = FileName;
parser.parsertools.LineCorrection = 0;
syntax_tree_node cu = null;
switch (ParseMode)
{
case ParseMode.Normal:
cu = (syntax_tree_node)parser.Parse(Text);
break;
case ParseMode.Expression:
case ParseMode.Statement:
return null;
}
if (cu != null && cu is compilation_unit)
{
(cu as compilation_unit).file_name = FileName;
(cu as compilation_unit).compiler_directives = parser.CompilerDirectives;
}
return cu;
}
public string Name
{
get
{
return "Haskell";
}
}
public string Version
{
get
{
return "1.0";
}
}
public string Copyright
{
get
{
return "(c) Бушманова Н. 2007";
}
}
public override string ToString()
{
return "Haskell Language Parser v1.0";
}
public IPreprocessor Preprocessor
{
get
{
return null;
}
}
}
}

View file

@ -1,35 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("HaskellParser")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HaskellParser")]
[assembly: AssemblyCopyright("Copyright © 2008")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5de18530-3349-4d82-ab06-b0a984196848")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -1,57 +0,0 @@
using System;
//using com.calitha.goldparser;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.Errors;
using System.Collections.Generic;
using PascalABCCompiler.KuMirParser;
namespace PascalABCCompiler.KuMirParser.Errors
{
public class nonterminal_token_return_null : SyntaxError
{
public nonterminal_token_return_null(string _file_name, SourceContext _source_context, syntax_tree_node _node, string nonterminal_token_name)
:
base(string.Format(StringResources.Get("NONTERMINALTOKEN_{0}_RETURN_NULL"), nonterminal_token_name),
_file_name, _source_context, _node)
{
}
}
public class UnexpectedToken : SyntaxError
{
private string _message;
public UnexpectedToken(PascalABCCompiler.ParserTools.GPBParser parser)
: base("", parser.current_file_name, parser.parsertools.GetTokenSourceContext(parser.LRParser), (syntax_tree_node)parser.prev_node)
{
List<GoldParser.Symbol> Symbols = parser.parsertools.GetPrioritySymbols(parser.LRParser.GetExpectedTokens());
if (Symbols.Count == 1)
{
string OneSybmolText = "ONE_" + Symbols[0].Name.ToUpper();
string LocOneSybmolText = StringResources.Get(OneSybmolText);
if (LocOneSybmolText != OneSybmolText)
{
_message = string.Format(LocOneSybmolText);
return;
}
}
_message = string.Format(StringResources.Get("EXPECTED{0}"), PascalABCCompiler.FormatTools.ObjectsToString(parser.parsertools.SymbolsToStrings(Symbols.ToArray()), ","));
}
public UnexpectedToken(string _file_name, string expected, SourceContext _source_context, syntax_tree_node _node)
: base("", _file_name, _source_context, _node)
{
_message = string.Format(StringResources.Get("EXPECTED{0}"), expected);
}
public override string Message
{
get
{
return _message;
}
}
}
}

View file

@ -1,114 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6C945895-BCE2-4522-8E35-F93B4661B2DA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KuMirParser</RootNamespace>
<AssemblyName>KuMirParser</AssemblyName>
<StartupObject>
</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>4.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Errors, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\bin\Errors.dll</HintPath>
</Reference>
<Reference Include="Localization, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\bin\Localization.dll</HintPath>
</Reference>
<Reference Include="ParserTools, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\bin\ParserTools.dll</HintPath>
</Reference>
<Reference Include="SyntaxTree, Version=1.0.2873.30699, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\bin\SyntaxTree.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Errors.cs" />
<Compile Include="KuMirParserTools.cs" />
<Compile Include="KuMir_lrparser.cs" />
<Compile Include="KuMir_lrparser_rules.cs" />
<Compile Include="Parser.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="KuMirLang.resources" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>Клиентский профиль .NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Установщик Windows 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -1,83 +0,0 @@
using System;
using System.Text;
//using com.calitha.goldparser;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.ParserTools;
using GoldParser;
namespace PascalABCCompiler.KuMirParser
{
public static class StringResources
{
private static string prefix = "KUMIRPARSER_";
public static string Get(string Id)
{
string ret = PascalABCCompiler.StringResources.Get(prefix + Id);
if (ret == prefix + Id)
return Id;
else
return ret;
}
}
public class KuMir_parsertools : parser_tools
{
public override string symbol_to_string(Symbol symbol)
{
switch (symbol.Index)
{
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_MINUS:
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_DIV:
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_MULT:
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_GREATER:
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_GREATEREQUAL:
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_LOWER:
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_LOWEREQUAL:
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_NOTEQUAL:
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_POWER:
return StringResources.Get("OPERATOR");
}
string res = StringResources.Get(symbol.Name);
/*if (res.IndexOf("TK_") == 0)
return res.Remove(0, 3).ToLower();
return res;*/
return res;
}
public override int symbol_priority(Symbol symbol)
{
switch (symbol.Index)
{
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_END:
return 8;
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_BEGIN:
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_INTEGER:
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_ROUNDCLOSE:
return 9;
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_IDENTIFIER:
return 10;
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_ASSIGN:
return 25;
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_EQUAL:
return 25;
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_EXPRESSION:
return 100;
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_STATEMENT:
return 110;
case (int)GPBParser_KuMir.SymbolConstants.SYMBOL_TK_SEMICOLON:
return 1000;
}
if (symbol.SymbolType == SymbolType.Terminal)
return 1;
return 0;
}
}
}

View file

@ -1,107 +0,0 @@
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Collections;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.Errors;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.KuMirParser.Errors;
namespace PascalABCCompiler.KuMirParser
{
public partial class GPBParser_KuMir : GPBParser
{
private Stack NodesStack;
private SyntaxError error;
private int unit_number;
public ArrayList _units;
Stream GrammarStream;
public GPBParser_KuMir(Stream stream)
: base(stream)
{
GrammarStream = stream;
parsertools = new KuMir_parsertools();
unit_number = 0;
_units = new ArrayList();
}
public object Parse(string source)
{
_units.Add(new unit_data());
unit_number++;
NodesStack = new Stack();
LRParser = new GoldParser.Parser(new StringReader(source), LanguageGrammar);
parsertools.parser = LRParser;
LRParser.TrimReductions = true;
try
{
while (true)
{
switch (LRParser.Parse())
{
case GoldParser.ParseMessage.LexicalError:
errors.Add(new TokenReadError(this));
LRParser.PopInputToken();
if (errors.Count >= max_errors)
return null;
break;
//sdes nugno vesti chtoto vrode steka poslednix oshibok. podumat
case GoldParser.ParseMessage.SyntaxError:
GoldParser.Symbol sym = LRParser.PopInputToken();
error = new KuMirParser.Errors.UnexpectedToken(this);
//error = new UnexpectedToken(this, parsertools.symbol_collection_to_string(this.LRParser.GetExpectedTokens()));
if (sym.SymbolType == GoldParser.SymbolType.End && errors.Count > 0)
return null;
errors.Add(error);
if (errors.Count >= max_errors)
return null;
break;
case GoldParser.ParseMessage.Reduction:
LRParser.TokenSyntaxNode = CreateNonTerminalObject(LRParser.ReductionRule.Index);
if ((LRParser.TokenSyntaxNode as syntax_tree_node) != null)
prev_node = LRParser.TokenSyntaxNode;
break;
case GoldParser.ParseMessage.Accept:
return LRParser.TokenSyntaxNode;
case GoldParser.ParseMessage.TokenRead:
LRParser.TokenSyntaxNode = CreateTerminalObject(LRParser.TokenSymbol.Index);
break;
case GoldParser.ParseMessage.InternalError:
errors.Add(new CompilerInternalError("KuMirParser", new Exception("ParseMessage.InternalError")));
return null;
case GoldParser.ParseMessage.NotLoadedError:
errors.Add(new CompilerInternalError("KuMirParser", new Exception("ParseMessage.NotLoadedError")));
return null;
case GoldParser.ParseMessage.CommentError:
errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "(EOF)"));
return null;
/*case ParseMessage.CommentBlockRead:
break;
case ParseMessage.CommentLineRead:
break;*/
}
}
}
catch (Exception e)
{
if (errors.Count > 0)
return null;
else
throw;
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,161 +0,0 @@
using System;
using System.IO;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.Parsers;
using System.Resources;
using System.Reflection;
using PascalABCCompiler.Errors;
using System.Collections.Generic;
namespace PascalABCCompiler.KuMirParser
{
public class KuMirLanguageParser : IParser
{
GPBParser_KuMir parser;
public KuMirLanguageParser()
{
filesExtensions = new string[1];
filesExtensions[0] = ".alg";
}
string[] filesExtensions;
public string[] FilesExtensions
{
get
{
return filesExtensions;
}
}
public ILanguageInformation LanguageInformation {
get {
return new DefaultLanguageInformation(this);
}
}
public void Reset()
{
parser = new GPBParser_KuMir(CGTResourceExtractor.Extract(new ResourceManager("KuMirParser.KuMirLang", Assembly.GetExecutingAssembly()), "KuMirLanguage"));
parser.max_errors = 30;
}
public bool CaseSensitive
{
get
{
return parser.LanguageGrammar.CaseSensitive;
}
}
public List<compiler_directive> CompilerDirectives
{
get
{
return new List<compiler_directive>();
}
}
SourceFilesProviderDelegate sourceFilesProvider = null;
public SourceFilesProviderDelegate SourceFilesProvider
{
get
{
return sourceFilesProvider;
}
set
{
sourceFilesProvider = value;
}
}
List<Error> errors = new List<Error>();
public List<Error> Errors
{
get
{
return errors;
}
set
{
errors = value;
}
}
public Keyword[] Keywords
{
get
{
return new Keyword[0];
}
}
public syntax_tree_node BuildTree(string FileName, string Text, string[] SearchPatchs, ParseMode ParseMode)
{
if (parser == null)
Reset();
parser.errors = Errors;
parser.current_file_name = FileName;
parser.parsertools.LineCorrection = 0;
syntax_tree_node cu = null;
switch (ParseMode)
{
case ParseMode.Normal:
cu = (syntax_tree_node)parser.Parse(Text);
break;
case ParseMode.Expression:
case ParseMode.Statement:
return null;
}
if (cu != null && cu is compilation_unit)
{
(cu as compilation_unit).file_name = FileName;
(cu as compilation_unit).compiler_directives = CompilerDirectives;
}
return cu;
}
public string Name
{
get
{
return "KuMir";
}
}
public string Version
{
get
{
return "1.0";
}
}
public string Copyright
{
get
{
return "(c) 3 course";
}
}
public override string ToString()
{
return "KuMir Language Parser v1.0";
}
public IPreprocessor Preprocessor
{
get
{
return null;
}
}
}
}

View file

@ -1,33 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("KuMirParser")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("3c")]
[assembly: AssemblyProduct("KuMirParser")]
[assembly: AssemblyCopyright("Copyright © 3c 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("48d49307-d409-4acd-878e-0e6561b69c9f")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -1,45 +0,0 @@
using System;
//using com.calitha.goldparser;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.PL0Parser;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.Errors;
using System.Collections.Generic;
namespace PascalABCCompiler.PL0Parser.Errors
{
public class UnexpectedToken : SyntaxError
{
private string _message;
public UnexpectedToken(PascalABCCompiler.ParserTools.GPBParser parser)
: base("", parser.current_file_name, parser.parsertools.GetTokenSourceContext(parser.LRParser), (syntax_tree_node)parser.prev_node)
{
List<GoldParser.Symbol> Symbols = parser.parsertools.GetPrioritySymbols(parser.LRParser.GetExpectedTokens());
if (Symbols.Count == 1)
{
string OneSybmolText = "ONE_" + Symbols[0].Name.ToUpper();
string LocOneSybmolText = StringResources.Get(OneSybmolText);
if (LocOneSybmolText != OneSybmolText)
{
_message = string.Format(LocOneSybmolText);
return;
}
}
_message = string.Format(StringResources.Get("EXPECTED{0}"), PascalABCCompiler.FormatTools.ObjectsToString(parser.parsertools.SymbolsToStrings(Symbols.ToArray()), ","));
}
public UnexpectedToken(string _file_name, string expected, SourceContext _source_context, syntax_tree_node _node)
: base("", _file_name, _source_context, _node)
{
_message = string.Format(StringResources.Get("EXPECTED{0}"), expected);
}
public override string Message
{
get
{
return _message;
}
}
}
}

Binary file not shown.

View file

@ -1,114 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{0DE2DAD6-D1E9-435E-8A19-91DA2AD3B59B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PL0Parser</RootNamespace>
<AssemblyName>PL0Parser</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>4.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Errors.cs" />
<Compile Include="Parser.cs" />
<Compile Include="PL0ParserTools.cs" />
<Compile Include="PL0_lrparser.cs" />
<Compile Include="PL0_lrparser_rules.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Errors\Errors.csproj">
<Project>{44A01F9E-DCE7-470C-AAE5-C3DE0CCBEE3B}</Project>
<Name>Errors</Name>
</ProjectReference>
<ProjectReference Include="..\..\Localization\Localization.csproj">
<Project>{2DE2842F-0912-4251-BC0F-480854C44A13}</Project>
<Name>Localization</Name>
</ProjectReference>
<ProjectReference Include="..\..\ParserTools\ParserTools.csproj">
<Project>{AF2EFD7B-69DD-4B43-AF65-B59B29349C23}</Project>
<Name>ParserTools</Name>
</ProjectReference>
<ProjectReference Include="..\..\SyntaxTree\SyntaxTree.csproj">
<Project>{C2CAC65A-B2AE-4CCC-B067-E6B8E75DF73A}</Project>
<Name>SyntaxTree</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="PL0Lang.resources" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>Клиентский профиль .NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Установщик Windows 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -1,82 +0,0 @@
using System;
using System.Text;
//using com.calitha.goldparser;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.ParserTools;
using GoldParser;
namespace PascalABCCompiler.PL0Parser
{
public static class StringResources
{
private static string prefix = "PL0PARSER_";
public static string Get(string Id)
{
string ret = PascalABCCompiler.StringResources.Get(prefix + Id);
if (ret == prefix + Id)
return Id;
else
return ret;
}
}
public class PL0_parsertools:parser_tools
{
public override string symbol_to_string(Symbol symbol)
{
switch (symbol.Index)
{
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKMINUS:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKSLASH:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKSTAR:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKGREATER:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKGREATEREQUAL:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKLOWER:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKLOWEREQUAL:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKNOTEQUAL:
return StringResources.Get("OPERATOR");
}
string res = StringResources.Get(symbol.Name.ToUpper());
if (res.IndexOf("TK") == 0)
return res.Remove(0, 2).ToLower();
return res;
}
public override int symbol_priority(Symbol symbol)
{
switch (symbol.Index)
{
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKEND:
return 8;
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKBEGIN:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKNUMBER:
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKROUNDCLOSE:
return 9;
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKIDENT:
return 10;
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKASSIGN:
return 25;
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKEQUAL:
return 25;
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_TKSEMICOLON:
return 30;
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_EXPRESSION:
return 100;
case (int)GPBParser_PL0.SymbolConstants.SYMBOL_STATEMENT:
return 110;
}
if (symbol.SymbolType == SymbolType.Terminal)
return 1;
return 0;
}
}
}

View file

@ -1,101 +0,0 @@
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Collections;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.Errors;
using PascalABCCompiler.PL0Parser.Errors;
using PascalABCCompiler.ParserTools;
namespace PascalABCCompiler.PL0Parser
{
public partial class GPBParser_PL0 : GPBParser
{
private Stack NodesStack;
private SyntaxError error;
Stream GrammarStream;
public GPBParser_PL0(Stream stream)
: base(stream)
{
GrammarStream = stream;
parsertools = new PL0_parsertools();
}
public object Parse(string source)
{
NodesStack = new Stack();
LRParser = new GoldParser.Parser(new StringReader(source), LanguageGrammar);
parsertools.parser = LRParser;
LRParser.TrimReductions = true;
try
{
while (true)
{
switch (LRParser.Parse())
{
case GoldParser.ParseMessage.LexicalError:
errors.Add(new TokenReadError(this));
LRParser.PopInputToken();
if (errors.Count >= max_errors)
return null;
break;
//sdes nugno vesti chtoto vrode steka poslednix oshibok. podumat
case GoldParser.ParseMessage.SyntaxError:
GoldParser.Symbol sym = LRParser.PopInputToken();
error = new PL0Parser.Errors.UnexpectedToken(this);
//error = new UnexpectedToken(this, parsertools.symbol_collection_to_string(this.LRParser.GetExpectedTokens()));
if (sym.SymbolType == GoldParser.SymbolType.End && errors.Count > 0)
return null;
errors.Add(error);
if (errors.Count >= max_errors)
return null;
break;
case GoldParser.ParseMessage.Reduction:
LRParser.TokenSyntaxNode = CreateNonTerminalObject(LRParser.ReductionRule.Index);
if ((LRParser.TokenSyntaxNode as syntax_tree_node) != null)
prev_node = LRParser.TokenSyntaxNode;
break;
case GoldParser.ParseMessage.Accept:
return LRParser.TokenSyntaxNode;
case GoldParser.ParseMessage.TokenRead:
LRParser.TokenSyntaxNode = CreateTerminalObject(LRParser.TokenSymbol.Index);
break;
case GoldParser.ParseMessage.InternalError:
errors.Add(new CompilerInternalError("PL0Parser", new Exception("ParseMessage.InternalError")));
return null;
case GoldParser.ParseMessage.NotLoadedError:
errors.Add(new CompilerInternalError("PL0Parser", new Exception("ParseMessage.NotLoadedError")));
return null;
case GoldParser.ParseMessage.CommentError:
errors.Add(new PascalABCCompiler.Errors.UnexpectedToken(this, "(EOF)"));
return null;
/*case ParseMessage.CommentBlockRead:
break;
case ParseMessage.CommentLineRead:
break;*/
}
}
}
catch (Exception e)
{
if (errors.Count > 0)
return null;
else
throw;
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,178 +0,0 @@
using System;
using System.IO;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.Parsers;
using System.Resources;
using System.Reflection;
using PascalABCCompiler.Errors;
using System.Collections.Generic;
namespace PascalABCCompiler.PL0Parser
{
public class PL0LanguageParser:IParser
{
GPBParser_PL0 parser;
public PL0LanguageParser()
{
filesExtensions = new string[1];
filesExtensions[0] = ".pl0";
}
string[] filesExtensions;
public string[] FilesExtensions
{
get
{
return filesExtensions;
}
}
ILanguageInformation languageInformation;
public ILanguageInformation LanguageInformation {
get {
if (languageInformation == null)
languageInformation = new DefaultLanguageInformation(this);
return languageInformation;
}
}
Keyword[] _keywords;
void initKeywords()
{
List<Keyword> key_words = new List<Keyword>();
key_words.Add(new Keyword("CONST"));
key_words.Add(new Keyword("VAR", KeywordKind.Var));
key_words.Add(new Keyword("CALL"));
key_words.Add(new Keyword("BEGIN"));
key_words.Add(new Keyword("END"));
key_words.Add(new Keyword("IF"));
key_words.Add(new Keyword("THEN"));
key_words.Add(new Keyword("WHILE"));
key_words.Add(new Keyword("DO"));
key_words.Add(new Keyword("PROCEDURE", KeywordKind.Function));
key_words.Add(new Keyword("ODD"));
_keywords = key_words.ToArray();
}
public Keyword[] Keywords
{
get
{
return _keywords;
}
}
public void Reset()
{
parser = new GPBParser_PL0(CGTResourceExtractor.Extract(new ResourceManager("PL0Parser.PL0Lang", Assembly.GetExecutingAssembly()), "PL0Language"));
parser.max_errors = 30;
}
public bool CaseSensitive
{
get
{
return parser.LanguageGrammar.CaseSensitive;
}
}
SourceFilesProviderDelegate sourceFilesProvider = null;
public SourceFilesProviderDelegate SourceFilesProvider
{
get
{
return sourceFilesProvider;
}
set
{
sourceFilesProvider = value;
}
}
public List<compiler_directive> CompilerDirectives
{
get
{
return new List<compiler_directive>();
}
}
List<Error> errors = new List<Error>();
public List<Error> Errors
{
get
{
return errors;
}
set
{
errors = value;
}
}
public syntax_tree_node BuildTree(string FileName, string Text, string[] SearchPatchs, ParseMode ParseMode)
{
if (parser == null)
Reset();
parser.errors = Errors;
parser.current_file_name = FileName;
parser.parsertools.LineCorrection = 0;
syntax_tree_node cu = null;
switch (ParseMode)
{
case ParseMode.Normal:
cu = (syntax_tree_node)parser.Parse(Text);
break;
case ParseMode.Expression:
case ParseMode.Statement:
return null;
}
if (cu != null && cu is compilation_unit)
{
(cu as compilation_unit).file_name = FileName;
(cu as compilation_unit).compiler_directives = CompilerDirectives;
}
return cu;
}
public string Name
{
get
{
return "PL/0";
}
}
public string Version
{
get
{
return "1.0";
}
}
public string Copyright
{
get
{
return "(c) Òêà÷óê À.Â., 2007";
}
}
public override string ToString()
{
return "PL/0 Language Parser v1.0";
}
public IPreprocessor Preprocessor
{
get
{
return null;
}
}
}
}

View file

@ -1,35 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PL0Parser")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("DSS")]
[assembly: AssemblyProduct("PascalABCParser")]
[assembly: AssemblyCopyright("Copyright © DSS 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e5788e70-934b-42a9-a652-255b64cf1709")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]

File diff suppressed because it is too large Load diff

View file

@ -1,88 +0,0 @@
using System;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.PascalABCParser;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.Errors;
using System.Collections.Generic;
namespace PascalABCCompiler.PascalABCParser.Errors
{
public class bad_operand_type: SyntaxError
{
public bad_operand_type(string _file_name,SourceContext _source_context,syntax_tree_node _node):
base(StringResources.Get("OPERATOR_NOT_IMPLEMET_TO_THIS_OPEAND_TYPE"), _file_name, _source_context, _node)
{
}
}
public class statement_expected : SyntaxError
{
public statement_expected(string _file_name,SourceContext _source_context,syntax_tree_node _node):
base(StringResources.Get("STATEMENT_EXPECTED"), _file_name, _source_context, _node)
{
}
}
public class bad_leftside_assigment : SyntaxError
{
public bad_leftside_assigment(string _file_name,SourceContext _source_context,syntax_tree_node _node):
base(StringResources.Get("LEFT_SIDE_ASSIGN_MUST_BE_VARIABLE"), _file_name, _source_context, _node)
{
}
}
public class nonterminal_token_return_null : SyntaxError
{
public nonterminal_token_return_null(string _file_name,SourceContext _source_context,syntax_tree_node _node,string nonterminal_token_name):
base(string.Format(StringResources.Get("NONTERMINALTOKEN_{0}_RETURN_NULL"), nonterminal_token_name),
_file_name,_source_context,_node)
{
}
}
public class unexpected_return_value : SyntaxError
{
public unexpected_return_value(string _file_name, SourceContext _source_context, syntax_tree_node _node)
: base(StringResources.Get("PROCEDURE_CANNOT_HAVE_RETURNED_VALUE"), _file_name, _source_context, _node)
{
}
}
public class unexpected_ident : SyntaxError
{
public unexpected_ident(string _file_name,ident unexpected_id,string expected,SourceContext _source_context, syntax_tree_node _node)
: base(string.Format(StringResources.Get("EXPECTED_{0}_BUT_FOUND_{1}"), expected, unexpected_id.name), _file_name, _source_context, _node)
{
}
}
public class PABCNETUnexpectedToken : SyntaxError
{
private string _message;
public PABCNETUnexpectedToken(PascalABCCompiler.ParserTools.GPBParser parser)
: base("", parser.current_file_name, parser.parsertools.GetTokenSourceContext(parser.LRParser), (syntax_tree_node)parser.prev_node)
{
List<GoldParser.Symbol> Symbols = parser.parsertools.GetPrioritySymbols(parser.LRParser.GetExpectedTokens());
if (Symbols.Count == 1)
{
string OneSybmolText = "ONE_" + Symbols[0].Name.ToUpper();
string LocOneSybmolText = StringResources.Get(OneSybmolText);
if (LocOneSybmolText != OneSybmolText)
{
_message = string.Format(LocOneSybmolText);
return;
}
}
_message = string.Format(StringResources.Get("EXPECTED{0}"), PascalABCCompiler.FormatTools.ObjectsToString(parser.parsertools.SymbolsToStrings(Symbols.ToArray()), ","));
}
public PABCNETUnexpectedToken(string _file_name, string expected, SourceContext _source_context, syntax_tree_node _node)
: base("", _file_name, _source_context, _node)
{
_message = string.Format(StringResources.Get("EXPECTED{0}"), expected);
}
public override string Message
{
get
{
return _message;
}
}
}
}

View file

@ -1,151 +0,0 @@
using System;
using System.IO;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.Parsers;
using System.Resources;
using System.Reflection;
using System.Collections.Generic;
using PascalABCCompiler.Errors;
using PascalABCCompiler.Preprocessor2;
namespace PascalABCCompiler.PascalABCParser
{
public class PascalABCLanguageParser : BaseParser, IParser
{
private GPBParser_PascalABC parser;
private GPBParser_PascalABC localparser; // Вынес localparser сюда для передачи между методами. После избавления от GPB должен остаться только этот парсер
public Preprocessor2.Preprocessor2 preprocessor2 = new PascalABCCompiler.Preprocessor2.Preprocessor2(null);
private Stream grammar_stream;
public PascalABCLanguageParser()
: base("PascalABC.NET", "2.2", "(c) Ткачук А.В. 2005,2008; Михалкович С.С. 2012", false, new string[1]{".gpas"})
{
parser = null;
}
public override void Reset()
{
CompilerDirectives.Clear();
grammar_stream = CGTResourceExtractor.Extract(new ResourceManager("PascalABCParser.PascalABCLang", Assembly.GetExecutingAssembly()),"PascalABCLanguage");
parser = new GPBParser_PascalABC(grammar_stream, preprocessor2);
parser.Parse("begin end.");
max_errors = 30;
}
public override SourceFilesProviderDelegate SourceFilesProvider
{
get
{
return sourceFilesProvider;
}
set
{
sourceFilesProvider = value;
preprocessor2.SourceFilesProvider = value;
}
}
int max_errors
{
get
{
return parser.max_errors;
}
set
{
parser.max_errors = value;
}
}
public override void PreBuildTree(string FileName)
{
if (this.parser == null)
Reset();
CompilerDirectives = new List<compiler_directive>();
localparser = new GPBParser_PascalABC(this.grammar_stream, this.parser.LanguageGrammar, preprocessor2);
localparser.CompilerDirectives = CompilerDirectives;
localparser.errors = Errors;
localparser.current_file_name = FileName;
localparser.parsertools.LineCorrection = 0;
localparser.build_tree_for_brackets = false;
preprocessor2 = new Preprocessor2.Preprocessor2(SourceFilesProvider);
}
public override syntax_tree_node BuildTreeInNormalMode(string FileName, string Text)
{
Errors.Clear();
string[] file_names = new string[1];
file_names[0] = FileName;
SourceContextMap scm = new SourceContextMap();
Text = preprocessor2.Build(file_names, Errors, scm);
localparser.scm = scm;
((localparser.parsertools) as pascalabc_parsertools).scm = scm;
if (Errors.Count > 0)
return null;
syntax_tree_node root = (syntax_tree_node)localparser.Parse(Text);
if (root != null && root is compilation_unit)
(root as compilation_unit).file_name = FileName;
if (preprocessor2.CompilerDirectives != null && preprocessor2.CompilerDirectives.Count != 0)
localparser.CompilerDirectives.AddRange(preprocessor2.CompilerDirectives);
return root;
}
public override syntax_tree_node BuildTreeInExprMode(string FileName, string Text)
{
Text = String.Concat("<<expression>>", Environment.NewLine, Text);
localparser.parsertools.LineCorrection = -1;
syntax_tree_node root = (syntax_tree_node)localparser.Parse(Text);
return root as expression;
}
public override syntax_tree_node BuildTreeInStatementMode(string FileName, string Text)
{
Text = String.Concat("<<statement>>", Environment.NewLine, Text);
localparser.parsertools.LineCorrection = -1;
syntax_tree_node root = (syntax_tree_node)localparser.Parse(Text);
return root as statement;
}
public override syntax_tree_node BuildTreeInSpecialMode(string FileName, string Text)
{
Errors.Clear();
syntax_tree_node root = (syntax_tree_node)localparser.Parse(Text);
return root;
}
public override syntax_tree_node BuildTreeInFormatterMode(string FileName, string Text)
{
localparser.build_tree_for_brackets = true;
Errors.Clear();
syntax_tree_node root = (syntax_tree_node)localparser.Parse(Text);
return root;
}
public override string ToString()
{
return "PascalABC.NET Language Parser v2.2";
}
public override IPreprocessor Preprocessor
{
get
{
//MZ
return preprocessor2;
}
}
}
}

View file

@ -1,123 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{93E024EA-632F-495C-9142-86769EA42118}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PascalABCParser</RootNamespace>
<AssemblyName>PascalABCOldParser</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>4.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Errors.cs" />
<Compile Include="Parser.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="PascalABCParserTools.cs" />
<Compile Include="pascalabc_lrparser.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="pascalabc_lrparser_rules.cs" />
<Compile Include="Preprocessor_2\Errors.cs" />
<Compile Include="Preprocessor_2\PABCPreprocessor2_lrparser.cs" />
<Compile Include="Preprocessor_2\Parser.cs" />
<Compile Include="Preprocessor_2\Preprocessor2.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="PascalABCLang.resources" />
<EmbeddedResource Include="Preprocessor_2\PABCPreprocessor2Lang.resources" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Errors\Errors.csproj">
<Project>{44A01F9E-DCE7-470C-AAE5-C3DE0CCBEE3B}</Project>
<Name>Errors</Name>
</ProjectReference>
<ProjectReference Include="..\..\Localization\Localization.csproj">
<Project>{2DE2842F-0912-4251-BC0F-480854C44A13}</Project>
<Name>Localization</Name>
</ProjectReference>
<ProjectReference Include="..\..\ParserTools\ParserTools.csproj">
<Project>{AF2EFD7B-69DD-4B43-AF65-B59B29349C23}</Project>
<Name>ParserTools</Name>
</ProjectReference>
<ProjectReference Include="..\..\SyntaxTree\SyntaxTree.csproj">
<Project>{C2CAC65A-B2AE-4CCC-B067-E6B8E75DF73A}</Project>
<Name>SyntaxTree</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>Клиентский профиль .NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Установщик Windows 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -1,172 +0,0 @@
using System;
using System.Text;
//using com.calitha.goldparser;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.ParserTools;
using GoldParser;
namespace PascalABCCompiler.PascalABCParser
{
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 class pascalabc_parsertools : parser_tools
{
public SourceContextMap scm = null;
public override SourceContext GetTokenSourceContext()
{
return GetTokenSourceContext(parser);
}
int NewLineLength = Environment.NewLine.Length;
int GetLinesCount(string s)
{
//Не учитывает последний перевод если за ним ничего
int i = s.IndexOf(Environment.NewLine);
int res = 0;
if (i >= 0 && i < s.Length - NewLineLength)
res++;
while (i >= 0)
{
i = s.IndexOf(Environment.NewLine, i + NewLineLength);
if (i >= 0 && i < s.Length - NewLineLength)
res++;
}
return res;
}
public override SourceContext GetTokenSourceContext(Parser parser)
{
int LineNum = parser.TokenLineNumber + LineCorrection;
SourceContext sc = new SourceContext(LineNum, parser.TokenLinePosition, LineNum + GetLinesCount(parser.TokenText), parser.TokenLinePosition + parser.TokenLength - 1, parser.TokenCharPosition, parser.TokenCharPosition + parser.TokenLength);
if (scm != null)
sc = scm.GetSourceContext(sc);
return sc;
}
public compiler_directive MakeDirective(token_info ti)
{
compiler_directive cd = new compiler_directive();
cd.Directive = new token_info();
string name = ti.text.Remove(0, 2).Replace("}","");
int i = name.IndexOf(' ');
if (i > 0)
{
cd.Directive = new token_info(name.Remove(0, i + 1));
cd.Directive.source_context = ti.source_context;
name = name.Remove(i);
cd.Directive.text = cd.Directive.text.Trim(' ');
cd.Directive.text = cd.Directive.text.Replace(@"'", "".ToString());
}
cd.Name = new token_info(name);
cd.Name.source_context = ti.source_context;
cd.source_context = ti.source_context;
return cd;
}
public override string symbol_to_string(Symbol symbol)
{
switch (symbol.Index)
{
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKMINUS:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKOR:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKXOR:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKAND:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKDIV:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKMOD:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKSHL:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKSHR:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKSLASH:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKSTAR:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKGREATER:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKGREATEREQUAL:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKIN:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKLOWER:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKLOWEREQUAL:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKNOTEQUAL:
return StringResources.Get("OPERATOR");
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKSQUARECLOSE:
return "]";
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKSQUAREOPEN:
return "[";
}
string res = StringResources.Get(symbol.Name.ToUpper());
if (res.IndexOf("TK") == 0)
return res.Remove(0, 2).ToLower();
return res;
}
public override int symbol_priority(Symbol symbol)
{
switch (symbol.Index)
{
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKEND:
return 8;
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKBEGIN:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKINTEGER:
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKROUNDCLOSE:
return 9;
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKIDENTIFIER:
return 10;
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKASSIGN:
return 25;
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKCOLON:
return 20;
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKEQUAL:
return 25;
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKSEMICOLON:
return 30;
// case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKDO:
// return 50;
//case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_TKPOINT:
// return 35;
// return 5;
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_EXPR:
return 100;
case (int)GPBParser_PascalABC.SymbolConstants.SYMBOL_STMT:
return 110;
}
if (symbol.SymbolType == SymbolType.Terminal)
return 1;
return 0;
}
/*public override void check_comment_text(GPBParser parser)
{
string original_text = parser.LRParser.TokenString;
if (original_text[0] == '{' && original_text[1] == '$')
{
string text = original_text.Substring(2, original_text.Length - 3);
int delim_pos = text.IndexOf(' ');
if (delim_pos > 1)
{
string dname = text.Substring(0, delim_pos - 1);
string derictive = text.Substring(delim_pos, text.Length - delim_pos - 1);
compiler_directive cd = new compiler_directive(dname, derictive);
cd.source_context = GetTokenSourceContext(parser.LRParser);
parser.CompilerDirectives.Add(cd);
}
}
}*/
}
}

View file

@ -1,173 +0,0 @@
using System;
using System.IO;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.SyntaxTree;
using System.Resources;
using System.Reflection;
using PascalABCCompiler.Parsers;
using System.Collections.Generic;
using PascalABCCompiler.Errors;
namespace PascalABCCompiler.PascalPreprocessor
{
public class PascalPreprocessorLanguageParser:IParser
{
private GPBPreprocessor_Pascal parser;
public PascalPreprocessorLanguageParser()
{
this.filesExtensions = new string[1];
this.filesExtensions[0] = ".paspr" + Parsers.Controller.HideParserExtensionPostfixChar;
parser = null;
}
string[] filesExtensions;
public string[] FilesExtensions
{
get
{
return filesExtensions;
}
}
ILanguageInformation lnginf = new DefaultLanguageInformation();
public ILanguageInformation LanguageInformation {
get {
return lnginf;
}
}
public bool CaseSensitive
{
get
{
return parser.LanguageGrammar.CaseSensitive;
}
}
public Keyword[] Keywords
{
get
{
return new Keyword[0];
}
}
public List<compiler_directive> compilerDirectives = new List<compiler_directive>();
public List<compiler_directive> CompilerDirectives
{
get
{
return compilerDirectives;
}
}
List<Error> errors = new List<Error>();
public List<Error> Errors
{
get
{
return errors;
}
set
{
errors = value;
}
}
private Stream grammar_stream = null;
public void Reset()
{
grammar_stream = CGTResourceExtractor.Extract(new ResourceManager("PascalABCParser.Preprocessor.PascalPreprocessorLang", Assembly.GetExecutingAssembly()), "PascalPreprocessorLanguage");
parser = new GPBPreprocessor_Pascal(grammar_stream);
max_errors = 5;
}
public virtual int max_errors
{
get
{
return parser.max_errors;
}
set
{
parser.max_errors=value;
}
}
SourceFilesProviderDelegate sourceFilesProvider = null;
public SourceFilesProviderDelegate SourceFilesProvider
{
get
{
return sourceFilesProvider;
}
set
{
sourceFilesProvider = value;
}
}
public syntax_tree_node BuildTree(string FileName, string Text, string[] SearchPatchs, ParseMode parseMode)
{
if (this.parser == null)
Reset();
GPBPreprocessor_Pascal parser = new GPBPreprocessor_Pascal(this.grammar_stream,this.parser.LanguageGrammar);
parser.errors = Errors;
parser.current_file_name = FileName;
compilerDirectives = new List<compiler_directive>();
parser.CompilerDirectives = compilerDirectives;
switch (parseMode)
{
case ParseMode.Expression:
case ParseMode.Statement:
return null;
}
syntax_tree_node cu = (syntax_tree_node)parser.Parse(Text);
if (cu != null && cu is compilation_unit)
{
(cu as compilation_unit).file_name = FileName;
(cu as compilation_unit).compiler_directives = compilerDirectives;
}
return cu;
}
public string Name
{
get
{
return "Pascal Preprocessor";
}
}
public string Version
{
get
{
return "0.2";
}
}
public string Copyright
{
get
{
return "(c) Ткачук А.В. 2008";
}
}
public override string ToString()
{
return "Pascal Preprocessor v0.1";
}
public IPreprocessor Preprocessor
{
get
{
return null;
}
}
}
}

View file

@ -1,329 +0,0 @@
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Collections;
using System.Collections.Generic;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.Errors;
using PascalABCCompiler.PascalABCParser.Errors;
using PascalABCCompiler.ParserTools;
using GoldParser;
using PascalABCCompiler.PascalABCParser;
namespace PascalABCCompiler.PascalPreprocessor
{
public class GPBPreprocessor_Pascal:GPBParser
{
private int operation_value=0;
private object left_node,right_node;
private Stack<compiler_directive> if_part = new Stack<compiler_directive>();
private Stack<compiler_directive> first_if = new Stack<compiler_directive>();
private pascalabc_parsertools pascal_parsertools;
public GPBPreprocessor_Pascal(Stream stream)
:base(stream)
{
pascal_parsertools = new pascalabc_parsertools();
parsertools = pascal_parsertools;
}
public GPBPreprocessor_Pascal(Stream stream, GoldParser.Grammar grammar):base(grammar)
{
pascal_parsertools = new pascalabc_parsertools();
parsertools = pascal_parsertools;
}
public object Parse(string source)
{
if_part.Clear();
first_if.Clear();
LRParser = new Parser(new StringReader(source), LanguageGrammar);
parsertools.parser = LRParser;
LRParser.TrimReductions = true;
try
{
while (true)
{
switch (LRParser.Parse())
{
case ParseMessage.LexicalError:
errors.Add(new TokenReadError(this));
LRParser.PopInputToken();
if (errors.Count > max_errors)
return null;
break;
case ParseMessage.SyntaxError:
if ((LRParser.TokenSyntaxNode as syntax_tree_node)!= null)
prev_node = LRParser.TokenSyntaxNode;
Error er = new PABCNETUnexpectedToken(this);
Symbol sym = LRParser.PopInputToken();
if (sym.SymbolType == SymbolType.End && errors.Count > 0)
return null;
errors.Add(er);
if (errors.Count > max_errors)
return null;
break;
case ParseMessage.Reduction:
LRParser.TokenSyntaxNode = CreateNonTerminalObject();
break;
case ParseMessage.Accept:
return LRParser.TokenSyntaxNode;
case ParseMessage.TokenRead:
LRParser.TokenSyntaxNode = CreateTerminalObject();
break;
case ParseMessage.InternalError:
errors.Add(new CompilerInternalError("CParser", new Exception("ParseMessage.InternalError")));
return null;
case ParseMessage.NotLoadedError:
errors.Add(new CompilerInternalError("CParser", new Exception("ParseMessage.NotLoadedError")));
return null;
case ParseMessage.CommentError:
errors.Add(new UnexpectedToken(this,"(EOF)"));
return null;
/*case ParseMessage.CommentBlockRead:
break;
case ParseMessage.CommentLineRead:
break;*/
}
}
}
catch (GoldParser.UnexpectedEOFinParseCommentBlock)
{
throw new TokenReadError(this);
}
catch (Exception e)
{
if (errors.Count > 0)
return null;
else
throw;
}
}
public enum SymbolConstants : int
{
SYMBOL_EOF = 0, // (EOF)
SYMBOL_ERROR = 1, // (Error)
SYMBOL_WHITESPACE = 2, // (Whitespace)
SYMBOL_COMMENTEND = 3, // (Comment End)
SYMBOL_COMMENTLINE = 4, // (Comment Line)
SYMBOL_COMMENTSTART = 5, // (Comment Start)
SYMBOL_TKDIRECTIVE = 6, // 'TKDIRECTIVE'
SYMBOL_TKNEWLINE = 7, // 'TKNEWLINE'
SYMBOL_TKPROGRAM_LINE_PART = 8, // 'TKPROGRAM_LINE_PART'
SYMBOL__DIRECTIVE_GROUPS = 9, // <_directive_groups>
SYMBOL_DIRECTIVE_GROUP = 10, // <directive_group>
SYMBOL_DIRECTIVE_GROUPS = 11, // <directive_groups>
SYMBOL_EMPTY = 12, // <empty>
SYMBOL_PREPROCESSOR_PROGRAM = 13 // <preprocessor_program>
};
public enum RuleConstants : int
{
RULE_PREPROCESSOR_PROGRAM = 0, // <preprocessor_program> ::= <directive_groups> <empty>
RULE_DIRECTIVE_GROUPS = 1, // <directive_groups> ::= <_directive_groups>
RULE_DIRECTIVE_GROUPS2 = 2, // <directive_groups> ::=
RULE__DIRECTIVE_GROUPS = 3, // <_directive_groups> ::= <directive_group> <empty>
RULE__DIRECTIVE_GROUPS2 = 4, // <_directive_groups> ::= <directive_groups> <directive_group>
RULE_DIRECTIVE_GROUP_TKNEWLINE = 5, // <directive_group> ::= 'TKNEWLINE'
RULE_DIRECTIVE_GROUP_TKPROGRAM_LINE_PART = 6, // <directive_group> ::= 'TKPROGRAM_LINE_PART'
RULE_DIRECTIVE_GROUP_TKDIRECTIVE = 7, // <directive_group> ::= 'TKDIRECTIVE' <empty>
RULE_EMPTY = 8 // <empty> ::=
};
private Object CreateTerminalObject()
{
switch ((SymbolConstants) LRParser.TokenSymbol.Index)
{
case SymbolConstants.SYMBOL_EOF :
//(EOF)
//TERMINAL:EOF
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_ERROR :
//(Error)
//TERMINAL:Error
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_WHITESPACE :
//(Whitespace)
/*Console.Error.WriteLine("\n\rwarning: TerminalToken 'Whitespace' return NULL! \n\r");*/return null;
case SymbolConstants.SYMBOL_COMMENTEND :
//(Comment End)
/*Console.Error.WriteLine("\n\rwarning: TerminalToken 'Comment End' return NULL! \n\r");*/return null;
case SymbolConstants.SYMBOL_COMMENTLINE :
//(Comment Line)
/*Console.Error.WriteLine("\n\rwarning: TerminalToken 'Comment Line' return NULL! \n\r");*/return null;
case SymbolConstants.SYMBOL_COMMENTSTART :
//(Comment Start)
/*Console.Error.WriteLine("\n\rwarning: TerminalToken 'Comment Start' return NULL! \n\r");*/return null;
case SymbolConstants.SYMBOL_TKDIRECTIVE :
//'TKDIRECTIVE'
{
token_info _token_info=new token_info(LRParser.TokenText);
_token_info.source_context=parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_TKNEWLINE :
//'TKNEWLINE'
{
token_info _token_info=new token_info(LRParser.TokenText);
_token_info.source_context=parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_TKPROGRAM_LINE_PART :
//'TKPROGRAM_LINE_PART'
{
token_info _token_info=new token_info(LRParser.TokenText);
_token_info.source_context=parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL__DIRECTIVE_GROUPS :
//<_directive_groups>
//TERMINAL:_directive_groups
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_DIRECTIVE_GROUP :
//<directive_group>
//TERMINAL:directive_group
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_DIRECTIVE_GROUPS :
//<directive_groups>
//TERMINAL:directive_groups
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_EMPTY :
//<empty>
//TERMINAL:empty
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_PREPROCESSOR_PROGRAM :
//<preprocessor_program>
//TERMINAL:preprocessor_program
return null;
//ENDTERMINAL
}
throw new SymbolException("Unknown symbol");
}
public Object CreateNonTerminalObject()
{
switch ((RuleConstants) LRParser.ReductionRule.Index)
{
case RuleConstants.RULE_PREPROCESSOR_PROGRAM :
//<preprocessor_program> ::= <directive_groups> <empty>
{
compilation_unit _compilation_unit=new compilation_unit();
_compilation_unit.Language=LanguageId.PascalABCNET;
if(LRParser.GetReductionSyntaxNode(0)!=null){
parsertools.create_source_context(_compilation_unit,LRParser.GetReductionSyntaxNode(0),LRParser.GetReductionSyntaxNode(0));
CompilerDirectives.AddRange(((compiler_directive_list)LRParser.GetReductionSyntaxNode(0)).directives);
}
return _compilation_unit;
}
case RuleConstants.RULE_DIRECTIVE_GROUPS :
//<directive_groups> ::= <_directive_groups>
return LRParser.GetReductionSyntaxNode(0);
case RuleConstants.RULE_DIRECTIVE_GROUPS2 :
//<directive_groups> ::=
//NONTERMINAL:<directive_groups> ::=
return null;
//ENDNONTERMINAL
case RuleConstants.RULE__DIRECTIVE_GROUPS :
//<_directive_groups> ::= <directive_group> <empty>
{
compiler_directive_list _compiler_directive_list=new compiler_directive_list();
if(LRParser.GetReductionSyntaxNode(0) is compiler_directive)
_compiler_directive_list.directives.Add((compiler_directive)LRParser.GetReductionSyntaxNode(0));
parsertools.create_source_context(_compiler_directive_list,LRParser.GetReductionSyntaxNode(0),LRParser.GetReductionSyntaxNode(0));
return _compiler_directive_list;
}
case RuleConstants.RULE__DIRECTIVE_GROUPS2 :
//<_directive_groups> ::= <directive_groups> <directive_group>
{
compiler_directive_list _compiler_directive_list=(compiler_directive_list)LRParser.GetReductionSyntaxNode(0);
if(LRParser.GetReductionSyntaxNode(1) is compiler_directive)
_compiler_directive_list.directives.Add((compiler_directive)LRParser.GetReductionSyntaxNode(1));
parsertools.create_source_context(_compiler_directive_list,LRParser.GetReductionSyntaxNode(0),LRParser.GetReductionSyntaxNode(1));
return _compiler_directive_list;
}
case RuleConstants.RULE_DIRECTIVE_GROUP_TKNEWLINE :
//<directive_group> ::= 'TKNEWLINE'
return LRParser.GetReductionSyntaxNode(0);
case RuleConstants.RULE_DIRECTIVE_GROUP_TKPROGRAM_LINE_PART :
//<directive_group> ::= 'TKPROGRAM_LINE_PART'
return LRParser.GetReductionSyntaxNode(0);
case RuleConstants.RULE_DIRECTIVE_GROUP_TKDIRECTIVE :
//<directive_group> ::= 'TKDIRECTIVE' <empty>
{
compiler_directive _compiler_directive=(compiler_directive)pascal_parsertools.MakeDirective((token_info)LRParser.GetReductionSyntaxNode(0));
return _compiler_directive;
}
case RuleConstants.RULE_EMPTY :
//<empty> ::=
//NONTERMINAL:<empty> ::=
return null;
//ENDNONTERMINAL
}
throw new RuleException("Unknown rule");
}
}
}

View file

@ -1,63 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using PascalABCCompiler;
using PascalABCCompiler.Errors;
using System.IO;
using PascalABCCompiler.SyntaxTree;
using System.Text.RegularExpressions;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.Parsers;
using PascalABCCompiler.PascalPreprocessor;
namespace PascalABCCompiler.PascalPreprocessor
{
public class Preprocessor : IPreprocessor
{
public Preprocessor(SourceFilesProviderDelegate sourceFilesProvider)
{
this.sourceFilesProvider = sourceFilesProvider;
}
SourceFilesProviderDelegate sourceFilesProvider;
public SourceFilesProviderDelegate SourceFilesProvider
{
get
{
return sourceFilesProvider;
}
set
{
sourceFilesProvider = value;
}
}
List<compiler_directive> compilerDirectives=null;
public List<compiler_directive> CompilerDirectives
{
get
{
return compilerDirectives;
}
}
PascalPreprocessorLanguageParser PascalPreprocessorParser;
public string Build(string[] fileNames,string[] SearchPaches, List<Error> errors, SourceContextMap sourceContextMap)
{
if (PascalPreprocessorParser == null)
PascalPreprocessorParser = new PascalPreprocessorLanguageParser();
compilerDirectives = new List<compiler_directive>();
string text = (string)SourceFilesProvider(fileNames[0], SourceFileOperation.GetText);
PascalPreprocessorParser.Errors = errors;
compilation_unit cu = PascalPreprocessorParser.BuildTree(fileNames[0], text, SearchPaches, PascalABCCompiler.Parsers.ParseMode.Normal) as compilation_unit;
if (errors.Count > 0)
return text;
if (cu == null)
errors.Add(new CompilerInternalError("PascalPreprocessor", new Exception("cu==null")));
if (cu != null)
compilerDirectives.AddRange(cu.compiler_directives);
return text;
}
}
}

View file

@ -1,165 +0,0 @@
using System;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.PascalABCParser;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.Errors;
using System.Collections.Generic;
namespace PascalABCCompiler.Preprocessor_2.Errors
{
public static class StringResources
{
private static string prefix = "PABCPreprocessor2_";
public static string Get(string Id)
{
string ret = PascalABCCompiler.StringResources.Get(prefix + Id);
if (ret == prefix + Id)
return Id;
else
return ret;
}
}
public class IncludeFileNotFound : SyntaxError
{
public IncludeFileNotFound(string _file_name, SourceContext _source_context, syntax_tree_node _node, string FileName)
:
base(String.Format(StringResources.Get("INCLUDE_FILE_{0}_NOTFOUND"), FileName), _file_name, _source_context, _node)
{
}
}
public class CircularInclude : SyntaxError
{
public CircularInclude(string _file_name, SourceContext _source_context, syntax_tree_node _node, string FileName)
:
base(String.Format(StringResources.Get("CIRCULAR_INCLUDE_{0}"), FileName), _file_name, _source_context, _node)
{
}
}
public class ErrorInDefineSyntax : SyntaxError
{
public ErrorInDefineSyntax(string _file_name, SourceContext _source_context)
:
base(StringResources.Get("ERROR_IN_DEFINE_SYNTAX"), _file_name, _source_context, null)
{
}
}
public class NameDefineError : SyntaxError
{
public NameDefineError(string name, string _file_name, SourceContext _source_context)
:
base(String.Format(StringResources.Get("NAME_IS_DEFINED_{0}"), name), _file_name, _source_context, null)
{
}
}
public class NameUndefError : SyntaxError
{
public NameUndefError(string name, string _file_name, SourceContext _source_context)
:
base(String.Format(StringResources.Get("NAME_WAS_NOT_DEFINED_{0}"), name), _file_name, _source_context, null)
{
}
}
public class ErrorInIncludeSyntax : SyntaxError
{
public ErrorInIncludeSyntax(string _file_name, SourceContext _source_context)
:
base(StringResources.Get("ERROR_IN_INCLUDE_SYNTAX"), _file_name, _source_context, null)
{
}
}
public class UnexpectedEndif : SyntaxError
{
public UnexpectedEndif(string _file_name, SourceContext _source_context)
:
base(StringResources.Get("UNEXPEXTED_ENDIF_DIRECTIVE"), _file_name, _source_context, null)
{
}
}
public class UnexpectedElse : SyntaxError
{
public UnexpectedElse(string _file_name, SourceContext _source_context)
:
base(StringResources.Get("UNEXPEXTED_ELSE_DIRECTIVE"), _file_name, _source_context, null)
{
}
}
public class UnexpectedEOF : SyntaxError
{
public UnexpectedEOF(string _file_name, SourceContext _source_context)
:
base(StringResources.Get("ENDIF_DIRECTIVE_EXPEXTED"), _file_name, _source_context, null)
{
}
}
public class SyntaxErrorInDirective : SyntaxError
{
public SyntaxErrorInDirective(string _file_name, SourceContext _source_context, string command)
:
base(String.Format(StringResources.Get("SYNTAX_ERROR_IN_DIRECTIVE_{0}"), command), _file_name, _source_context, null)
{
}
}
public class UnknownDirective : SyntaxError
{
public UnknownDirective(string _file_name, SourceContext _source_context, string command)
:
base(String.Format(StringResources.Get("UNKNOWN_DIRECTIVE_{0}"), command), _file_name, _source_context, null)
{
}
}
//aspects
public class AspSpacesError : SyntaxError
{
public AspSpacesError(string _file_name, SourceContext _source_context, string command)
:
base(String.Format(StringResources.Get("UNEXPECTED_SPACES_IN_DIRECTIVE_{0}"), command), _file_name, _source_context, null)
{
}
}
public class UnexpAspData : SyntaxError
{
public UnexpAspData(string _file_name, SourceContext _source_context, string command)
:
base(String.Format(StringResources.Get("UNEXPECTED_ASPDATA_DIRECTIVE_{0}"), command), _file_name, _source_context, null)
{
}
}
public class DoubleAspData : SyntaxError
{
public DoubleAspData(string _file_name, SourceContext _source_context, string command)
:
base(String.Format(StringResources.Get("DOUBLE_ASPDATA_DIRECTIVE_{0}"), command), _file_name, _source_context, null)
{
}
}
public class ErrorAspData : SyntaxError
{
public ErrorAspData(string _file_name, SourceContext _source_context, string command)
:
base(String.Format(StringResources.Get("ERROR_ASPDATA_DIRECTIVE_{0}"), command), _file_name, _source_context, null)
{
}
}
public class AspBeginEndError : SyntaxError
{
public AspBeginEndError(string _file_name, SourceContext _source_context, string command)
:
base(String.Format(StringResources.Get("ASPBEGINEND_ERROR_IN_DIRECTIVE_{0}"), command), _file_name, _source_context, null)
{
}
}
//end aspects
}

View file

@ -1,597 +0,0 @@
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!!!
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Collections;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.Errors;
using PascalABCCompiler.PascalABCParser.Errors;
using PascalABCCompiler.Preprocessor_2.Errors;
using PascalABCCompiler.ParserTools;
using GoldParser;
using PascalABCCompiler.PascalABCParser;
namespace PascalABCCompiler.Preprocessor2
{
public class GPB_PABCPreprocessor2 : GPBParser
{
public PascalABCCompiler.Preprocessor2.Preprocessor2 prepr;
private pascalabc_parsertools pascal_parsertools;
public GPB_PABCPreprocessor2(Stream stream, PascalABCCompiler.Preprocessor2.Preprocessor2 prepr1)
: base(stream)
{
pascal_parsertools = new pascalabc_parsertools();
parsertools = pascal_parsertools;
prepr = prepr1;
}
public GPB_PABCPreprocessor2(Stream stream, GoldParser.Grammar grammar, PascalABCCompiler.Preprocessor2.Preprocessor2 prepr1)
: base(grammar)
{
pascal_parsertools = new pascalabc_parsertools();
parsertools = pascal_parsertools;
prepr = prepr1;
}
public object Parse(string source)
{
LRParser = new Parser(new StringReader(source), LanguageGrammar);
parsertools.parser = LRParser;
LRParser.TrimReductions = true;
try
{
while (true)
{
switch (LRParser.Parse())
{
case ParseMessage.LexicalError:
errors.Add(new TokenReadError(this));
LRParser.PopInputToken();
if (errors.Count > max_errors)
return null;
break;
case ParseMessage.SyntaxError:
if ((LRParser.TokenSyntaxNode as syntax_tree_node) != null)
prev_node = LRParser.TokenSyntaxNode;
Error er = new PABCNETUnexpectedToken(this);
Symbol sym = LRParser.PopInputToken();
if (sym.SymbolType == SymbolType.End && errors.Count > 0)
return null;
errors.Add(er);
if (errors.Count > max_errors)
return null;
break;
case ParseMessage.Reduction:
LRParser.TokenSyntaxNode = CreateNonTerminalObject();
break;
case ParseMessage.Accept:
return LRParser.TokenSyntaxNode;
case ParseMessage.TokenRead:
LRParser.TokenSyntaxNode = CreateTerminalObject();
break;
case ParseMessage.InternalError:
errors.Add(new CompilerInternalError("PABCPreprocessor2", new Exception("ParseMessage.InternalError")));
return null;
case ParseMessage.NotLoadedError:
errors.Add(new CompilerInternalError("PABCPreprocessor2", new Exception("ParseMessage.NotLoadedError")));
return null;
case ParseMessage.CommentError:
errors.Add(new UnexpectedToken(this, "(EOF)"));
return null;
case ParseMessage.CommentBlockRead:
{
SourceContext sc1 = parsertools.GetTokenSourceContext(this.LRParser);
string comment = this.LRParser.CommentText;
SourceContext sc2 = new SourceContext(sc1, parsertools.GetTokenSourceContext(this.LRParser));
if (comment[0] == '{' && comment[1] == '$')
prepr.Errors.Add(new SyntaxErrorInDirective(prepr.CurrentFileName, sc2, comment));
//if (prepr.sm.AllowWrite())
//prepr.WriteToThread(sc2, comment.Replace(Environment.NewLine, " "));
//prepr.WriteToStream(sc2, comment.Replace("\r\n", " "));
}
break;
case ParseMessage.CommentLineRead:
{
SourceContext sc1 = parsertools.GetTokenSourceContext(this.LRParser);
string comment = this.LRParser.CommentText;
SourceContext sc2 = new SourceContext(sc1, sc1);
if (prepr.sm.AllowWrite())
prepr.WriteToStream(sc1, comment.Replace("\r\n", " "));
//prepr.WriteToStream(sc1, comment);
}
break;
}
}
}
catch (GoldParser.UnexpectedEOFinParseCommentBlock)
{
throw new TokenReadError(this);
}
catch (Exception e)
{
if (errors.Count > 0)
return null;
else
throw;
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//SymbolConstants
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
public enum SymbolConstants : int
{
SYMBOL_EOF = 0, // (EOF)
SYMBOL_ERROR = 1, // (Error)
SYMBOL_WHITESPACE = 2, // (Whitespace)
SYMBOL_COMMENTEND = 3, // (Comment End)
SYMBOL_COMMENTLINE = 4, // (Comment Line)
SYMBOL_COMMENTSTART = 5, // (Comment Start)
SYMBOL_TK_AP = 6, // 'TK_AP'
SYMBOL_TK_DIRECTIVE = 7, // 'TK_DIRECTIVE'
SYMBOL_TK_KAV = 8, // 'TK_KAV'
SYMBOL_TK_NEWLINE = 9, // 'TK_NEWLINE'
SYMBOL_TK_PROGRAM_LINE = 10, // 'TK_PROGRAM_LINE'
SYMBOL_TK_SLASH = 11, // 'TK_SLASH'
SYMBOL_TK_SLASHEKV = 12, // 'TK_SLASHEKV'
SYMBOL__PREPROCESSOR_LEXEMS = 13, // <_preprocessor_lexems>
SYMBOL_EMPTY = 14, // <empty>
SYMBOL_PREPROCESSOR_LEXEM = 15, // <preprocessor_lexem>
SYMBOL_PREPROCESSOR_LEXEMS = 16, // <preprocessor_lexems>
SYMBOL_PREPROCESSOR_PROGRAM = 17 // <preprocessor_program>
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//RuleConstants
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
public enum RuleConstants : int
{
RULE_PREPROCESSOR_PROGRAM = 0, // <preprocessor_program> ::= <preprocessor_lexems> <empty>
RULE_PREPROCESSOR_LEXEMS = 1, // <preprocessor_lexems> ::= <_preprocessor_lexems>
RULE_PREPROCESSOR_LEXEMS2 = 2, // <preprocessor_lexems> ::=
RULE__PREPROCESSOR_LEXEMS = 3, // <_preprocessor_lexems> ::= <preprocessor_lexem> <empty>
RULE__PREPROCESSOR_LEXEMS2 = 4, // <_preprocessor_lexems> ::= <preprocessor_lexems> <preprocessor_lexem>
RULE_PREPROCESSOR_LEXEM_TK_NEWLINE = 5, // <preprocessor_lexem> ::= 'TK_NEWLINE'
RULE_PREPROCESSOR_LEXEM_TK_SLASH = 6, // <preprocessor_lexem> ::= 'TK_SLASH'
RULE_PREPROCESSOR_LEXEM_TK_SLASHEKV = 7, // <preprocessor_lexem> ::= 'TK_SLASHEKV'
RULE_PREPROCESSOR_LEXEM_TK_AP = 8, // <preprocessor_lexem> ::= 'TK_AP'
RULE_PREPROCESSOR_LEXEM_TK_KAV = 9, // <preprocessor_lexem> ::= 'TK_KAV'
RULE_PREPROCESSOR_LEXEM_TK_PROGRAM_LINE = 10, // <preprocessor_lexem> ::= 'TK_PROGRAM_LINE'
RULE_PREPROCESSOR_LEXEM_TK_DIRECTIVE = 11, // <preprocessor_lexem> ::= 'TK_DIRECTIVE' <empty>
RULE_EMPTY = 12 // <empty> ::=
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//CreateTerminalObject
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
private Object CreateTerminalObject()
{
switch ((SymbolConstants)LRParser.TokenSymbol.Index)
{
case SymbolConstants.SYMBOL_EOF :
//(EOF)
//TERMINAL:EOF
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_ERROR :
//(Error)
//TERMINAL:Error
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_WHITESPACE :
//(Whitespace)
/*Console.Error.WriteLine("\n\rwarning: TerminalToken 'Whitespace' return NULL! \n\r");*/return null;
case SymbolConstants.SYMBOL_COMMENTEND :
//(Comment End)
/*Console.Error.WriteLine("\n\rwarning: TerminalToken 'Comment End' return NULL! \n\r");*/return null;
case SymbolConstants.SYMBOL_COMMENTLINE :
//(Comment Line)
/*Console.Error.WriteLine("\n\rwarning: TerminalToken 'Comment Line' return NULL! \n\r");*/return null;
case SymbolConstants.SYMBOL_COMMENTSTART :
//(Comment Start)
/*Console.Error.WriteLine("\n\rwarning: TerminalToken 'Comment Start' return NULL! \n\r");*/return null;
case SymbolConstants.SYMBOL_TK_AP :
//'TK_AP'
{
token_info _token_info = new token_info(LRParser.TokenText);
_token_info.source_context = parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_TK_DIRECTIVE :
//'TK_DIRECTIVE'
{
token_info _token_info = new token_info(LRParser.TokenText);
_token_info.source_context = parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_TK_KAV :
//'TK_KAV'
{
token_info _token_info = new token_info(LRParser.TokenText);
_token_info.source_context = parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_TK_NEWLINE :
//'TK_NEWLINE'
/*Console.Error.WriteLine("\n\rwarning: TerminalToken 'TK_NEWLINE' return NULL! \n\r");*/return null;
case SymbolConstants.SYMBOL_TK_PROGRAM_LINE :
//'TK_PROGRAM_LINE'
{
token_info _token_info = new token_info(LRParser.TokenText);
_token_info.source_context = parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_TK_SLASH :
//'TK_SLASH'
{
token_info _token_info = new token_info(LRParser.TokenText);
_token_info.source_context = parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL_TK_SLASHEKV :
//'TK_SLASHEKV'
{
token_info _token_info = new token_info(LRParser.TokenText);
_token_info.source_context = parsertools.GetTokenSourceContext();
return _token_info;
}
case SymbolConstants.SYMBOL__PREPROCESSOR_LEXEMS :
//<_preprocessor_lexems>
//TERMINAL:_preprocessor_lexems
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_EMPTY :
//<empty>
//TERMINAL:empty
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_PREPROCESSOR_LEXEM :
//<preprocessor_lexem>
//TERMINAL:preprocessor_lexem
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_PREPROCESSOR_LEXEMS :
//<preprocessor_lexems>
//TERMINAL:preprocessor_lexems
return null;
//ENDTERMINAL
case SymbolConstants.SYMBOL_PREPROCESSOR_PROGRAM :
//<preprocessor_program>
//TERMINAL:preprocessor_program
return null;
//ENDTERMINAL
}
throw new SymbolException("Unknown symbol");
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//CreateNonTerminalObject
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
public Object CreateNonTerminalObject()
{
switch ((RuleConstants)LRParser.ReductionRule.Index)
{
case RuleConstants.RULE_PREPROCESSOR_PROGRAM :
//<preprocessor_program> ::= <preprocessor_lexems> <empty>
{
compilation_unit _compilation_unit = new compilation_unit();
_compilation_unit.Language = LanguageId.PascalABCNET;
if (LRParser.GetReductionSyntaxNode(0) != null)
{
parsertools.create_source_context(_compilation_unit, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
CompilerDirectives.AddRange(((compiler_directive_list)LRParser.GetReductionSyntaxNode(0)).directives);
if (CompilerDirectives.Count != 0)
prepr.CompilerDirectives.AddRange(CompilerDirectives);
}
return _compilation_unit;
}
case RuleConstants.RULE_PREPROCESSOR_LEXEMS :
//<preprocessor_lexems> ::= <_preprocessor_lexems>
return LRParser.GetReductionSyntaxNode(0);
case RuleConstants.RULE_PREPROCESSOR_LEXEMS2 :
//<preprocessor_lexems> ::=
//NONTERMINAL:<preprocessor_lexems> ::=
return null;
//ENDNONTERMINAL
case RuleConstants.RULE__PREPROCESSOR_LEXEMS :
//<_preprocessor_lexems> ::= <preprocessor_lexem> <empty>
{
compiler_directive_list _compiler_directive_list = new compiler_directive_list();
if (LRParser.GetReductionSyntaxNode(0) is compiler_directive)
_compiler_directive_list.directives.Add((compiler_directive)LRParser.GetReductionSyntaxNode(0));
parsertools.create_source_context(_compiler_directive_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(0));
return _compiler_directive_list;
}
case RuleConstants.RULE__PREPROCESSOR_LEXEMS2 :
//<_preprocessor_lexems> ::= <preprocessor_lexems> <preprocessor_lexem>
{
compiler_directive_list _compiler_directive_list = (compiler_directive_list)LRParser.GetReductionSyntaxNode(0);
if (LRParser.GetReductionSyntaxNode(1) is compiler_directive)
_compiler_directive_list.directives.Add((compiler_directive)LRParser.GetReductionSyntaxNode(1));
parsertools.create_source_context(_compiler_directive_list, LRParser.GetReductionSyntaxNode(0), LRParser.GetReductionSyntaxNode(1));
return _compiler_directive_list;
}
case RuleConstants.RULE_PREPROCESSOR_LEXEM_TK_NEWLINE :
//<preprocessor_lexem> ::= 'TK_NEWLINE'
return LRParser.GetReductionSyntaxNode(0);
case RuleConstants.RULE_PREPROCESSOR_LEXEM_TK_SLASH :
//<preprocessor_lexem> ::= 'TK_SLASH'
{
if (prepr.sm.AllowWrite())
prepr.WriteToStream(((token_info)LRParser.GetReductionSyntaxNode(0)).source_context, ((token_info)LRParser.GetReductionSyntaxNode(0)).text);
return LRParser.GetReductionSyntaxNode(0);
}
case RuleConstants.RULE_PREPROCESSOR_LEXEM_TK_SLASHEKV :
//<preprocessor_lexem> ::= 'TK_SLASHEKV'
{
if (prepr.sm.AllowWrite())
prepr.WriteToStream(((token_info)LRParser.GetReductionSyntaxNode(0)).source_context, ((token_info)LRParser.GetReductionSyntaxNode(0)).text);
return LRParser.GetReductionSyntaxNode(0);
}
case RuleConstants.RULE_PREPROCESSOR_LEXEM_TK_AP :
//<preprocessor_lexem> ::= 'TK_AP'
{
if (prepr.sm.AllowWrite())
prepr.WriteToStream(((token_info)LRParser.GetReductionSyntaxNode(0)).source_context, ((token_info)LRParser.GetReductionSyntaxNode(0)).text);
return LRParser.GetReductionSyntaxNode(0);
}
case RuleConstants.RULE_PREPROCESSOR_LEXEM_TK_KAV :
//<preprocessor_lexem> ::= 'TK_KAV'
{
if (prepr.sm.AllowWrite())
prepr.WriteToStream(((token_info)LRParser.GetReductionSyntaxNode(0)).source_context, ((token_info)LRParser.GetReductionSyntaxNode(0)).text);
return LRParser.GetReductionSyntaxNode(0);
}
case RuleConstants.RULE_PREPROCESSOR_LEXEM_TK_PROGRAM_LINE :
//<preprocessor_lexem> ::= 'TK_PROGRAM_LINE'
{
if (prepr.sm.AllowWrite())
prepr.WriteToStream(((token_info)LRParser.GetReductionSyntaxNode(0)).source_context, ((token_info)LRParser.GetReductionSyntaxNode(0)).text);
return LRParser.GetReductionSyntaxNode(0);
}
case RuleConstants.RULE_PREPROCESSOR_LEXEM_TK_DIRECTIVE :
//<preprocessor_lexem> ::= 'TK_DIRECTIVE' <empty>
{
bool inline = ( ((token_info)LRParser.GetReductionSyntaxNode(0)).source_context.begin_position.line_num - ((token_info)LRParser.GetReductionSyntaxNode(0)).source_context.end_position.line_num == 0 );
string token_text = ((token_info)LRParser.GetReductionSyntaxNode(0)).text;
if (token_text[1] == '$' && inline)
{
compiler_directive _compiler_directive = (compiler_directive)pascal_parsertools.MakeDirective((token_info)LRParser.GetReductionSyntaxNode(0));
_compiler_directive.source_context.FileName = prepr.CurrentFileName;
prepr.CurrentFileName = _compiler_directive.source_context.FileName;
//INCLUDE
if (_compiler_directive.Name.text == prepr.INCLUDE)
{
if (prepr.sm.AllowWrite())
{
string IncludeFileName = _compiler_directive.Directive.text;
if (prepr.ProcessedFileNames.Contains(IncludeFileName) || Path.GetFileName(prepr.CurrentFileName) == Path.GetFileName(IncludeFileName))
{
prepr.Errors.Add(new CircularInclude(prepr.CurrentFileName, _compiler_directive.source_context, null, IncludeFileName));
}
else
{
if (!(bool)prepr.SourceFilesProvider(IncludeFileName, SourceFileOperation.Exists))
prepr.Errors.Add(new IncludeFileNotFound(prepr.CurrentFileName, _compiler_directive.source_context, null, IncludeFileName));
string b = prepr.CurrentFileName;
//string t = prepr.SourceText;
//string[] sl = prepr.SourceLines;
prepr.ProcessFile(IncludeFileName);
prepr.CurrentFileName = b;
//prepr.SourceText = t;
//prepr.SourceLines = sl;
prepr.ProcessedFileNames.Remove(IncludeFileName);
}
}
return _compiler_directive;
}
//DEFINE
if (_compiler_directive.Name.text == prepr.DEFINE)
{
if (prepr.sm.AllowWrite())
{
string directive = _compiler_directive.Directive.text;
string name = prepr.getFirstIdent(directive);
string text = prepr.getSecondIdent(directive);
prepr.AddDefineDirective(name, text, _compiler_directive);
}
return _compiler_directive;
}
//UNDEF
if (_compiler_directive.Name.text == prepr.UNDEF)
{
if (prepr.sm.AllowWrite())
{
string directive = _compiler_directive.Directive.text;
string name = prepr.getFirstIdent(directive);
if (name != null)
if (prepr.DefineDirectiveDefinded(name))
prepr.DeleteDefineDirective(name, _compiler_directive);
}
return _compiler_directive;
}
//IFDEF
if (_compiler_directive.Name.text == prepr.IFDEF)
{
string directive = _compiler_directive.Directive.text;
if (prepr.sm.AllowWrite())
{
if (directive != null)
{
if (!prepr.DefineDirectiveDefinded(directive))
prepr.sm.ChangeState(false, 1);
else
prepr.sm.ChangeState(true, 1);
}
}
else
prepr.sm.ChangeState(false, -1);
return _compiler_directive;
}
//IFNDEF
if (_compiler_directive.Name.text == prepr.IFNDEF)
{
string directive = _compiler_directive.Directive.text;
if (prepr.sm.AllowWrite())
{
if (directive != null)
{
if (prepr.DefineDirectiveDefinded(directive))
prepr.sm.ChangeState(false, 1);
else
prepr.sm.ChangeState(true, 1);
}
}
else
prepr.sm.ChangeState(false, -1);
return _compiler_directive;
}
//ELSE
if (_compiler_directive.Name.text == prepr.ELSE)
{
if (prepr.sm.GetEndifCount() == 0 || prepr.sm.AllowElse() == false)
{
prepr.Errors.Add(new UnexpectedElse(prepr.CurrentFileName, _compiler_directive.source_context));
}
else
{
if (prepr.sm.AllowWrite())
prepr.sm.ChangeState(false, false);
else
{
if (prepr.sm.LastCondition() == 1)
prepr.sm.ChangeState(true, false);
else
prepr.sm.ChangeState(false, false);
}
}
return _compiler_directive;
}
//ENDIF
if (_compiler_directive.Name.text == prepr.ENDIF)
{
if (prepr.sm.GetEndifCount() == 0)
{
prepr.Errors.Add(new UnexpectedEndif(prepr.CurrentFileName, _compiler_directive.source_context));
}
else
{
if (prepr.sm.AllowWrite())
prepr.sm.ChangeState(true, true);
else
{
if (prepr.sm.LastEndifCondition() == 1)
prepr.sm.ChangeState(true, true);
else
prepr.sm.ChangeState(false, true);
}
}
return _compiler_directive;
}
return _compiler_directive;
}
return LRParser.GetReductionSyntaxNode(0);
}
case RuleConstants.RULE_EMPTY :
//<empty> ::=
//NONTERMINAL:<empty> ::=
return null;
//ENDNONTERMINAL
}
throw new RuleException("Unknown rule");
}
}
}

View file

@ -1,173 +0,0 @@
using System;
using System.IO;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.SyntaxTree;
using System.Resources;
using System.Reflection;
using PascalABCCompiler.Parsers;
using System.Collections.Generic;
using PascalABCCompiler.Errors;
namespace PascalABCCompiler.Preprocessor2
{
public class PascalPreprocessor2LanguageParser:IParser
{
public GPB_PABCPreprocessor2 parser;
public PascalPreprocessor2LanguageParser()
{
this.filesExtensions = new string[1];
this.filesExtensions[0] = ".paspr2" + Parsers.Controller.HideParserExtensionPostfixChar;
parser = null;
}
string[] filesExtensions;
public string[] FilesExtensions
{
get
{
return filesExtensions;
}
}
ILanguageInformation lnginf = new DefaultLanguageInformation();
public ILanguageInformation LanguageInformation {
get {
return lnginf;
}
}
public bool CaseSensitive
{
get
{
return parser.LanguageGrammar.CaseSensitive;
}
}
public Keyword[] Keywords
{
get
{
return new Keyword[0];
}
}
public List<compiler_directive> compilerDirectives = new List<compiler_directive>();
public List<compiler_directive> CompilerDirectives
{
get
{
return compilerDirectives;
}
}
List<Error> errors = new List<Error>();
public List<Error> Errors
{
get
{
return errors;
}
set
{
errors = value;
}
}
private Stream grammar_stream = null;
public void Reset()
{
grammar_stream = CGTResourceExtractor.Extract(new ResourceManager("PascalABCParser.Preprocessor_2.PABCPreprocessor2Lang", Assembly.GetExecutingAssembly()), "PABCPreprocessor2Language");
parser = new GPB_PABCPreprocessor2(grammar_stream,null);
max_errors = 5;
}
public virtual int max_errors
{
get
{
return parser.max_errors;
}
set
{
parser.max_errors=value;
}
}
SourceFilesProviderDelegate sourceFilesProvider = null;
public SourceFilesProviderDelegate SourceFilesProvider
{
get
{
return sourceFilesProvider;
}
set
{
sourceFilesProvider = value;
}
}
public syntax_tree_node BuildTree(string FileName, string Text, ParseMode parseMode)
{
if (this.parser == null)
Reset();
GPB_PABCPreprocessor2 parser = new GPB_PABCPreprocessor2(this.grammar_stream, this.parser.LanguageGrammar, this.parser.prepr);
parser.errors = Errors;
parser.current_file_name = FileName;
compilerDirectives = new List<compiler_directive>();
parser.CompilerDirectives = compilerDirectives;
switch (parseMode)
{
case ParseMode.Expression:
case ParseMode.Statement:
return null;
}
syntax_tree_node cu = (syntax_tree_node)parser.Parse(Text);
if (cu != null && cu is compilation_unit)
{
(cu as compilation_unit).file_name = FileName;
(cu as compilation_unit).compiler_directives = compilerDirectives;
}
return cu;
}
public string Name
{
get
{
return "PABCPreprocessor2";
}
}
public string Version
{
get
{
return "0.1";
}
}
public string Copyright
{
get
{
return "(c) Зарубин М.А. 2009";
}
}
public override string ToString()
{
return "PABCPreprocessor2 v0.1";
}
public IPreprocessor Preprocessor
{
get
{
return null;
}
}
}
}

View file

@ -1,620 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using PascalABCCompiler;
using PascalABCCompiler.Errors;
using PascalABCCompiler.Preprocessor_2.Errors;
using System.IO;
using PascalABCCompiler.SyntaxTree;
using System.Text.RegularExpressions;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.Parsers;
using PascalABCCompiler.Preprocessor_2;
namespace PascalABCCompiler.Preprocessor2
{
public class Preprocessor2 : IPreprocessor
{
public string DEFINE = "define";
public string UNDEF = "undef";
public string INCLUDE = "include";
public string IFDEF = "ifdef";
public string IFNDEF = "ifndef";
public string ENDIF = "endif";
public string ELSE = "else";
public string ASP = "asp";
public string ENDASP = "endasp";
public string ASPDATA = "aspdata";
PascalABCCompiler.Preprocessor2.PascalPreprocessor2LanguageParser preprocessor_parser = new PascalPreprocessor2LanguageParser();
public StatesManager sm = new StatesManager();
public List<compiler_directive> Directives = new List<compiler_directive>();
public SourceContextMap SourceContextMap;
public TextWriter tw;
//public string SourceText;
//public string[] SourceLines;
public int CurrentLineNumber = 1;
public int Position = 0;
public List<Error> Errors;
public string CurrentFileName;
public List<string> ProcessedFileNames = new List<string>();
Dictionary<string, string> DefineDirectives = new Dictionary<string, string>();
//Aspects
public string CurrentAspectDirective = "";
public bool InAspect = false;
public Dictionary<string, Aspect> AspectsMap = new Dictionary<string, Aspect>();
public List<string> AspectsNames = new List<string>();
//-------
public int newLineLength = Environment.NewLine.Length;
SourceFilesProviderDelegate sourceFilesProvider;
public SourceFilesProviderDelegate SourceFilesProvider
{
get
{
return sourceFilesProvider;
}
set
{
sourceFilesProvider = value;
}
}
List<compiler_directive> compilerDirectives = null;
public List<compiler_directive> CompilerDirectives
{
get
{
return compilerDirectives;
}
}
public void AddDefineDirective(string name, string text, compiler_directive _compiler_directive)
{
if (!DefineDirectives.ContainsKey(name))
{
DefineDirectives.Add(name, text);
}
else
{
Errors.Add(new NameDefineError(name, CurrentFileName, _compiler_directive.source_context));
}
}
public void DeleteDefineDirective(string name, compiler_directive _compiler_directive)
{
if (name != null)
{
if (DefineDirectives.ContainsKey(name))
{
DefineDirectives.Remove(name);
}
else
{
Errors.Add(new NameUndefError(name, CurrentFileName, _compiler_directive.source_context));
}
}
}
public bool DefineDirectiveDefinded(string name)
{
return DefineDirectives.ContainsKey(name);
}
public string getFirstIdent(string s)
{
s.Trim();
int n = s.IndexOf(' ');
if (n > 0)
return s.Substring(0, s.IndexOf(' '));
else
return s;
}
public string getSecondIdent(string s)
{
string s1 = getFirstIdent(s);
return s.Substring(s1.Length, s.Length - s1.Length).Trim();
}
public Preprocessor2(SourceFilesProviderDelegate sourceFilesProvider)
{
this.sourceFilesProvider = sourceFilesProvider;
this.sm.Reset();
}
public string Build(string[] fileNames, List<Error> errors, SourceContextMap sourceContextMap)
{
compilerDirectives = new List<compiler_directive>();
StringWriter sw = new StringWriter();
tw = sw;
Errors = errors;
SourceContextMap = sourceContextMap;
//AspectsMap.Clear();
ProcessedFileNames.Clear();
DefineDirectives.Clear();
foreach (string name in fileNames)
{
ProcessFile(name);
if (sm.GetEndifCount() != 0)
Errors.Add(new UnexpectedEOF(CurrentFileName, new SourceContext(int.MaxValue, 1, int.MaxValue, 1)));
if (errors.Count > 0)
return null;
}
return sw.ToString();
}
//Aspects
public string GetAspects(List<compiler_directive> cd_list, SourceContextMap sourceContextMap)
{
try
{
compilerDirectives = new List<compiler_directive>(cd_list);
//AspectsMap.Clear();
//GetStructures
foreach (compiler_directive cd in compilerDirectives)
{
if (cd.Name.text == ASP)
{
if (!(AspectsNames.Contains(cd.Directive.text)))
//if (!(AspectsMap.ContainsKey(cd.Directive.text)))
{
AspectsNames.Add(cd.Directive.text);
AspectsMap.Add(cd.Directive.text, new Aspect(cd.Directive.text));
AspectsMap[cd.Directive.text].AddBegin(cd.source_context);
}
else
AspectsMap[cd.Directive.text].AddBegin(cd.source_context);
}
//if (cd.Name.text == )
}
foreach (compiler_directive cd in compilerDirectives)
{
if (cd.Name.text == ENDASP)
{
if (!AspectsNames.Contains(cd.Directive.text))
{
//Error - unexp end of aspect
}
else
AspectsMap[cd.Directive.text].AddEnd(cd.source_context);
//AspectsMap.Add(cd.Directive.text, new Aspect(cd.Directive.text, false, cd.source_context));
}
}
//Get Text
StringWriter sw = new StringWriter();
//SourceContextMap = sourceContextMap;
List<SourceContext> beg;
List<SourceContext> end;
string CurrentFileName;
string CurrentFileText;
foreach (string str in AspectsMap.Keys)
{
beg = AspectsMap[str].GetBeginList();
end = AspectsMap[str].GetEndList();
for (int i = 0; i < beg.Count; i++)
{
CurrentFileName = beg[i].FileName;
CurrentFileText = (string)SourceFilesProvider(CurrentFileName, SourceFileOperation.GetText);
sw.WriteLine(CurrentFileText.Substring(beg[i].Position, end[i].Position - beg[i].Position + end[i].Length));
}
//AspectsMap[str].GetBeginList();
}
return sw.ToString();
}
catch (Exception e)
{
this.Errors.Add(new PascalABCCompiler.Errors.Error("Error in aspects reading"));
return "Error in aspects reading";
}
}
public string WriteAspects(string aspects, string proj)
{
StringWriter sw = new StringWriter();
List<SourceContext> beg;
List<SourceContext> end;
string CurrentAspectText;
string CurrentFileText;
string CurrentFileName;
string CurrentPath;
if (proj != "")
CurrentPath = proj + "\\";
else
CurrentPath = "";
foreach (string str in AspectsMap.Keys)
{
beg = AspectsMap[str].GetBeginList();
end = AspectsMap[str].GetEndList();
int asp_num = 0;
int asp_num_file = 0;
string asp_file_name = CurrentPath + beg[0].FileName;
for (int i = 0; i < beg.Count; i++)
{
///Files names & asp_num?
CurrentFileName = CurrentPath + beg[i].FileName;
CurrentFileText = (string)SourceFilesProvider(CurrentFileName, SourceFileOperation.GetText);
if (asp_file_name != CurrentFileName)
{
asp_num_file = 0;
asp_file_name = CurrentFileName;
}
if (aspects.IndexOf("{$asp " + str + "}", asp_num)>=0)
{
CurrentAspectText = aspects.Substring(aspects.IndexOf("{$asp " + str + "}", asp_num), aspects.IndexOf("{$endasp " + str + "}", asp_num) - aspects.IndexOf("{$asp " + str + "}", asp_num) + ("{$endasp " + str + "}").Length);
asp_num = aspects.IndexOf("{$endasp " + str + "}", asp_num) + ("{$endasp " + str + "}").Length;
int d = CurrentFileText.IndexOf("{$asp " + str + "}", asp_num_file);
int c = CurrentFileText.IndexOf("{$endasp " + str + "}", asp_num_file);
if (d >= 0 && c >= 0)
{
CurrentFileText = CurrentFileText.Substring(0, asp_num_file) + CurrentFileText.Substring(asp_num_file, d - asp_num_file) + CurrentAspectText + CurrentFileText.Substring(c + ("{$endasp " + str + "}").Length);
c = d + CurrentAspectText.Length;
asp_num_file = c + ("{$endasp " + str + "}").Length; ;
}
else
break;
StreamWriter swrt = new StreamWriter(Path.GetDirectoryName(CurrentFileName) + "\\" + Path.GetFileNameWithoutExtension(CurrentFileName) + ".pas", false, Encoding.UTF8);
swrt.Write(CurrentFileText);
swrt.Close();
}
}
}
return sw.ToString();
}
public string WriteAspect(string aspects, string proj, string str)
{
StringWriter sw = new StringWriter();
List<SourceContext> beg;
List<SourceContext> end;
string CurrentAspectText;
string CurrentFileText;
string CurrentFileName;
string CurrentPath;
if (proj != "")
CurrentPath = proj + "\\";
else
CurrentPath = "";
beg = AspectsMap[str].GetBeginList();
end = AspectsMap[str].GetEndList();
int asp_num = 0;
int asp_num_file = 0;
string asp_file_name = CurrentPath + beg[0].FileName;
for (int i = 0; i < beg.Count; i++)
{
CurrentFileName = CurrentPath + beg[i].FileName;
CurrentFileText = (string)SourceFilesProvider(CurrentFileName, SourceFileOperation.GetText);
if (asp_file_name != CurrentFileName)
{
asp_num_file = 0;
asp_file_name = CurrentFileName;
}
if (aspects.IndexOf("{$asp " + str + "}", asp_num) >= 0)
{
CurrentAspectText = aspects.Substring(aspects.IndexOf("{$asp " + str + "}", asp_num), aspects.IndexOf("{$endasp " + str + "}", asp_num) - aspects.IndexOf("{$asp " + str + "}", asp_num) + ("{$endasp " + str + "}").Length);
asp_num = aspects.IndexOf("{$endasp " + str + "}", asp_num) + ("{$endasp " + str + "}").Length;
int d = CurrentFileText.IndexOf("{$asp " + str + "}", asp_num_file);
int c = CurrentFileText.IndexOf("{$endasp " + str + "}", asp_num_file);
if (d >= 0 && c >= 0)
{
CurrentFileText = CurrentFileText.Substring(0, asp_num_file) + CurrentFileText.Substring(asp_num_file, d - asp_num_file) + CurrentAspectText + CurrentFileText.Substring(c + ("{$endasp " + str + "}").Length);
c = d + CurrentAspectText.Length;
asp_num_file = c + ("{$endasp " + str + "}").Length;
}
else
{
break;
}
StreamWriter swrt = new StreamWriter(Path.GetDirectoryName(CurrentFileName) + "\\" + Path.GetFileNameWithoutExtension(CurrentFileName) + ".pas", false, Encoding.UTF8);
swrt.Write(CurrentFileText);
swrt.Close();
}
}
return sw.ToString();
}
//end aspects
public void ProcessFile(string FileName)
{
ProcessedFileNames.Add(Path.GetFileName(FileName));
string Text = (string)SourceFilesProvider(FileName, SourceFileOperation.GetText);
CurrentFileName = FileName;
//SourceText = Text;
//string[] s ={ "\r\n" };
//SourceLines = Text.Split(s, StringSplitOptions.None);
preprocessor_parser.Reset();
preprocessor_parser.Errors = Errors;
preprocessor_parser.parser.prepr = this;
compilation_unit cu = preprocessor_parser.BuildTree(FileName, Text, PascalABCCompiler.Parsers.ParseMode.Normal) as compilation_unit;
CurrentFileName = FileName;
//if (cu.compiler_directives.Count != 0)
// CompilerDirectives.AddRange(cu.compiler_directives);
ProcessedFileNames.Remove(FileName);
}
/*
public void WriteToStream(int line1, int line2)
{
int startl = 1;
int endl = SourceLines.Length;
if (line1 >= 0)
startl = line1;
if (line2 >= 0)
endl = line2;
if (endl - startl < 0)
return;
int Length = 0;
for (int i = startl; i <= endl; i++)
{
tw.WriteLine(SourceLines[i - 1]);
Length += SourceLines[i - 1].Length + newLineLength;
}
SourceContext nsc = new SourceContext(CurrentLineNumber, 1, CurrentLineNumber + endl - startl, int.MaxValue, Position, Position + Length);
SourceContext rsc = new SourceContext(startl, 1, endl, int.MaxValue);
rsc.FileName = CurrentFileName;
SourceContextMap.AddArea(nsc, rsc);
CurrentLineNumber += endl - startl + 1;
Position += Length;
}
public void WriteToStream(int line1, int line2, int col1, int col2)
{
int startl = 1;
int endl = SourceLines.Length;
if (line1 >= 0)
startl = line1;
if (line2 >= 0)
endl = line2;
if (endl - startl < 0)
return;
int Length = 0;
for (int i = startl; i <= endl; i++)
{
string s = (SourceLines[i - 1]).Substring(col1 - 1, col2 - col1 + 1);
Length += s.Length + newLineLength;
}
SourceContext nsc = new SourceContext(CurrentLineNumber, col1 - 1, CurrentLineNumber + endl - startl, int.MaxValue, Position, Position + Length);
SourceContext rsc = new SourceContext(startl, 1, endl, int.MaxValue);
rsc.FileName = CurrentFileName;
SourceContextMap.AddArea(nsc, rsc);
CurrentLineNumber += endl - startl + 1;
Position += Length;
}
*/
public void WriteToStream(SourceContext sc, string text)
{
tw.WriteLine(text);
sc.FileName = CurrentFileName;
SourceContextMap.AddArea(new SourceContext(CurrentLineNumber, 1, CurrentLineNumber + sc.end_position.line_num - sc.begin_position.line_num, sc.end_position.column_num, Position, Position + text.Length), sc);
CurrentLineNumber += 1;// sc.end_position.line_num - sc.begin_position.line_num + 1;
Position += text.Length;
}
}
public class StatesManager
{
private Stack<int> if_stack;
private Stack<int> endif_stack;
bool allow_write;
bool allow_else;
public StatesManager()
{
allow_write = true;
allow_else = false;
if_stack = new Stack<int>();
endif_stack = new Stack<int>();
}
public void Reset()
{
allow_write = true;
if_stack.Clear();
endif_stack.Clear();
}
public void AddCondition(int i)
{
allow_else = true;
if_stack.Push(i);
endif_stack.Push(i);
}
public int GetIfCount()
{
return if_stack.Count;
}
public int GetEndifCount()
{
return endif_stack.Count;
}
public int DeleteCondition(bool endif)
{
int i = 0;
if (endif)
{
allow_else = true;
i = endif_stack.Pop();
}
else
allow_else = false;
if (if_stack.Count != 0)
return if_stack.Pop();
else
{
//error
return i;
}
}
public int LastCondition()
{
if (if_stack.Count != 0)
return if_stack.Peek();
else
return 0;
}
public int LastEndifCondition()
{
if (endif_stack.Count != 0)
return endif_stack.Peek();
else
return 0;
}
public bool AllowWrite()
{
return allow_write;
}
public bool AllowElse()
{
return allow_else;
}
public void ChangeState(bool new_mode)
{
allow_write = new_mode;
}
public void ChangeState(bool new_mode, int new_if)
{
allow_write = new_mode;
AddCondition(new_if);
}
public void ChangeState(bool new_mode, bool endif)
{
allow_write = new_mode;
int i = DeleteCondition(endif);
// return i;
}
}
//Aspects
public class Aspect
{
private string AspName;
private string AspAuthor = "name";
private string AspVersion = "0.1";
private List<SourceContext> begin_list;
private List<SourceContext> end_list;
bool allow_mod;
bool saved_params;
public Aspect(string name)
{
this.AspName = name;
begin_list = new List<SourceContext>();
end_list = new List<SourceContext>();
allow_mod = true;
}
public Aspect(string name, string auth, string ver)
{
this.AspName = name;
this.AspAuthor = auth;
this.AspVersion = ver;
begin_list = new List<SourceContext>();
end_list = new List<SourceContext>();
allow_mod = true;
}
public void AddBegin(SourceContext sc)
{
if (!begin_list.Contains(sc))
begin_list.Add(sc);
}
public void AddEnd(SourceContext sc)
{
if (!end_list.Contains(sc))
end_list.Add(sc);
}
public bool IsSavedParams
{
set
{
IsSavedParams = value;
}
get
{
return saved_params;
}
}
public string Author
{
set
{
AspAuthor = value;
}
get
{
return AspAuthor;
}
}
public string Version
{
set
{
AspVersion = value;
}
get
{
return AspVersion;
}
}
public List<SourceContext> GetBeginList()
{
return new List<SourceContext>(begin_list);
}
public List<SourceContext> GetEndList()
{
return new List<SourceContext>(end_list);
}
public void Reset()
{
allow_mod = true;
begin_list.Clear();
end_list.Clear();
}
}
//end aspects
}

View file

@ -1,35 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PascalABCParser")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("DSS")]
[assembly: AssemblyProduct("PascalABCParser")]
[assembly: AssemblyCopyright("Copyright © DSS 2006-2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e5788e70-934b-42a9-a652-255b64cf1709")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.6.*")]
[assembly: AssemblyFileVersion("1.6.*")]

View file

@ -1,422 +0,0 @@
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Collections;
using System.Collections.Generic;
using PascalABCCompiler.SyntaxTree;
using PascalABCCompiler.Errors;
using PascalABCCompiler.PascalABCParser.Errors;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.Preprocessor2;
namespace PascalABCCompiler.PascalABCParser
{
public partial class GPBParser_PascalABC : GPBParser
{
public Preprocessor2.Preprocessor2 prepr;
internal SourceContextMap scm;
public bool build_tree_for_brackets = false;
private Stack NodesStack;
private SyntaxError error;
Stream GrammarStream;
public GPBParser_PascalABC(Stream stream, GoldParser.Grammar grammar, Preprocessor2.Preprocessor2 prepr1)
: base(grammar)
{
prepr = prepr1;
GrammarStream = stream;
parsertools = new pascalabc_parsertools();
}
public GPBParser_PascalABC(Stream stream, Preprocessor2.Preprocessor2 prepr1)
: base(stream)
{
prepr = prepr1;
GrammarStream = stream;
parsertools = new pascalabc_parsertools();
}
public object Parse(string source)
{
NodesStack = new Stack();
LRParser = new GoldParser.Parser(new StringReader(source), LanguageGrammar);
parsertools.parser = LRParser;
LRParser.TrimReductions = true;
try
{
while (true)
{
switch (LRParser.Parse())
{
case GoldParser.ParseMessage.LexicalError:
errors.Add(new TokenReadError(this));
LRParser.PopInputToken();
if (errors.Count >= max_errors)
return null;
break;
//sdes nugno vesti chtoto vrode steka poslednix oshibok. podumat
case GoldParser.ParseMessage.SyntaxError:
GoldParser.Symbol sym = LRParser.PopInputToken();
error = new PABCNETUnexpectedToken(this);
//error = new UnexpectedToken(this, parsertools.symbol_collection_to_string(this.LRParser.GetExpectedTokens()));
if (sym.SymbolType == GoldParser.SymbolType.End && errors.Count > 0)
return null;
errors.Add(error);
if (errors.Count >= max_errors)
return null;
break;
case GoldParser.ParseMessage.Reduction:
LRParser.TokenSyntaxNode = CreateNonTerminalObject(LRParser.ReductionRule.Index);
if ((LRParser.TokenSyntaxNode as syntax_tree_node) != null)
prev_node = LRParser.TokenSyntaxNode;
break;
case GoldParser.ParseMessage.Accept:
return LRParser.TokenSyntaxNode;
case GoldParser.ParseMessage.TokenRead:
LRParser.TokenSyntaxNode = CreateTerminalObject(LRParser.TokenSymbol.Index);
break;
case GoldParser.ParseMessage.InternalError:
errors.Add(new CompilerInternalError("PascalABCParser", new Exception("ParseMessage.InternalError")));
return null;
case GoldParser.ParseMessage.NotLoadedError:
errors.Add(new CompilerInternalError("PascalABCParser", new Exception("ParseMessage.NotLoadedError")));
return null;
case GoldParser.ParseMessage.CommentError:
errors.Add(new UnexpectedToken(this, "(EOF)"));
return null;
case GoldParser.ParseMessage.CommentBlockRead:
{
/*
compiler_directive cd = new compiler_directive();
cd.source_context = parsertools.GetTokenSourceContext(this.LRParser);
string comment = this.LRParser.CommentText;
cd.Name = new token_info(comment);
cd.Directive = new token_info(comment);
cd.source_context = new SourceContext(cd.source_context,parsertools.GetTokenSourceContext(this.LRParser));
if (cd.Directive.text[0] == '{' && cd.Directive.text[1] == '$')
this.errors.Add(new Preprocessor_2.Errors.SyntaxErrorInDirective(cd.source_context.FileName, cd.source_context, cd.Directive.text));
this.CompilerDirectives.Add(cd);
*/
} break;
case GoldParser.ParseMessage.CommentLineRead:
{
/*
compiler_directive cd = new compiler_directive();
cd.source_context = parsertools.GetTokenSourceContext(this.LRParser);
string comment = this.LRParser.CommentText;
cd.Name = new token_info(comment);
cd.Directive = new token_info(comment);
cd.source_context = new SourceContext(cd.source_context.begin_position.line_num, cd.source_context.begin_position.column_num, cd.source_context.end_position.line_num, cd.source_context.end_position.column_num + comment.Length - Environment.NewLine.Length);
this.CompilerDirectives.Add(cd);
*/
} break;
}
}
}
catch (GoldParser.UnexpectedEOFinParseCommentBlock)
{
throw new TokenReadError(this);
}
catch (Exception e)
{
if (errors.Count > 0)
return null;
else
throw;
}
}
////////////////////////////////////tasha_16.04.2010
/// SSM перенес из pascalabc_lparser_rules сюда, т.к. это partial класс, а та часть генерировалась автоматически. Голову отрывать надо
int lambda_num = 0;
List<function_lambda_definition> pascalABC_lambda_definitions = new List<function_lambda_definition>();
List<var_def_statement> pascalABC_var_statements = new List<var_def_statement>();
List<type_declaration> pascalABC_type_declarations = new List<type_declaration>();
procedure_definition lambda(function_lambda_definition _function_lambda_definition)
{
procedure_definition _func_def = new procedure_definition();
method_name _method_name1 = new method_name(null,null, new SyntaxTree.ident(_function_lambda_definition.lambda_name), null);
parsertools.create_source_context(_method_name1, _method_name1.meth_name, _method_name1.meth_name);
function_header _function_header1 = new function_header();
object rt1 = new object();
_function_header1.name = _method_name1;
if (_function_header1.name.meth_name is template_type_name)
{
_function_header1.template_args = (_function_header1.name.meth_name as template_type_name).template_args;
ident id = new ident(_function_header1.name.meth_name.name);
parsertools.create_source_context(id, _function_header1.name.meth_name, _function_header1.name.meth_name);
_function_header1.name.meth_name = id;
}
SyntaxTree.formal_parameters fps = new PascalABCCompiler.SyntaxTree.formal_parameters();
_function_header1.parameters = _function_lambda_definition.formal_parameters;//fps;
/*SyntaxTree.named_type_reference _named_type_reference = new SyntaxTree.named_type_reference();
SyntaxTree.ident idtype = new SyntaxTree.ident("object");
_named_type_reference.source_context = idtype.source_context;
_named_type_reference.names.Add(idtype);
rt1 = _named_type_reference;
_function_header1.return_type = (SyntaxTree.type_definition)_named_type_reference;*/
_function_header1.return_type = _function_lambda_definition.return_type;
_function_header1.of_object = false;
_function_header1.class_keyword = false;
token_info _token_info = new token_info("function");
_token_info.source_context = parsertools.GetTokenSourceContext();
parsertools.create_source_context(_function_header1, _token_info, _token_info);
SyntaxTree.block _block1 = new SyntaxTree.block(null, null);
SyntaxTree.statement_list sl1 = new SyntaxTree.statement_list();
sl1.subnodes.Add(_function_lambda_definition.proc_body);
_block1.program_code = sl1;
_func_def.proc_header = _function_header1;
_func_def.proc_body = (SyntaxTree.proc_block)_block1;
if (_function_lambda_definition.defs != null)
{
if (((block)_func_def.proc_body).defs == null)
((block)_func_def.proc_body).defs = new declarations();
for (int l = 0; l < _function_lambda_definition.defs.Count; l++)
((block)_func_def.proc_body).defs.defs.Add(_function_lambda_definition.defs[l] as procedure_definition);
}
_function_lambda_definition.proc_definition = _func_def;
parsertools.create_source_context(_func_def, _function_header1, _function_header1);
return _func_def;
}
public function_lambda_definition find_pascalABC_lambda_name(string name)
{
int i = 0;
while (i < pascalABC_lambda_definitions.Count && (pascalABC_lambda_definitions[i] == null || ((function_lambda_definition)pascalABC_lambda_definitions[i]).lambda_name != name))
i++;
if (i < pascalABC_lambda_definitions.Count)
return (function_lambda_definition)pascalABC_lambda_definitions[i];
else
return null;
}
public var_def_statement find_var_statements(string name)
{
int i = pascalABC_var_statements.Count - 1;
bool b = false;
while (!b && i >= 0)
{
var_def_statement vds = (var_def_statement)pascalABC_var_statements[i];
int j = 0;
while (j < vds.vars.idents.Count &&
vds.vars.idents[j].name != name)
j++;
if (j < vds.vars.idents.Count)
b = true;
else
i--;
}
if (i >= 0 && i < pascalABC_var_statements.Count &&
((var_def_statement)pascalABC_var_statements[i]).vars_type != null)
return (var_def_statement)pascalABC_var_statements[i];
else
return null;
}
public ident func_decl_lambda(object lr0, object lr2)
{
statement_list _statement_list = (statement_list)lr2;
expression_list _expression_list = new expression_list();
ident_list _i_l = new ident_list();
formal_parameters _formal_parameters = new formal_parameters();
if (lr0 != null)
{
List<object> ar = (List<object>)lr0;
for (int i = 0; i < ar.Count; i++)
if (ar[i] is ident)
_i_l.idents.Add((ident)ar[i]);
else
_i_l.idents.Add(((var_def_statement)ar[i]).vars.idents[0]);
for (int i = 0; i < _i_l.idents.Count; i++)
_expression_list.expressions.Add(_i_l.idents[i]);
for (int i = 0; i < ar.Count; i++)
{
ident_list _ident_list = new ident_list();
ident id = _i_l.idents[i];
_ident_list.idents.Add(id);
string name_param = id.name;
typed_parameters _typed_parameters = null;
int k = 0;
{
named_type_reference _named_type_reference = new named_type_reference();
type_definition t_d = new type_definition();
if (ar[i] is ident)
{
ident idtype = new ident("object");
_named_type_reference.names.Add(idtype);
t_d = (type_definition)_named_type_reference;
}
else
{
t_d = ((var_def_statement)ar[i]).vars_type;
}
_typed_parameters = new typed_parameters(_ident_list, t_d, parametr_kind.none, null);
parsertools.create_source_context(_typed_parameters, _ident_list, t_d);
}
_formal_parameters.params_list.Add(_typed_parameters);
}
}
//////////////////////////
named_type_reference _named_type_reference1 = new named_type_reference();
ident idtype1 = new ident("object");
_named_type_reference1.source_context = idtype1.source_context;
_named_type_reference1.names.Add(idtype1);
/////////////////////////////
lambda_num++;
function_lambda_definition _procedure_definition = new function_lambda_definition();
_procedure_definition.formal_parameters = _formal_parameters;
_procedure_definition.return_type = (type_definition)_named_type_reference1;
_procedure_definition.ident_list = _i_l;
_procedure_definition.proc_body = null;
_procedure_definition.parameters = _expression_list;
_procedure_definition.lambda_name = "__lambda__" + lambda_num;
//new function_lambda_definition(_formal_parameters, (type_definition)_named_type_reference1, _i_l, null, _expression_list, "lambda" + lambda_num);
object rt = _i_l;
_procedure_definition.proc_body = _statement_list;
//////////////////////////////vnutrennie lambda
if (_procedure_definition.defs == null)
_procedure_definition.defs = new List<declaration>();
while (pascalABC_lambda_definitions.Count > 0 && pascalABC_lambda_definitions[pascalABC_lambda_definitions.Count - 1] != null)
{
_procedure_definition.defs.Add(lambda((function_lambda_definition)pascalABC_lambda_definitions[pascalABC_lambda_definitions.Count - 1]));
pascalABC_lambda_definitions.RemoveAt(pascalABC_lambda_definitions.Count - 1);
}
if (pascalABC_lambda_definitions.Count > 0 && pascalABC_lambda_definitions[pascalABC_lambda_definitions.Count - 1] == null)
pascalABC_lambda_definitions.RemoveAt(pascalABC_lambda_definitions.Count - 1);
pascalABC_lambda_definitions.Add(_procedure_definition);
///////////////////////////////////////////////
parsertools.create_source_context(_procedure_definition, _expression_list, rt);
ident _name = new ident(_procedure_definition.lambda_name);
if (lr0 != null)
_name.source_context = _i_l.idents[0].source_context;
return _name;
}
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 add_lambda_to_program_block(block _block)
{
//tasha 16.04.2010
if (pascalABC_lambda_definitions.Count > 0)
{
if (_block.defs == null)
_block.defs = new declarations();
for (int i = 0; i < pascalABC_lambda_definitions.Count; i++)
_block.defs.defs.Add(lambda((function_lambda_definition)pascalABC_lambda_definitions[i]));
pascalABC_lambda_definitions.Clear();
}
}
public void add_lambda(object lr1, procedure_definition _procedure_definition)
{
if (pascalABC_lambda_definitions.Count > 0)//tasha 16.04.2010
{
block _block = (block)lr1;
if (_block.defs == null)
_block.defs = new declarations();
for (int i = 0; i < pascalABC_lambda_definitions.Count; i++)
_block.defs.defs.Add(lambda((function_lambda_definition)pascalABC_lambda_definitions[i]));
pascalABC_lambda_definitions.Clear();
_procedure_definition.proc_body = (proc_block)_block;
}
else
//////////////////////////tasha 16.04.2010
_procedure_definition.proc_body = (proc_block)lr1;
}
public void for_assignment(object lr0, object lr2)
{
if (lr0 is ident && lr2 is ident && ((ident)lr2).name.Contains("__lambda__"))
{
string type_name = "";
var_def_statement vds = find_var_statements(((ident)lr0).name);
if (vds != null)
type_name = ((named_type_reference)vds.vars_type).names[0].name;
if (type_name != "")
{
int ii = 0;
while (ii < pascalABC_type_declarations.Count &&
((type_declaration)pascalABC_type_declarations[ii]).type_name.name != type_name)
ii++;
if (ii < pascalABC_type_declarations.Count)
{
type_definition td = ((type_declaration)pascalABC_type_declarations[ii]).type_def;
function_lambda_definition fld = find_pascalABC_lambda_name(((ident)lr2).name);
fld.return_type = ((function_header)td).return_type;
for (int k = 0; k < fld.formal_parameters.params_list.Count && k < ((function_header)td).parameters.params_list.Count; k++)
fld.formal_parameters.params_list[k].vars_type = ((function_header)td).parameters.params_list[k].vars_type;
}
pascalABC_var_statements.Remove(vds);
}
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@
ВАЖНЕЙШИЕ УСЛОВИЯ РАСПРОСТРАНЕНИЯ ПРОДУКТА PascalABC.NET
Copyright (C) 2005-2015 by Ivan Bondarev, Stanislav Mihalkovich
Copyright (C) 2005-2016 by Ivan Bondarev, Stanislav Mihalkovich
Это программное обеспечение является свободным; вы можете распространять и/или
модифицировать его на условиях GNU LGPL версии 3 с разъяснениями и исключениями, данными ниже.

View file

@ -3,7 +3,7 @@ A copy of the GNU GPL is appended to this file.
IMPORTANT PascalABC.NET LICENSE TERMS
Copyright (C) 2005-2015 by Ivan Bondarev, Stanislav Mihalkovich
Copyright (C) 2005-2016 by Ivan Bondarev, Stanislav Mihalkovich
This program is free software; you may redistribute and/or modify it under the terms of the GNU LGPL version 3 with the clarifications and exceptions described below.
PascalABC.NET can be linked with non-free modules and libraries. This condition is mainly concerned with possibility of adding foreign modules and libraries to PascalABC.NET, aimed at education. In particular, PascalABC.NET includes as a part PROGRAMMING TASKBOOK FOR PASCALABC.NET (in agreement with the author of this product), which is distributed under the terms of proprietary license (see \bin\PT4)

View file

@ -1 +1 @@
Copyright (C) 2005-2015 by Ivan Bondarev, Stanislav Mihalkovich
Copyright (C) 2005-2016 by Ivan Bondarev, Stanislav Mihalkovich

View file

@ -3,7 +3,7 @@ A copy of the GNU GPL is appended to this file.
IMPORTANT PascalABC.NET LICENSE TERMS
Copyright (C) 2005-2015 by Ivan Bondarev, Stanislav Mihalkovich
Copyright (C) 2005-2016 by Ivan Bondarev, Stanislav Mihalkovich
This program is free software; you may redistribute and/or modify it under the terms of the GNU LGPL version 3 with the clarifications and exceptions described below.
PascalABC.NET can be linked with non-free modules and libraries. This condition is mainly concerned with possibility of adding foreign modules and libraries to PascalABC.NET, aimed at education. In particular, PascalABC.NET includes as a part PROGRAMMING TASKBOOK FOR PASCALABC.NET (in agreement with the author of this product), which is distributed under the terms of proprietary license (see \bin\PT4)

View file

@ -1 +1 @@
Copyright (C) 2005-2015 by Ivan Bondarev, Stanislav Mihalkovich
Copyright (C) 2005-2016 by Ivan Bondarev, Stanislav Mihalkovich

View file

@ -3,7 +3,7 @@
ВАЖНЕЙШИЕ УСЛОВИЯ РАСПРОСТРАНЕНИЯ ПРОДУКТА PascalABC.NET
Copyright (C) 2005-2015 by Ivan Bondarev, Stanislav Mihalkovich
Copyright (C) 2005-2016 by Ivan Bondarev, Stanislav Mihalkovich
Это программное обеспечение является свободным; вы можете распространять и/или
модифицировать его на условиях GNU LGPL версии 3 с разъяснениями и исключениями, данными ниже.