Esempio n. 1
0
        bool ScannerSpecification()
        {
            bool result = true;
            if (term(TokenType.CHARACTERS, false))
            {
                result = result && term(TokenType.CHARACTERS, true);
                while (term(TokenType.Ident, false))
                {
                    LexerCharacterSet tmpSet = new LexerCharacterSet();
                    result = result && SetDecl(out tmpSet);
                    characterDefinitions.Add(tmpSet);
                }
                form.appendText("parsed CHARACTERSE\n");
            }

            if (term(TokenType.KEYWORDS, false))
            {
                result = result && term(TokenType.KEYWORDS, true);
                while (term(TokenType.Ident, false))
                {
                    result = result && KeywordDecl();
                }
                form.appendText("parsed KEYWORDS\n");
            }

            if (term(TokenType.TOKENS, false))
            {
                result = result && term(TokenType.TOKENS, true);
                while (term(TokenType.Ident, false))
                {
                    LexerToken tmpToken = new LexerToken();
                    result = result && TokenDecl(out tmpToken);
                    tokenDefinitions.Add(tmpToken);
                }

                form.appendText("parsed TOKENS\n");
            }

            while (term(TokenType.IGNORE, false))
            {
                result = result && WhiteSpaceDecl();
            }
            if (result)
            {
                form.appendText("Parsed scannerspec \n");
            }

            return result;
        }
Esempio n. 2
0
        bool TokenDecl(out LexerToken tmpToken)
        {
            tmpToken = new LexerToken();
            bool result = true;
            string regexp = "";
            string id = "";
            if (term(TokenType.Ident, false))
            {
                id = tokenEnumerator.Current.getValue();
                result = result && term(TokenType.Ident, true);
            }
            if (term(TokenType.EQUALS, false))
            {
                result = result && term(TokenType.EQUALS, true)
                    && TokenExpr(out regexp);
            }

            if (term(TokenType.EXCEPT, false))
            {
                result = result && term(TokenType.EXCEPT, true)
                    && term(TokenType.KEYWORDS, true);
            }

            tmpToken = new LexerToken(id, regexp);

            result = result && term(TokenType.DOT, true);
            if (result)
            {
                form.appendText("Parsed Tokendecl \n");
            }
            return result;
        }
Esempio n. 3
0
        bool ParserSymbol(out Lr0Symbol theSymbol)
        {
            theSymbol = new Lr0Symbol();
            bool result = true;
            if (term(TokenType.Ident, false) || term(TokenType.String, false) || term(TokenType.Char, false))
            {
                string currentString = tokenEnumerator.Current.getValue();
                if (term(TokenType.Ident, false))
                {
                    bool isToken = false;
                    foreach (LexerToken t in tokenDefinitions)
                    {
                        if (currentString == t.Identifier)
                        {
                            theSymbol = new Lr0Symbol(t.Identifier, t.Identifier);
                            isToken = true;
                        }
                    }
                    if (!isToken)
                    {
                        if (currentString == "$")
                            theSymbol = Lr0GenerationHelper.getEndSymbol();
                        else if (currentString == "3")
                            theSymbol = Lr0GenerationHelper.getEpsylonSymbol();
                        else
                            theSymbol = new Lr0Symbol(currentString);
                    }
                    result = result && term(TokenType.Ident, true);
                    if (result)
                    {
                        form.appendText("Parsed ParseSymbol \n");
                    }
                    return result;
                }

                if (term(TokenType.String, false))
                {

                    string tmpString = LexerGenerationHelper.getStringValue(currentString);
                    if (tmpString == "$")
                    {
                        theSymbol = Lr0GenerationHelper.getEndSymbol();
                    }
                    else if (tmpString == "3")
                    {
                        theSymbol = Lr0GenerationHelper.getEpsylonSymbol();
                    }
                    else
                    {
                        List<LexerToken> oldDefinitions = new List<LexerToken>(tokenDefinitions);
                        tokenDefinitions = new List<LexerToken>();
                        LexerToken tmpToken = new LexerToken();
                        theSymbol = new Lr0Symbol(currentString);
                        tokenDefinitions.Add(new LexerToken(Lr0GenerationHelper.getSafeName(tmpString), tmpString));
                        foreach (LexerToken oldToken in oldDefinitions)
                        {
                            tokenDefinitions.Add(oldToken);
                        }
                        theSymbol = new Lr0Symbol(Lr0GenerationHelper.getSafeName(tmpString), tmpString);
                    }
                    result = result && term(TokenType.String, true);
                    if (result)
                    {
                        form.appendText("Parsed ParseSymbol \n");
                    }
                    return result;
                }

                if (term(TokenType.Char, false))
                {
                    string tmpString = LexerGenerationHelper.getCharValue(currentString).ToString();
                    if (tmpString == "$")
                    {
                        theSymbol = Lr0GenerationHelper.getEndSymbol();
                    }
                    else if (tmpString == "3")
                    {
                        theSymbol = Lr0GenerationHelper.getEpsylonSymbol();
                    }
                    else
                    {
                    List<LexerToken> oldDefinitions = new List<LexerToken>(tokenDefinitions);
                    tokenDefinitions = new List<LexerToken>();
                    tokenDefinitions.Add(new LexerToken(Lr0GenerationHelper.getSafeName(tmpString), tmpString));
                    foreach (LexerToken oldToken in oldDefinitions)
                    {
                        tokenDefinitions.Add(oldToken);
                    }
                    theSymbol = new Lr0Symbol(Lr0GenerationHelper.getSafeName(tmpString), tmpString);
                    }
                    result = result && term(TokenType.Char, true);
                    if (result)
                    {
                        form.appendText("Parsed ParseSymbol \n");
                    }
                    return result;
                }
            }
            else
            {
                return false;
            }

            return result;
        }