public ActionResult <Result> Post([FromBody] Dto dto)
        {
            if (dto == null || string.IsNullOrEmpty(dto.Text))
            {
                return(BadRequest());
            }

            string       add = dto.Text.Last().Equals('\n') ? " " : "\n";
            OuterLexemes lex = _manager.LexicalAnalyzer(dto.Text + add);
            SyntaxResult syn = _manager.SyntaxAnalyzer(lex);

            if (!syn.Success)
            {
                return(new Result
                {
                    OuterLexemes = lex,
                    SyntaxResult = syn,
                    ReferenceNumber = Guid.NewGuid()
                });
            }

            PolishResult polishResult = _polishManager.Run(lex);

            Guid referenceNumber = Guid.NewGuid();

            _cache.Set(referenceNumber, new ExecutionPoint {
                PolishResult = polishResult
            });

            return(new Result
            {
                OuterLexemes = lex,
                SyntaxResult = syn,
                // todo Use AutoMapper
                PolishResult = new PolishResultDto
                {
                    ReversePolishNotation = string.Join(" ", polishResult.ReversePolishNotation.Select(pn => pn.Token)),
                    Trace = polishResult.Trace.Select(t => new PolishTraceDto
                    {
                        Input = t.Input,
                        Stack = string.Join(" | ", t.Stack.Select(pn => pn.Token)),
                        ReversePolishNotation = string.Join(" ", t.ReversePolishNotation.Select(pn => pn.Token))
                    })
                },
                ReferenceNumber = referenceNumber
            });
        }
        public PolishResult Run(OuterLexemes lexemes)
        {
            _i            = 3;  // skip program <program name> & delimiter
            _outerLexemes = lexemes;
            _labelNumber  = 0;
            _labelAddresses.Clear();
            ReversePolishNotation.Clear();

            ParseStatementsList();

            return(new PolishResult
            {
                ReversePolishNotation = ReversePolishNotation,
                Trace = Trace,
                LabelAddresses = _labelAddresses
            });
        }
        private List <SyntaxError> SyntaxParse(OuterLexemes lexemes)
        {
            int i = 0;

            if (lexemes.Errors.Any())
            {
                SyntaxErr.Add(new SyntaxError
                {
                    Line = 0,
                    Text = "Lexical errors detected"
                });
                return(SyntaxErr);
            }

            ParseProgram(lexemes.Lexemes, ref i);


            return(SyntaxErr);
        }
 public SyntaxResult SyntaxAnalyzer(OuterLexemes lexemes)
 {
     try
     {
         List <SyntaxError> res = SyntaxParse(lexemes);
         return(new SyntaxResult
         {
             Success = !res?.Any() ?? true,
             Text = res
         });
     }
     catch (SyntaxException e)
     {
         return(new SyntaxResult
         {
             Success = false,
             Text = new List <SyntaxError> {
                 new SyntaxError {
                     Text = e.Message
                 }
             }
         });
     }
 }