Exemplo n.º 1
0
 private bool Accept(Token.Types excepted)
 {
     if (CurrentToken.Type == excepted)
     {
         AcceptedToken = CurrentToken;
         NextToken();
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
 private bool Accept(Token.Types[] excepted)
 {
     if (Array.IndexOf(excepted, CurrentToken.Type) != -1)
     {
         AcceptedToken = CurrentToken;
         NextToken();
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
        private void Process(Token t) {

            if (exptFuCallFlag) 
                ExcpectFunctionCall(t);

            else if (opBlockFlag) {
                if (t.type == Token.Type.Operator && t.lexema == "}") {
                    opBlockFlag = false;
                    this.pStack.Push(newblock);
                }
                else {
                    newblock.Append(t);
                }
            }
            else
                switch (t.type) {
                    case Token.Type.Indexer:
                        pStack.Push(int.Parse(t.lexema));
                        CallFunction(new Id("~indexer"));
                        break;
                    case Token.Type.Operator:
                        ProcessOperator(t.lexema);
                        break;
                
                    case Token.Type.FunctionCall:
                        CallFunction(new Id(t.lexema));
                        break;
                    case Token.Type.String:
                        pStack.Push(t.lexema);
                        break;
                    case Token.Type.Double:
                        pStack.Push(Double.Parse(t.lexema));
                        break;
                    case Token.Type.Integer:
                        pStack.Push(Double.Parse(t.lexema));
                        break;
                
                    case Token.Type.IdHead:
                        pStack.Push(new Id(t.lexema));
                        break;
                    case Token.Type.IdSingle:
                        pStack.Push(new Id(t.lexema));
                        
                        break;

                    case Token.Type.IdTail:
                        Id before = (Id)pStack.Peek();
                        before.AddPath(t.lexema);
                        break;
                    case Token.Type.EOS:
                        break;
                }
        }
Exemplo n.º 4
0
 private Token Match(Token.Types excepted)
 {
     if (CurrentToken.Type != excepted)
     {
         if (excepted == Token.Types.LineTerm)
             return new Token(Token.Types.LineTerm, CurrentToken.Line, CurrentToken.Column);
         throw new ParserException(String.Format("Expected {0}, got {1} instead at line {2} column {3}.",
             excepted, CurrentToken.Type, CurrentToken.Line, CurrentToken.Column));
     }
     Token match = CurrentToken;
     NextToken();
     return match;
 }
Exemplo n.º 5
0
 public void Append(Token t) {
     if (t.type == Token.Type.Operator && t.lexema == "{") {
         flag = true;
         newblock = new Opcodes();
     }
     if (flag) {
         if (t.type == Token.Type.Operator && t.lexema == "}") {
             flag = false;
             this.ops.AddLast(newblock);
         }
         else 
             newblock.Append(t);   
     }
     else 
         ops.AddLast(t);
 }
Exemplo n.º 6
0
 private BinaryExpr CreateBinaryExpr(Token token = null)
 {
     if (token == null)
     {
         token = AcceptedToken;
     }
     BinaryExpr expr = new BinaryExpr(token.Line, token.Column);
     switch(token.Type)
     {
         case Token.Types.OpPlus: expr.Op = Operator.Plus; break;
         case Token.Types.OpMinus: expr.Op = Operator.Minus; break;
         case Token.Types.OpMultiply: expr.Op = Operator.Times; break;
         case Token.Types.OpDivide: expr.Op = Operator.Divide; break;
         case Token.Types.OpLess: expr.Op = Operator.Less; break;
         case Token.Types.OpEquals: expr.Op = Operator.Equals; break;
         case Token.Types.OpAnd: expr.Op = Operator.And; break;
     }
     return expr;
 }
Exemplo n.º 7
0
        void BreakCarry(Token.Type with)
        {
            if (carryType == Token.Type.EOS) {
                carryType = with;
                return;
            }
            if (carryType == Token.Type.IdTail && with!=Token.Type.IdTail)
                carryType = Token.Type.IdEnd;
            if (carryType == Token.Type.IdHead && with != Token.Type.IdTail)
                carryType = Token.Type.IdSingle;

            output.AddLast(new Token(carry, carryType));
            carry = "";
            carryType = with;
        }
Exemplo n.º 8
0
 private void ReadNextToken()
 {
     currentToken = scanner.GetNextToken ();
     if ((Token.Types)currentToken.Type == Token.Types.ERROR) {
         throw new LexicalError ("malformed token \"" + currentToken.Lexeme + "\"", currentToken.Row,
             currentToken.Column);
     }
 }
Exemplo n.º 9
0
        private Token Match(Token.Types type)
        {
            if ((Token.Types)currentToken.Type == type) {
                Token current = currentToken;
                ReadNextToken ();
                return current;
            }

            throw new SyntaxError ("invalid token " + currentToken.Type + ", expected: " + type, currentToken.Row,
                currentToken.Column);
        }
Exemplo n.º 10
0
 private void NextToken()
 {
     CurrentToken = Scanner.GetNextToken();
 }
Exemplo n.º 11
0
 public Parser(Scanner scanner, ErrorHandler errors)
 {
     Scanner = scanner;
     Errors = errors;
     CurrentToken = Scanner.GetNextToken();
 }
Exemplo n.º 12
0
 void ExcpectFunctionCall(Token t) {
     if (t.type == Token.Type.IdSingle) {
         CallFunction(new Id(t.lexema));
         exptFuCallFlag = false;
     }
     else if (t.type == Token.Type.IdHead) {
         pStack.Push(new Id(t.lexema));
     }
     else if (t.type == Token.Type.IdTail) {
         Id before = (Id)pStack.Peek();
         before.AddPath(t.lexema);
     }
     else if (t.type == Token.Type.IdEnd) {
         Id before = (Id)pStack.Pop();
         before.AddPath(t.lexema);
         CallFunction(before);
         exptFuCallFlag = false;
     }
     else
         throw new Exception("invalid function call");
 }
Exemplo n.º 13
0
 public Token(string lexema, Token.Type type)
 {
     this.type = type;
     this.lexema = lexema;
 }
Exemplo n.º 14
0
 public Node(Token token)
 {
     Name = token.Lexeme;
     Row = token.Row;
     Column = token.Column;
 }