-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexicalgrammar
113 lines (103 loc) · 2.64 KB
/
lexicalgrammar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Lexical grammar for j--
// Copyright 2013 Bill Campbell, Swami Iyer and Bahar Akbal-Delibas
// Whitespace -- ignored
" "|"\t"|"\n"|"\r"|"\f"
// Comments -- ignored
"//" {~("\n"|"\r")} ("\n"|"\r"["\n"])
"/*" {~("*/")} ("*/")
// Reserved words
ABSTRACT ::= "abstract"
BOOLEAN ::= "boolean"
BREAK ::= "break"
BYTE ::= "byte"
CASE ::= "case"
CATCH ::= "catch"
CHAR ::= "char"
CLASS ::= "class"
CONST ::= "const"
CONTINUE ::= "continue"
DEFAULT ::= "default"
DO ::= "do"
DOUBLE ::= "double"
ELSE ::= "else"
EXTENDS ::= "extends"
FALSE ::= "false"
FINAL ::= "final"
FINALLY ::= "finally"
FLOAT ::= "float"
FOR ::= "for"
GOTO ::= "goto"
IF ::= "if"
IMPLEMENTS ::= "implements"
IMPORT ::= "import"
INSTANCEOF ::= "instanceof"
INT ::= "int"
INTERFACE ::= "interface"
LONG ::= "long"
NATIVE ::= "native"
NEW ::= "new"
NULL ::= "null"
PACKAGE ::= "package"
PRIVATE ::= "private"
PROTECTED ::= "protected"
PUBLIC ::= "public"
RETURN ::= "return"
SHORT ::= "short"
STATIC ::= "static"
STRICTFP ::= "strictfp"
SUPER ::= "super"
SWITCH ::= "switch"
SYNCHRONIZED ::= "synchronized"
THIS ::= "this"
THROW ::= "throw"
THROWS ::= "throws"
TRANSIENT ::= "transient"
TRUE ::= "true"
TRY ::= "try"
VOID ::= "void"
VOLATILE ::= "volatile"
WHILE ::= "while"
// Operators
ASSIGN ::= "="
EQUAL ::= "=="
GT ::= ">"
INC ::= "++"
LAND ::= "&&"
LE ::= "<="
LNOT ::= "!"
MINUS ::= "-"
PLUS ::= "+"
PLUS_ASSIGN ::= "+="
STAR ::= "*"
DIVIDE ::= "/"
REMAINDER ::= "%"
BITWISE_AND ::= "&"
BITWISE_OR ::= "|"
BITWISE_XOR ::= "^"
BITWISE_NOT ::= "~"
LSHIFT ::= "<<"
RSHIFT ::= ">>"
RSHIFT_ZERO ::= ">>>"
// Separators
COMMA ::= ","
DOT ::= "."
LBRACK ::= "["
LCURLY ::= "{"
LPAREN ::= "("
RBRACK ::= "]"
RCURLY ::= "}"
RPAREN ::= ")"
SEMI ::= ";"
COLON ::= ":"
QUESTION_MARK ::= "?"
// Identifiers
IDENTIFIER ::= ("a"-"z"|"A"-"Z"|"_"|"$") {"a"-"z"|"A"-"Z"|"_"|"0"-"9"|"$"}
// Literals
INT_LITERAL ::= "0" | ("1"-"9") {"0"-"9"}
DOUBLE_LITERAL ::= INT_LITERAL DOT {"0"-"9"} | DOT ("0"-"9") {"0"-"9"}
// DOUBLE_LITERAL ::= {"0"-"9"} [ [DOT] {"0"-"9"} [(e|E) [+ | -] ("0"-"9") {"0"-"9"} ]] [d|D]
ESC ::= "\\" ("n"|"r"|"t"|"b"|"f"|"'"|"\""|"\\")
STRING_LITERAL ::= "\"" {ESC | ~("\""|"\\"|"\n"|"\r")} "\""
CHAR_LITERAL ::= "'" (ESC | ~("'"|"\n"|"\r"|"\\")) "'"
// End of file
EOF ::= "<end of file>"