Esempio n. 1
0
        private Identifier parseIdentifier(bool compoundAllowed)
        {
            string name = "";
            int    row;
            int    col;

            if (currentScannerToken == GingerToken.Identifier)
            {
                row = scanner.row;
                col = scanner.col;
            }
            else
            {
                throw new ParseException(scanner.row, scanner.col, $"Expected '{GingerToken.Identifier.ToString()}', found '{currentScannerToken.ToString()}'", ExceptionLevel.ERROR);
            }

            do
            {
                name += new string(scanner.tokenValue);

                //nextScannerToken();
                spyScannerToken();
                if (spiedScannerToken == GingerToken.IdentifierSeparator)
                {
                    if (compoundAllowed)
                    {
                        nextScannerToken();
                        name += Lexicon.IDENT_SEPARATOR;

                        nextScannerToken();
                        if (currentScannerToken != GingerToken.Identifier)
                        {
                            throw new ParseException(scanner.row, scanner.col, $"Expected '{GingerToken.Identifier.ToString()}', found '{currentScannerToken.ToString()}'", ExceptionLevel.ERROR);
                        }
                    }
                    else
                    {
                        throw new ParseException(scanner.row, scanner.col, $"Found compound identifier, where one is not allowed", ExceptionLevel.ERROR);
                    }
                }
                else
                {
                    break;
                }
            } while (currentScannerToken == GingerToken.Identifier);

            return(new Identifier(row, col, name));
        }
Esempio n. 2
0
        private StatementList parseStatementList(GingerToken endToken)
        {
            StatementList sl = new StatementList();
            do
            {
                try
                {
                    sl.add(parseStatement());
                }
                catch (ParseException pe)
                {
                    _errors.Add(pe);
                }

                nextScannerToken();

                if (currentScannerToken != endToken && currentScannerToken == GingerToken.EndOfFile)
                {
                    _errors.Add(new ParseException(scanner.row, scanner.col, $"Expected '{endToken.ToString()}', found '{currentScannerToken.ToString()}'", ExceptionLevel.ERROR));
                }
            } while (currentScannerToken != endToken && currentScannerToken != GingerToken.EndOfFile);

            return sl;
        }