options{
STATIC = false;
JAVA_UNICODE_ESCAPE = false;
}
PARSER_BEGIN(SlimJJParser)
package tmp.generated_gcide;
import java.io.*;
import java.util.*;
import cide.gast.*;
import cide.gparser.*;
public class SlimJJParser{
/**
* Accumulate {@link Token} objects from the token stream until a token
* matching tokenKind is consumed from the stream. The tokens
* are accumulated in buffer, including the terminating
* token.
*
* @return a {@link Token} formed by concatenating all intervening tokens
* and special tokens.
*/
final private Token accumulateUntilToken(int tokenKind)
throws ParseException {
StringBuffer buffer = new StringBuffer();
Token token = getNextToken();
// Initialize result with known information (starting position, etc.):
//
Token result = Token.newToken(OTHER);
result.specialToken = null;
Token startToken = firstSpecial(token);
result.beginColumn = startToken.beginColumn;
result.beginLine = startToken.beginLine;
// Accumulate tokens until a tokenKind token is found:
//
while (token.kind != tokenKind) {
// Update information in result:
//
result.endColumn = token.endColumn;
result.endLine = token.endLine;
result.next = token.next;
if (token.kind == EOF)
throw new ParseException("from line " + result.beginLine
+ " at column " + result.beginColumn
+ ": EOF reached before " + tokenImage[tokenKind]
+ " found");
accumulate(token, buffer);
token = getNextToken();
}
accumulate(token, buffer);
result.image = buffer.toString();
return result;
}
/**
* Append the given {@link Token} and any preceding special tokens to a
* given {@link StringBuffer}.
*
* @param token
* the given JavaCC {@link Token} object
* @param buffer
* the buffer to which to append token
*/
final private static void accumulate(Token token, StringBuffer buffer) {
// Append preceding special tokens to buffer:
//
Token special = firstSpecial(token);
if (special != token)
while (special != null) {
buffer.append(" "+special.toString());
special = special.next;
}
// Finally, append the token itself:
//
buffer.append(" "+token.toString());
}
/**
* Finds the first token, special or otherwise, in the list of special
* tokens preceding this {@link Token}. If this list is non-empty, the
* result will be a special token. Otherwise, it will be the starting token.
*
* @param token
* the given {@link Token}.
* @return the first special token preceding token.
*/
final private static Token firstSpecial(Token token) {
while (token.specialToken != null)
token = token.specialToken;
return token;
}
}PARSER_END(SlimJJParser)
/* WHITE SPACE */
SKIP:{
" "
| "\t"
| "\n"
| "\r"
| "\f"
}
/* COMMENTS */
MORE:{
"//":IN_SINGLE_LINE_COMMENT
| <"/**"~["/"]>{
input_stream.backup(1);
}
:IN_FORMAL_COMMENT
| "/*":IN_MULTI_LINE_COMMENT
}
SPECIAL_TOKEN:{
:DEFAULT
}
SPECIAL_TOKEN:{
:DEFAULT
}
SPECIAL_TOKEN:{
:DEFAULT
}
MORE:{
<~[]>
}
/* RESERVED WORDS AND LITERALS */
TOKEN:{
<_GRAMMARSTART:"GRAMMARSTART">
|
|
|
|
|
|
|
|
|
|
|
| <_DEFAULT:"default">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| <_LOOK_AHEAD:"LOOK_AHEAD">
|
| <_JAVA:"JAVA">
| <_JAVATOKEN:"JAVATOKEN">
}
/* LITERALS */
TOKEN:{
(["l", "L"])?
| (["l", "L"])?
| (["l", "L"])?>
| <#DECIMAL_LITERAL:["1"-"9"](["0"-"9"])*>
| <#HEX_LITERAL:"0"["x", "X"](["0"-"9", "a"-"f", "A"-"F"])+>
| <#OCTAL_LITERAL:"0"(["0"-"7"])*>
| )?(["f", "F", "d", "D"])?
| "."(["0"-"9"])+()?(["f", "F", "d", "D"])?
| (["0"-"9"])+(["f", "F", "d", "D"])?
| (["0"-"9"])+()?["f", "F", "d", "D"]>
| <#EXPONENT:["e", "E"](["+", "-"])?(["0"-"9"])+>
|
|
}
/* SEPARATORS */
TOKEN:{
|
|
|
|
|
|
|
|
|
}
/* OPERATORS */
TOKEN:{
|
| ">
|
|
|
|
|
|
| =">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| >=">
| >>=">
|
}
/* IDENTIFIERS */
TOKEN:{
(
| )*>
| <#LETTER:["\u0024", "\u0041"-"\u005a", "\u005f", "\u0061"-"\u007a", "\u00c0"-"\u00d6", "\u00d8"-"\u00f6", "\u00f8"-"\u00ff", "\u0100"-"\u1fff", "\u3040"-"\u318f", "\u3300"-"\u337f", "\u3400"-"\u3d2d", "\u4e00"-"\u9fff", "\uf900"-"\ufaff"]>
| <#DIGIT:["\u0030"-"\u0039", "\u0660"-"\u0669", "\u06f0"-"\u06f9", "\u0966"-"\u096f", "\u09e6"-"\u09ef", "\u0a66"-"\u0a6f", "\u0ae6"-"\u0aef", "\u0b66"-"\u0b6f", "\u0be7"-"\u0bef", "\u0c66"-"\u0c6f", "\u0ce6"-"\u0cef", "\u0d66"-"\u0d6f", "\u0e50"-"\u0e59", "\u0ed0"-"\u0ed9", "\u1040"-"\u1049"]>
|
}
JAVACODE
Token findIntroductionBlock () {
return accumulateUntilToken (_GRAMMARSTART) ;
}
GRAMMARSTART
Grammar :
JAVATOKEN(findIntroductionBlock) @!
(Production)*
;
Production:
@RefTarget(Production)
":" @+! &LI Choice ( @! "|" &LI Choice )* @-! ";" @!@!
;
Choice:
(Text)* ( MultAndText )+
["::" ]
;
MultAndText:
Mult (Text)*
;
Mult:
LOOK_AHEAD("OneOrMore()") OneOrMore |
LOOK_AHEAD("ZeroOrMore()") ZeroOrMore |
LOOK_AHEAD("Wrappee()") Wrappee |
OneOrZero |
Unit |
OptionalWithDefault
;
OneOrMore:
"(" (Text)* Unit (Text)* ")" "+"
;
ZeroOrMore:
"(" (Text)* Unit (Text)* ")" "*"
;
OneOrZero:
"[" (Text)* Unit (Text)* "]"
;
OptionalWithDefault:
"OPTIONAL" "(" Unit "," ")"
;
Wrappee:
Unit "!"
;
Unit:
NonTerminal
| Ident
;
NonTerminal:
@Reference(Production)
[ LOOK_AHEAD(3) "{" "}" ]
;
Ident:
"JAVATOKEN" "(" ")"
|
"<" ">"
;
Text:
Lookahead
|
Java
|
|
LayoutHint
;
LayoutHint:
"@" ["+" ] ["-" ] ["!" ]
;
Lookahead:
"LOOK_AHEAD" "(" LookaheadBody ")"
;
LookaheadBody: |;
Java:
"JAVA" "(" ")"
;