1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.millscript.millscript.syntax;
24
25 import org.millscript.millscript.conf.Configuration;
26
27 import java.io.Reader;
28
29
30
31
32
33
34
35
36
37 /**
38 * This class implements the MillScript parser.
39 */
40 public class ParserImpl extends ConfigurationParserImpl {
41
42
43 static {
44
45
46
47 Syntax reserved = new ReservedSyntax();
48 put( "!!", reserved );
49 put( "present", reserved );
50 put( "nonAbsent", reserved );
51 put( "downto", reserved );
52 put( "endmethod", reserved );
53 put( "into", reserved );
54 put( "facet", reserved );
55 put( "as", reserved );
56
57
58 Syntax nonfix = new NonfixSyntax();
59 put( "..", nonfix );
60 put( "=>", nonfix );
61 put( "/>", nonfix );
62 put( "</", nonfix );
63 put( "</", nonfix );
64 put( ";", nonfix );
65 put( "]", nonfix );
66 put( "}", nonfix );
67 put( ":", nonfix );
68 put( "case", nonfix );
69 put( "default", nonfix );
70 put( "do", nonfix );
71 put( "else", nonfix );
72 put( "elseif", nonfix );
73 put( "elseunless", nonfix );
74 put( "endclass", nonfix );
75 put( "enddefine", nonfix );
76 put( "endfunction", nonfix );
77 put( "endif", nonfix );
78 put( "endfor", nonfix );
79 put( "endfun", nonfix );
80 put( "endunless", nonfix );
81 put( "endwhile", nonfix );
82 put( "endswitch", nonfix );
83 put( "extends", nonfix );
84 put( "finally", nonfix );
85 put( "from", nonfix );
86 put( "in", nonfix );
87 put( "memo", nonfix );
88 put( "method", nonfix );
89 put( "override", reserved );
90 put( "slot", nonfix );
91 put( "then", nonfix );
92 put( "to", nonfix );
93 put( "where", nonfix );
94
95
96 put( "^", new ThisSyntax() );
97 put( "{", new ListSyntax() );
98 put( "<!--", new XMLCommentSyntax() );
99 put( "class", new SpiceClassSyntax( "endclass" ) );
100 put( "const", new VarSyntax( true ) );
101 put( "define", new DefineSyntax() );
102 put( "function", new FunctionSyntax( "endfunction" ) );
103 put( "for", new ForSyntax() );
104 put( "fun", new FunSyntax() );
105 put( "if", new ConditionalSyntax( "endif" ) );
106 put( "import", new ImportSyntax() );
107 put( "init", new InitSyntax() );
108 put( "none", new NoneSyntax() );
109 put( "not", new NotSyntax() );
110 put( "package", new PackageSyntax() );
111 put( "pragma", new PragmaSyntax() );
112 put( "unless", new ConditionalSyntax( "endunless" ) );
113 put( "switch", new SwitchSyntax() );
114 put( "val", new VarSyntax( true ) );
115 put( "var", new VarSyntax( false ) );
116 put( "while", new WhileSyntax() );
117
118
119 put( ":=", new AssignSyntax().setPrec( LOW_PREC + 100 ) );
120 put( "||", new OrAbsentSyntax().setPrec( LOW_PREC + 200 ) );
121 put( "&&", new AndAbsentSyntax().setPrec( LOW_PREC + 300 ) );
122 put( "or", new OrSyntax().setPrec( LOW_PREC + 400 ) );
123 put( "and", new AndSyntax().setPrec( LOW_PREC + 500 ) );
124
125 put( "...", new ExplodeSyntax().setPrec( COMMA_PREC + 200 ) );
126 put( "++", new AppendSyntax().setPrec( COMMA_PREC + 300 ) );
127
128
129 Syntax relop = new RelationalOperationSyntax().setPrec( RELOP_PREC + 100 );
130 put( "<", new XMLElementSyntax().setPrec( RELOP_PREC + 100 ) );
131 put( "<=", relop );
132 put( "=", relop );
133 put( "/=", relop );
134 put( "==", relop );
135 put( "/==", relop );
136 put( ">", relop );
137 put( ">=", relop );
138 put( "@", new DotSyntax().setPrec( RELOP_PREC + 300 ) );
139
140
141 Syntax a = new ArithSyntax().setPrec( ARITH_PREC + 100 );
142 Syntax b = new ArithSyntax().setPrec( ARITH_PREC + 200 );
143 put( "+", a );
144 put( "-", a );
145 put( "*", b );
146 put( "mod", b );
147 put( "div", b );
148
149
150 Syntax s = new MapletSyntax().setPrec( TIGHT_PREC + 100 );
151
152 put( "==>", s );
153 put( "[", new IndexSyntax().setPrec( TIGHT_PREC + 200 ) );
154 put( ".", new DotSyntax().setPrec( TIGHT_PREC + 300 ) );
155 put( "::", new QualifiedNameSyntax().setPrec( TIGHT_PREC + 500 ) );
156 }
157
158 /**
159 * Constructs a new <code>ParserImpl</code> with the specified origin, source,
160 * interactive prompt and end of line comment status.
161 *
162 * @param origin the origin message for this tokenizer
163 * @param r the character source to tokenize
164 * @param eolc flag indicating if end of line comments are supported
165 * @param c the configuration
166 */
167 public ParserImpl( final String origin, final Reader r, final boolean eolc, final Configuration c ) {
168 super( origin, r, eolc, c );
169 }
170
171 }