-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jorge Lucángeli Obes <[email protected]>
- Loading branch information
1 parent
7eee6fa
commit 80a61ab
Showing
6 changed files
with
3,682 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
/* | ||
* Copyright 2011 Jorge Lucángeli Obes | ||
* | ||
* This file is part of fj-llvm. | ||
* | ||
* fj-llvm is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* fj-llvm is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with fj-llvm. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
grammar fj; | ||
|
||
options { | ||
language = Python; | ||
output = AST; | ||
backtrack = true; | ||
} | ||
|
||
tokens { | ||
DOT = '.'; | ||
COMMA = ','; | ||
SEMICOLON = ';'; | ||
LPAREN = '('; | ||
RPAREN = ')'; | ||
LBRACE = '{'; | ||
RBRACE = '}'; | ||
ASSIGN = '='; | ||
UNDERSCORE = '_'; | ||
CLASS = 'class'; | ||
EXTENDS = 'extends'; | ||
SUPER = 'super'; | ||
THIS = 'this'; | ||
RETURN = 'return'; | ||
NEW = 'new'; | ||
} | ||
|
||
@header { | ||
# Copyright 2011 Jorge Lucángeli Obes | ||
# | ||
# This file is part of fj-llvm. | ||
# | ||
# fj-llvm is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# fj-llvm is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with fj-llvm. If not, see <http://www.gnu.org/licenses/>. | ||
} | ||
|
||
/********* LEXER ******************************************************/ | ||
fragment | ||
LETTER | ||
: | ||
'a'..'z' | ||
| 'A'..'Z' | ||
; | ||
|
||
fragment | ||
DIGIT | ||
: | ||
'0'..'9' | ||
; | ||
|
||
fragment | ||
ANY_CHAR | ||
: | ||
LETTER | ||
| UNDERSCORE | ||
| DIGIT | ||
; | ||
|
||
NAME | ||
: | ||
( | ||
LETTER | ||
| UNDERSCORE | ||
) | ||
ANY_CHAR* | ||
; | ||
|
||
WHITESPACE | ||
: | ||
( | ||
' ' | ||
| '\t' | ||
| '\r' | ||
| '\n' | ||
)+ | ||
|
||
{ | ||
$channel = HIDDEN; | ||
} | ||
; | ||
|
||
/********* PARSER *****************************************************/ | ||
program | ||
: | ||
classDefinition+ expression | ||
; | ||
|
||
classDefinition | ||
: | ||
CLASS NAME EXTENDS NAME LBRACE fields constructor methods RBRACE | ||
; | ||
|
||
fields | ||
: | ||
(field SEMICOLON)* | ||
; | ||
|
||
field | ||
: | ||
NAME NAME | ||
; | ||
|
||
constructor | ||
: | ||
NAME LPAREN vars RPAREN LBRACE SUPER LPAREN names RPAREN SEMICOLON inits RBRACE | ||
; | ||
|
||
vars | ||
: | ||
(var (COMMA var)*)? | ||
; | ||
|
||
var | ||
: | ||
NAME NAME | ||
; | ||
|
||
names | ||
: | ||
(NAME COMMA)* | ||
; | ||
|
||
inits | ||
: | ||
(init SEMICOLON)* | ||
; | ||
|
||
init | ||
: | ||
THIS DOT NAME ASSIGN NAME | ||
; | ||
|
||
methods | ||
: | ||
method* | ||
; | ||
|
||
method | ||
: | ||
NAME NAME LPAREN vars RPAREN LBRACE RETURN expression SEMICOLON RBRACE | ||
; | ||
|
||
expression | ||
: | ||
baseExpression | ||
| dotExpression | ||
; | ||
|
||
dotExpression | ||
: | ||
( | ||
baseExpression | ||
| THIS | ||
) | ||
(DOT NAME parenExpressions?)+ // field or method call | ||
; | ||
|
||
baseExpression | ||
: | ||
NAME | ||
| NEW NAME parenExpressions // new object | ||
| LPAREN NAME RPAREN expression // cast | ||
; | ||
|
||
parenExpressions | ||
: | ||
LPAREN (expression (COMMA expression)*)? RPAREN | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
CLASS=13 | ||
RBRACE=10 | ||
LETTER=19 | ||
LBRACE=9 | ||
NEW=18 | ||
WHITESPACE=23 | ||
UNDERSCORE=12 | ||
SEMICOLON=6 | ||
LPAREN=7 | ||
ANY_CHAR=21 | ||
RPAREN=8 | ||
NAME=22 | ||
COMMA=5 | ||
ASSIGN=11 | ||
THIS=16 | ||
RETURN=17 | ||
DIGIT=20 | ||
SUPER=15 | ||
DOT=4 | ||
EXTENDS=14 | ||
'}'=10 | ||
'class'=13 | ||
'new'=18 | ||
'extends'=14 | ||
'{'=9 | ||
'this'=16 | ||
';'=6 | ||
'return'=17 | ||
'='=11 | ||
'('=7 | ||
','=5 | ||
'_'=12 | ||
'.'=4 | ||
')'=8 | ||
'super'=15 |
Oops, something went wrong.