Esempio n. 1
0
        public Token Execute(Token rootToken, string code)
        {
            this.pos = 0;
            this.checkpoints = new Stack<ParserCheckpoint>();
            this.code = code;
            FindLines();

            if (rootToken.Match(this) && pos == code.Length)
            {
                if (rootToken is Node)
                {
                    return ((Node)rootToken).Interpret();
                }
                else
                {
                    return rootToken;
                }
            }
            else
            {
                int p, line, col;
                GetLineCol(out p, out line, out col);
                var ex = new ParserException(String.Format(ExceptionMessages.NotUnderstandableToken, line + 1, col + 1));
                ex.Pos = p; ex.Line = line; ex.Col = col;
                throw ex;
            }
        }
Esempio n. 2
0
        private void CopyMembers(Token old)
        {
            this.pos = old.pos;
            this.line = old.line;
            this.col = old.col;
            this.value = old.value;

            this.parent = old.parent;
        }
Esempio n. 3
0
        protected Exception CreateException(string message, Token token)
        {
            string msg;

            msg = String.Format(message, null, token.Line + 1, token.Pos + 1);

            ValidatorException ex = new ValidatorException(msg);
            ex.Token = token;

            return ex;
        }
Esempio n. 4
0
        protected internal virtual bool WriteNode(Token node)
        {
            var res = node.AcceptCodeGenerator(this);

            if (res && node is Node)
            {
                WriteChildren((Node)node);
            }

            return res;
        }
Esempio n. 5
0
 /// <summary>
 /// Writes a node by visiting its children.
 /// </summary>
 /// <param name="token"></param>
 /// <returns></returns>
 /// <remarks>
 /// Depending on the behavior of derived classes, this function
 /// might or might not traverse the parsing tree further.
 /// </remarks>
 protected virtual void WriteNode(Token token)
 {
     if (token is Node)
     {
         // Traverse tree
         WriteChildren((Node)token);
     }
     else
     {
         // Write terminal
         WriteToken(token);
     }
 }
Esempio n. 6
0
        public static CommentOrWhitespace Create(Token t)
        {
            var ncw = new CommentOrWhitespace();

            if (t is Whitespace || t is SingleLineComment || t is MultiLineComment)
            {
                ncw.Stack.AddLast(t);
            }
            else
            {
                throw new NotImplementedException();
            }

            return ncw;
        }
Esempio n. 7
0
 TreeNode GenerateToken(Token t)
 {
     TreeNode ni = new TreeNode(t.GetType().Name + " " + t.Value);
     ni.ForeColor = Color.Gray;
     return ni;
 }
Esempio n. 8
0
 void GenerateCodeToken(ref string code, Token t)
 {
     code += t.Value + " ";
 }
Esempio n. 9
0
 /// <summary>
 /// Writes the value of a token to the stream.
 /// </summary>
 /// <param name="token"></param>
 /// <remarks>
 /// This function is called only for terminals
 /// </remarks>
 protected void WriteToken(Token token)
 {
     writer.Write(token.Value);
 }
Esempio n. 10
0
 private void InitializeMembers()
 {
     this.token = null;
 }
Esempio n. 11
0
 public NameResolverException(string message, Token token)
     : base(message)
 {
     this.token = token;
 }
Esempio n. 12
0
 protected internal virtual bool WriteToken(Token t)
 {
     writer.Write(t.Value);
     return true;
 }
Esempio n. 13
0
 public Token(Token old)
 {
     CopyMembers(old);
 }
Esempio n. 14
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="token"></param>
 /// <returns></returns>
 /// <remarks>
 /// Do dispatching here based on node type
 /// </remarks>
 protected override void WriteNode(Token token)
 {
     if (token is TableAlias)
     {
         WriteTableAlias((TableAlias)token);
     }
     else if (token is TableOrViewName)
     {
         WriteTableOrViewName((TableOrViewName)token);
     }
     else if (token is ColumnIdentifier)
     {
         WriteColumnIdentifier((ColumnIdentifier)token);
     }
     else if (token is ColumnExpression)
     {
         WriteColumnExpression((ColumnExpression)token);
     }
     else if (token is FunctionIdentifier)
     {
         WriteFunctionIdentifier((FunctionIdentifier)token);
     }
     else
     {
         base.WriteNode(token);
     }
 }
Esempio n. 15
0
 public ValidatorException(string message, Token token)
     : base(message)
 {
     this.token = token;
 }