Ejemplo n.º 1
0
 public SimpleIfStatement(SimpleContext context, SimpleExpression ifClause,
                          SimpleStatement thenClause, SimpleStatement elseClause) : base(context)
 {
     m_ifClause   = ifClause;
     m_thenClause = thenClause;
     m_elseClause = elseClause;
 }
Ejemplo n.º 2
0
 public SimpleBinaryExpression(SimpleContext context,
                               SimpleExpression leftOperand, string op, SimpleExpression rightOperand)
     : base(context)
 {
     m_leftOperand  = leftOperand;
     m_operator     = op;
     m_rightOperand = rightOperand;
 }
Ejemplo n.º 3
0
 public SimpleSyntaxNode(SimpleContext context)
 {
     m_context = context;
 }
Ejemplo n.º 4
0
 public SimpleID(SimpleContext context, string name) : base(context)
 {
     m_name = name;
 }
Ejemplo n.º 5
0
        private bool DoParse()
        {
            //This procedure starts the GOLD Parser Engine and handles each of the
            //messages it returns. Each time a reduction is made, a new instance of a
            //"Simple" object is created and stored in the parse tree. The resulting tree
            //will be a pure representation of the Simple language and will be ready to
            //implement.
            StringReader reader = new StringReader(txtProgram.Text);
            Parser       parser = new Parser(reader, m_grammar);

            parser.TrimReductions = true;
            m_context             = new SimpleContext(parser);
            while (true)
            {
                switch (parser.Parse())
                {
                case ParseMessage.LexicalError:
                    Log("LEXICAL ERROR. Line " + parser.LineNumber + ". Cannot recognize token: " + parser.TokenText);
                    return(false);

                case ParseMessage.SyntaxError:
                    StringBuilder text = new StringBuilder();
                    foreach (Symbol tokenSymbol in parser.GetExpectedTokens())
                    {
                        text.Append(' ');
                        text.Append(tokenSymbol.ToString());
                    }
                    Log("SYNTAX ERROR. Line " + parser.LineNumber + ". Expecting:" + text.ToString());
                    return(false);

                case ParseMessage.Reduction:
                    //== Create a new customized object and replace the
                    //== CurrentReduction with it. This saves memory and allows
                    //== easier interpretation
                    parser.TokenSyntaxNode = m_context.GetSimpleObject();
                    break;

                case ParseMessage.Accept:
                    //=== Success!
                    m_program = (SimpleStatement)parser.TokenSyntaxNode;
                    Log("-- Program Accepted --");
                    return(true);

                case ParseMessage.TokenRead:
                    //=== Make sure that we store token string for needed tokens.
                    parser.TokenSyntaxNode = m_context.GetTokenText();
                    break;

                case ParseMessage.InternalError:
                    Log("INTERNAL ERROR! Something is horribly wrong");
                    return(false);

                case ParseMessage.NotLoadedError:
                    //=== Due to the if-statement above, this case statement should never be true
                    Log("NOT LOADED ERROR! Compiled Grammar Table not loaded");
                    return(false);

                case ParseMessage.CommentError:
                    Log("COMMENT ERROR! Unexpected end of file");
                    return(false);

                case ParseMessage.CommentBlockRead:
                    //=== Do nothing
                    break;

                case ParseMessage.CommentLineRead:
                    //=== Do nothing
                    break;
                }
            }
        }
Ejemplo n.º 6
0
 public SimpleAssignmentStatement(SimpleContext context,
                                  string name, SimpleExpression assignValue) : base(context)
 {
     m_name        = name;
     m_assignValue = assignValue;
 }
Ejemplo n.º 7
0
 public SimpleStatementList(SimpleContext context,
                            SimpleStatement currentStatement, SimpleStatement nextStatement) : base(context)
 {
     m_currentStatement = currentStatement;
     m_nextStatement    = nextStatement;
 }
Ejemplo n.º 8
0
 public SimpleWhileStatement(SimpleContext context, SimpleExpression whileClause,
                             SimpleStatement doClause) : base(context)
 {
     m_whileClause = whileClause;
     m_doClause    = doClause;
 }
Ejemplo n.º 9
0
		public SimpleString(SimpleContext context, string text) : base(context)
		{	
			m_value = text;
		}
Ejemplo n.º 10
0
 public SimpleExpression(SimpleContext context) : base(context)
 {
 }
Ejemplo n.º 11
0
 public SimpleDisplayStatement(SimpleContext context,
                               SimpleExpression displayClause, string readID) : base(context)
 {
     m_displayClause = displayClause;
     m_readID        = readID;
 }
Ejemplo n.º 12
0
 public SimpleNegate(SimpleContext context, SimpleExpression expression)
     : base(context)
 {
     m_expr = expression;
 }
Ejemplo n.º 13
0
 public SimpleNumber(SimpleContext context, double value) : base(context)
 {
     m_value = value;
 }
Ejemplo n.º 14
0
 public SimpleStatement(SimpleContext context) : base(context)
 {
 }