MOD() { return getTokens(VSLParser.MOD); }
- public TerminalNode MOD(int i) {
- return getToken(VSLParser.MOD, i);
- }
- public Td_expressionContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
- public Td_expressionContext(ParserRuleContext parent, int invokingState, SymTable table) {
- super(parent, invokingState);
- this.table = table;
- }
- @Override public int getRuleIndex() { return RULE_td_expression; }
- }
-
- public final Td_expressionContext td_expression(SymTable table) throws RecognitionException {
- Td_expressionContext _localctx = new Td_expressionContext(_ctx, getState(), table);
- enterRule(_localctx, 12, RULE_td_expression);
- int _la;
- try {
- enterOuterAlt(_localctx, 1);
- {
- setState(61);
- ((Td_expressionContext)_localctx).left = lit(table);
-
- ((Td_expressionContext)_localctx).out = ((Td_expressionContext)_localctx).left.out;
- ((Td_expressionContext)_localctx).return_Type = ((Td_expressionContext)_localctx).left.return_Type;
-
- setState(69);
- _errHandler.sync(this);
- _la = _input.LA(1);
- while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 469762048L) != 0)) {
- {
- {
- setState(63);
- ((Td_expressionContext)_localctx).op = _input.LT(1);
- _la = _input.LA(1);
- if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 469762048L) != 0)) ) {
- ((Td_expressionContext)_localctx).op = (Token)_errHandler.recoverInline(this);
- }
- else {
- if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
- _errHandler.reportMatch(this);
- consume();
- }
- setState(64);
- ((Td_expressionContext)_localctx).right = lit(table);
-
- ((Td_expressionContext)_localctx).out = new Program.BinopExpressionImp(
- switch(((Td_expressionContext)_localctx).op.getType()) {
- case TIMES -> Op.TIMES;
- case DIV -> Op.DIV;
- case MOD -> Op.MOD;
- default -> throw new IllegalArgumentException("Unknown operator");
- },
- _localctx.out,
- ((Td_expressionContext)_localctx).right.out
- );
- ((Td_expressionContext)_localctx).return_Type = ((Td_expressionContext)_localctx).left.return_Type;
-
- }
- }
- setState(71);
- _errHandler.sync(this);
- _la = _input.LA(1);
- }
- }
- }
- catch (RecognitionException re) {
- _localctx.exception = re;
- _errHandler.reportError(this, re);
- _errHandler.recover(this, re);
- }
- finally {
- exitRule();
- }
- return _localctx;
- }
-
- @SuppressWarnings("CheckReturnValue")
- public static class LitContext extends ParserRuleContext {
- public SymTable table;
- public Expression out;
- public Type return_Type;
- public Token NUMBER;
- public ExpressionContext e;
- public TerminalNode NUMBER() { return getToken(VSLParser.NUMBER, 0); }
- public TerminalNode ParO() { return getToken(VSLParser.ParO, 0); }
- public TerminalNode ParF() { return getToken(VSLParser.ParF, 0); }
- public ExpressionContext expression() {
- return getRuleContext(ExpressionContext.class,0);
- }
- public LitContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
- public LitContext(ParserRuleContext parent, int invokingState, SymTable table) {
- super(parent, invokingState);
- this.table = table;
- }
- @Override public int getRuleIndex() { return RULE_lit; }
- }
-
- public final LitContext lit(SymTable table) throws RecognitionException {
- LitContext _localctx = new LitContext(_ctx, getState(), table);
- enterRule(_localctx, 14, RULE_lit);
- try {
- setState(79);
- _errHandler.sync(this);
- switch (_input.LA(1)) {
- case NUMBER:
- enterOuterAlt(_localctx, 1);
- {
- setState(72);
- ((LitContext)_localctx).NUMBER = match(NUMBER);
-
- ((LitContext)_localctx).return_Type = new Type_intImp();
- ((LitContext)_localctx).out = new ConstImp((((LitContext)_localctx).NUMBER!=null?Integer.valueOf(((LitContext)_localctx).NUMBER.getText()):0));
-
- }
- break;
- case ParO:
- enterOuterAlt(_localctx, 2);
- {
- setState(74);
- match(ParO);
- setState(75);
- ((LitContext)_localctx).e = expression(table);
- setState(76);
- match(ParF);
-
- ((LitContext)_localctx).out = ((LitContext)_localctx).e.out;
- ((LitContext)_localctx).return_Type = ((LitContext)_localctx).e.return_Type;
-
- }
- break;
- default:
- throw new NoViableAltException(this);
- }
- }
- catch (RecognitionException re) {
- _localctx.exception = re;
- _errHandler.reportError(this, re);
- _errHandler.recover(this, re);
- }
- finally {
- exitRule();
- }
- return _localctx;
- }
-
- @SuppressWarnings("CheckReturnValue")
- public static class IdentContext extends ParserRuleContext {
- public String out;
- public Token IDENT;
- public TerminalNode IDENT() { return getToken(VSLParser.IDENT, 0); }
- public IdentContext(ParserRuleContext parent, int invokingState) {
- super(parent, invokingState);
- }
- @Override public int getRuleIndex() { return RULE_ident; }
- }
-
- public final IdentContext ident() throws RecognitionException {
- IdentContext _localctx = new IdentContext(_ctx, getState());
- enterRule(_localctx, 16, RULE_ident);
- try {
- enterOuterAlt(_localctx, 1);
- {
- setState(81);
- ((IdentContext)_localctx).IDENT = match(IDENT);
- ((IdentContext)_localctx).out = ((IdentContext)_localctx).IDENT.getText();
- }
- }
- catch (RecognitionException re) {
- _localctx.exception = re;
- _errHandler.reportError(this, re);
- _errHandler.recover(this, re);
- }
- finally {
- exitRule();
- }
- return _localctx;
- }
-
- @SuppressWarnings("CheckReturnValue")
- public static class TypeContext extends ParserRuleContext {
- public Type return_type;
- public TerminalNode TYPE_INT() { return getToken(VSLParser.TYPE_INT, 0); }
- public TerminalNode TYPE_VOID() { return getToken(VSLParser.TYPE_VOID, 0); }
- public TypeContext(ParserRuleContext parent, int invokingState) {
- super(parent, invokingState);
- }
- @Override public int getRuleIndex() { return RULE_type; }
- }
-
- public final TypeContext type() throws RecognitionException {
- TypeContext _localctx = new TypeContext(_ctx, getState());
- enterRule(_localctx, 18, RULE_type);
- try {
- setState(88);
- _errHandler.sync(this);
- switch (_input.LA(1)) {
- case TYPE_INT:
- enterOuterAlt(_localctx, 1);
- {
- setState(84);
- match(TYPE_INT);
- ((TypeContext)_localctx).return_type = new Type_intImp();
- }
- break;
- case TYPE_VOID:
- enterOuterAlt(_localctx, 2);
- {
- setState(86);
- match(TYPE_VOID);
- ((TypeContext)_localctx).return_type = new Type_voidImp();
- }
- break;
- default:
- throw new NoViableAltException(this);
- }
- }
- catch (RecognitionException re) {
- _localctx.exception = re;
- _errHandler.reportError(this, re);
- _errHandler.recover(this, re);
- }
- finally {
- exitRule();
- }
- return _localctx;
- }
-
- public static final String _serializedATN =
- "\u0004\u0001\u001f[\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+
- "\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004\u0007\u0004\u0002"+
- "\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007\u0007\u0007\u0002"+
- "\b\u0007\b\u0002\t\u0007\t\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000"+
- "\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
- "\u0001\u0001\u0001\u0001\u0005\u0001!\b\u0001\n\u0001\f\u0001$\t\u0001"+
- "\u0001\u0002\u0001\u0002\u0001\u0003\u0001\u0003\u0001\u0003\u0004\u0003"+
- "+\b\u0003\u000b\u0003\f\u0003,\u0001\u0004\u0001\u0004\u0001\u0004\u0001"+
- "\u0004\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001"+
- "\u0005\u0005\u00059\b\u0005\n\u0005\f\u0005<\t\u0005\u0001\u0006\u0001"+
- "\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0005\u0006D\b"+
- "\u0006\n\u0006\f\u0006G\t\u0006\u0001\u0007\u0001\u0007\u0001\u0007\u0001"+
- "\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0003\u0007P\b\u0007\u0001"+
- "\b\u0001\b\u0001\b\u0001\t\u0001\t\u0001\t\u0001\t\u0003\tY\b\t\u0001"+
- "\t\u0000\u0000\n\u0000\u0002\u0004\u0006\b\n\f\u000e\u0010\u0012\u0000"+
- "\u0002\u0001\u0000\u0018\u0019\u0001\u0000\u001a\u001cV\u0000\u0014\u0001"+
- "\u0000\u0000\u0000\u0002\"\u0001\u0000\u0000\u0000\u0004%\u0001\u0000"+
- "\u0000\u0000\u0006*\u0001\u0000\u0000\u0000\b.\u0001\u0000\u0000\u0000"+
- "\n2\u0001\u0000\u0000\u0000\f=\u0001\u0000\u0000\u0000\u000eO\u0001\u0000"+
- "\u0000\u0000\u0010Q\u0001\u0000\u0000\u0000\u0012X\u0001\u0000\u0000\u0000"+
- "\u0014\u0015\u0003\u0002\u0001\u0000\u0015\u0016\u0005\u0000\u0000\u0001"+
- "\u0016\u0017\u0006\u0000\uffff\uffff\u0000\u0017\u0001\u0001\u0000\u0000"+
- "\u0000\u0018\u0019\u0005\u0001\u0000\u0000\u0019\u001a\u0003\u0012\t\u0000"+
- "\u001a\u001b\u0003\u0010\b\u0000\u001b\u001c\u0005\u0016\u0000\u0000\u001c"+
- "\u001d\u0005\u0017\u0000\u0000\u001d\u001e\u0003\u0006\u0003\u0000\u001e"+
- "\u001f\u0006\u0001\uffff\uffff\u0000\u001f!\u0001\u0000\u0000\u0000 \u0018"+
- "\u0001\u0000\u0000\u0000!$\u0001\u0000\u0000\u0000\" \u0001\u0000\u0000"+
- "\u0000\"#\u0001\u0000\u0000\u0000#\u0003\u0001\u0000\u0000\u0000$\"\u0001"+
- "\u0000\u0000\u0000%&\u0001\u0000\u0000\u0000&\u0005\u0001\u0000\u0000"+
- "\u0000\'(\u0003\b\u0004\u0000()\u0006\u0003\uffff\uffff\u0000)+\u0001"+
- "\u0000\u0000\u0000*\'\u0001\u0000\u0000\u0000+,\u0001\u0000\u0000\u0000"+
- ",*\u0001\u0000\u0000\u0000,-\u0001\u0000\u0000\u0000-\u0007\u0001\u0000"+
- "\u0000\u0000./\u0005\u0013\u0000\u0000/0\u0003\n\u0005\u000001\u0006\u0004"+
- "\uffff\uffff\u00001\t\u0001\u0000\u0000\u000023\u0003\f\u0006\u00003:"+
- "\u0006\u0005\uffff\uffff\u000045\u0007\u0000\u0000\u000056\u0003\f\u0006"+
- "\u000067\u0006\u0005\uffff\uffff\u000079\u0001\u0000\u0000\u000084\u0001"+
- "\u0000\u0000\u00009<\u0001\u0000\u0000\u0000:8\u0001\u0000\u0000\u0000"+
- ":;\u0001\u0000\u0000\u0000;\u000b\u0001\u0000\u0000\u0000<:\u0001\u0000"+
- "\u0000\u0000=>\u0003\u000e\u0007\u0000>E\u0006\u0006\uffff\uffff\u0000"+
- "?@\u0007\u0001\u0000\u0000@A\u0003\u000e\u0007\u0000AB\u0006\u0006\uffff"+
- "\uffff\u0000BD\u0001\u0000\u0000\u0000C?\u0001\u0000\u0000\u0000DG\u0001"+
- "\u0000\u0000\u0000EC\u0001\u0000\u0000\u0000EF\u0001\u0000\u0000\u0000"+
- "F\r\u0001\u0000\u0000\u0000GE\u0001\u0000\u0000\u0000HI\u0005\u0015\u0000"+
- "\u0000IP\u0006\u0007\uffff\uffff\u0000JK\u0005\u0016\u0000\u0000KL\u0003"+
- "\n\u0005\u0000LM\u0005\u0017\u0000\u0000MN\u0006\u0007\uffff\uffff\u0000"+
- "NP\u0001\u0000\u0000\u0000OH\u0001\u0000\u0000\u0000OJ\u0001\u0000\u0000"+
- "\u0000P\u000f\u0001\u0000\u0000\u0000QR\u0005\u001d\u0000\u0000RS\u0006"+
- "\b\uffff\uffff\u0000S\u0011\u0001\u0000\u0000\u0000TU\u0005\u0003\u0000"+
- "\u0000UY\u0006\t\uffff\uffff\u0000VW\u0005\u0004\u0000\u0000WY\u0006\t"+
- "\uffff\uffff\u0000XT\u0001\u0000\u0000\u0000XV\u0001\u0000\u0000\u0000"+
- "Y\u0013\u0001\u0000\u0000\u0000\u0006\",:EOX";
- public static final ATN _ATN =
- new ATNDeserializer().deserialize(_serializedATN.toCharArray());
- static {
- _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
- for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
- _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
- }
- }
-}
\ No newline at end of file
diff --git a/src/main/antlr/.antlr/VSLParser.tokens b/src/main/antlr/.antlr/VSLParser.tokens
deleted file mode 100644
index 69a58ba..0000000
--- a/src/main/antlr/.antlr/VSLParser.tokens
+++ /dev/null
@@ -1,57 +0,0 @@
-FUNCTION=1
-PROTOTYPE=2
-TYPE_INT=3
-TYPE_VOID=4
-LE=5
-LT=6
-GE=7
-GT=8
-ASSIGN=9
-IF=10
-THEN=11
-ELSE=12
-FIN=13
-WHILE=14
-DO=15
-DONE=16
-READ=17
-PRINT=18
-RETURN=19
-TEXT=20
-NUMBER=21
-ParO=22
-ParF=23
-PLUS=24
-MINUS=25
-DIV=26
-TIMES=27
-MOD=28
-IDENT=29
-WS=30
-COMMENT=31
-'FUNC'=1
-'PROTO'=2
-'INT'=3
-'VOID'=4
-'<='=5
-'<'=6
-'>='=7
-'>'=8
-':='=9
-'IF'=10
-'THEN'=11
-'ELSE'=12
-'FI'=13
-'WHILE'=14
-'DO'=15
-'DONE'=16
-'READ'=17
-'PRINT'=18
-'RETURN'=19
-'('=22
-')'=23
-'+'=24
-'-'=25
-'/'=26
-'*'=27
-'%'=28
diff --git a/src/main/antlr/.antlr/VSLParserBaseListener.java b/src/main/antlr/.antlr/VSLParserBaseListener.java
deleted file mode 100644
index 1b05a5b..0000000
--- a/src/main/antlr/.antlr/VSLParserBaseListener.java
+++ /dev/null
@@ -1,166 +0,0 @@
-// Generated from c:/Users/Thibaut/Documents/Git/PDS/tp2-vsl-pds/src/main/antlr/VSLParser.g by ANTLR 4.13.1
-
- package TP2;
- import TP2.asd.Program.*;
- import TP2.asd.*;
- import TP2.asd.Interface.*;
- import TP2.asd.Eval.*;
-
-
-import org.antlr.v4.runtime.ParserRuleContext;
-import org.antlr.v4.runtime.tree.ErrorNode;
-import org.antlr.v4.runtime.tree.TerminalNode;
-
-/**
- * This class provides an empty implementation of {@link VSLParserListener},
- * which can be extended to create a listener which only needs to handle a subset
- * of the available methods.
- */
-@SuppressWarnings("CheckReturnValue")
-public class VSLParserBaseListener implements VSLParserListener {
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void enterProgram(VSLParser.ProgramContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void exitProgram(VSLParser.ProgramContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void enterFunction(VSLParser.FunctionContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void exitFunction(VSLParser.FunctionContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void enterPrototype(VSLParser.PrototypeContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void exitPrototype(VSLParser.PrototypeContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void enterList_instr(VSLParser.List_instrContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void exitList_instr(VSLParser.List_instrContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void enterInstruction(VSLParser.InstructionContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void exitInstruction(VSLParser.InstructionContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void enterExpression(VSLParser.ExpressionContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void exitExpression(VSLParser.ExpressionContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void enterTd_expression(VSLParser.Td_expressionContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void exitTd_expression(VSLParser.Td_expressionContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void enterLit(VSLParser.LitContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void exitLit(VSLParser.LitContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void enterIdent(VSLParser.IdentContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void exitIdent(VSLParser.IdentContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void enterType(VSLParser.TypeContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void exitType(VSLParser.TypeContext ctx) { }
-
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void enterEveryRule(ParserRuleContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void exitEveryRule(ParserRuleContext ctx) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void visitTerminal(TerminalNode node) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- @Override public void visitErrorNode(ErrorNode node) { }
-}
\ No newline at end of file
diff --git a/src/main/antlr/.antlr/VSLParserListener.java b/src/main/antlr/.antlr/VSLParserListener.java
deleted file mode 100644
index ab73cf1..0000000
--- a/src/main/antlr/.antlr/VSLParserListener.java
+++ /dev/null
@@ -1,116 +0,0 @@
-// Generated from c:/Users/Thibaut/Documents/Git/PDS/tp2-vsl-pds/src/main/antlr/VSLParser.g by ANTLR 4.13.1
-
- package TP2;
- import TP2.asd.Program.*;
- import TP2.asd.*;
- import TP2.asd.Interface.*;
- import TP2.asd.Eval.*;
-
-import org.antlr.v4.runtime.tree.ParseTreeListener;
-
-/**
- * This interface defines a complete listener for a parse tree produced by
- * {@link VSLParser}.
- */
-public interface VSLParserListener extends ParseTreeListener {
- /**
- * Enter a parse tree produced by {@link VSLParser#program}.
- * @param ctx the parse tree
- */
- void enterProgram(VSLParser.ProgramContext ctx);
- /**
- * Exit a parse tree produced by {@link VSLParser#program}.
- * @param ctx the parse tree
- */
- void exitProgram(VSLParser.ProgramContext ctx);
- /**
- * Enter a parse tree produced by {@link VSLParser#function}.
- * @param ctx the parse tree
- */
- void enterFunction(VSLParser.FunctionContext ctx);
- /**
- * Exit a parse tree produced by {@link VSLParser#function}.
- * @param ctx the parse tree
- */
- void exitFunction(VSLParser.FunctionContext ctx);
- /**
- * Enter a parse tree produced by {@link VSLParser#prototype}.
- * @param ctx the parse tree
- */
- void enterPrototype(VSLParser.PrototypeContext ctx);
- /**
- * Exit a parse tree produced by {@link VSLParser#prototype}.
- * @param ctx the parse tree
- */
- void exitPrototype(VSLParser.PrototypeContext ctx);
- /**
- * Enter a parse tree produced by {@link VSLParser#list_instr}.
- * @param ctx the parse tree
- */
- void enterList_instr(VSLParser.List_instrContext ctx);
- /**
- * Exit a parse tree produced by {@link VSLParser#list_instr}.
- * @param ctx the parse tree
- */
- void exitList_instr(VSLParser.List_instrContext ctx);
- /**
- * Enter a parse tree produced by {@link VSLParser#instruction}.
- * @param ctx the parse tree
- */
- void enterInstruction(VSLParser.InstructionContext ctx);
- /**
- * Exit a parse tree produced by {@link VSLParser#instruction}.
- * @param ctx the parse tree
- */
- void exitInstruction(VSLParser.InstructionContext ctx);
- /**
- * Enter a parse tree produced by {@link VSLParser#expression}.
- * @param ctx the parse tree
- */
- void enterExpression(VSLParser.ExpressionContext ctx);
- /**
- * Exit a parse tree produced by {@link VSLParser#expression}.
- * @param ctx the parse tree
- */
- void exitExpression(VSLParser.ExpressionContext ctx);
- /**
- * Enter a parse tree produced by {@link VSLParser#td_expression}.
- * @param ctx the parse tree
- */
- void enterTd_expression(VSLParser.Td_expressionContext ctx);
- /**
- * Exit a parse tree produced by {@link VSLParser#td_expression}.
- * @param ctx the parse tree
- */
- void exitTd_expression(VSLParser.Td_expressionContext ctx);
- /**
- * Enter a parse tree produced by {@link VSLParser#lit}.
- * @param ctx the parse tree
- */
- void enterLit(VSLParser.LitContext ctx);
- /**
- * Exit a parse tree produced by {@link VSLParser#lit}.
- * @param ctx the parse tree
- */
- void exitLit(VSLParser.LitContext ctx);
- /**
- * Enter a parse tree produced by {@link VSLParser#ident}.
- * @param ctx the parse tree
- */
- void enterIdent(VSLParser.IdentContext ctx);
- /**
- * Exit a parse tree produced by {@link VSLParser#ident}.
- * @param ctx the parse tree
- */
- void exitIdent(VSLParser.IdentContext ctx);
- /**
- * Enter a parse tree produced by {@link VSLParser#type}.
- * @param ctx the parse tree
- */
- void enterType(VSLParser.TypeContext ctx);
- /**
- * Exit a parse tree produced by {@link VSLParser#type}.
- * @param ctx the parse tree
- */
- void exitType(VSLParser.TypeContext ctx);
-}
\ No newline at end of file
diff --git a/src/main/antlr/VSLLexer.g b/src/main/antlr/VSLLexer.g
index 0650516..ea274fc 100644
--- a/src/main/antlr/VSLLexer.g
+++ b/src/main/antlr/VSLLexer.g
@@ -54,6 +54,10 @@ ParO: '('
;
ParF: ')'
;
+BacO: '{'
+ ;
+BacF: '}'
+ ;
PLUS: '+'
;
MINUS: '-'
@@ -64,9 +68,11 @@ TIMES: '*'
;
MOD: '%'
;
+VIRGULE: ','
+ ;
IDENT: ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'-')*
;
-WS : (' '|'\n'|'\t') { skip(); }
+WS : (' '|'\n'|'\t'| '\r') { skip(); }
;
COMMENT : '//' (~'\n')* { skip(); }
diff --git a/src/main/antlr/VSLParser.g b/src/main/antlr/VSLParser.g
index cd90e99..3559c02 100644
--- a/src/main/antlr/VSLParser.g
+++ b/src/main/antlr/VSLParser.g
@@ -31,12 +31,23 @@ program returns [ProgramImp p] :
function returns [ArrayList out]
@init{
SymTable sym_table = new SymTable();
+ sym_table.next_layer();
$out = new ArrayList();
}:
- (FUNCTION t=type i=ident ParO ParF instrs=list_instr[sym_table]
- {
- $out.add(new FunctionImp($t.return_type, $i.out, $instrs.out));
- })*
+ (FUNCTION t=type i=ident ParO ParF
+ (
+ BacO instrs=list_instr[sym_table] BacF
+ {
+ $out.add(new FunctionImp($t.return_type, $i.out, $instrs.out));
+ }
+ | instr= instruction[sym_table]
+ {
+ ArrayList single = new ArrayList();
+ single.add($instr.out);
+ $out.add(new FunctionImp($t.return_type, $i.out, single));
+ }
+ )*
+ )
;
prototype returns [Program p]:
@@ -52,10 +63,25 @@ list_instr [SymTable table] returns [ArrayList out]
;
instruction [SymTable table] returns [Instruction out]:
+ //RETURN
RETURN e=expression [table]
{
$out =new Return_instrImp($e.out);}
-
+ //| //ASSIGN
+ //i=ident ASSIGN e=expression [table]
+ // {
+ // $out = new AssignImp($i.out, $e.out);
+ // }
+ | //DECLARATION
+ t=type i=ident
+ {
+ $table.addVar($i.out,$t.return_type);
+ $out = new DeclarationImp($t.return_type, $i.out);
+ }(VIRGULE i2=ident
+ {
+ $table.addVar($i2.out,$t.return_type);
+ $out = new DeclarationImp($t.return_type, $i2.out);
+ })*
;
//Priorité lit(val, const ou paranthese) -> td_exp (*/%) -> exp (+-)
diff --git a/src/main/java/TP2/asd/Interface.java b/src/main/java/TP2/asd/Interface.java
index ce449ac..6a65645 100644
--- a/src/main/java/TP2/asd/Interface.java
+++ b/src/main/java/TP2/asd/Interface.java
@@ -40,6 +40,7 @@ public interface Interface{
public interface InstrVisitor{
public S visitReturn(Return_instrImp e, H h);
public S visitAssign(AssignImp e, H h);
+ public S visitDeclaration(DeclarationImp e,H h);
}
//////////Expression
diff --git a/src/main/java/TP2/asd/Program.java b/src/main/java/TP2/asd/Program.java
index caee95d..be1845a 100644
--- a/src/main/java/TP2/asd/Program.java
+++ b/src/main/java/TP2/asd/Program.java
@@ -184,6 +184,25 @@ public class Program{
}
}
+ public static record DeclarationImp(Type t, String s) implements Instruction{
+
+ @Override
+ public S accept(InstrVisitor v, H h) {
+ return v.visitDeclaration(this, h);
+ }
+
+ @Override
+ public String prettyprinter(String indent) {
+ return "declare "+t.toString()+s;
+ }
+
+ @Override
+ public ArrayList toLLVM() {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException("Unimplemented method 'toLLVM'");
+ }
+
+ }
public static record Type_voidImp() implements Type{
public String prettyprinter() {
@@ -241,8 +260,7 @@ public class Program{
@Override
public Integer visitReturn(Return_instrImp e, Map h) {
- ExprEval exprEval = new ExprEval();
- return e.e().accept(exprEval, h);
+ return e.accept(this, h);
}
@Override
public Integer visitAssign(AssignImp e, Map h) {
@@ -250,6 +268,10 @@ public class Program{
//TODO
return 1;
}
+ @Override
+ public Integer visitDeclaration(DeclarationImp e, Map h) {
+ return e.accept(this, h);
+ }
}
diff --git a/src/main/java/TP2/asd/SymTable.java b/src/main/java/TP2/asd/SymTable.java
index 6135a44..9ac003f 100644
--- a/src/main/java/TP2/asd/SymTable.java
+++ b/src/main/java/TP2/asd/SymTable.java
@@ -45,4 +45,15 @@ public class SymTable {
}
return false;
}
+
+ public String print_all(){
+ StringBuilder str = new StringBuilder();
+ for(int i= stackMap.size()-1; i>=0; i--){
+ str.append("level ").append(i).append("\n");
+ for(String s: stackMap.get(i).keySet()){
+ str.append(s).append(" ").append(stackMap.get(i).get(s)).append("\n");
+ }
+ }
+ return str.toString();
+ }
}
diff --git a/src/main/java/TP2/asd/test_symtable.java b/src/main/java/TP2/asd/test_symtable.java
new file mode 100644
index 0000000..5c8d9bb
--- /dev/null
+++ b/src/main/java/TP2/asd/test_symtable.java
@@ -0,0 +1,15 @@
+package TP2.asd;
+import TP2.asd.Interface.*;
+import TP2.asd.Program.Type_intImp;
+import TP2.asd.SymTable.*;
+public class test_symtable{
+ private static final Type Type_intImp = null;
+
+ public static void main(String[] args){
+ SymTable test_symTable = new SymTable();
+ test_symTable.next_layer();
+ //test_symTable.peppapeek();
+ test_symTable.addVar("a", Type_intImp);
+ System.out.print(test_symTable.print_all());
+ }
+}
\ No newline at end of file
diff --git a/tests/aLaMain.vsl b/tests/aLaMain.vsl
index 29a0cda..ea5d850 100644
--- a/tests/aLaMain.vsl
+++ b/tests/aLaMain.vsl
@@ -1 +1,3 @@
- FUNC INT main() RETURN 0 + 1
\ No newline at end of file
+FUNC INT main() {
+ INT a
+ RETURN 4 + 6 * 5 + 3 }
\ No newline at end of file