From 3434e971780159b9d97001dd1b870e149b38bd45 Mon Sep 17 00:00:00 2001 From: szabototo89 Date: Wed, 5 Feb 2014 22:40:50 +0100 Subject: [PATCH] Added MetaCode lexer grammar --- grammar/MetaCode.g4 | 23 ++++ grammar/example.txt | 2 + grammar/run.rb | 11 ++ grammar/src/MetaCode.tokens | 3 + grammar/src/MetaCodeBaseListener.class | Bin 0 -> 982 bytes grammar/src/MetaCodeBaseListener.java | 51 ++++++++ grammar/src/MetaCodeBaseVisitor.class | Bin 0 -> 816 bytes grammar/src/MetaCodeBaseVisitor.java | 21 ++++ grammar/src/MetaCodeLexer.class | Bin 0 -> 3237 bytes grammar/src/MetaCodeLexer.java | 96 ++++++++++++++ grammar/src/MetaCodeLexer.tokens | 3 + grammar/src/MetaCodeListener.class | Bin 0 -> 437 bytes grammar/src/MetaCodeListener.java | 20 +++ grammar/src/MetaCodeParser$InitContext.class | Bin 0 -> 1671 bytes grammar/src/MetaCodeParser.class | Bin 0 -> 3637 bytes grammar/src/MetaCodeParser.java | 125 +++++++++++++++++++ grammar/src/MetaCodeVisitor.class | Bin 0 -> 575 bytes grammar/src/MetaCodeVisitor.java | 19 +++ scripts/antlr4.rb | 39 ++++++ scripts/grun.bat | 1 + 20 files changed, 414 insertions(+) create mode 100644 grammar/MetaCode.g4 create mode 100644 grammar/example.txt create mode 100644 grammar/run.rb create mode 100644 grammar/src/MetaCode.tokens create mode 100644 grammar/src/MetaCodeBaseListener.class create mode 100644 grammar/src/MetaCodeBaseListener.java create mode 100644 grammar/src/MetaCodeBaseVisitor.class create mode 100644 grammar/src/MetaCodeBaseVisitor.java create mode 100644 grammar/src/MetaCodeLexer.class create mode 100644 grammar/src/MetaCodeLexer.java create mode 100644 grammar/src/MetaCodeLexer.tokens create mode 100644 grammar/src/MetaCodeListener.class create mode 100644 grammar/src/MetaCodeListener.java create mode 100644 grammar/src/MetaCodeParser$InitContext.class create mode 100644 grammar/src/MetaCodeParser.class create mode 100644 grammar/src/MetaCodeParser.java create mode 100644 grammar/src/MetaCodeVisitor.class create mode 100644 grammar/src/MetaCodeVisitor.java create mode 100644 scripts/antlr4.rb create mode 100644 scripts/grun.bat diff --git a/grammar/MetaCode.g4 b/grammar/MetaCode.g4 new file mode 100644 index 0000000..9ef2a0a --- /dev/null +++ b/grammar/MetaCode.g4 @@ -0,0 +1,23 @@ +grammar MetaCode; + +init : (NUMBER NEWLINE?)+ + ; + +WHITESPACE : [ \t]+ -> skip; +NEWLINE : '\r'? '\n' -> skip; + +NUMBER : INT + | FLOAT; + +fragment +INT : DIGIT+ + ; + +fragment +FLOAT : DIGIT+ '.' DIGIT* + | '.' DIGIT+ + ; + +fragment +DIGIT : [0-9] + ; \ No newline at end of file diff --git a/grammar/example.txt b/grammar/example.txt new file mode 100644 index 0000000..0b4445e --- /dev/null +++ b/grammar/example.txt @@ -0,0 +1,2 @@ +545 +18. \ No newline at end of file diff --git a/grammar/run.rb b/grammar/run.rb new file mode 100644 index 0000000..bed61a5 --- /dev/null +++ b/grammar/run.rb @@ -0,0 +1,11 @@ + example = if ARGV[0].nil? + File.open("example.txt", "w") if not File.exist?("example.txt") + "example.txt" + else + ARGV[0].to_s + end + puts "Running MetaCode parser ..." + Dir.mkdir("src") if not Dir.exists? "src" + Dir.chdir("src") + system('call antlr4 "../MetaCode.g4" -visitor') + system('call grun MetaCode init -gui ..\\' + example) diff --git a/grammar/src/MetaCode.tokens b/grammar/src/MetaCode.tokens new file mode 100644 index 0000000..4497d1d --- /dev/null +++ b/grammar/src/MetaCode.tokens @@ -0,0 +1,3 @@ +WHITESPACE=1 +NEWLINE=2 +NUMBER=3 diff --git a/grammar/src/MetaCodeBaseListener.class b/grammar/src/MetaCodeBaseListener.class new file mode 100644 index 0000000000000000000000000000000000000000..a9f99fa91c206bb0b1bd8d232092f14bf641330d GIT binary patch literal 982 zcmah{T}vB56g?BG+r%WsYOS$;QjxTZ3)VNKpus{QMp5y7l3rwFcNS)6gZ?a^3VrYg z_@l%-Ygcqt_T}E0JLjBx=FZ&R|GNe76Dt*rV9vu=5Az-t1jcriR`!>`NbCE#z=wA9 zhXf|NN>eWh`((~!Kj2E4v?bGFtcN9makpwmT)VOY)sEI=+JTH?iUpQh-9xg{NgYcQ zlUaR+-f?YKPZDiaNF6;?vEl}dlOb`3J*^`vt%@`Yed|W%!k5|x#vg9`=8@!wDjxW~ z$o7&T*b(?hSIW8$0`=78!H~@LN#bm;x89a`^yM)BFOk}+Ii+XpnsaB*$b?GE;C(e~ zi2MxJ<7=mC^^|>JOk`Y5p!JTKl>UTExs}r>F$4Oo+$EaXH1}mpT@_p6X>VT2p{!yQ zV*=A}0R$Qj;s;V+_(%Oq8t{M`88Vacuq-f_RbM|B&-CRXR#4(U#9xI!l*gGJaP)Y$ zz*%q}{qYy#h8O%c9NjTc<5=ccN})}zlpG=tn?jw-o)emI=V%mjnt9G7J{9#@&U2=U mIcs^&G(H#g*~oKd@TG{e^^#M + * The default implementation does nothing. + */ + @Override public void enterInit(@NotNull MetaCodeParser.InitContext ctx) { } + /** + * {@inheritDoc} + *

