Skip to content

Commit

Permalink
New changes in AST. I should add semantic nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
szabototo89 committed Mar 27, 2014
1 parent 8249366 commit aee77d3
Show file tree
Hide file tree
Showing 180 changed files with 37,931 additions and 1,792 deletions.
Binary file modified docs/Diplomamunka_Szabo_Tamas.docx
Binary file not shown.
Binary file modified docs/draft.docx
Binary file not shown.
25 changes: 16 additions & 9 deletions grammar/MetaCode.g4
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ statements : (statement ';')+
;

statement : Expression=expression
| Return=returnStatement
| Attributes=attributes? VariableDeclaration=variableDeclaration
| Attributes=attributes? If=ifStatement
| Attributes=attributes? Block=blockStatement
Expand Down Expand Up @@ -39,21 +40,23 @@ expression : PrimaryExpression=primaryExpression
functionCallExpression : primaryExpression '(' expression? ')'
;

memberExpression : primaryExpression ('.' (identifier | functionCallExpression))+
memberExpression : (primaryExpression | functionCallExpression) ('.' memberTagExpression)+
;

memberTagExpression : identifier | functionCallExpression;

primaryExpression : Attributes=attributes? Constant=constant
| Attributes=attributes? Id=identifier
| Attributes=attributes? Id=ID
| Attributes=attributes? Function=functionExpression
| Attributes=attributes? Assignment=assignmentExpression
| Attributes=attributes? '(' InnerExpression=expression ')'
;

functionExpression : FUNCTION FunctionName=identifier? '(' Parameters=formalParameterList? ')' (':' ReturnType=typeName)? DO BodyStatements=statements END
| FUNCTION FunctionName=identifier? '(' Parameters=formalParameterList? ')' (':' ReturnType=typeName)? '=' BodyExpression=expression
functionExpression : FUNCTION FunctionName=ID? '(' Parameters=formalParameterList? ')' (':' ReturnType=typeName) DO BodyStatements=statements END
| FUNCTION FunctionName=ID? '(' Parameters=formalParameterList? ')' (':' ReturnType=typeName) '=' BodyExpression=expression
;

foreachStatement : FOREACH '(' Var=VAR? Id=identifier (':' VariableType=typeName)? IN ArrayExpression=expression ')' Body=statement
foreachStatement : FOREACH '(' Var=VAR? Id=ID (':' VariableType=typeName)? IN ArrayExpression=expression ')' Body=statement
;

whileStatement : WHILE '(' ConditionExpression=expression ')' Body=statement
Expand All @@ -64,22 +67,24 @@ blockStatement : DO Body=statements END

skipStatement : SKIP;

assignmentExpression: Variable=identifier ASSIGN Value=expression (ConditionalAttributes=attributes? IF '(' ConditionalExpression=expression ')')?
returnStatement : RETURN expression;

assignmentExpression: Variable=ID ASSIGN Value=expression (ConditionalAttributes=attributes? IF '(' ConditionalExpression=expression ')')?
;

ifStatement : IF '(' Condition=expression ')' Statements=statements
ElseIfExpressions=elseIfStatement*
ElseIfStatements=elseIfStatement*
(ELSE ElseStatements=statements)?
END
;

elseIfStatement : ELSE IF '(' expression ')' statements
elseIfStatement : ELSE IF '(' Condition=expression ')' Statements=statements
;

formalParameterList : formalParameter (',' formalParameter)*
;

formalParameter : attributes? identifier ':' typeName
formalParameter : Attributes=attributes? Name=ID ':' Type=typeName
;

actualParameterList : expression (',' expression)*
Expand Down Expand Up @@ -155,6 +160,8 @@ NOT : 'not';

NULL : 'null';

RETURN : 'return';

LEFT_PARENTHESIS : '(';

RIGHT_PARENTHESIS : ')';
Expand Down
6 changes: 5 additions & 1 deletion grammar/example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ else
end;
*/

(5 + 5).ToString();

var a = ToString().Parse("Hello World!").Hiii;

var a : System.Boolean = false;

foreach (var i: Integer in 1 to 100 by 34) do
Expand All @@ -41,7 +45,7 @@ if (not (@convert false))
@cast("System.Int32") (0 to 3 by 2);
end;

@tail-recursive(false) function max(a: Integer, b: Integer) do
@tail-recursive(false) function max(a: Integer, b: Integer): Integer do
if (a < b)
a;
else
Expand Down
26 changes: 14 additions & 12 deletions grammar/src/MetaCode.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ FUNCTION=19
WHILE=21
NULL=34
ELSE=23
NUMBER=42
ATTRIBUTE_ID=40
WHITESPACE=43
NUMBER=43
ATTRIBUTE_ID=41
WHITESPACE=44
DO=24
NOT=33
ID=37
ID=38
AND=31
T__9=9
T__8=10
Expand All @@ -17,31 +17,32 @@ T__5=13
IF=22
SKIP=27
T__4=14
MULTILINE_COMMENT=39
MULTILINE_COMMENT=40
BOOLEAN=26
T__16=2
IN=29
T__15=3
NEWLINE=44
RIGHT_PARENTHESIS=36
NEWLINE=45
RIGHT_PARENTHESIS=37
T__17=1
T__12=6
T__11=7
T__14=4
LEFT_PARENTHESIS=35
LEFT_PARENTHESIS=36
T__13=5
T__1=17
T__0=18
OR=32
T__10=8
T__3=15
RETURN=35
ASSIGN=30
T__2=16
VAR=28
FOREACH=20
COMMENT=38
COMMENT=39
END=25
STRING=41
STRING=42
'foreach'=20
'end'=25
'>='=18
Expand All @@ -50,9 +51,10 @@ STRING=41
'null'=34
'>'=14
';'=11
'return'=35
'='=30
'+'=4
')'=36
')'=37
'.'=2
'function'=19
'do'=24
Expand All @@ -66,7 +68,7 @@ STRING=41
'!='=10
'<'=9
'if'=22
'('=35
'('=36
'not'=33
':'=8
'or'=32
Expand Down
Binary file modified grammar/src/MetaCodeBaseListener.class
Binary file not shown.
Loading

0 comments on commit aee77d3

Please sign in to comment.