Skip to content

Commit

Permalink
Implemented scope into AST
Browse files Browse the repository at this point in the history
  • Loading branch information
szabototo89 committed Mar 23, 2014
1 parent 1e1e892 commit 8249366
Show file tree
Hide file tree
Showing 104 changed files with 1,608 additions and 1,147 deletions.
43 changes: 20 additions & 23 deletions grammar/MetaCode.g4
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ statement : Expression=expression
variableDeclaration : Attributes=attributes? VAR VariableName=ID (':' VariableType=typeName)? ASSIGN VariableDefaultValue=expression
;

expression : primaryExpression
| functionCallExpression
| memberExpression
expression : PrimaryExpression=primaryExpression
| FunctionCallExpression=functionCallExpression
| MemberExpression=memberExpression
| Operator=NOT Expression=expression
| Left=expression Operator='+' Right=expression
| Left=expression Operator='-' Right=expression
Expand All @@ -36,27 +36,24 @@ expression : primaryExpression
| Left=expression Operator=OR Right=expression
;

binaryExpression :

functionCallExpression : primaryExpression '(' expression? ')'
;

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

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

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

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

whileStatement : WHILE '(' ConditionExpression=expression ')' Body=statement
Expand All @@ -65,31 +62,30 @@ whileStatement : WHILE '(' ConditionExpression=expression ')' Body=statem
blockStatement : DO Body=statements END
;

skipStatement : SKIP
;
skipStatement : SKIP;

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

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

elseIfStatement : ELSE IF '(' expression ')' statements
;

formalParameterList : formalParameter (',' formalParameter)*
;

formalParameter : attributes? ID ':' typeName
formalParameter : attributes? identifier ':' typeName
;

actualParameterList : expression (',' expression)*
;

typeName : attributes? ID
typeName : attributes? ID ('.' ID)*
;

constant : Number=numberConstant
Expand All @@ -99,6 +95,9 @@ constant : Number=numberConstant
| Interval=intervalConstant
;

identifier : Id=ID
;

numberConstant : NUMBER;

stringConstant : STRING;
Expand Down Expand Up @@ -148,15 +147,13 @@ IN : 'in';

ASSIGN : '=';

AND : 'and';

OR : 'or';
AND : 'and';

NOT : 'not';
OR : 'or';

NEW : 'new';
NOT : 'not';

NULL : 'null';
NULL : 'null';

LEFT_PARENTHESIS : '(';

Expand Down
2 changes: 1 addition & 1 deletion grammar/example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ else
end;
*/

var a = new Type();
var a : System.Boolean = false;

foreach (var i: Integer in 1 to 100 by 34) do
skip;
Expand Down
Binary file modified grammar/src/MetaCodeBaseListener.class
Binary file not shown.
Loading

0 comments on commit 8249366

Please sign in to comment.