+ * The default implementation does nothing. + */ + @Override public void exitInit(@NotNull MetaCodeParser.InitContext ctx) { } + + /** + * {@inheritDoc} + *

+ * The default implementation does nothing. + */ + @Override public void enterEveryRule(@NotNull ParserRuleContext ctx) { } + /** + * {@inheritDoc} + *

+ * The default implementation does nothing. + */ + @Override public void exitEveryRule(@NotNull ParserRuleContext ctx) { } + /** + * {@inheritDoc} + *

+ * The default implementation does nothing. + */ + @Override public void visitTerminal(@NotNull TerminalNode node) { } + /** + * {@inheritDoc} + *

+ * The default implementation does nothing. + */ + @Override public void visitErrorNode(@NotNull ErrorNode node) { } +} \ No newline at end of file diff --git a/grammar/src/MetaCodeBaseVisitor.class b/grammar/src/MetaCodeBaseVisitor.class new file mode 100644 index 0000000000000000000000000000000000000000..74aa90e030a20573f4de279f00fc12fe6078d16d GIT binary patch literal 816 zcmaJyeHUZ3oe(-Zk~PF6qzBz-rE&l-i#i9>?N;aF$y(Luy;kOBhNa zJtQV~YHiAzO=^Y7i%#kWk+z(;X!JI6e}bZ+$@)<@%40_-VlPr!$JQmFdTa_h<@myWE$No~eN&hmu1vheBaUA$ih`*MXP zD9p)a7DP+OA|J_bN3;?>ck~_Vt32d3M3%>3Rb+@o3HGkL5?b)KqnF=M`0}6cI+g?} fU>Pf-1D|zO9>qI&4eMj`2CAY%u`b{#DwzKbYLwfp literal 0 HcmV?d00001 diff --git a/grammar/src/MetaCodeBaseVisitor.java b/grammar/src/MetaCodeBaseVisitor.java new file mode 100644 index 0000000..43031e9 --- /dev/null +++ b/grammar/src/MetaCodeBaseVisitor.java @@ -0,0 +1,21 @@ +// Generated from ../MetaCode.g4 by ANTLR 4.1 +import org.antlr.v4.runtime.misc.NotNull; +import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; + +/** + * This class provides an empty implementation of {@link MetaCodeVisitor}, + * which can be extended to create a visitor which only needs to handle a subset + * of the available methods. + * + * @param The return type of the visit operation. Use {@link Void} for + * operations with no return type. + */ +public class MetaCodeBaseVisitor extends AbstractParseTreeVisitor implements MetaCodeVisitor { + /** + * {@inheritDoc} + *

+ * The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}. + */ + @Override public T visitInit(@NotNull MetaCodeParser.InitContext ctx) { return visitChildren(ctx); } +} \ No newline at end of file diff --git a/grammar/src/MetaCodeLexer.class b/grammar/src/MetaCodeLexer.class new file mode 100644 index 0000000000000000000000000000000000000000..af7bfec23103a456db4c8a67cb13ce77f4c2f85f GIT binary patch literal 3237 zcma)8TXS1U5&mY*{piRS*@Au^lJ!F006PR*S5JNJ&NY!R)E;}) z7R9RXmJjG1#T~C+a?7QUysczDD-dd@t`_~d;nTyTd2*vKm#U@4n*!s}_S6(5jTYs( zmBiFN0X0Pn7wF8Cs$O=t^1!R--3MhF32l3gn{~HRaqDZP=3)hUqf_k`7bI@}Sa@fm zQ*CqL5bw@WD^No#se`xrV#>c-{T5 z6=3(#t``riUHE^jv9XTUVK~$@mp99;%qvl5*tyznebeLIQ8L%PhRd1Gcu&3hEFTXC zSFt1zJ2gRX7a`LTPt*PtmSm}UNVzjq0^_Nvv~n+ zEpsc$?MnJ)IxplK%0Ko#`{x%w`|{PV{{HE+FMs{hzkU4bFQ5MQug^Z0+OjEBX-QSF z6jilURkJizw{+F83`Od)+m=DuAw!C!zoIGqwsQDW6;)G5ZB@~9?Yyl8wGM4u(RDp) z>p{IkpHg&1H}qLscc?cPpdQaIG-nqz{hF;ShGIxlQKY6Sh9)d20#XE}P^7BLKwxZ4 zk(U#1k!MLi%|}|6lu8$)*2id!Fj_>FGO)xLyw2F!Z4q{LvfNDpNE!0ALOm?^^fLCI zF$vG8ET8Q+I;HG8%W_{oWB&l-K-h4k3=gtA7~#c6be4xkDOYlMR14^GWQa#bh8agq z#&hSjpdrW3v3!1QRa9hRJ z72n-ViGD&6noZ!9bO?r8| zX!2l?>UD!^=X5mvH7>tGrkH0=**A9oRW3aW^bK>4K7s%n5w5EwMYyz5JAg?a$L?G?-)+6j{$6>%E3X^b8K!fVt^z#uQcU~GCH zBK8up5PJ^gIn?LS_Mv|U+Y zy7cB84XZq?(J;;RRpC$Rpu>jOKm<@yUPxbd;SKoozm(HbOW{|2aCO_wg", + "WHITESPACE", "NEWLINE", "NUMBER" + }; + public static final String[] ruleNames = { + "WHITESPACE", "NEWLINE", "NUMBER", "INT", "FLOAT", "DIGIT" + }; + + + public MetaCodeLexer(CharStream input) { + super(input); + _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); + } + + @Override + public String getGrammarFileName() { return "MetaCode.g4"; } + + @Override + public String[] getTokenNames() { return tokenNames; } + + @Override + public String[] getRuleNames() { return ruleNames; } + + @Override + public String[] getModeNames() { return modeNames; } + + @Override + public ATN getATN() { return _ATN; } + + @Override + public void action(RuleContext _localctx, int ruleIndex, int actionIndex) { + switch (ruleIndex) { + case 0: WHITESPACE_action((RuleContext)_localctx, actionIndex); break; + + case 1: NEWLINE_action((RuleContext)_localctx, actionIndex); break; + } + } + private void WHITESPACE_action(RuleContext _localctx, int actionIndex) { + switch (actionIndex) { + case 0: skip(); break; + } + } + private void NEWLINE_action(RuleContext _localctx, int actionIndex) { + switch (actionIndex) { + case 1: skip(); break; + } + } + + public static final String _serializedATN = + "\3\uacf5\uee8c\u4f5d\u8b0d\u4a45\u78bd\u1b2f\u3378\2\5<\b\1\4\2\t\2\4"+ + "\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\3\2\6\2\21\n\2\r\2\16\2\22\3\2"+ + "\3\2\3\3\5\3\30\n\3\3\3\3\3\3\3\3\3\3\4\3\4\5\4 \n\4\3\5\6\5#\n\5\r\5"+ + "\16\5$\3\6\6\6(\n\6\r\6\16\6)\3\6\3\6\7\6.\n\6\f\6\16\6\61\13\6\3\6\3"+ + "\6\6\6\65\n\6\r\6\16\6\66\5\69\n\6\3\7\3\7\2\b\3\3\2\5\4\3\7\5\1\t\2\1"+ + "\13\2\1\r\2\1\3\2\4\4\2\13\13\"\"\3\2\62;@\2\3\3\2\2\2\2\5\3\2\2\2\2\7"+ + "\3\2\2\2\3\20\3\2\2\2\5\27\3\2\2\2\7\37\3\2\2\2\t\"\3\2\2\2\138\3\2\2"+ + "\2\r:\3\2\2\2\17\21\t\2\2\2\20\17\3\2\2\2\21\22\3\2\2\2\22\20\3\2\2\2"+ + "\22\23\3\2\2\2\23\24\3\2\2\2\24\25\b\2\2\2\25\4\3\2\2\2\26\30\7\17\2\2"+ + "\27\26\3\2\2\2\27\30\3\2\2\2\30\31\3\2\2\2\31\32\7\f\2\2\32\33\3\2\2\2"+ + "\33\34\b\3\3\2\34\6\3\2\2\2\35 \5\t\5\2\36 \5\13\6\2\37\35\3\2\2\2\37"+ + "\36\3\2\2\2 \b\3\2\2\2!#\5\r\7\2\"!\3\2\2\2#$\3\2\2\2$\"\3\2\2\2$%\3\2"+ + "\2\2%\n\3\2\2\2&(\5\r\7\2\'&\3\2\2\2()\3\2\2\2)\'\3\2\2\2)*\3\2\2\2*+"+ + "\3\2\2\2+/\7\60\2\2,.\5\r\7\2-,\3\2\2\2.\61\3\2\2\2/-\3\2\2\2/\60\3\2"+ + "\2\2\609\3\2\2\2\61/\3\2\2\2\62\64\7\60\2\2\63\65\5\r\7\2\64\63\3\2\2"+ + "\2\65\66\3\2\2\2\66\64\3\2\2\2\66\67\3\2\2\2\679\3\2\2\28\'\3\2\2\28\62"+ + "\3\2\2\29\f\3\2\2\2:;\t\3\2\2;\16\3\2\2\2\13\2\22\27\37$)/\668"; + public static final ATN _ATN = + ATNSimulator.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/grammar/src/MetaCodeLexer.tokens b/grammar/src/MetaCodeLexer.tokens new file mode 100644 index 0000000..4497d1d --- /dev/null +++ b/grammar/src/MetaCodeLexer.tokens @@ -0,0 +1,3 @@ +WHITESPACE=1 +NEWLINE=2 +NUMBER=3 diff --git a/grammar/src/MetaCodeListener.class b/grammar/src/MetaCodeListener.class new file mode 100644 index 0000000000000000000000000000000000000000..22ae0c27138e4a5bc9efca514d8fa510b3740249 GIT binary patch literal 437 zcmZut%}#$&)>{`ky2}iGu*0}Hm`N|x4Ba{ zwk@*6HqEAOxE+Vig@9+F(sG)bVY`;29WH22$9BzquDK59TAe%lrfpa?ikvS}j$B&L zTo=y}t$nDjmpAB8Fm2Nsy-r=v(8>_sY;~Lle`|_~4p+Hrh;e&; zn-N-2F^f4BFEOv;4(>7xbwSE7*bt?mt#_= z3HrlfNSwQ=x=r0JSw_3f+YD1Z1r-=EO_Ii2Z|!lLoQ8$60-EmcB7}7Gn`qBdiJ-|a zmabf0j1+|wfd`Hqim`fUlGjy^!TB;|dlr9QkABZdi!xW~lWFZZ+-6w0N*>}N$cNZd zZ-eKFVw`>~3Hs3hG0;Q8074j~+hf`p?a^%CDcA{}NDSgGtwul`wl7EMaiM?=YLqQ+-0&qz(XImO#Y(GWbPLt#~8@{L?rtSeIbY(A=xG`$0{`_ zj}%$MV4_ze{|gcg1}RdIwX;D+@rbgBhOhZdQp7|##vn0Kh)I74Cpp?-+ YgC+gGiCK?H;1kTy9w(-8{veIhpI!a3#$GJ4kMV8};&_L5VEvSmps8y6;DM^I^buF)D)w-C~ zDz!tQg|-wz6KJ93Qc6ppghE2nnAk}(f$#hYhM_YseBcK#KzPndb`@t8%4p`@^PcnG zZ|CTb|9SuS0Pe$k0gMGPgwIRx1qr^WVFwB-o|K3o!MFxLigGof!j#`hji96y3m+1EOVkQ zGGP>_Oo3hQY=&Kn9VT(PXj4Zg3ngjC4y1C)?BRGKDIih;JtSz@)P2;bG))iVF9g&~ z@>n{RNlH`^@Mn%3d?Yz4F%L!9^=Y$~F{;v;)nnt|^qc zXxZuCE5q@yz}AR6siU6}G>z)W;86juq!-vg(FaZ2kft9tEQW4NM{zL#Jz3i*P9HR8 z9ADTAP7&HFUSg_}vqf`8mH|^0*juc$ZSX{-1}$4}T18WajfuQj$xfM77V^^W&eCoj zBiO6s(-J&_gpPw?@`k$l-LjV6XUo-Q#jxv^ju<|!V;4RlnZK#yTR17uzog?<_jG(4 zFY7pk(~{vkI=+inbi688-^2HHyoT3R{6NPK@gp5S#v3YrqT@~cRL5I*TgT7vgutMy zfum-zUSfb5n&lYjID?<-_yyk4@k_iT5OZbi-e1y4YV2Ft5v>2csm#%MI<=1l@SNxG z^Oyhe{>vX+fAeqWPJQt1i+??H{maYkFUq81Qic|K1J0OzY^4x9;H{&JPP*| zt^@Mp^{YNb@u{j;QT#r+<5wkAgAxY35(XuYqB-QA>??sS(nXmO3W_sCK^ z{f~j!ow>_gl-;0mUfHHKBe1IoJu7fqSLD2C4`FfyI5OCZhxWyRT~4#VKCCL~kQrrp%lzJ5ygqe`%g_@VRrj4HgOsS>{aLvYoIAJbruU{}0Jd z9IqB)(Sb`UhYhc=~v^<;1JYga5W&W zAb!{Kt+|`8lTUK3;8Vo!@4)vEf1m?@kT`EZhwq_|{fD{FOVQc?4C2f3ws4>KB==SB z?L(4qKe2WE3VuCdagiT^M+yDT)&SuFqzEOU#3Z5j5|ovc8+r1W8>MF@z^y-hhnvlVJz7adxJFM19BeDspEMZJW;B7&Epy~pF0`Mr=2y$F05L_eZf zg+n+@cB&Ljc)1T;xrR_a`a9^+1@tVUHys`FcouL+bjZ7azG$C+0jqc%j$XxT1zg?f zy^6aOJQVfG6CQu;SX6BhEgcQ`-bSxHS|y2i-WTX5Wx)T|jVn~W<}6~Fq2bF|>nIz( zihhsO7LIbcj!TC`f6yxzYrTIMx=8!i;CY4s|^$g~{jKnZwu?IQU!V#VxMHa{K1o9}NfHIy$0|x(3j8n%nUP6V^O+I`k`PwPr z4NOtjG_UFkHBDoIe^5S4EgRwcH}UC_$d%_#Dd2e`AHt!4Hlg<0Xo3ry!yse{qx%Py&EMV&uY@3%g zz>ICbj>tSz&q#j@J%jbEjs9zh", "WHITESPACE", "NEWLINE", "NUMBER" + }; + public static final int + RULE_init = 0; + public static final String[] ruleNames = { + "init" + }; + + @Override + public String getGrammarFileName() { return "MetaCode.g4"; } + + @Override + public String[] getTokenNames() { return tokenNames; } + + @Override + public String[] getRuleNames() { return ruleNames; } + + @Override + public ATN getATN() { return _ATN; } + + public MetaCodeParser(TokenStream input) { + super(input); + _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); + } + public static class InitContext extends ParserRuleContext { + public List NEWLINE() { return getTokens(MetaCodeParser.NEWLINE); } + public TerminalNode NEWLINE(int i) { + return getToken(MetaCodeParser.NEWLINE, i); + } + public TerminalNode NUMBER(int i) { + return getToken(MetaCodeParser.NUMBER, i); + } + public List NUMBER() { return getTokens(MetaCodeParser.NUMBER); } + public InitContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_init; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof MetaCodeListener ) ((MetaCodeListener)listener).enterInit(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof MetaCodeListener ) ((MetaCodeListener)listener).exitInit(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof MetaCodeVisitor ) return ((MetaCodeVisitor)visitor).visitInit(this); + else return visitor.visitChildren(this); + } + } + + public final InitContext init() throws RecognitionException { + InitContext _localctx = new InitContext(_ctx, getState()); + enterRule(_localctx, 0, RULE_init); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(6); + _errHandler.sync(this); + _la = _input.LA(1); + do { + { + { + setState(2); match(NUMBER); + setState(4); + _la = _input.LA(1); + if (_la==NEWLINE) { + { + setState(3); match(NEWLINE); + } + } + + } + } + setState(8); + _errHandler.sync(this); + _la = _input.LA(1); + } while ( _la==NUMBER ); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public static final String _serializedATN = + "\3\uacf5\uee8c\u4f5d\u8b0d\u4a45\u78bd\u1b2f\u3378\3\5\r\4\2\t\2\3\2\3"+ + "\2\5\2\7\n\2\6\2\t\n\2\r\2\16\2\n\3\2\2\3\2\2\2\r\2\b\3\2\2\2\4\6\7\5"+ + "\2\2\5\7\7\4\2\2\6\5\3\2\2\2\6\7\3\2\2\2\7\t\3\2\2\2\b\4\3\2\2\2\t\n\3"+ + "\2\2\2\n\b\3\2\2\2\n\13\3\2\2\2\13\3\3\2\2\2\4\6\n"; + public static final ATN _ATN = + ATNSimulator.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/grammar/src/MetaCodeVisitor.class b/grammar/src/MetaCodeVisitor.class new file mode 100644 index 0000000000000000000000000000000000000000..fbe4d0ba1a35715d8ba5749d80f3ad651ed474e9 GIT binary patch literal 575 zcmaJ;O-n*S6g{KnSULCetw85w6_-aP5Iwde=*qoVsv zp;TH7_v_qq?>+PR_5K0i3Wppuj$MvDhQdt8I&`fL9Ce0L>UEqA>MbyoyVfe-F*1%- z%y4zv&}H?dEDO*@ssuxICCyM The return type of the visit operation. Use {@link Void} for + * operations with no return type. + */ +public interface MetaCodeVisitor extends ParseTreeVisitor { + /** + * Visit a parse tree produced by {@link MetaCodeParser#init}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitInit(@NotNull MetaCodeParser.InitContext ctx); +} \ No newline at end of file diff --git a/scripts/antlr4.rb b/scripts/antlr4.rb new file mode 100644 index 0000000..7a1279d --- /dev/null +++ b/scripts/antlr4.rb @@ -0,0 +1,39 @@ +switches = [] + +ARGV.each do |arg| + switches << arg if arg.start_with? "-" +end + +if switches.include? "-init" + if not ARGV[1].nil? + File.open("run.rb", "w") { |file| + puts "Initialize grammar ..." + code = <<-CODE + example = if ARGV[0].nil? + File.open("example.txt", "w") if not File.exist?("example.txt") + "example.txt" + else + ARGV[0].to_s + end + puts "Running #{ARGV[1]} parser ..." + Dir.mkdir("src") if not Dir.exists? "src" + Dir.chdir("src") + system('call antlr4 "../#{ARGV[1]}.g4" -visitor') + system('call grun #{ARGV[1]} init -gui ..\\\\' + example) + CODE + file.puts(code) + puts "Initialization is completed." + } + else + puts "Use this: antlr4 -init " + end +elsif switches.include? "-help" + puts "Usage: 'antlr4 ' or" + puts " 'antlr4 '" + puts "Switches: " + puts " -init Initialize ANTLR grammar" + puts " -help Show help" +else + system("java -cp e:\Development\Libraries\ANTLR\antlr-4.1-complete.jar;%CLASSPATH% org.antlr.v4.Tool #{ARGV[0]} -visitor") + system("javac *.java") +end \ No newline at end of file diff --git a/scripts/grun.bat b/scripts/grun.bat new file mode 100644 index 0000000..ebcb057 --- /dev/null +++ b/scripts/grun.bat @@ -0,0 +1 @@ +java -cp .;%CLASSPATH% org.antlr.v4.runtime.misc.TestRig %* \ No newline at end of file