forked from potigol/potigol
-
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.
Alteração da sintaxe para permitir a declaração explicita de tipos
- Loading branch information
Showing
5 changed files
with
56 additions
and
32 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -17,14 +17,14 @@ | |
*/ | ||
|
||
/** | ||
* _____ _ _ _ | ||
* _____ _ _ _ | ||
* | __ \ | | (_) | | | ||
* | |__) |__ | |_ _ __ _ ___ | | | ||
* | ___/ _ \| __| |/ _` |/ _ \| | | ||
* | | | (_) | |_| | (_| | (_) | | | ||
* |_| \___/ \__|_|\__, |\___/|_| | ||
* __/ | | ||
* |___/ | ||
* __/ | | ||
* |___/ | ||
* | ||
* @author Leonardo Lucena ([email protected]) | ||
*/ | ||
|
@@ -56,10 +56,10 @@ decl | |
| decl_uso ; | ||
|
||
decl_valor | ||
: id1 '=' expr # valor_simples | ||
| id2 '=' expr2 # valor_multiplo | ||
| 'var' id1 (':='| '=') expr # decl_var_simples | ||
| 'var' id2 (':='| '=') expr2 # decl_var_multipla ; | ||
: id1 (':' tipo)? '=' expr # valor_simples | ||
| id2 (':' tipo)? '=' expr2 # valor_multiplo | ||
| 'var' id1 (':' tipo)? (':='| '=') expr # decl_var_simples | ||
| 'var' id2 (':' tipo)? (':='| '=') expr2 # decl_var_multipla ; | ||
|
||
decl_funcao | ||
: ID '(' dcls ')' (':' tipo)? '=' expr # def_funcao | ||
|
@@ -77,7 +77,7 @@ retorne | |
|
||
dcl | ||
: id1 ':' tipo ; | ||
|
||
dcl_var | ||
: 'var' id1 ':' tipo ; | ||
|
||
|
@@ -95,7 +95,7 @@ tipo | |
| '(' tipo2 ')' # tipo_tupla | ||
| <assoc=right> tipo '=>' tipo # tipo_funcao ; | ||
|
||
// Expressao | ||
// Expressao | ||
expr | ||
: literal # lit | ||
| expr '.' ID ('(' expr1 ')')? # chamada_metodo | ||
|
@@ -129,7 +129,7 @@ literal | |
| FLOAT # real | ||
| CHAR # char ; | ||
|
||
|
||
// Decisao | ||
decisao | ||
: se | ||
|
@@ -166,7 +166,7 @@ padrao | |
| padrao ('|' padrao)+ # padrao_ou | ||
| padrao (',' padrao)+ # padrao_virgula ; | ||
|
||
// Repeticao | ||
// Repeticao | ||
repeticao | ||
: para_faca | ||
| para_gere | ||
|
@@ -204,7 +204,7 @@ id1 | |
id2 | ||
: ID (',' ID)+ ; | ||
|
||
qualid | ||
qualid | ||
: (ID '.')* ID; | ||
|
||
qualid1 | ||
|
@@ -222,7 +222,7 @@ exprlist | |
|
||
// Lexer | ||
//channels { WSCHANNEL, MYHIDDEN }; | ||
|
||
ID | ||
: (ALPHA|ACENTO) (ALPHA|ACENTO|DIGIT)* ; | ||
|
||
|
@@ -233,7 +233,7 @@ fragment ALPHA | |
|
||
fragment ACENTO | ||
: '\u00a1' .. '\ufffc' ; | ||
|
||
INT | ||
: DIGIT+ ; | ||
|
||
|
@@ -275,4 +275,3 @@ COMMENT | |
NL | ||
: '\n' ->channel(2) ; | ||
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
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 |
---|---|---|
|
@@ -17,14 +17,14 @@ | |
*/ | ||
|
||
/** | ||
* _____ _ _ _ | ||
* _____ _ _ _ | ||
* | __ \ | | (_) | | | ||
* | |__) |__ | |_ _ __ _ ___ | | | ||
* | ___/ _ \| __| |/ _` |/ _ \| | | ||
* | | | (_) | |_| | (_| | (_) | | | ||
* |_| \___/ \__|_|\__, |\___/|_| | ||
* __/ | | ||
* |___/ | ||
* __/ | | ||
* |___/ | ||
* | ||
* @author Leonardo Lucena ([email protected]) | ||
*/ | ||
|
@@ -316,20 +316,22 @@ public void exitDecl(final DeclContext ctx) { | |
public void exitDecl_var_multipla(final Decl_var_multiplaContext ctx) { | ||
final String id = data.getValue(ctx.id2()); | ||
final String[] ids = M.split(id); | ||
final String tipo = data.getOrElse(ctx.tipo()); | ||
final String exp = data.getValue(ctx.expr2()); | ||
final String[] exps = M.split(exp); | ||
final String resposta = M.declVariavelMult(ids, exps); | ||
final String resposta = M.declVariavelMult(ids, exps, tipo); | ||
data.setValue(ctx, resposta.toString()); | ||
data.verificarDuplicados(M.string2List(id), ctx); | ||
data.verificarDuplicados(M.string2List(id), ctx, tipo.isEmpty()); | ||
} | ||
|
||
@Override | ||
public void exitDecl_var_simples(final Decl_var_simplesContext ctx) { | ||
final String id = data.getValue(ctx.id1()); | ||
final String tipo = data.getOrElse(ctx.tipo()); | ||
final String exp = data.getValue(ctx.expr()); | ||
final String resposta = M.declVariavel(id, exp); | ||
final String resposta = M.declVariavel(id, exp, tipo); | ||
data.setValue(ctx, resposta); | ||
data.verificarDuplicados(M.string2List(id), ctx); | ||
data.verificarDuplicados(M.string2List(id), ctx, tipo.isEmpty()); | ||
} | ||
|
||
@Override | ||
|
@@ -658,20 +660,22 @@ public void exitTupla(final TuplaContext ctx) { | |
@Override | ||
public void exitValor_multiplo(final Valor_multiploContext ctx) { | ||
final List<String> ids = M.string2List(data.getValue(ctx.id2())); | ||
final String tipo = data.getOrElse(ctx.tipo()); | ||
final List<String> exps = M.string2List(data.getValue(ctx.expr2())); | ||
final String resposta = M.valorMultiplo(ids, exps); | ||
final String resposta = M.valorMultiplo(ids, exps, tipo); | ||
data.setValue(ctx, resposta); | ||
data.verificarDuplicados(ids, ctx); | ||
data.verificarDuplicados(ids, ctx, tipo.isEmpty()); | ||
} | ||
|
||
@Override | ||
public void exitValor_simples(final Valor_simplesContext ctx) { | ||
final String id = data.getValue(ctx.id1()); | ||
final String tipo = data.getOrElse(ctx.tipo()); | ||
final String exp = data.getValue(ctx.expr()); | ||
final List<String> ids = M.string2List(id); | ||
final String resposta = M.declValor(id, exp); | ||
final String resposta = M.declValor(id, exp, tipo); | ||
data.setValue(ctx, resposta); | ||
data.verificarDuplicados(ids, ctx); | ||
data.verificarDuplicados(ids, ctx, tipo.isEmpty()); | ||
} | ||
|
||
@Override | ||
|
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
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