public program_module NewProgramModule(program_name progName, Object optHeadCompDirs,
                                                   uses_list mainUsesClose, syntax_tree_node progBlock, Object optPoint, LexLocation loc)
            {
                var progModule = new program_module(progName, mainUsesClose, progBlock as block, null, loc);

                progModule.Language = LanguageId.PascalABCNET;
                if (optPoint == null && progBlock != null)
                {
                    var fp      = progBlock.source_context.end_position;
                    var err_stn = progBlock;
                    if ((progBlock is block) && (progBlock as block).program_code != null &&
                        (progBlock as block).program_code.subnodes != null &&
                        (progBlock as block).program_code.subnodes.Count > 0)
                    {
                        err_stn = (progBlock as block).program_code.subnodes[
                            (progBlock as block).program_code.subnodes.Count - 1];
                    }
                    parsertools.errors.Add(new PABCNETUnexpectedToken(parsertools.CurrentFileName,
                                                                      StringResources.Get("TKPOINT"),
                                                                      new SourceContext(fp.line_num, fp.column_num + 1, fp.line_num, fp.column_num + 1, 0, 0),
                                                                      err_stn));
                }

                return(progModule);
            }
예제 #2
0
        //vremenno, potom ubrat
        private compilation_unit get_fictive_unit(string s, string FileName)
        {
            program_module prog = new program_module();
            int            line = 1;
            int            col  = 1;

            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == '\n')
                {
                    line++;
                    col = 1;
                }
                else
                {
                    col++;
                }
            }
            prog.source_context = new SourceContext(1, 1, line + 3, 3);
            prog.program_block  = new block();
            prog.file_name      = FileName;
            statement_list sl = new statement_list();

            prog.program_block.program_code = sl;
            prog.program_block.program_code.left_logical_bracket = new token_info("begin");
            prog.program_block.program_code.left_logical_bracket.source_context = new SourceContext(1, 1, 1, 5);
            prog.program_block.program_code.right_logical_bracket = new token_info("end");
            prog.program_block.program_code.right_logical_bracket.source_context = new SourceContext(line + 3, 1, line + 3, 3);
            sl.subnodes.Add(new empty_statement());
            return(prog);
        }
예제 #3
0
 public override void visit(program_module _program_module)
 {
     prepare_node(_program_module.program_name, "program name");
     prepare_node(_program_module.used_units, "used_units");
     prepare_node(_program_module.using_namespaces, "using_namespaces");
     prepare_node(_program_module.program_block, "program block");
     prepare_collection(_program_module.compiler_directives, "compiler_directives");
 }
예제 #4
0
 public override void visit(program_module _program_module)
 {
     if (_program_module.program_name != null)
     {
         _program_module.program_name.visit(this);
     }
     if (_program_module.used_units != null)
     {
         _program_module.used_units.visit(this);
     }
     _program_module.program_block.visit(this);
 }
예제 #5
0
        private static SyntaxTree.program_module InternalCreateProgramModule(statement_list statements, declarations defs)
        {
            block block = new block();

            if (defs != null)
            {
                block.defs = defs;
            }
            statements.Add(new SyntaxTree.empty_statement());
            statements.left_logical_bracket  = new token_info("begin");
            statements.right_logical_bracket = new token_info("end");
            block.program_code = statements;

            program_module res = new program_module();

            res.program_block = block;
            //res.used_units = create_standard_uses_list();
            return(res);
        }
예제 #6
0
 public override void visit(program_module _program_module)
 {
     text = System.IO.Path.GetFileName(_program_module.file_name);
 }
예제 #7
0
 public virtual void visit(program_module _program_module)
 {
     DefaultVisit(_program_module);
 }
예제 #8
0
		public virtual void post_do_visit(program_module _program_module)
		{
		}
예제 #9
0
		public override void visit(program_module _program_module)
		{
			DefaultVisit(_program_module);
			pre_do_visit(_program_module);
			visit(program_module.program_name);
			visit(program_module.used_units);
			visit(program_module.program_block);
			visit(program_module.using_namespaces);
			post_do_visit(_program_module);
		}
