-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexicalgrammar
75 lines (65 loc) · 1.66 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
// Lexical grammar for j--
// Copyright 2013 Bill Campbell, Swami Iyer and Bahar Akbal-Delibas
// Whitespace -- ignored
" "|"\t"|"\n"|"\r"|"\f"
// Single line comment -- ignored
"//" {~("\n"|"\r")} ("\n"|"\r"["\n"])
// Reserved words
ABSTRACT ::= "abstract"
BOOLEAN ::= "boolean"
CHAR ::= "char"
CLASS ::= "class"
ELSE ::= "else"
EXTENDS ::= "extends"
FALSE ::= "false"
IF ::= "if"
IMPORT ::= "import"
INSTANCEOF ::= "instanceof"
INT ::= "int"
NEW ::= "new"
NULL ::= "null"
PACKAGE ::= "package"
PRIVATE ::= "private"
PROTECTED ::= "protected"
PUBLIC ::= "public"
RETURN ::= "return"
STATIC ::= "static"
SUPER ::= "super"
THIS ::= "this"
TRUE ::= "true"
VOID ::= "void"
WHILE ::= "while"
// Operators
ASSIGN ::= "="
BITWISE_AND ::= "&"
BITWISE_COMP ::= "~"
DIV ::= "/"
EQUAL ::= "=="
GT ::= ">"
INC ::= "++"
LAND ::= "&&"
LE ::= "<="
LNOT ::= "!"
MINUS ::= "-"
PLUS ::= "+"
PLUS_ASSIGN ::= "+="
STAR ::= "*"
// Separators
COMMA ::= ","
DOT ::= "."
LBRACK ::= "["
LCURLY ::= "{"
LPAREN ::= "("
RBRACK ::= "]"
RCURLY ::= "}"
RPAREN ::= ")"
SEMI ::= ";"
// Identifiers
IDENTIFIER ::= ("a"-"z"|"A"-"Z"|"_"|"$") {"a"-"z"|"A"-"Z"|"_"|"0"-"9"|"$"}
// Literals
INT_LITERAL ::= "0" | ("1"-"9") {"0"-"9"}
ESC ::= "\\" ("n"|"r"|"t"|"b"|"f"|"'"|"\""|"\\")
STRING_LITERAL ::= "\"" {ESC | ~("\""|"\\"|"\n"|"\r")} "\""
CHAR_LITERAL ::= "'" (ESC | ~("'"|"\n"|"\r"|"\\")) "'"
// End of file
EOF ::= "<end of file>"