コード例 #1
0
ファイル: ASTNode.cs プロジェクト: AxFab/amy
 public ASTNode(Token token, ASTOperand operand)
 {
     Token = token;
     Priority = 0;
     Operand = operand;
     Type = operand.Type;
     Operator = ASTOperator.None;
 }
コード例 #2
0
ファイル: ASTNode.cs プロジェクト: AxFab/amy
 public ASTNode(Token token, ASTType type, long value)
 {
     Token = token;
     Type = type;
     Operator = ASTOperator.None;
     Operand = null;
     IValue = value;
     Computed = true;
 }
コード例 #3
0
ファイル: ASTStatement.cs プロジェクト: AxFab/amy
 public ASTStatement CloseParenthesis(Token token)
 {
     ASTNode node = inFixStack.Pop();
     while (node.Operator != ASTOperator.Parenthesis)
     {
         addPostFixOperator(node);
         node = inFixStack.Pop();
         if (node == null)
         {
             throw new Exception("Too much parenthesis");
         }
     }
     return this;
 }
コード例 #4
0
ファイル: ASTNode.cs プロジェクト: AxFab/amy
 public ASTNode(Token token, ASTOperator op)
 {
     Token = token;
     Operator = op;
     Priority = Priorities[(int)op];
 }
コード例 #5
0
ファイル: ErrorReport.cs プロジェクト: AxFab/amy
 public static void RegError(Token token, string message)
 {
     Console.ForegroundColor = ConsoleColor.Red;
       Console.WriteLine("\nAt " + token.File + ":" + token.Start.Row + " - " + message, token.Litteral);
       Console.ForegroundColor = ConsoleColor.Gray;
 }
コード例 #6
0
ファイル: Tokenizer.cs プロジェクト: AxFab/amy
        /*
        protected int ReadChar()
        {
        int ch;
        if (lastChar == '\n')
        {
            cursorRow++;
            column = 1;
        }
        else if (lastChar > 0)
        {
            column++;
        }

        if (peekChar >= 0)
        {
            ch = peekChar;
            peekChar = 0;
            lastChar = peekChar;
            return peekChar;
        }

        ch = reader.Read();
        peekChar = -1;
        if (ch <= 0)
        {
            ch = 0;
        }

        if (ch == '\r')
        {
            ch = reader.Read();
        }

        lastChar = ch;
        return ch;
        }

        protected int PeekChar()
        {
        if (peekChar < 0)
        {
            peekChar = ReadChar();
        }

        return peekChar;
        }
        */
        public Token ReadToken()
        {
            Token token = null;
              if (string.IsNullOrEmpty(textData))
            return token;

              // Read delimiters
              if (token == null) {
            TokenDelimiter tkDelSelected = null;
            foreach (TokenDelimiter tkdel in lang.Delimiters) {
              if (textData.StartsWith(tkdel.Start)) {
            if (lang.isOrdered) {
              tkDelSelected = tkdel;
              break;
            } else {
              if (tkDelSelected == null) {
                tkDelSelected = tkdel;

              } else if (tkDelSelected.Start.Length <= tkdel.Start.Length) {

                int idxEndP = tkDelSelected.GetLength(textData);
                int idxEndN = tkdel.GetLength(textData);

                if (idxEndP >= 0 && idxEndN >= 0 && idxEndN < idxEndP) {
                  tkDelSelected = tkdel;
                }
                /*
            else if (idxEndP >= 0 && idxEndN >= 0)
            {
                // tkDelSelected = tkdel;

            }
            else if (idxEndN > idxEndP)
            {
                tkDelSelected = tkdel;
            }*/
              }
            }
              }
            }

            if (tkDelSelected != null) {
              int idxEnd = tkDelSelected.GetLength(textData);
              string value = textData.Substring(0, idxEnd);
              token = new Token()
              {
            Start = position,
            Type = tkDelSelected.Type,
            Litteral = value
              };
            }
              }

              // Read operators
              if (token == null) {
            TokenKeyword tkOprSelected = null;
            foreach (TokenKeyword tkopr in lang.Operators) {
              if (textData.StartsWith(tkopr.Litteral)) {
            if (lang.isOrdered) {
              tkOprSelected = tkopr;
              break;
            } else {
              if (tkOprSelected == null ||
                  tkOprSelected.Litteral.Length < tkopr.Litteral.Length) {
                tkOprSelected = tkopr;
              }
            }
              }
            }

            if (tkOprSelected != null) {
              token = new Token()
              {
            Start = position,
            Type = tkOprSelected.Type,
            Litteral = tkOprSelected.Litteral
              };
            }
              }

              // Read field
              if (token == null) {
            TokenExpr tkExSelected = null;
            foreach (TokenExpr tkEx in lang.Groups) {
              Match m = tkEx.Expression.Match(textData);
              if (m.Index == 0 && m.Length != 0) {
            tkExSelected = tkEx;
            token = new Token()
            {
              Start = position,
              Type = tkEx.Type,
              Litteral = textData.Substring(0, m.Length)
            };
            break;
              }
            }
              }

              if (token == null) {
            string stray = textData.Substring(0, textData.IndexOfAny(Tokenizer.WhiteChars));
            throw new Exception("Lexical error, found stray '" + stray + "' at " + ":" + position.Row);
            // GCC throw new Exception("error: stray '?' in program");
              }

              token.End = ConsumeCharacters(token.Litteral.Length);

              // Keyword
              if (token.Type == 1) {
            foreach (TokenKeyword tkw in lang.Keywords)
              if (tkw.Litteral == token.Litteral) {
            token.Type = tkw.Type;
            break;
              }

              }
              return token;
        }
コード例 #7
0
ファイル: ASTStatement.cs プロジェクト: AxFab/amy
        public ASTStatement PushOperator(Token token, ASTOperator opcode)
        {
            ASTNode node = new ASTNode(token, opcode);
            while (inFixStack.Count > 0 && inFixStack.Peek().Priority > node.Priority)
            {
                ASTNode nd = inFixStack.Pop();
                addPostFixOperator(nd);
            }

            inFixStack.Push(node);
            return this;
        }
コード例 #8
0
ファイル: ASTStatement.cs プロジェクト: AxFab/amy
 public ASTStatement PushOperand(Token token, ASTOperand operand)
 {
     ASTNode node = new ASTNode(token, operand);
     addPostFixOperand(node);
     return this;
 }
コード例 #9
0
ファイル: ASTStatement.cs プロジェクト: AxFab/amy
 public ASTStatement PushInteger(Token token, ASTType type, long value)
 {
     ASTNode node = new ASTNode(token, type, value);
     addPostFixOperand(node);
     return this;
 }
コード例 #10
0
ファイル: ASTStatement.cs プロジェクト: AxFab/amy
 public ASTStatement OpenParenthesis(Token token)
 {
     ASTNode node = new ASTNode(token, ASTOperator.Parenthesis);
     inFixStack.Push(node);
     return this;
 }
コード例 #11
0
ファイル: MacroSession.cs プロジェクト: AxFab/amy
 public int SetUpMacro(Macro macro, Token token)
 {
     currentMacro_ = macro;
       // currentArgs_ = null;
       // currentIdx_ = 0;
       return macro.Arguments.Count;
 }