Exemplo n.º 1
0
        /// <summary>
        /// Parser for EachStatement
        /// </summary>
        /// <returns>Parsed EachStatement</returns>
        public EachStatement ParseEachStatement()
        {
            EachStatement eachStatement = new EachStatement();

            //Skip each token
            NextToken("each", "each (identifier : expression) Statement", "each");

            //Skip ( token
            NextToken("(", "each (identifier : expression) Statement", '(');

            //Parse identifier
            CurrentToken = TokenStream.NextToken();
            eachStatement.SetIdentifier(CurrentToken.GetValue().ToString());

            //Skip : token
            NextToken(":", "each (identifier : expression) Statement", ':');

            //Parse expression
            eachStatement.SetExpression(expressionParser.ParseExpression());

            //Skip ) token
            NextToken(")", "each (identifier : expression) Statement", ')');

            //Parse statement
            eachStatement.SetStatement(ParseStatement());

            return(eachStatement);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parse an SymbolExpression
        /// </summary>
        /// <returns>Parsed SymbolExpression</returns>
        public SymExpression ParseSymExpression()
        {
            SymExpression symExpression = new SymExpression();

            CurrentToken = TokenStream.NextToken();
            symExpression.SetSym(CurrentToken.GetValue().ToString());

            return(symExpression);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parse an NumericExpression
        /// </summary>
        /// <returns>Parsed Numeric Expression</returns>
        public NumExpression ParseNumExpression()
        {
            NumExpression numExpression = new NumExpression();

            CurrentToken = TokenStream.NextToken();
            numExpression.SetNum(ObjectToInt(CurrentToken.GetValue()));

            return(numExpression);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Parse an TextExpression
        /// </summary>
        /// <returns>Parsed TextExpression</returns>
        public TextExpression ParseTextExpression()
        {
            TextExpression textExpression = new TextExpression();

            CurrentToken = TokenStream.NextToken();
            textExpression.SetText(CurrentToken.GetValue().ToString());

            return(textExpression);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Parse an VariableExpression
        /// </summary>
        /// <returns>Parsed VariableExpression</returns>
        public VarExpression ParseVarExpression()
        {
            VarExpression varExpression = new VarExpression();

            CurrentToken = TokenStream.NextToken();
            varExpression.SetVariableIdentifier(CurrentToken.GetValue().ToString());

            return(varExpression);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Parser for Formal
        /// </summary>
        /// <returns>Parsed Formal</returns>
        public Formal ParseFormal()
        {
            Formal formal = new Formal();

            CurrentToken = TokenStream.NextToken();
            formal.SetIdentifier(CurrentToken.GetValue().ToString());

            return(formal);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Parser for WidthAttribute
        /// </summary>
        /// <returns>Parsed HeightAttribute</returns>
        public WidthAttribute ParseWidthAttribute()
        {
            WidthAttribute widthAttribute = new WidthAttribute();

            //Get height
            CurrentToken = TokenStream.NextToken();
            widthAttribute.SetWidth(ObjectToInt(CurrentToken.GetValue()));

            return(widthAttribute);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Parser for IdAttribute
        /// </summary>
        /// <returns>Parsed IdAttribute</returns>
        public IdAttribute ParseIdAttribute()
        {
            IdAttribute idAttribute = new IdAttribute();

            //Get id token
            CurrentToken = TokenStream.NextToken();
            idAttribute.SetId(CurrentToken.GetValue().ToString());

            return(idAttribute);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Parser for NameAttribute
        /// </summary>
        /// <returns>Parsed NameAttribute</returns>
        public NameAttribute ParseNameAttribute()
        {
            NameAttribute nameAttribute = new NameAttribute();

            //Get name token
            CurrentToken = TokenStream.NextToken();
            nameAttribute.SetName(CurrentToken.GetValue().ToString());

            return(nameAttribute);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Parser for TypeAttribute
        /// </summary>
        /// <returns>Parsed TypeAttribute</returns>
        public TypeAttribute ParseTypeAttribute()
        {
            TypeAttribute typeAttribute = new TypeAttribute();

            //Get type token
            CurrentToken = TokenStream.NextToken();
            typeAttribute.SetType(CurrentToken.GetValue().ToString());

            return(typeAttribute);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Parser for ClassAttribute
        /// </summary>
        /// <returns>Parsed ClassAttribute</returns>
        public ClassAttribute ParseClassAttribute()
        {
            ClassAttribute classAttribute = new ClassAttribute();

            //Get class token
            CurrentToken = TokenStream.NextToken();
            classAttribute.SetClass(CurrentToken.GetValue().ToString());

            return(classAttribute);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Parser for CommentStatement
        /// </summary>
        /// <returns>Parsed CommentStatement</returns>
        public CommentStatement ParseCommentStatement()
        {
            CommentStatement commentStatement = new CommentStatement();

            //Skip comment token
            NextToken("comment", "comment thisisacomment;", "comment");

            //Parse comment
            CurrentToken = TokenStream.NextToken();
            commentStatement.SetCommentString(CurrentToken.GetValue().ToString());

            //Skip ; token
            NextToken(";", "comment thisisacomment;", ';');

            return(commentStatement);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Parse an FieldExpression
        /// </summary>
        /// <param name="expression">Expression which is already parsed</param>
        /// <returns></returns>
        public Expression ParseFieldExpression(Expression expression)
        {
            FieldExpression fieldExpression = new FieldExpression();

            //Add already parsed expression to field
            fieldExpression.SetExpression(expression);

            //Skip . token
            NextToken(".", "expression.identifier", '.');

            //Parse identifier
            CurrentToken = TokenStream.NextToken();
            fieldExpression.SetIdentifier(CurrentToken.GetValue().ToString());

            return(fieldExpression);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Parser for AttrArgument
        /// </summary>
        /// <returns>Parsed AttrArgument</returns>
        public AttrArgument ParseAttrArgument()
        {
            AttrArgument argument = new AttrArgument();

            //Parse identifier
            CurrentToken = TokenStream.NextToken();
            argument.SetIdentifier(CurrentToken.GetValue().ToString());

            //Skip = token
            NextToken("=", "identifier = expression", '=');

            //Parse expression
            argument.SetExpression(expressionParser.ParseExpression());

            return(argument);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Parse an KeyValuePair
        /// </summary>
        /// <returns>Parsed KeyValuePair</returns>
        public KeyValuePair ParseKeyValuePair()
        {
            KeyValuePair keyValuePair = new KeyValuePair();

            //Get key
            CurrentToken = TokenStream.NextToken();
            keyValuePair.SetKey(CurrentToken.GetValue().ToString());

            //Skip :
            NextToken(":", "key : value", ':');

            //Get value
            keyValuePair.SetValue(ParseExpression());

            return(keyValuePair);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Parser for Width_HeightAttribute
        /// </summary>
        /// <returns>Parsed Width_HeightAttribute</returns>
        public Width_HeightAttribute ParseWidth_HeightAttribute()
        {
            Width_HeightAttribute widthHeightAttribute = new Width_HeightAttribute();

            //Get width
            CurrentToken = TokenStream.NextToken();
            widthHeightAttribute.SetWidth(ObjectToInt(CurrentToken.GetValue()));

            //Skip % token
            NextToken("%", "@width %height", '%');

            //Get height
            CurrentToken = TokenStream.NextToken();
            widthHeightAttribute.SetHeight(ObjectToInt(CurrentToken.GetValue()));

            return(widthHeightAttribute);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Parse one module
        /// </summary>
        /// <param name="module">Module to parse</param>
        public Module ParseModule()
        {
            Module module = new Module();

            //Skip module token
            NextToken("module", "module identifier", "module");

            //Parse first the identifier of the module and set it
            ModuleId moduleIdentifier = ParseModuleId();

            module.SetModuleId(moduleIdentifier);

            //Look for elements like SITE, DEF, etc
            while (TokenStream.HasNext())
            {
                if (MatchValue(TokenStream.Peek(1).GetValue().ToString(), Waebric.WaebricKeyword.MODULE.ToString()))
                {   //New module found, raise exception, only one module per file allowed
                    throw new UnexpectedToken("Unexpected token, found second module definition:", "module", TokenStream.Peek(1).GetLine());
                }
                CurrentToken = TokenStream.NextToken();


                //Check for different elements which may appear in a module
                if (MatchValue(CurrentToken.GetValue().ToString(), Waebric.WaebricKeyword.DEF.ToString()))
                {   //Function definition found
                    module.AddFunctionDefinition(functionParser.ParseFunctionDefinition());
                }
                else if (MatchValue(CurrentToken.GetValue().ToString(), Waebric.WaebricKeyword.SITE.ToString()))
                {   //Site definition found, call siteparser
                    module.AddSite(siteParser.ParseSite());
                }
                else if (MatchValue(CurrentToken.GetValue().ToString(), Waebric.WaebricKeyword.IMPORT.ToString()))
                {   //Imports found
                    module.AddImport(ParseImport());
                }
                else
                {
                    //Exception
                    throw new UnexpectedToken("Unexpected token found:", CurrentToken.GetValue().ToString(), CurrentToken.GetLine());
                }
            }

            return(module);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Parser for VarBindAssignment
        /// </summary>
        /// <returns>Parsed VarBindAssignment</returns>
        public VarBindAssignment ParseVarBindAssignment()
        {
            VarBindAssignment varBindAssignment = new VarBindAssignment();

            //Parse identifier
            CurrentToken = TokenStream.NextToken();
            varBindAssignment.SetIdentifier(CurrentToken.GetValue().ToString());

            //Skip = token
            NextToken("=", "identifier = expression;", '=');

            //Parse expression
            varBindAssignment.SetExpression(expressionParser.ParseExpression());

            //Skip ; token
            NextToken(";", "identifier = expression;", ';');

            return(varBindAssignment);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Parser for Attribute
        /// </summary>
        /// <returns>Parsed Attribute</returns>
        public Attribute ParseAttribute()
        {
            CurrentToken = TokenStream.NextToken();
            Attribute attribute = null;

            switch (CurrentToken.GetValue().ToString())
            {         //Determine different types of attributes
            case "#": //Id attribute
                attribute = ParseIdAttribute();
                break;

            case ".":     //Class attribute
                attribute = ParseClassAttribute();
                break;

            case "$":     //Name attribute
                attribute = ParseNameAttribute();
                break;

            case ":":     //Type attribute
                attribute = ParseTypeAttribute();
                break;

            case "@":   //Width_(Height) attribute
                if (TokenStream.Peek(2).GetValue().ToString() == "%")
                {       //Width-Height attribute
                    attribute = ParseWidth_HeightAttribute();
                }
                else
                {       //Only width attribute
                    attribute = ParseWidthAttribute();
                }
                break;

            default:
                throw new UnexpectedToken("Expected attribute, but found:", CurrentToken.GetValue().ToString(), CurrentToken.GetLine());
            }

            return(attribute);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Parser for FunctionDefinition
        /// </summary>
        /// <returns>Parsed FunctionDefinition</returns>
        public FunctionDefinition ParseFunctionDefinition()
        {
            FunctionDefinition functionDefinition = new FunctionDefinition();

            //Parse FunctionId
            CurrentToken = TokenStream.NextToken();
            functionDefinition.SetIdentifier(CurrentToken.GetValue().ToString());

            //Parse Formals
            ParseFormals(functionDefinition);

            //Parse Statements
            while (TokenStream.HasNext() && TokenStream.Peek(1).GetValue().ToString() != "end")
            {
                functionDefinition.AddStatement(statementParser.ParseStatement());
            }

            //Skip end token
            NextToken("end", "def function() statements end", "end");

            return(functionDefinition);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Parser for Embedding
        /// </summary>
        /// <returns>Parsed Embedding</returns>
        public Embedding ParseEmbedding()
        {
            //Get iterator for specific embedding
            if (TokenStream.Peek(1).GetType() == TokenType.EMBEDDING)
            {   //Store embedding in internal tokeniterator to parse internally
                CurrentToken         = TokenStream.NextToken();
                EmbeddingTokenStream = ((EmbeddingToken)CurrentToken).GetTokenIterator();
            }
            else
            {   //Raise exception
                throw new UnexpectedToken("Embedding expected, but found:", CurrentToken.GetValue().ToString(), CurrentToken.GetLine());
            }

            //Let's parse embedding
            Embedding embedding = new Embedding();

            embedding.SetPreText(ParsePreText());
            embedding.SetEmbed(ParseEmbed());
            embedding.SetTextTail(ParseTextTail());

            return(embedding);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Parser for Type
        /// </summary>
        /// <returns>Parsed Type</returns>
        public Type ParseType()
        {
            //return specific type
            CurrentToken = TokenStream.NextToken();

            if (CurrentToken.GetValue().ToString() == "list")
            {   //ListType
                return(new ListType());
            }
            else if (CurrentToken.GetValue().ToString() == "record")
            {   //RecordType
                return(new RecordType());
            }
            else if (CurrentToken.GetValue().ToString() == "string")
            {   //StringType
                return(new StringType());
            }
            else
            {   //Unexpected type, throw exception
                throw new UnexpectedToken("Type expected, but found:", CurrentToken.GetValue().ToString(), CurrentToken.GetLine());
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Parser for FuncBindAssignment
        /// </summary>
        /// <returns>Parsed FuncBindAssignment</returns>
        public FuncBindAssignment ParseFuncBindAssignment()
        {
            FuncBindAssignment funcBindAssignment = new FuncBindAssignment();

            //Parse identifier
            CurrentToken = TokenStream.NextToken();
            funcBindAssignment.SetIdentifier(CurrentToken.GetValue().ToString());

            //Skip ( token
            NextToken("(", "identifier(identifier1, identifier2) = statement;", '(');

            //Parse identifiers
            while (TokenStream.HasNext())
            {
                if (TokenStream.HasNext() && TokenStream.Peek(1).GetValue().ToString() == ")")
                {   //No more identifiers
                    break;
                }
                else if (TokenStream.Peek(1).GetValue().ToString() == ",")
                {
                    //Skip , token
                    NextToken(",", "(identifier1, identifier2)", ',');
                }
                CurrentToken = TokenStream.NextToken();
                funcBindAssignment.AddIdentifier(CurrentToken.GetValue().ToString());
            }

            //Skip ) token
            NextToken(")", "identifier(identifier1, identifier2) = statement;", ')');

            //Skip = token
            NextToken("=", "identifier(identifier1, identifier2) = statement;", '=');

            //Parse statement
            funcBindAssignment.SetStatement(ParseStatement());

            return(funcBindAssignment);
        }