예제 #10
0
 public virtual void visit(program_module _program_module)
 {
 }
 public override void visit(program_module _program_module)
 {
     _program_module.program_block.visit(this);
 }
예제 #12
0
		public virtual void visit(program_module _program_module)
		{
		}
		public virtual void visit(program_module _program_module)
		{
			DefaultVisit(_program_module);
		}
예제 #14
0
		public override void visit(program_module _program_module)
		{
			executer.visit(_program_module);
			if (_program_module.program_name != null)
				this.visit((dynamic)_program_module.program_name);
			if (_program_module.used_units != null)
				this.visit((dynamic)_program_module.used_units);
			if (_program_module.program_block != null)
				this.visit((dynamic)_program_module.program_block);
			if (_program_module.using_namespaces != null)
				this.visit((dynamic)_program_module.using_namespaces);
			if (_program_module.compiler_directives != null)
			foreach (dynamic x in _program_module.compiler_directives)
				if(x != null)
					this.visit(x);
		}
예제 #15
0
        protected override void DoAction(int action)
        {
            switch (action)
            {
            case 2: // module -> MODULE, ident, SEMICOLUMN, Declarations, BEGIN, StatementSequence,
                    //           END, ident, COMMA
            {
                if (ValueStack[ValueStack.Depth - 8].id.name != ValueStack[ValueStack.Depth - 2].id.name)
                {
                    PT.AddError("Имя " + ValueStack[ValueStack.Depth - 2].id.name + " должно совпадать с именем модуля " + ValueStack[ValueStack.Depth - 8].id.name, LocationStack[LocationStack.Depth - 2]);
                }

                // Подключение стандартной библиотеки
                ident_list il = new ident_list();
                il.Add(new ident("Oberon00System"));
                unit_or_namespace un = new unit_or_namespace(il);
                uses_list         ul = new uses_list();
                ul.units.Insert(0, un);

                // Формирование главного модуля
                var b = new block(ValueStack[ValueStack.Depth - 6].decl, ValueStack[ValueStack.Depth - 4].sl, LocationStack[LocationStack.Depth - 6].Merge(LocationStack[LocationStack.Depth - 2]));
                var r = new program_module(null, ul, b, null, CurrentLocationSpan);
                r.Language = LanguageId.Oberon00;
                root       = r;
            }
            break;

            case 3: // module -> INVISIBLE, expr
            {       // Для Intellisense
                root = ValueStack[ValueStack.Depth - 1].ex;
            }
            break;

            case 4: // ident -> ID
            {
                CurrentSemanticValue.id = new ident(ValueStack[ValueStack.Depth - 1].sVal, CurrentLocationSpan);
            }
            break;

            case 5: // expr -> ident
            {
                CurrentSemanticValue.ex = ValueStack[ValueStack.Depth - 1].id;
            }
            break;

            case 6: // expr -> INTNUM
            {
                CurrentSemanticValue.ex = new int32_const(ValueStack[ValueStack.Depth - 1].iVal, CurrentLocationSpan);
            }
            break;

            case 7: // expr -> TRUE
            {
                CurrentSemanticValue.ex = new bool_const(true, CurrentLocationSpan);
            }
            break;

            case 8: // expr -> FALSE
            {
                CurrentSemanticValue.ex = new bool_const(false, CurrentLocationSpan);
            }
            break;

            case 9: // expr -> MINUS, expr
            {
                CurrentSemanticValue.ex = new un_expr(ValueStack[ValueStack.Depth - 1].ex, Operators.Minus, CurrentLocationSpan);
            }
            break;

            case 10: // expr -> LPAREN, expr, RPAREN
            { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth - 2].ex; }
            break;

            case 11: // expr -> NOT, expr
            {
                CurrentSemanticValue.ex = new un_expr(ValueStack[ValueStack.Depth - 1].ex, Operators.LogicalNOT, CurrentLocationSpan);
            }
            break;

            case 12: // expr -> expr, PLUS, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.Plus, CurrentLocationSpan);
            }
            break;

            case 13: // expr -> expr, MINUS, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.Minus, CurrentLocationSpan);
            }
            break;

            case 14: // expr -> expr, MULT, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.Multiplication, CurrentLocationSpan);
            }
            break;

            case 15: // expr -> expr, DIVIDE, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.IntegerDivision, CurrentLocationSpan);
            }
            break;

            case 16: // expr -> expr, AND, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.LogicalAND, CurrentLocationSpan);
            }
            break;

            case 17: // expr -> expr, OR, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.LogicalOR, CurrentLocationSpan);
            }
            break;

            case 18: // expr -> expr, EQ, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.Equal, CurrentLocationSpan);
            }
            break;

            case 19: // expr -> expr, NE, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.NotEqual, CurrentLocationSpan);
            }
            break;

            case 20: // expr -> expr, LT, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.Less, CurrentLocationSpan);
            }
            break;

            case 21: // expr -> expr, LE, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.LessEqual, CurrentLocationSpan);
            }
            break;

            case 22: // expr -> expr, GT, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.Greater, CurrentLocationSpan);
            }
            break;

            case 23: // expr -> expr, GE, expr
            {
                CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth - 3].ex, ValueStack[ValueStack.Depth - 1].ex, Operators.GreaterEqual, CurrentLocationSpan);
            }
            break;

            case 24: // Assignment -> ident, ASSIGN, expr
            {
                CurrentSemanticValue.st = new assign(ValueStack[ValueStack.Depth - 3].id, ValueStack[ValueStack.Depth - 1].ex, Operators.Assignment, CurrentLocationSpan);
            }
            break;

            case 25: // IfStatement -> IF, expr, THEN, StatementSequence, END
            {
                CurrentSemanticValue.st = new if_node(ValueStack[ValueStack.Depth - 4].ex, ValueStack[ValueStack.Depth - 2].sl, null, CurrentLocationSpan);
            }
            break;

            case 26: // IfStatement -> IF, expr, THEN, StatementSequence, ELSE, StatementSequence, END
            {
                CurrentSemanticValue.st = new if_node(ValueStack[ValueStack.Depth - 6].ex, ValueStack[ValueStack.Depth - 4].sl, ValueStack[ValueStack.Depth - 2].sl, CurrentLocationSpan);
            }
            break;

            case 27: // WhileStatement -> WHILE, expr, DO, StatementSequence, END
            {
                CurrentSemanticValue.st = new while_node(ValueStack[ValueStack.Depth - 4].ex, ValueStack[ValueStack.Depth - 2].sl, WhileCycleType.While, CurrentLocationSpan);
            }
            break;

            case 28: // WriteStatement -> EXCLAMATION, expr
            {
                expression_list el = new expression_list(ValueStack[ValueStack.Depth - 1].ex);
                method_call     mc = new method_call(el);
                mc.dereferencing_value  = new ident("print");
                CurrentSemanticValue.st = mc;
            }
            break;

            case 29: // factparams -> expr
            {
                CurrentSemanticValue.el = new expression_list(ValueStack[ValueStack.Depth - 1].ex, CurrentLocationSpan);
            }
            break;

            case 30: // factparams -> factparams, COLUMN, expr
            {
                ValueStack[ValueStack.Depth - 3].el.Add(ValueStack[ValueStack.Depth - 1].ex, CurrentLocationSpan);
                CurrentSemanticValue.el = ValueStack[ValueStack.Depth - 3].el;
            }
            break;

            case 31: // ProcCallStatement -> ident, LPAREN, factparams, RPAREN
            {
                CurrentSemanticValue.st = new method_call(ValueStack[ValueStack.Depth - 4].id, ValueStack[ValueStack.Depth - 2].el, CurrentLocationSpan);
            }
            break;

            case 32: // EmptyStatement -> /* empty */
            {
                CurrentSemanticValue.st = new empty_statement();
            }
            break;

            case 39: // StatementSequence -> Statement
            {
                CurrentSemanticValue.sl = new statement_list(ValueStack[ValueStack.Depth - 1].st, CurrentLocationSpan);
            }
            break;

            case 40: // StatementSequence -> StatementSequence, SEMICOLUMN, Statement
            {
                ValueStack[ValueStack.Depth - 3].sl.Add(ValueStack[ValueStack.Depth - 1].st, CurrentLocationSpan);
                CurrentSemanticValue.sl = ValueStack[ValueStack.Depth - 3].sl;
            }
            break;

            case 41: // type -> BOOLEAN
            {
                CurrentSemanticValue.ntr = new named_type_reference("boolean", CurrentLocationSpan);
            }
            break;

            case 42: // type -> INTEGER
            {
                CurrentSemanticValue.ntr = new named_type_reference("integer", CurrentLocationSpan);
            }
            break;

            case 43: // IDList -> ident
            {
                CurrentSemanticValue.il = new ident_list(ValueStack[ValueStack.Depth - 1].id, CurrentLocationSpan);
            }
            break;

            case 44: // IDList -> IDList, COLUMN, ident
            {
                ValueStack[ValueStack.Depth - 3].il.Add(ValueStack[ValueStack.Depth - 1].id, CurrentLocationSpan);
                CurrentSemanticValue.il = ValueStack[ValueStack.Depth - 3].il;
            }
            break;

            case 45: // VarDecl -> IDList, COLON, type, SEMICOLUMN
            {
                CurrentSemanticValue.vds = new var_def_statement(ValueStack[ValueStack.Depth - 4].il, ValueStack[ValueStack.Depth - 2].ntr, null, definition_attribute.None, false, CurrentLocationSpan);
            }
            break;

            case 46: // VarDeclarations -> VarDecl
            {
                CurrentSemanticValue.vdss = new variable_definitions(ValueStack[ValueStack.Depth - 1].vds, CurrentLocationSpan);
            }
            break;

            case 47: // VarDeclarations -> VarDeclarations, VarDecl
            {
                ValueStack[ValueStack.Depth - 2].vdss.Add(ValueStack[ValueStack.Depth - 1].vds, CurrentLocationSpan);
                CurrentSemanticValue.vdss = ValueStack[ValueStack.Depth - 2].vdss;
            }
            break;

            case 48: // ConstDecl -> ident, EQ, ConstExpr, SEMICOLUMN
            {
                CurrentSemanticValue.scd = new simple_const_definition(ValueStack[ValueStack.Depth - 4].id, ValueStack[ValueStack.Depth - 2].ex, CurrentLocationSpan);
            }
            break;

            case 50: // ConstDeclarations -> ConstDecl
            {
                CurrentSemanticValue.cdl = new consts_definitions_list(ValueStack[ValueStack.Depth - 1].scd, CurrentLocationSpan);
            }
            break;

            case 51: // ConstDeclarations -> ConstDeclarations, ConstDecl
            {
                ValueStack[ValueStack.Depth - 2].cdl.Add(ValueStack[ValueStack.Depth - 1].scd, CurrentLocationSpan);
                CurrentSemanticValue.cdl = ValueStack[ValueStack.Depth - 2].cdl;
            }
            break;

            case 52: // ConstDeclarationsSect -> CONST, ConstDeclarations
            {
                CurrentSemanticValue.cdl = ValueStack[ValueStack.Depth - 1].cdl;
                CurrentSemanticValue.cdl.source_context = CurrentLocationSpan;
            }
            break;

            case 53: // VarDeclarationsSect -> VAR, VarDeclarations
            {
                CurrentSemanticValue.vdss = ValueStack[ValueStack.Depth - 1].vdss;
                CurrentSemanticValue.vdss.source_context = CurrentLocationSpan;
            }
            break;

            case 54: // Declarations -> VarDeclarationsSect
            {
                CurrentSemanticValue.decl = new declarations(ValueStack[ValueStack.Depth - 1].vdss, CurrentLocationSpan);
            }
            break;

            case 55: // Declarations -> ConstDeclarationsSect, VarDeclarationsSect
            {
                CurrentSemanticValue.decl = new declarations(ValueStack[ValueStack.Depth - 1].vdss, CurrentLocationSpan);
                CurrentSemanticValue.decl.Add(ValueStack[ValueStack.Depth - 1].vdss);
//		$$.source_context = @$;
            }
            break;
            }
        }