Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ide swing #1

Merged
merged 27 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
with:
java-version: '22'
java-version: '23-ea'
distribution: 'graalvm'
cache: 'maven'
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -31,12 +31,18 @@ jobs:
- name: Example step using Maven plugin
run: |
cd dev.thihup.jvisualg.ide
mvn --no-transfer-progress -Pnative -DautoClose=true gluonfx:runagent
mvn --no-transfer-progress -Pnative gluonfx:build
mvn --no-transfer-progress -Pnative package
- name: Compress
run: |
mkdir dev.thihup.jvisualg.ide/target/lib
copy $env:JAVA_HOME/lib/fontconfig.bfc dev.thihup.jvisualg.ide/target/lib
Get-ChildItem -Path dev.thihup.jvisualg.ide/target/*.dll, dev.thihup.jvisualg.ide/target/JVisualG.exe |
Compress-Archive -DestinationPath dev.thihup.jvisualg.ide/target/JVisualG.zip
Compress-Archive -Path dev.thihup.jvisualg.ide/target/lib -DestinationPath dev.thihup.jvisualg.ide/target/JVisualG.zip -Update
- name: Release
uses: ncipollo/release-action@v1
with:
artifacts: "dev.thihup.jvisualg.ide/target/gluonfx/x86_64-windows/JVisualG.exe"
artifacts: "dev.thihup.jvisualg.ide/target/JVisualG.zip"
replacesArtifacts: true
tag: JVisualg
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
algoritmo "semnome"

CONST
MAX = 2

tipo

UDT1 = registro
x: inteiro
fimregistro

UDT2 = registro
x: inteiro
z: UDT1
fimregistro

procedimento referencia(var x: logico)
inicio
x <- verdadeiro
fimprocedimento

funcao narrowArguments(x: inteiro): inteiro
inicio
retorne x
fimfuncao

funcao widenArguments(x: real): real
inicio
retorne x
fimfuncao

VAR
A: UDT1
B: UDT2
C: vetor[0..MAX] de UDT1
D: vetor[0..MAX] de UDT2

arrayInteiro: vetor[1..10] de inteiro
matrizInteiro: vetor[1..2,1..2] de inteiro

arrayReal: vetor[1..10] de real
matrizReal: vetor[1..2,1..2] de real


arrayLogico: vetor[1..10] de logico
matrizLogico: vetor[1..2,1..2] de logico


arrayCaracter: vetor[1..10] de caracter
matrizCaracter: vetor[1..2,1..2] de caracter


flutuante: real

meuInteiro: inteiro
meuReal: real
meuCaracter: caracter
meuLogico: logico

x, y, resultado: real
texto1, texto2, resultadoStr: caracter
i: inteiro

inicio

aleatorio on

leia(A.x)
leia(B.x)
leia(C[0].x)
leia(D[0].x)

escreval(A.x)

escreval(B.x)

escreval(C[0].x)

escreval(D[0].x)

A.x <- 4
B.x <- 1
C[0].x <- 3
D[0].x <- 8

escreval(A.x)

escreval(B.x)

escreval(C[0].x)

escreval(D[0].x)

// *** Fun��es Matem�ticas ***

x := 5.0
y := 10.0

resultado := ABS(x)
resultado := ARCCOS(x)
resultado := ARCSEN(x)
resultado := ARCTAN(x)
resultado := COS(x)
resultado := COTAN(x)
resultado := EXP(x, y)
resultado := GRAUPRAD(x)
resultado := INT(x)
resultado := LOG(x)
resultado := LOGN(x)
resultado := PI()
resultado := QUAD(x)
resultado := RADPGRAU(x)
resultado := RAIZQ(x)
resultado := RAND()
i := RANDI(100)
resultado := SEN(x)
resultado := TAN(x)

// *** Fun��es de Strings ***

texto1 := "1000"
texto2 := "1"

i := ASC(texto1)
resultadoStr := CARAC(65)
i := CARACPNUM(texto1)
i := COMPR(texto1)
resultadoStr := COPIA(texto1, 2, 3)
resultadoStr := MAIUSC(texto1)
resultadoStr := MINUSC(texto1)
resultadoStr := NUMPCARAC(65)
i := POS(texto2, texto1)


aleatorio on

mudaCor("VERMELHO", "FRENTE")
mudaCor("Amarelo", "FUNDOS")
mudaCor("azul", "FRENTE")
mudaCor("branco", "FUNDOS")
mudaCor("preto", "FUNDOS")
mudaCor("verde", "FUNDOS")

flutuante <- pi
meuInteiro <- narrowArguments(flutuante)
escreval(meuInteiro)

meuReal <- widenArguments(12)
escreval(meuReal)
meuReal <- widenArguments(meuInteiro)

leia(arrayInteiro[1])
leia(matrizInteiro[1,2])

escreval(arrayInteiro[1])
escreval(matrizInteiro[1,2])

arrayInteiro[1] <- 5
matrizInteiro[1,2] <- 10

arrayReal[1] <- arrayInteiro[1]
matrizReal[1, 2] <- arrayInteiro[1]

meuReal <- 2 ^ 5

debug 1 < 1

referencia(meuLogico)

escreval(+meuInteiro)
escreval(+meuReal)

escolha arrayInteiro[1] faca
caso 4
escreval("Nao aparecer")
caso 5
escreval("Apareci")
fimescolha

escolha matrizInteiro[1,2] faca
caso 1 ate 3
escreval("Nao aparecer")
caso 4 ate 10
escreval("Apareci")
fimescolha

leia(meuCaracter)
leia(meuLogico)
leia(meuInteiro)
leia(meuReal)

fimalgoritmo
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
algoritmo "FuncoesMatematicasEStrings"


var
x, y, resultado: real
texto1, texto2, resultadoStr: caracter
i: inteiro

inicio
// *** Fun��es Matem�ticas ***

x := 5.0
y := 10.0

resultado := ABS(x)
resultado := ARCCOS(x)
resultado := ARCSEN(x)
resultado := ARCTAN(x)
resultado := COS(x)
resultado := COTAN(x)
resultado := EXP(x, y)
resultado := GRAUPRAD(x)
resultado := INT(x)
resultado := LOG(x)
resultado := LOGN(x)
resultado := PI()
resultado := QUAD(x)
resultado := RADPGRAU(x)
resultado := RAIZQ(x)
resultado := RAND()
i := RANDI(100)
resultado := SEN(x)
resultado := TAN(x)

// *** Fun��es de Strings ***

texto1 := "1000"
texto2 := "1"

i := ASC(texto1)
resultadoStr := CARAC(65)
i := CARACPNUM(texto1)
i := COMPR(texto1)
resultadoStr := COPIA(texto1, 2, 3)
resultadoStr := MAIUSC(texto1)
resultadoStr := MINUSC(texto1)
resultadoStr := NUMPCARAC(65)
i := POS(texto2, texto1)

fimalgoritmo
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ REAL_LITERAL : [0-9]+ '.' [0-9]*;
// String literals
STRING : '"' (~["\r\n] | '\\"' | '\\\\')* '"';

// Unterminated string literal
UNCLOSED_STRING : '"' (~["\r\n] | '\\"' | '\\\\')* -> channel(HIDDEN);

// Logical literals
VERDADEIRO : 'verdadeiro';
FALSO : 'falso';
Expand Down Expand Up @@ -106,7 +109,15 @@ DOT : '.';
ID : [a-z_][a-z0-9_]*;

// Comments
COMMENT : '//' ~[\r\n]* -> skip;
COMMENT: '{' .*? '}' -> channel(HIDDEN);
LINE_COMMENT : '//' ~[\r\n]* -> channel(HIDDEN);

// Whitespace
WS : [ \t\r\n]+ -> skip;
WS : [ \t\r\n]+ -> channel(HIDDEN);

// Error handling
ERROR : . ;

// Fragment to avoid confusion with other token rules
fragment DIGIT : [0-9];
fragment LETTER : [a-z_];
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,14 @@ record Constant(String name, Type type, Location location) implements Declaratio
}
}

sealed interface Subprogram extends Declaration {
String name();
SequencedMap<String, Variable> parameters();
Location location();
}

record Function(String name, Type returnType, SequencedMap<String, Variable> parameters,
Location location) implements Declaration {
Location location) implements Subprogram {
public Function {
name = name.toLowerCase();
}
Expand All @@ -103,7 +109,7 @@ record Function(String name, Type returnType, SequencedMap<String, Variable> par
}

record Procedure(String name, SequencedMap<String, Variable> parameters,
Location location) implements Declaration {
Location location) implements Subprogram {
public Procedure {
name = name.toLowerCase();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,28 @@ static class BaseErrorListener extends org.antlr.v4.runtime.BaseErrorListener {
final List<Error> errors = new ArrayList<>();

@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
errors.add(new Error(msg, new Location(line, charPositionInLine, line, charPositionInLine)));
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException exception) {

int startIndex;
int length = -1;
if (offendingSymbol instanceof Token errorToken) {
startIndex = errorToken.getStartIndex();
length = errorToken.getStopIndex() - startIndex + 1;
} else if (exception != null) {
if (exception.getOffendingToken() != null) {
startIndex = exception.getOffendingToken().getStartIndex();
length = exception.getOffendingToken().getStopIndex() - startIndex + 1;
} else if (exception instanceof LexerNoViableAltException) {
length = 1;
}
}

if (length == 0) {
length = -1;
}


errors.add(new Error(msg, new Location(line, charPositionInLine, line, charPositionInLine + length)));
}
}

Expand Down
6 changes: 2 additions & 4 deletions dev.thihup.jvisualg.frontend/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import org.jspecify.annotations.NullMarked;

@NullMarked
module dev.thihup.jvisualg.frontend {
requires org.antlr.antlr4.runtime;
requires org.jspecify;
Expand All @@ -11,6 +8,7 @@
dev.thihup.jvisualg.interpreter, dev.thihup.jvisualg.ide;
exports dev.thihup.jvisualg.frontend to
dev.thihup.jvisualg.lsp,
dev.thihup.jvisualg.interpreter;
dev.thihup.jvisualg.interpreter, dev.thihup.jvisualg.ide;
exports dev.thihup.jvisualg.frontend.impl.antlr;

}
Loading