1 | COMPILER GPDefSyntaxAnalyzer
|
---|
2 |
|
---|
3 | CHARACTER SETS
|
---|
4 | letter = 'A'..'Z' + 'a'..'z'.
|
---|
5 | digit = '0'..'9'.
|
---|
6 | whiteSpace = CHR(9) + EOL IGNORE. /* ' ' ignored by default */
|
---|
7 |
|
---|
8 | COMMENTS
|
---|
9 | FROM '/*' TO '*/' NESTED.
|
---|
10 |
|
---|
11 | KEYWORDS
|
---|
12 | 'PROBLEM'. 'END'. 'EPS'.
|
---|
13 | 'LOCAL'. 'NONTERMINALS'. 'RULES'.
|
---|
14 | 'SEM'. 'MAXIMIZE'. 'MINIMIZE'. 'TERMINALS'. 'CONSTRAINTS'. 'INIT'. 'CODE'.
|
---|
15 | 'IN'. 'SET'. 'RANGE'.
|
---|
16 |
|
---|
17 | TOKENS
|
---|
18 | '='. '|'. '.'. '('. ')'. '['. ']'. '{'. '}'. '>>'. '..'.
|
---|
19 |
|
---|
20 | TOKEN CLASSES
|
---|
21 | ident = letter {letter | digit}.
|
---|
22 |
|
---|
23 | PRAGMAS
|
---|
24 | source = '<<' SEM <<for (; ; ) {
|
---|
25 | switch (GPDefSyntaxAnalyzerLex.curCh) {
|
---|
26 | case Utils.EF:
|
---|
27 | Errors.SemError(GPDefSyntaxAnalyzerLex.curLine, GPDefSyntaxAnalyzerLex.curCol, "end of file in source text");
|
---|
28 | return;
|
---|
29 | case '<':
|
---|
30 | GPDefSyntaxAnalyzerLex.NextCh();
|
---|
31 | if (GPDefSyntaxAnalyzerLex.curCh == '<') {
|
---|
32 | Errors.Warning(GPDefSyntaxAnalyzerLex.curLine, GPDefSyntaxAnalyzerLex.curCol, "non closed source text before?");
|
---|
33 | GPDefSyntaxAnalyzerLex.NextCh();
|
---|
34 | }
|
---|
35 | break;
|
---|
36 | case '>':
|
---|
37 | GPDefSyntaxAnalyzerLex.NextCh();
|
---|
38 | if (GPDefSyntaxAnalyzerLex.curCh == '>') {
|
---|
39 | GPDefSyntaxAnalyzerLex.curCh = ' '; // force GPDefSyntaxAnalyzerLex to get next character
|
---|
40 | return;
|
---|
41 | }
|
---|
42 | break;
|
---|
43 | default:
|
---|
44 | GPDefSyntaxAnalyzerLex.NextCh();
|
---|
45 | break;
|
---|
46 | }
|
---|
47 | }>>
|
---|
48 | .
|
---|
49 | NONTERMINALS
|
---|
50 | GPDefSyntaxAnalyzer.
|
---|
51 | SemDecl. SemAction. NonterminalDecl.
|
---|
52 | RuleDef. SynExpr. SynTerm. SynFact. TerminalDecl.
|
---|
53 | ConstraintDef. ConstraintRule. SetDefinition.
|
---|
54 |
|
---|
55 | RULES
|
---|
56 | GPDefSyntaxAnalyzer =
|
---|
57 | 'PROBLEM' ident
|
---|
58 | ['CODE' /* SourceText */]
|
---|
59 | ['INIT' /* SourceText */]
|
---|
60 | 'NONTERMINALS' { NonterminalDecl }
|
---|
61 | 'TERMINALS' { TerminalDecl }
|
---|
62 | 'RULES' { RuleDef }
|
---|
63 | ('MAXIMIZE' | 'MINIMIZE') /* SourceText */
|
---|
64 | 'END' ident '.'.
|
---|
65 |
|
---|
66 |
|
---|
67 | SemDecl = 'LOCAL' /* SourceText */
|
---|
68 | .
|
---|
69 |
|
---|
70 | SemAction = 'SEM' /* SourceText */
|
---|
71 | .
|
---|
72 |
|
---|
73 | NonterminalDecl = ident /* FormalAttrList */ '.'
|
---|
74 |
|
---|
75 |
|
---|
76 |
|
---|
77 | .
|
---|
78 |
|
---|
79 | TerminalDecl = ident /* FormalAttrList */
|
---|
80 | [ 'CONSTRAINTS' ConstraintDef ]
|
---|
81 | '.'
|
---|
82 | .
|
---|
83 |
|
---|
84 | ConstraintDef = { ConstraintRule }.
|
---|
85 | ConstraintRule = ident 'IN' SetDefinition .
|
---|
86 | SetDefinition =
|
---|
87 | 'SET' /* SourceText */
|
---|
88 | | 'RANGE' /* SourceText */ '..' /* SourceText */
|
---|
89 | .
|
---|
90 |
|
---|
91 | RuleDef = ident /* FormalAttrList */ '=' [SemDecl] SynExpr '.'
|
---|
92 | .
|
---|
93 |
|
---|
94 | SynExpr = SynTerm {'|' SynTerm}
|
---|
95 | .
|
---|
96 |
|
---|
97 | SynTerm = SynFact {SynFact}
|
---|
98 | .
|
---|
99 |
|
---|
100 | SynFact =
|
---|
101 | ident /* ActualAttrList */
|
---|
102 | | 'EPS'
|
---|
103 | | '(' SynExpr ')'
|
---|
104 | | '[' SynExpr ']'
|
---|
105 | | '{' SynExpr '}'
|
---|
106 | | SemAction
|
---|
107 | .
|
---|
108 |
|
---|
109 | END GPDefSyntaxAnalyzer. |
---|