Exemplo n.º 1
0
        public override ICodeNode Parse(Token token)
        {
            token = NextToken(); // after method
            ICodeNode methodNode = IntermediateCodeFactory.CreateICodeNode("method");

            StatementParser statementParser = new StatementParser(this);
            statementParser.ParseList(token, ref methodNode, "end", "missing_end");
            token = CurrentToken();
            return methodNode;
        }
Exemplo n.º 2
0
 public void OnMessage(Token token)
 {
     Parser.OnMessage(this, MessageType.Token, new Dictionary<string, object>()
             {
                 {"LineNumber", token.LineNumber},
                 {"Position", token.Position},
                 {"TokenType", token.TokenType},
                 {"TokenText", token.Text},
                 {"TokenValue", token.Value}
             });
 }
Exemplo n.º 3
0
        public void Flag(Token token, ILangErrorCode errorCode, Parser parser)
        {
            Parser.OnMessage(parser, MessageType.SyntaxError, new Dictionary<string, object>()
            {
                {"LineNumber", token.LineNumber},
                {"Position", token.Position},
                {"TokenText", token.Text},
                {"Error", errorCode}
            });

            if (++errors > MAX_ERROR)
                Fatal("too_many_errors", parser);
        }
Exemplo n.º 4
0
        public override ICodeNode Parse(Token token)
        {
            ICodeNode node = null;
            switch (token.TokenType.ToString())
            {
                case "method":
                    MethodParser methodParser = new MethodParser(this);
                    node = methodParser.Parse(token);
                    // CurrentToken() == ";"
                    break;
                case "identifier":
                    AssignmentParser assignmentParser = new AssignmentParser(this);
                    node = assignmentParser.Parse(token);
                    break;
                default:
                    node = IntermediateCodeFactory.CreateICodeNode("no_op");
                    break;
            }
            if (node != null)
                node.SetAttribute("line", token.LineNumber);

            return node;
        }
Exemplo n.º 5
0
        public void ParseList(Token token, ref ICodeNode parent, ILangTokenType terminator, ILangErrorCode error)
        {
            // As long as we are parseing neither endToken or terminating token
            // do this
            while (!(token is EndOfFileToken) && (token.TokenType.ToString() != terminator.ToString()))
            {
                ICodeNode statementNode = Parse(token);
                parent.AddChild(statementNode);

                // token have been moved; get the latest
                token = CurrentToken();

                if (token.TokenType == "semicolon")
                {
                    token = NextToken(); // move beyond the statement separator.
                }
                else if (token.TokenType == "identifier")
                {
                    ErrorHandler.Singleton.Flag(token, "missing_semicolon", this);
                }
                else if (token.TokenType != terminator)
                {
                    ErrorHandler.Singleton.Flag(token, "unexpected_token", this);
                    token = NextToken();
                }
            }

            if (token.TokenType == terminator)
            {
                token = NextToken();
            }
            else
            {
                ErrorHandler.Singleton.Flag(token, error, this);
            }
        }
Exemplo n.º 6
0
 public virtual ICodeNode Parse(Token token)
 {
     return null;
 }
Exemplo n.º 7
0
 public virtual Token NextToken()
 {
     _current = ExtractToken();
     return _current;
 }