Source Code Cross Referenced for Parser.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » client » session » parser » kernel » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.client.session.parser.kernel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package net.sourceforge.squirrel_sql.client.session.parser.kernel;
0002:
0003:        import net.sourceforge.squirrel_sql.client.session.parser.kernel.completions.*;
0004:
0005:        import java.util.*;
0006:
0007:        public class Parser {
0008:            private static final int maxT = 103;
0009:
0010:            private static final boolean T = true;
0011:            private static final boolean x = false;
0012:            private static final int minErrDist = 2;
0013:
0014:            private int errDist = minErrDist;
0015:
0016:            private Vector<ParserListener> parserListeners = new Vector<ParserListener>();
0017:            private Vector<SQLSelectStatementListener> sqlSelectStatlisteners = new Vector<SQLSelectStatementListener>();
0018:
0019:            protected Scanner scanner; // input scanner
0020:            protected Token token; // last recognized token
0021:            protected Token t; // lookahead token
0022:
0023:            public List<SQLStatement> statements = new ArrayList<SQLStatement>();
0024:            public SQLSchema rootSchema;
0025:
0026:            private Stack<SQLStatementContext> stack;
0027:
0028:            protected void addRootStatement(SQLStatement statement) {
0029:                statement.setSqlSchema(rootSchema);
0030:                fireStatementAdded(statement);
0031:                statements.add(statement);
0032:                stack = new Stack<SQLStatementContext>();
0033:                stack.push(statement);
0034:            }
0035:
0036:            private void fireStatementAdded(SQLStatement statement) {
0037:                ParserListener[] clone = parserListeners
0038:                        .toArray(new ParserListener[parserListeners.size()]);
0039:
0040:                for (int i = 0; i < clone.length; i++) {
0041:                    clone[i].statementAdded(statement);
0042:                }
0043:
0044:            }
0045:
0046:            public void addParserListener(ParserListener l) {
0047:                parserListeners.add(l);
0048:            }
0049:
0050:            public void removeaddParserListener(ParserListener l) {
0051:                parserListeners.remove(l);
0052:            }
0053:
0054:            public void addSQLSelectStatementListener(
0055:                    SQLSelectStatementListener l) {
0056:                sqlSelectStatlisteners.add(l);
0057:            }
0058:
0059:            public void removeSQLSelectStatementListener(
0060:                    SQLSelectStatementListener l) {
0061:                sqlSelectStatlisteners.remove(l);
0062:            }
0063:
0064:            private SQLStatementContext getContext() {
0065:                return stack.peek();
0066:            }
0067:
0068:            private void pushContext(SQLStatementContext context) {
0069:                SQLStatementContext parent = stack.peek();
0070:                parent.addContext(context);
0071:                stack.push(context);
0072:            }
0073:
0074:            private SQLStatementContext popContext() {
0075:                return stack.pop();
0076:            }
0077:
0078:            void Error(int n) {
0079:                if (errDist >= minErrDist)
0080:                    scanner.err.ParsErr(n, t.line, t.col);
0081:                errDist = 0;
0082:            }
0083:
0084:            void SemError(int n) {
0085:                if (errDist >= minErrDist)
0086:                    scanner.err.SemErr(n, token.line, token.col);
0087:                errDist = 0;
0088:            }
0089:
0090:            boolean Successful() {
0091:                return scanner.err.count == 0;
0092:            }
0093:
0094:            String LexString() {
0095:                return token.str;
0096:            }
0097:
0098:            String LexName() {
0099:                return token.val;
0100:            }
0101:
0102:            String LookAheadString() {
0103:                return t.str;
0104:            }
0105:
0106:            String LookAheadName() {
0107:                return t.val;
0108:            }
0109:
0110:            private void Get() {
0111:                for (;;) {
0112:                    token = t;
0113:                    t = scanner.Scan();
0114:                    if (t.kind <= maxT) {
0115:                        errDist++;
0116:                        return;
0117:                    }
0118:
0119:                    t = token;
0120:                }
0121:            }
0122:
0123:            private void Expect(int n) {
0124:                if (t.kind == n)
0125:                    Get();
0126:                else
0127:                    Error(n);
0128:            }
0129:
0130:            private boolean StartOf(int s) {
0131:                if (0 > s || 0 > t.kind || set.length <= s
0132:                        || set[0].length <= t.kind) {
0133:                    return false;
0134:                }
0135:
0136:                return set[s][t.kind];
0137:            }
0138:
0139:            private void ExpectWeak(int n, int follow) {
0140:                if (t.kind == n)
0141:                    Get();
0142:                else {
0143:                    Error(n);
0144:                    while (!StartOf(follow))
0145:                        Get();
0146:                }
0147:            }
0148:
0149:            boolean WeakSeparator(int n, int syFol, int repFol) {
0150:                boolean[] s = new boolean[maxT + 1];
0151:                if (t.kind == n) {
0152:                    Get();
0153:                    return true;
0154:                } else if (StartOf(repFol))
0155:                    return false;
0156:                else {
0157:                    for (int i = 0; i <= maxT; i++) {
0158:                        s[i] = set[syFol][i] || set[repFol][i] || set[0][i];
0159:                    }
0160:                    Error(n);
0161:                    while (!s[t.kind])
0162:                        Get();
0163:                    return StartOf(syFol);
0164:                }
0165:            }
0166:
0167:            private final void IndexName() {
0168:                Expect(1);
0169:            }
0170:
0171:            private final void IndexColumnList() {
0172:                IndexColumn();
0173:                while (t.kind == ParsingConstants.KIND_COMMA) {
0174:                    ItemSeparator();
0175:                    IndexColumn();
0176:                }
0177:            }
0178:
0179:            private final void IndexColumn() {
0180:                SimpleColumnName();
0181:                if (t.kind == ParsingConstants.KW_DESC
0182:                        || t.kind == ParsingConstants.KW_ASC) {
0183:                    if (t.kind == ParsingConstants.KW_ASC) {
0184:                        Get();
0185:                    } else {
0186:                        Get();
0187:                    }
0188:                }
0189:            }
0190:
0191:            private final void DropPart() {
0192:                Expect(ParsingConstants.KW_DROP);
0193:                if (t.kind == 1) {
0194:                    SimpleColumnName();
0195:                    CascadeRestrict();
0196:                } else if (t.kind == ParsingConstants.KW_PRIMARY) {
0197:                    Get();
0198:                    Expect(ParsingConstants.KW_KEY);
0199:                } else if (t.kind == ParsingConstants.KW_FOREIGN) {
0200:                    Get();
0201:                    Expect(ParsingConstants.KW_KEY);
0202:                    RelationName();
0203:                } else if (t.kind == ParsingConstants.KW_CONSTRAINT) {
0204:                    Get();
0205:                    ConstraintName();
0206:                    CascadeRestrict();
0207:                } else
0208:                    Error(104);
0209:            }
0210:
0211:            private final void AlterPart() {
0212:                Expect(ParsingConstants.KW_ALTER);
0213:                SimpleColumnName();
0214:                if (t.kind == ParsingConstants.KW_DROP) {
0215:                    Get();
0216:                    Expect(ParsingConstants.KW_DEFAULT);
0217:                } else if (t.kind == ParsingConstants.KW_SET) {
0218:                    Get();
0219:                    ColumnDefault();
0220:                } else
0221:                    Error(105);
0222:            }
0223:
0224:            private final void AddPart() {
0225:                Expect(ParsingConstants.KW_ADD);
0226:                if (t.kind == 1) {
0227:                    ColumnDefList();
0228:                } else if (t.kind == ParsingConstants.KW_PRIMARY) {
0229:                    PrimaryKey();
0230:                } else if (t.kind == ParsingConstants.KW_CONSTRAINT) {
0231:                    ForeignKeyAdd();
0232:                } else if (t.kind == ParsingConstants.KW_UNIQUE) {
0233:                    Unique();
0234:                } else if (t.kind == 92) {
0235:                    CheckConstraint();
0236:                } else
0237:                    Error(106);
0238:            }
0239:
0240:            private final void IndexAndName() {
0241:                Expect(ParsingConstants.KW_INDEX);
0242:                IndexName();
0243:            }
0244:
0245:            private final void DropTable() {
0246:                Expect(ParsingConstants.KW_TABLE);
0247:                QualifiedTable();
0248:                if (t.kind == ParsingConstants.KW_CASCADE
0249:                        || t.kind == ParsingConstants.KW_RESTRICT) {
0250:                    CascadeRestrict();
0251:                }
0252:            }
0253:
0254:            private final void CascadeRestrict() {
0255:                if (t.kind == ParsingConstants.KW_CASCADE) {
0256:                    Get();
0257:                } else if (t.kind == ParsingConstants.KW_RESTRICT) {
0258:                    Get();
0259:                } else
0260:                    Error(107);
0261:            }
0262:
0263:            private final void CreateIndex() {
0264:                if (t.kind == ParsingConstants.KW_UNIQUE) {
0265:                    Get();
0266:                }
0267:                IndexAndName();
0268:                Expect(ParsingConstants.KW_ON);
0269:                Table(null);
0270:                Expect(ParsingConstants.KIND_OPENING_BRAKET);
0271:                IndexColumnList();
0272:                CloseParens();
0273:            }
0274:
0275:            private final void CreateTable() {
0276:                Expect(ParsingConstants.KW_TABLE);
0277:                Table(null);
0278:                Expect(ParsingConstants.KIND_OPENING_BRAKET);
0279:                CreatePart();
0280:                while (t.kind == ParsingConstants.KIND_COMMA) {
0281:                    ItemSeparator();
0282:                    CreatePart();
0283:                }
0284:                CloseParens();
0285:            }
0286:
0287:            private final void CreatePart() {
0288:                if (t.kind == 1) {
0289:                    ColumnDef();
0290:                } else if (t.kind == ParsingConstants.KW_PRIMARY) {
0291:                    PrimaryKey();
0292:                } else if (t.kind == ParsingConstants.KW_FOREIGN) {
0293:                    ForeignKeyCreatePart();
0294:                } else if (t.kind == ParsingConstants.KW_CONSTRAINT) {
0295:                    Constraint();
0296:                } else if (t.kind == ParsingConstants.KW_UNIQUE) {
0297:                    Unique();
0298:                } else if (t.kind == 92) {
0299:                    CheckConstraint();
0300:                } else
0301:                    Error(108);
0302:            }
0303:
0304:            private final void CheckConstraint() {
0305:                Expect(92);
0306:                Expect(ParsingConstants.KIND_OPENING_BRAKET);
0307:                Expression();
0308:                CloseParens();
0309:            }
0310:
0311:            private final void Unique() {
0312:                Expect(ParsingConstants.KW_UNIQUE);
0313:                SimpleColumnParam();
0314:            }
0315:
0316:            private final void Constraint() {
0317:            }
0318:
0319:            private final void ForeignKeyAdd() {
0320:                Expect(ParsingConstants.KW_CONSTRAINT);
0321:                RelationName();
0322:
0323:                if (t.kind == ParsingConstants.KW_FOREIGN) {
0324:                    Get();
0325:                    Expect(ParsingConstants.KW_KEY);
0326:                    SimpleColumnParam();
0327:                    Expect(ParsingConstants.KW_REFERENCES);
0328:                    Table(null);
0329:                    if (t.kind == ParsingConstants.KW_MATCH) {
0330:                        Get();
0331:                        if (t.kind == ParsingConstants.KW_FULL) {
0332:                            Get();
0333:                        } else if (t.kind == ParsingConstants.KW_PARTIAL) {
0334:                            Get();
0335:                        } else
0336:                            Error(109);
0337:                    }
0338:                    while (t.kind == ParsingConstants.KW_ON
0339:                            || t.kind == ParsingConstants.KW_NO) {
0340:                        if (t.kind == ParsingConstants.KW_ON) {
0341:                            Get();
0342:                            if (t.kind == ParsingConstants.KW_DELETE) {
0343:                                Get();
0344:                            } else if (t.kind == ParsingConstants.KW_UPDATE) {
0345:                                Get();
0346:                            } else
0347:                                Error(110);
0348:                            if (t.kind == ParsingConstants.KW_CASCADE) {
0349:                                Get();
0350:                            } else if (t.kind == ParsingConstants.KW_SET) {
0351:                                Get();
0352:                                if (t.kind == ParsingConstants.KW_NULL) {
0353:                                    Get();
0354:                                } else if (t.kind == ParsingConstants.KW_DEFAULT) {
0355:                                    Get();
0356:                                } else
0357:                                    Error(111);
0358:                            } else
0359:                                Error(112);
0360:                        } else {
0361:                            Get();
0362:                            Expect(ParsingConstants.KW_ACTION);
0363:                        }
0364:                    }
0365:                } else {
0366:                    Expect(ParsingConstants.KW_UNIQUE);
0367:                    SimpleColumnParam();
0368:                }
0369:
0370:            }
0371:
0372:            private final void ForeignKeyCreatePart() {
0373:                Expect(ParsingConstants.KW_FOREIGN);
0374:                Expect(ParsingConstants.KW_KEY);
0375:                RelationName();
0376:                SimpleColumnParam();
0377:                Expect(ParsingConstants.KW_REFERENCES);
0378:                Table(null);
0379:                if (t.kind == ParsingConstants.KW_MATCH) {
0380:                    Get();
0381:                    if (t.kind == ParsingConstants.KW_FULL) {
0382:                        Get();
0383:                    } else if (t.kind == ParsingConstants.KW_PARTIAL) {
0384:                        Get();
0385:                    } else
0386:                        Error(109);
0387:                }
0388:                while (t.kind == ParsingConstants.KW_ON
0389:                        || t.kind == ParsingConstants.KW_NO) {
0390:                    if (t.kind == ParsingConstants.KW_ON) {
0391:                        Get();
0392:                        if (t.kind == ParsingConstants.KW_DELETE) {
0393:                            Get();
0394:                        } else if (t.kind == ParsingConstants.KW_UPDATE) {
0395:                            Get();
0396:                        } else
0397:                            Error(110);
0398:                        if (t.kind == ParsingConstants.KW_CASCADE) {
0399:                            Get();
0400:                        } else if (t.kind == ParsingConstants.KW_SET) {
0401:                            Get();
0402:                            if (t.kind == ParsingConstants.KW_NULL) {
0403:                                Get();
0404:                            } else if (t.kind == ParsingConstants.KW_DEFAULT) {
0405:                                Get();
0406:                            } else
0407:                                Error(111);
0408:                        } else
0409:                            Error(112);
0410:                    } else {
0411:                        Get();
0412:                        Expect(ParsingConstants.KW_ACTION);
0413:                    }
0414:                }
0415:            }
0416:
0417:            private final void ConstraintName() {
0418:                Expect(1);
0419:            }
0420:
0421:            private final void RelationName() {
0422:                Expect(1);
0423:            }
0424:
0425:            private final void PrimaryKey() {
0426:                Expect(ParsingConstants.KW_PRIMARY);
0427:                Expect(ParsingConstants.KW_KEY);
0428:                SimpleColumnParam();
0429:            }
0430:
0431:            private final void ColumnDef() {
0432:                SimpleColumnName();
0433:                DataType();
0434:                while (t.kind == ParsingConstants.KW_NOT
0435:                        || t.kind == ParsingConstants.KW_DEFAULT
0436:                        || t.kind == ParsingConstants.KW_PRIMARY) {
0437:                    if (t.kind == ParsingConstants.KW_DEFAULT) {
0438:                        ColumnDefault();
0439:                    } else if (t.kind == ParsingConstants.KW_NOT) {
0440:                        NotOperator();
0441:                        Expect(ParsingConstants.KW_NULL);
0442:                    } else {
0443:                        Expect(ParsingConstants.KW_PRIMARY);
0444:                        Expect(ParsingConstants.KW_KEY);
0445:                    }
0446:                }
0447:            }
0448:
0449:            private final void ColumnDefList() {
0450:                ColumnDef();
0451:                while (t.kind == ParsingConstants.KIND_COMMA) {
0452:                    ItemSeparator();
0453:                    ColumnDef();
0454:                }
0455:            }
0456:
0457:            private final void ColumnDefault() {
0458:                Expect(ParsingConstants.KW_DEFAULT);
0459:                if (t.kind == 4) {
0460:                    Get();
0461:                } else if (t.kind == 2) {
0462:                    Get();
0463:                } else if (t.kind == 3) {
0464:                    Get();
0465:                } else
0466:                    Error(113);
0467:            }
0468:
0469:            private final void DataType() {
0470:                switch (t.kind) {
0471:                case 72:
0472:                case 73: {
0473:                    if (t.kind == ParsingConstants.KW_CHAR) {
0474:                        Get();
0475:                    } else {
0476:                        Get();
0477:                    }
0478:                    lenParam();
0479:                    break;
0480:                }
0481:                case ParsingConstants.KW_VARCHAR: {
0482:                    Get();
0483:                    lenParam();
0484:                    break;
0485:                }
0486:                case ParsingConstants.KW_INTEGER:
0487:                case ParsingConstants.KW_INT: {
0488:                    if (t.kind == ParsingConstants.KW_INTEGER) {
0489:                        Get();
0490:                    } else {
0491:                        Get();
0492:                    }
0493:                    break;
0494:                }
0495:                case ParsingConstants.KW_SMALLINT: {
0496:                    Get();
0497:                    break;
0498:                }
0499:                case ParsingConstants.KW_NUMERIC: {
0500:                    Get();
0501:                    Expect(ParsingConstants.KIND_OPENING_BRAKET);
0502:                    precision();
0503:                    CloseParens();
0504:                    break;
0505:                }
0506:                case ParsingConstants.KW_DATE: {
0507:                    Get();
0508:                    break;
0509:                }
0510:                case ParsingConstants.KW_TIME: {
0511:                    Get();
0512:                    lenParam();
0513:                    break;
0514:                }
0515:                case ParsingConstants.KW_TIMESTAMP: {
0516:                    Get();
0517:                    lenParam();
0518:                    break;
0519:                }
0520:                default:
0521:                    Error(114);
0522:                }
0523:            }
0524:
0525:            private final void precision() {
0526:                Expect(2);
0527:                ItemSeparator();
0528:                Expect(2);
0529:            }
0530:
0531:            private final void lenParam() {
0532:                Expect(ParsingConstants.KIND_OPENING_BRAKET);
0533:                len();
0534:                CloseParens();
0535:            }
0536:
0537:            private final void len() {
0538:                Expect(2);
0539:            }
0540:
0541:            private final void BetweenExpr() {
0542:                Expect(ParsingConstants.KW_BETWEEN);
0543:                Field();
0544:                Expect(ParsingConstants.KW_AND);
0545:                Field();
0546:            }
0547:
0548:            private final void InSetExpr() {
0549:                Expect(ParsingConstants.KW_IN);
0550:                Expect(ParsingConstants.KIND_OPENING_BRAKET);
0551:                if (StartOf(1)) {
0552:                    FieldList();
0553:                } else if (t.kind == ParsingConstants.KW_SELECT) {
0554:                    SelectStmt();
0555:                } else
0556:                    Error(115);
0557:                CloseParens();
0558:            }
0559:
0560:            private final void NullTest() {
0561:                Expect(ParsingConstants.KW_IS);
0562:                if (t.kind == ParsingConstants.KW_NOT) {
0563:                    NotOperator();
0564:                }
0565:                Expect(ParsingConstants.KW_NULL);
0566:            }
0567:
0568:            private final void LikeTest() {
0569:                Expect(ParsingConstants.KW_LIKE);
0570:                if (t.kind == 4) {
0571:                    Get();
0572:                } else if (t.kind == 53) {
0573:                    Param();
0574:                } else
0575:                    Error(116);
0576:                if (t.kind == ParsingConstants.KW_ESCAPE) {
0577:                    Get();
0578:                    Expect(4);
0579:                }
0580:            }
0581:
0582:            private final void WordOperator() {
0583:                if (t.kind == ParsingConstants.KW_AND) {
0584:                    Get();
0585:                } else if (t.kind == ParsingConstants.KW_OR) {
0586:                    Get();
0587:                } else
0588:                    Error(117);
0589:            }
0590:
0591:            private final void MathOperator() {
0592:                if (t.kind == ParsingConstants.KIND_ASTERISK) {
0593:                    Get();
0594:                } else if (t.kind == 55) {
0595:                    Get();
0596:                } else if (t.kind == 56) {
0597:                    Get();
0598:                } else if (t.kind == 52) {
0599:                    Get();
0600:                } else
0601:                    Error(118);
0602:            }
0603:
0604:            private final void TestExpr() {
0605:                if (t.kind == ParsingConstants.KW_IS) {
0606:                    NullTest();
0607:                } else if (StartOf(2)) {
0608:                    if (t.kind == ParsingConstants.KW_NOT) {
0609:                        NotOperator();
0610:                    }
0611:                    if (t.kind == ParsingConstants.KW_IN) {
0612:                        InSetExpr();
0613:                    } else if (t.kind == ParsingConstants.KW_BETWEEN) {
0614:                        BetweenExpr();
0615:                    } else if (t.kind == ParsingConstants.KW_LIKE) {
0616:                        LikeTest();
0617:                    } else
0618:                        Error(119);
0619:                } else
0620:                    Error(120);
0621:            }
0622:
0623:            private final void Operator() {
0624:                if (StartOf(3)) {
0625:                    MathOperator();
0626:                } else if (t.kind == ParsingConstants.KW_AND
0627:                        || t.kind == ParsingConstants.KW_OR) {
0628:                    WordOperator();
0629:                } else
0630:                    Error(121);
0631:            }
0632:
0633:            private final void Term() {
0634:                if (t.kind == 52) {
0635:                    Get();
0636:                }
0637:                if (StartOf(1)) {
0638:                    Field();
0639:                    if (StartOf(4)) {
0640:                        TestExpr();
0641:                    }
0642:                } else if (StartOf(ParsingConstants.KIND_OPENING_BRAKET)) {
0643:                    ColumnFunction();
0644:                } else if (StartOf(6)) {
0645:                    FunctionExpr();
0646:                } else if (t.kind == ParsingConstants.KIND_OPENING_BRAKET) {
0647:                    Get();
0648:                    if (StartOf(ParsingConstants.KW_UNION)) {
0649:                        Expression();
0650:                    } else if (t.kind == ParsingConstants.KW_SELECT) {
0651:                        SelectStmt();
0652:                    } else if (t.kind == ParsingConstants.KW_CASE) {
0653:                        CaseStatment();
0654:                    } else
0655:                        Error(122);
0656:                    CloseParens();
0657:                } else
0658:                    Error(123);
0659:            }
0660:
0661:            private final void NotOperator() {
0662:                Expect(ParsingConstants.KW_NOT);
0663:            }
0664:
0665:            private final void Relation() {
0666:                switch (t.kind) {
0667:                case ParsingConstants.KIND_EQUALS: {
0668:                    Get();
0669:                    break;
0670:                }
0671:                case 62: {
0672:                    Get();
0673:                    break;
0674:                }
0675:                case 63: {
0676:                    Get();
0677:                    break;
0678:                }
0679:                case 64: {
0680:                    Get();
0681:                    break;
0682:                }
0683:                case 65: {
0684:                    Get();
0685:                    break;
0686:                }
0687:                case 66: {
0688:                    Get();
0689:                    break;
0690:                }
0691:                default:
0692:                    Error(124);
0693:                }
0694:            }
0695:
0696:            private final void SimpleExpression() {
0697:                if (t.kind == ParsingConstants.KW_NOT) {
0698:                    NotOperator();
0699:                }
0700:                Term();
0701:                while (StartOf(ParsingConstants.KW_EXCEPT)) {
0702:                    Operator();
0703:                    if (t.kind == ParsingConstants.KW_NOT) {
0704:                        NotOperator();
0705:                    }
0706:                    Term();
0707:                }
0708:            }
0709:
0710:            private final void OrderByField() {
0711:                if (t.kind == 1) {
0712:                    ColumnName();
0713:                } else if (t.kind == 2) {
0714:                    Get();
0715:                } else
0716:                    Error(125);
0717:                if (t.kind == ParsingConstants.KW_DESC
0718:                        || t.kind == ParsingConstants.KW_ASC) {
0719:                    if (t.kind == ParsingConstants.KW_DESC) {
0720:                        Get();
0721:                    } else {
0722:                        Get();
0723:                    }
0724:                }
0725:            }
0726:
0727:            private final void Param() {
0728:                Expect(53);
0729:                Expect(1);
0730:            }
0731:
0732:            private final void Field() {
0733:                switch (t.kind) {
0734:                case 1: {
0735:                    ColumnName();
0736:                    break;
0737:                }
0738:                case ParsingConstants.KW_NULL: {
0739:                    Get();
0740:                    break;
0741:                }
0742:                case 3: {
0743:                    Get();
0744:                    break;
0745:                }
0746:                case 2: {
0747:                    Get();
0748:                    break;
0749:                }
0750:                case 4: {
0751:                    Get();
0752:                    break;
0753:                }
0754:                case 53: {
0755:                    Param();
0756:                    break;
0757:                }
0758:                default:
0759:                    Error(126);
0760:                }
0761:            }
0762:
0763:            private final void SimpleColumnParam() {
0764:                Expect(ParsingConstants.KIND_OPENING_BRAKET);
0765:                SimpleColumnList();
0766:                CloseParens();
0767:            }
0768:
0769:            private final void SimpleColumnList() {
0770:                SimpleColumnName();
0771:                while (t.kind == ParsingConstants.KIND_COMMA) {
0772:                    ItemSeparator();
0773:                    SimpleColumnName();
0774:                }
0775:            }
0776:
0777:            private final void SimpleColumnName() {
0778:                Expect(1);
0779:            }
0780:
0781:            private final void ColumnFunction() {
0782:                if (t.kind == ParsingConstants.KW_COUNT) {
0783:                    Get();
0784:                } else if (t.kind == ParsingConstants.KW_SUM) {
0785:                    Get();
0786:                } else if (t.kind == ParsingConstants.KW_MAX) {
0787:                    Get();
0788:                } else if (t.kind == ParsingConstants.KW_MIN) {
0789:                    Get();
0790:                } else if (t.kind == ParsingConstants.KW_AVG) {
0791:                    Get();
0792:                } else
0793:                    Error(127);
0794:                Expect(ParsingConstants.KIND_OPENING_BRAKET);
0795:                if (t.kind == ParsingConstants.KIND_ASTERISK) {
0796:                    Get();
0797:                } else if (StartOf(ParsingConstants.KW_INTERSECT)) {
0798:                    if (t.kind == ParsingConstants.KW_DISTINCT) {
0799:                        Get();
0800:                    }
0801:                    Expression();
0802:                } else
0803:                    Error(128);
0804:                CloseParens();
0805:            }
0806:
0807:            private final void FunctionExpr() {
0808:                if (t.kind == ParsingConstants.KW_TIMESTAMP) {
0809:                    Get();
0810:                } else if (t.kind == ParsingConstants.KW_UPPER) {
0811:                    Get();
0812:                } else if (t.kind == ParsingConstants.KW_MONTH) {
0813:                    Get();
0814:                } else if (t.kind == ParsingConstants.KW_YEAR) {
0815:                    Get();
0816:                } else
0817:                    Error(129);
0818:                Expect(ParsingConstants.KIND_OPENING_BRAKET);
0819:                Expression();
0820:                while (t.kind == ParsingConstants.KIND_COMMA) {
0821:                    ItemSeparator();
0822:                    Expression();
0823:                }
0824:                CloseParens();
0825:            }
0826:
0827:            private final void SelectField() {
0828:                if (StartOf(ParsingConstants.KW_UNION)) {
0829:                    Expression();
0830:                    if (t.kind == ParsingConstants.KW_AS) {
0831:                        Get();
0832:                        Alias();
0833:                    }
0834:                } else if (t.kind == ParsingConstants.KIND_ASTERISK) {
0835:                    Get();
0836:                } else if (t.kind == ParsingConstants.KW_CASE) {
0837:                    CaseStatment();
0838:                } else
0839:                    Error(130);
0840:            }
0841:
0842:            private void CaseStatment() {
0843:                Expect(ParsingConstants.KW_CASE);
0844:                if (t.kind == ParsingConstants.KW_WHEN) {
0845:                    Expect(ParsingConstants.KW_WHEN);
0846:                    Expression();
0847:                    Expect(ParsingConstants.KW_THEN);
0848:                    Expression();
0849:
0850:                    while (t.kind == ParsingConstants.KW_WHEN) {
0851:                        Get();
0852:                        Expression();
0853:                        Expect(ParsingConstants.KW_THEN);
0854:                        Expression();
0855:                    }
0856:
0857:                    Expect(ParsingConstants.KW_ELSE);
0858:                    Expression();
0859:                    Expect(ParsingConstants.KW_END);
0860:
0861:                    if (t.kind == ParsingConstants.KW_AS) {
0862:                        Get();
0863:                        Alias();
0864:                    }
0865:
0866:                } else {
0867:                    ColumnName();
0868:                    Expect(ParsingConstants.KW_WHEN);
0869:                    Expression();
0870:                    Expect(ParsingConstants.KW_THEN);
0871:                    Expression();
0872:
0873:                    while (t.kind == ParsingConstants.KW_WHEN) {
0874:                        Get();
0875:                        Expression();
0876:                        Expect(ParsingConstants.KW_THEN);
0877:                        Expression();
0878:                    }
0879:
0880:                    Expect(ParsingConstants.KW_ELSE);
0881:                    Expression();
0882:                    Expect(ParsingConstants.KW_END);
0883:
0884:                    if (t.kind == ParsingConstants.KW_AS) {
0885:                        Get();
0886:                        Alias();
0887:                    }
0888:                }
0889:            }
0890:
0891:            private final void OrderByFldList() {
0892:                OrderByField();
0893:                while (t.kind == ParsingConstants.KIND_COMMA) {
0894:                    ItemSeparator();
0895:                    OrderByField();
0896:                }
0897:            }
0898:
0899:            private final void SearchCondition() {
0900:                Expression();
0901:            }
0902:
0903:            private final void JoinExpr() {
0904:                if (t.kind == ParsingConstants.KW_ON) {
0905:                    Get();
0906:                    Expression();
0907:                } else if (t.kind == ParsingConstants.KW_USING) {
0908:                    Get();
0909:                    Expect(ParsingConstants.KIND_OPENING_BRAKET);
0910:                    ColumnList();
0911:                    CloseParens();
0912:                } else
0913:                    Error(131);
0914:            }
0915:
0916:            private final void JoinType() {
0917:                if (t.kind == ParsingConstants.KW_NATURAL) {
0918:                    Get();
0919:                }
0920:                if (t.kind == ParsingConstants.KW_INNER) {
0921:                    Get();
0922:                } else if (t.kind == ParsingConstants.KW_FULL
0923:                        || t.kind == ParsingConstants.KW_LEFT
0924:                        || t.kind == ParsingConstants.KW_RIGHT) {
0925:                    if (t.kind == ParsingConstants.KW_FULL) {
0926:                        Get();
0927:                    } else if (t.kind == ParsingConstants.KW_LEFT) {
0928:                        Get();
0929:                    } else {
0930:                        Get();
0931:                    }
0932:                    if (t.kind == ParsingConstants.KW_OUTER) {
0933:                        Get();
0934:                    }
0935:                } else
0936:                    Error(132);
0937:            }
0938:
0939:            private final void CrossJoin() {
0940:                Expect(ParsingConstants.KW_CROSS);
0941:                Expect(ParsingConstants.KW_JOIN);
0942:                QualifiedTable();
0943:            }
0944:
0945:            private final void Alias() {
0946:                Expect(1);
0947:            }
0948:
0949:            private final void JoinStmt() {
0950:                if (t.kind == ParsingConstants.KW_CROSS) {
0951:                    CrossJoin();
0952:                } else if (StartOf(ParsingConstants.KW_MINUS)) {
0953:                    if (StartOf(ParsingConstants.KW_ALL)) {
0954:                        JoinType();
0955:                    }
0956:                    Expect(ParsingConstants.KW_JOIN);
0957:                    QualifiedTable();
0958:                    if (t.kind == ParsingConstants.KW_ON
0959:                            || t.kind == ParsingConstants.KW_USING) {
0960:                        JoinExpr();
0961:                    }
0962:                } else
0963:                    Error(133);
0964:            }
0965:
0966:            private final void QualifiedTable() {
0967:                // Fix for Bug #982127
0968:                //SQLSelectStatement statement = (SQLSelectStatement) getContext();
0969:                SQLStatement statement = (SQLStatement) getContext();
0970:
0971:                SQLTable table = new SQLTable(statement, t.pos);
0972:                statement.addTable(table);
0973:                boolean wasSet = false;
0974:
0975:                Expect(1);
0976:                if (t.val.equals("."))
0977:                    table.setSchema(token.str, token.pos);
0978:                else
0979:                    table.setName(token.str, token.pos);
0980:
0981:                if (t.kind == 22) {
0982:                    Get();
0983:                    Expect(1);
0984:                    table.setName(token.str, token.pos);
0985:                }
0986:                if (t.kind == 1 || t.kind == ParsingConstants.KW_AS) {
0987:                    if (t.kind == ParsingConstants.KW_AS) {
0988:                        Get();
0989:                    }
0990:                    table.setAlias(t.str, t.pos);
0991:                    wasSet = true;
0992:                    if (statement.setTable(table) == false)
0993:                        SemError(ParsingConstants.KW_MINUS);
0994:
0995:                    Alias();
0996:                }
0997:                if (!wasSet && statement.setTable(table) == false)
0998:                    SemError(ParsingConstants.KW_MINUS);
0999:
1000:            }
1001:
1002:            private final void FromTableList() {
1003:                QualifiedTable();
1004:                while (StartOf(ParsingConstants.KW_UPDATE)) {
1005:                    if (t.kind == ParsingConstants.KIND_COMMA) {
1006:                        ItemSeparator();
1007:                        QualifiedTable();
1008:                    } else {
1009:                        JoinStmt();
1010:                    }
1011:                }
1012:            }
1013:
1014:            private final void SelectFieldList() {
1015:                SelectField();
1016:                while (t.kind == ParsingConstants.KIND_COMMA) {
1017:                    ItemSeparator();
1018:                    SelectField();
1019:                }
1020:            }
1021:
1022:            private final void OrderByClause() {
1023:                SQLSelectStatement statement = (SQLSelectStatement) getContext();
1024:                statement.setOrderByStart(scanner.pos);
1025:
1026:                while (!(t.kind == 0 || t.kind == ParsingConstants.KW_ORDER)) {
1027:                    Error(134);
1028:                    Get();
1029:                }
1030:                Expect(ParsingConstants.KW_ORDER);
1031:                Expect(ParsingConstants.KW_BY);
1032:                OrderByFldList();
1033:                statement.setOrderByEnd(t.pos);
1034:            }
1035:
1036:            private final void HavingClause() {
1037:                SQLSelectStatement statement = (SQLSelectStatement) getContext();
1038:                statement.setHavingStart(scanner.pos);
1039:
1040:                while (!(t.kind == 0 || t.kind == ParsingConstants.KW_HAVING)) {
1041:                    Error(135);
1042:                    Get();
1043:                }
1044:                Expect(ParsingConstants.KW_HAVING);
1045:                SearchCondition();
1046:                statement.setHavingEnd(t.pos);
1047:            }
1048:
1049:            private final void GroupByClause() {
1050:                SQLSelectStatement statement = (SQLSelectStatement) getContext();
1051:                statement.setGroupByStart(scanner.pos);
1052:
1053:                while (!(t.kind == 0 || t.kind == ParsingConstants.KW_GROUP)) {
1054:                    Error(136);
1055:                    Get();
1056:                }
1057:                Expect(ParsingConstants.KW_GROUP);
1058:                Expect(ParsingConstants.KW_BY);
1059:                FieldList();
1060:                statement.setGroupByEnd(t.pos);
1061:            }
1062:
1063:            private final void FromClause() {
1064:                SQLSelectStatement statement = (SQLSelectStatement) getContext();
1065:                statement.setFromStart(scanner.pos);
1066:
1067:                while (!(t.kind == 0 || t.kind == ParsingConstants.KW_FROM)) {
1068:                    Error(137);
1069:                    Get();
1070:                }
1071:                Expect(ParsingConstants.KW_FROM);
1072:                FromTableList();
1073:                statement.setFromEnd(t.pos);
1074:            }
1075:
1076:            private final void SelectClause() {
1077:                SQLSelectStatement statement = (SQLSelectStatement) getContext();
1078:                statement.setSelectListStart(scanner.pos);
1079:
1080:                while (!(t.kind == 0 || t.kind == ParsingConstants.KW_SELECT)) {
1081:                    Error(138);
1082:                    Get();
1083:                }
1084:                Expect(ParsingConstants.KW_SELECT);
1085:                if (t.kind == ParsingConstants.KW_ALL
1086:                        || t.kind == ParsingConstants.KW_DISTINCT) {
1087:                    if (t.kind == ParsingConstants.KW_DISTINCT) {
1088:                        Get();
1089:                    } else {
1090:                        Get();
1091:                    }
1092:                }
1093:                SelectFieldList();
1094:                statement.setSelectListEnd(t.pos);
1095:            }
1096:
1097:            private final void FieldList() {
1098:                Field();
1099:                while (t.kind == ParsingConstants.KIND_COMMA) {
1100:                    ItemSeparator();
1101:                    Field();
1102:                }
1103:            }
1104:
1105:            private final void CloseParens() {
1106:                ExpectWeak(ParsingConstants.KIND_CLOSING_BRAKET,
1107:                        ParsingConstants.KW_SET);
1108:            }
1109:
1110:            private final void ColumnList() {
1111:                ColumnName();
1112:                while (t.kind == ParsingConstants.KIND_COMMA) {
1113:                    ItemSeparator();
1114:                    ColumnName();
1115:                }
1116:            }
1117:
1118:            private final void Expression() {
1119:                SimpleExpression();
1120:                while (StartOf(ParsingConstants.KIND_EQUALS)) {
1121:                    Relation();
1122:                    SimpleExpression();
1123:                }
1124:            }
1125:
1126:            private final void ColumnName() {
1127:                SQLStatementContext context = getContext();
1128:                SQLColumn column = new SQLColumn(context, t.pos);
1129:                context.addColumn(column);
1130:                if (scanner.ch == '.')
1131:                    column.setQualifier(t.str, t.pos);
1132:                else
1133:                    column.setColumn(t.str, t.pos);
1134:
1135:                Expect(1);
1136:                if (t.kind == 22) {
1137:                    Get();
1138:                    if (t.kind == 1) {
1139:                        Get();
1140:                        column.setColumn(token.str, token.pos);
1141:                    } else if (t.kind == ParsingConstants.KIND_ASTERISK) {
1142:                        Get();
1143:                    } else
1144:                        Error(139);
1145:                }
1146:            }
1147:
1148:            private final void ItemSeparator() {
1149:                ExpectWeak(ParsingConstants.KIND_COMMA,
1150:                        ParsingConstants.KW_INSERT);
1151:            }
1152:
1153:            private final void UpdateField() {
1154:                ColumnName();
1155:                Expect(ParsingConstants.KIND_EQUALS);
1156:                Expression();
1157:            }
1158:
1159:            private final void WhereClause() {
1160:                SQLStatement statement = (SQLStatement) getContext();
1161:                SQLWhere where = new SQLWhere(statement, t.pos);
1162:                pushContext(where);
1163:
1164:                while (!(t.kind == 0 || t.kind == ParsingConstants.KW_WHERE)) {
1165:                    Error(140);
1166:                    Get();
1167:                }
1168:                Expect(ParsingConstants.KW_WHERE);
1169:                SearchCondition();
1170:                where.setEndPosition(t.pos);
1171:                popContext();
1172:
1173:            }
1174:
1175:            private final void UpdateFieldList() {
1176:                UpdateField();
1177:                while (t.kind == ParsingConstants.KIND_COMMA) {
1178:                    ItemSeparator();
1179:                    UpdateField();
1180:                }
1181:            }
1182:
1183:            private final void Table(SQLTable table) {
1184:                if (table != null)
1185:                    table.setName(t.str, t.pos);
1186:
1187:                Expect(1);
1188:            }
1189:
1190:            private final void SetOperator() {
1191:                if (t.kind == ParsingConstants.KW_UNION) {
1192:                    Get();
1193:                } else if (t.kind == ParsingConstants.KW_EXCEPT) {
1194:                    Get();
1195:                } else if (t.kind == ParsingConstants.KW_INTERSECT) {
1196:                    Get();
1197:                } else if (t.kind == ParsingConstants.KW_MINUS) {
1198:                    Get();
1199:                } else
1200:                    Error(141);
1201:                if (t.kind == ParsingConstants.KW_ALL) {
1202:                    Get();
1203:                }
1204:            }
1205:
1206:            private final void SimpleSelect() {
1207:                SQLSelectStatement statement = new SQLSelectStatement(t.pos);
1208:
1209:                SQLSelectStatementListener[] clone = sqlSelectStatlisteners
1210:                        .toArray(new SQLSelectStatementListener[sqlSelectStatlisteners
1211:                                .size()]);
1212:
1213:                for (int i = 0; i < clone.length; i++) {
1214:                    statement.addListener(clone[i]);
1215:                }
1216:
1217:                pushContext(statement);
1218:
1219:                SelectClause();
1220:                FromClause();
1221:                if (t.kind == ParsingConstants.KW_WHERE) {
1222:                    WhereClause();
1223:                }
1224:                if (t.kind == ParsingConstants.KW_GROUP) {
1225:                    GroupByClause();
1226:                }
1227:                if (t.kind == ParsingConstants.KW_HAVING) {
1228:                    HavingClause();
1229:                }
1230:                if (t.kind == ParsingConstants.KW_ORDER) {
1231:                    OrderByClause();
1232:                }
1233:                popContext();
1234:            }
1235:
1236:            private final void Transaction() {
1237:                if (t.kind == ParsingConstants.KW_COMMIT) {
1238:                    Get();
1239:                } else if (t.kind == ParsingConstants.KW_ROLLBACK) {
1240:                    Get();
1241:                } else
1242:                    Error(142);
1243:                if (t.kind == ParsingConstants.KW_WORK) {
1244:                    Get();
1245:                }
1246:            }
1247:
1248:            private final void AlterTable() {
1249:                Expect(ParsingConstants.KW_ALTER);
1250:                Expect(ParsingConstants.KW_TABLE);
1251:                QualifiedTable();
1252:                if (t.kind == ParsingConstants.KW_ADD) {
1253:                    AddPart();
1254:                } else if (t.kind == ParsingConstants.KW_ALTER) {
1255:                    AlterPart();
1256:                } else if (t.kind == ParsingConstants.KW_DROP) {
1257:                    DropPart();
1258:                } else
1259:                    Error(143);
1260:            }
1261:
1262:            private final void Drop() {
1263:                Expect(ParsingConstants.KW_DROP);
1264:                if (t.kind == ParsingConstants.KW_TABLE) {
1265:                    DropTable();
1266:                } else if (t.kind == ParsingConstants.KW_INDEX) {
1267:                    IndexAndName();
1268:                } else
1269:                    Error(144);
1270:            }
1271:
1272:            private final void CreateStmt() {
1273:                Expect(ParsingConstants.KW_CREATE);
1274:                if (t.kind == ParsingConstants.KW_TABLE) {
1275:                    CreateTable();
1276:                } else if (t.kind == ParsingConstants.KW_UNIQUE
1277:                        || t.kind == ParsingConstants.KW_INDEX) {
1278:                    CreateIndex();
1279:                } else if (t.kind == ParsingConstants.KW_VIEW) {
1280:                    CreateView();
1281:                } else
1282:                    Error(145);
1283:            }
1284:
1285:            private void CreateView() {
1286:                Expect(ParsingConstants.KW_VIEW);
1287:                Table(null);
1288:                Expect(ParsingConstants.KW_AS);
1289:                SelectStmt();
1290:            }
1291:
1292:            private final void DeleteStmt() {
1293:                SQLModifyingStatement statement = new SQLModifyingStatement(
1294:                        t.pos);
1295:                pushContext(statement);
1296:
1297:                Expect(ParsingConstants.KW_DELETE);
1298:                SQLTable table = new SQLTable(statement, scanner.pos + 1);
1299:                statement.addTable(table);
1300:
1301:                Expect(ParsingConstants.KW_FROM);
1302:                table.setName(t.str, t.pos);
1303:                Table(table);
1304:                if (t.kind == ParsingConstants.KW_WHERE) {
1305:                    WhereClause();
1306:                }
1307:                statement.setEndPosition(token.pos);
1308:                popContext();
1309:
1310:            }
1311:
1312:            private final void UpdateStmt() {
1313:                SQLModifyingStatement statement = new SQLModifyingStatement(
1314:                        t.pos);
1315:                SQLTable table = new SQLTable(statement, scanner.pos + 1);
1316:                statement.addTable(table);
1317:                pushContext(statement);
1318:
1319:                Expect(ParsingConstants.KW_UPDATE);
1320:                table.setName(t.str, t.pos);
1321:                Table(null);
1322:                statement.setUpdateListStart(t.pos + 4);
1323:                Expect(ParsingConstants.KW_SET);
1324:                UpdateFieldList();
1325:                statement.setUpdateListEnd(token.pos);
1326:                if (t.kind == ParsingConstants.KW_WHERE) {
1327:                    WhereClause();
1328:                }
1329:                statement.setEndPosition(token.pos);
1330:                popContext();
1331:
1332:            }
1333:
1334:            private final void InsertStmt() {
1335:                SQLModifyingStatement statement = new SQLModifyingStatement(
1336:                        t.pos);
1337:                pushContext(statement);
1338:
1339:                Expect(ParsingConstants.KW_INSERT);
1340:                SQLTable table = new SQLTable(statement, scanner.pos + 1);
1341:                statement.addTable(table);
1342:
1343:                Expect(ParsingConstants.KW_INTO);
1344:                SQLColumn column = new SQLColumn(statement, scanner.pos + 2);
1345:                table.setName(t.str, t.pos);
1346:                column.setRepeatable(true);
1347:                statement.addColumn(column);
1348:
1349:                Table(table);
1350:                if (t.kind == ParsingConstants.KIND_OPENING_BRAKET) {
1351:                    Get();
1352:                    ColumnList();
1353:                    CloseParens();
1354:                }
1355:                column.setEndPosition(token.pos);
1356:                if (t.kind == ParsingConstants.KW_VALUES) {
1357:                    Get();
1358:                    Expect(ParsingConstants.KIND_OPENING_BRAKET);
1359:                    FieldList();
1360:                    CloseParens();
1361:                } else if (t.kind == ParsingConstants.KW_SELECT) {
1362:                    SelectStmt();
1363:                } else
1364:                    Error(146);
1365:                statement.setEndPosition(token.pos);
1366:                popContext();
1367:
1368:            }
1369:
1370:            private final void SelectStmt() {
1371:                pushContext(new SQLStatement(token.pos));
1372:                SimpleSelect();
1373:                while (StartOf(ParsingConstants.KW_INTO)) {
1374:                    SetOperator();
1375:                    SimpleSelect();
1376:                }
1377:                popContext();
1378:            }
1379:
1380:            private final void SQLStatement() {
1381:                addRootStatement(new SQLStatement(token.pos));
1382:                switch (t.kind) {
1383:                case ParsingConstants.KW_SELECT: {
1384:                    SelectStmt();
1385:                    break;
1386:                }
1387:                case ParsingConstants.KW_INSERT: {
1388:                    InsertStmt();
1389:                    break;
1390:                }
1391:                case ParsingConstants.KW_UPDATE: {
1392:                    UpdateStmt();
1393:                    break;
1394:                }
1395:                case ParsingConstants.KW_DELETE: {
1396:                    DeleteStmt();
1397:                    break;
1398:                }
1399:                case ParsingConstants.KW_CREATE: {
1400:                    CreateStmt();
1401:                    break;
1402:                }
1403:                case ParsingConstants.KW_DROP: {
1404:                    Drop();
1405:                    break;
1406:                }
1407:                case ParsingConstants.KW_ALTER: {
1408:                    AlterTable();
1409:                    break;
1410:                }
1411:                case ParsingConstants.KW_COMMIT:
1412:                case ParsingConstants.KW_ROLLBACK: {
1413:                    Transaction();
1414:                    break;
1415:                }
1416:                default:
1417:                    Error(147);
1418:                }
1419:                if (t.kind == 6) {
1420:                    Get();
1421:                }
1422:            }
1423:
1424:            private final void squirrelSQL() {
1425:                SQLStatement();
1426:                while (StartOf(ParsingConstants.KW_VALUES)) {
1427:                    SQLStatement();
1428:                }
1429:                Expect(0);
1430:            }
1431:
1432:            public Parser(Scanner _scanner) {
1433:                scanner = _scanner;
1434:                t = new Token();
1435:            }
1436:
1437:            public void parse() {
1438:                Get();
1439:                squirrelSQL();
1440:
1441:            }
1442:
1443:            private static boolean[][] set = {
1444:                    { T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1445:                            T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, T, T,
1446:                            x, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1447:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1448:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1449:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1450:                            x },
1451:                    { x, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1452:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1453:                            x, x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, x,
1454:                            T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1455:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1456:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1457:                            x },
1458:                    { x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1459:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1460:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1461:                            x, T, x, x, x, x, T, x, x, x, x, x, x, x, T, T, x,
1462:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1463:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1464:                            x },
1465:                    { x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1466:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1467:                            x, x, x, T, x, x, x, x, x, x, x, x, x, x, x, x, T,
1468:                            x, x, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x,
1469:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1470:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1471:                            x },
1472:                    { x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1473:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1474:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1475:                            x, T, x, x, x, x, T, x, T, x, x, x, x, x, T, T, x,
1476:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1477:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1478:                            x },
1479:                    { x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1480:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1481:                            x, x, x, x, x, x, x, x, T, T, T, T, T, x, x, x, x,
1482:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1483:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1484:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1485:                            x },
1486:                    { x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1487:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1488:                            x, x, x, x, T, T, T, T, x, x, x, x, x, x, x, x, x,
1489:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1490:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1491:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1492:                            x },
1493:                    { x, T, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x,
1494:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1495:                            x, x, x, x, T, T, T, T, T, T, T, T, T, T, x, x, T,
1496:                            T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1497:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1498:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1499:                            x },
1500:                    { x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1501:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1502:                            x, x, x, T, x, x, x, x, x, x, x, x, x, x, x, x, T,
1503:                            x, x, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x,
1504:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1505:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1506:                            x },
1507:                    { x, T, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x,
1508:                            x, x, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1509:                            x, x, x, x, T, T, T, T, T, T, T, T, T, T, x, x, T,
1510:                            T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1511:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1512:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1513:                            x },
1514:                    { x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1515:                            x, x, x, x, x, T, x, T, T, T, T, T, x, x, x, x, x,
1516:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1517:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1518:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1519:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1520:                            x },
1521:                    { x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1522:                            x, x, x, x, x, x, x, T, T, T, T, T, x, x, x, x, x,
1523:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1524:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1525:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1526:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1527:                            x },
1528:                    { x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1529:                            x, x, x, x, x, T, T, T, T, T, T, T, x, x, x, x, x,
1530:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1531:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1532:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1533:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, x, x,
1534:                            x },
1535:                    { T, x, x, x, x, x, T, T, T, T, T, x, T, x, T, T, x, T, T,
1536:                            T, T, x, x, T, T, T, T, T, T, T, T, x, x, x, T, T,
1537:                            x, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, T,
1538:                            x, T, T, T, T, T, x, x, x, T, T, T, T, T, x, x, T,
1539:                            T, x, x, x, x, x, x, x, x, x, x, T, x, x, x, T, x,
1540:                            x, x, x, x, x, x, T, x, x, T, x, T, x, x, T, T, x,
1541:                            x },
1542:                    { x, x, x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, x, x,
1543:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1544:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1545:                            x, x, x, x, x, x, x, x, x, T, T, T, T, T, x, x, x,
1546:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1547:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1548:                            x },
1549:                    { T, T, T, T, T, T, x, x, x, x, x, x, x, x, x, x, x, x, x,
1550:                            T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, T, T,
1551:                            x, T, T, T, T, T, T, T, T, T, T, T, T, T, x, x, T,
1552:                            T, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1553:                            x, x, x, x, x, x, x, x, x, x, x, x, T, x, T, x, x,
1554:                            x, x, x, x, T, T, x, x, x, x, x, x, x, x, x, x, x,
1555:                            x },
1556:                    { x, x, x, x, x, x, x, T, T, T, T, x, x, x, x, x, x, x, x,
1557:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1558:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1559:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1560:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1561:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1562:                            x },
1563:                    { x, x, x, x, x, x, x, x, x, x, x, x, T, x, x, T, x, x, T,
1564:                            x, T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1565:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1566:                            x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, T,
1567:                            T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x,
1568:                            x, x, x, x, x, x, T, x, x, T, x, T, x, x, x, x, x,
1569:                            x }
1570:
1571:            };
1572:        }
w_w_w___._ja__v__a2__s_._c_o___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.