-
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.
- Loading branch information
1 parent
0502153
commit 3434e97
Showing
20 changed files
with
414 additions
and
0 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 |
---|---|---|
@@ -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] | ||
; |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
545 | ||
18. |
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 |
---|---|---|
@@ -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) |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
WHITESPACE=1 | ||
NEWLINE=2 | ||
NUMBER=3 |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Generated from ../MetaCode.g4 by ANTLR 4.1 | ||
|
||
import org.antlr.v4.runtime.ParserRuleContext; | ||
import org.antlr.v4.runtime.misc.NotNull; | ||
import org.antlr.v4.runtime.tree.ErrorNode; | ||
import org.antlr.v4.runtime.tree.TerminalNode; | ||
|
||
/** | ||
* This class provides an empty implementation of {@link MetaCodeListener}, | ||
* which can be extended to create a listener which only needs to handle a subset | ||
* of the available methods. | ||
*/ | ||
public class MetaCodeBaseListener implements MetaCodeListener { | ||
/** | ||
* {@inheritDoc} | ||
* <p/> | ||
* The default implementation does nothing. | ||
*/ | ||
@Override public void enterInit(@NotNull MetaCodeParser.InitContext ctx) { } | ||
/** | ||
* {@inheritDoc} | ||
* <p/> | ||
* The default implementation does nothing. | ||
*/ | ||
@Override public void exitInit(@NotNull MetaCodeParser.InitContext ctx) { } | ||
|
||
/** | ||
* {@inheritDoc} | ||
* <p/> | ||
* The default implementation does nothing. | ||
*/ | ||
@Override public void enterEveryRule(@NotNull ParserRuleContext ctx) { } | ||
/** | ||
* {@inheritDoc} | ||
* <p/> | ||
* The default implementation does nothing. | ||
*/ | ||
@Override public void exitEveryRule(@NotNull ParserRuleContext ctx) { } | ||
/** | ||
* {@inheritDoc} | ||
* <p/> | ||
* The default implementation does nothing. | ||
*/ | ||
@Override public void visitTerminal(@NotNull TerminalNode node) { } | ||
/** | ||
* {@inheritDoc} | ||
* <p/> | ||
* The default implementation does nothing. | ||
*/ | ||
@Override public void visitErrorNode(@NotNull ErrorNode node) { } | ||
} |
Binary file not shown.
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 |
---|---|---|
@@ -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 <T> The return type of the visit operation. Use {@link Void} for | ||
* operations with no return type. | ||
*/ | ||
public class MetaCodeBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements MetaCodeVisitor<T> { | ||
/** | ||
* {@inheritDoc} | ||
* <p/> | ||
* The default implementation returns the result of calling | ||
* {@link #visitChildren} on {@code ctx}. | ||
*/ | ||
@Override public T visitInit(@NotNull MetaCodeParser.InitContext ctx) { return visitChildren(ctx); } | ||
} |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Generated from ../MetaCode.g4 by ANTLR 4.1 | ||
import org.antlr.v4.runtime.Lexer; | ||
import org.antlr.v4.runtime.CharStream; | ||
import org.antlr.v4.runtime.Token; | ||
import org.antlr.v4.runtime.TokenStream; | ||
import org.antlr.v4.runtime.*; | ||
import org.antlr.v4.runtime.atn.*; | ||
import org.antlr.v4.runtime.dfa.DFA; | ||
import org.antlr.v4.runtime.misc.*; | ||
|
||
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) | ||
public class MetaCodeLexer extends Lexer { | ||
protected static final DFA[] _decisionToDFA; | ||
protected static final PredictionContextCache _sharedContextCache = | ||
new PredictionContextCache(); | ||
public static final int | ||
WHITESPACE=1, NEWLINE=2, NUMBER=3; | ||
public static String[] modeNames = { | ||
"DEFAULT_MODE" | ||
}; | ||
|
||
public static final String[] tokenNames = { | ||
"<INVALID>", | ||
"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); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
WHITESPACE=1 | ||
NEWLINE=2 | ||
NUMBER=3 |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Generated from ../MetaCode.g4 by ANTLR 4.1 | ||
import org.antlr.v4.runtime.misc.NotNull; | ||
import org.antlr.v4.runtime.tree.ParseTreeListener; | ||
|
||
/** | ||
* This interface defines a complete listener for a parse tree produced by | ||
* {@link MetaCodeParser}. | ||
*/ | ||
public interface MetaCodeListener extends ParseTreeListener { | ||
/** | ||
* Enter a parse tree produced by {@link MetaCodeParser#init}. | ||
* @param ctx the parse tree | ||
*/ | ||
void enterInit(@NotNull MetaCodeParser.InitContext ctx); | ||
/** | ||
* Exit a parse tree produced by {@link MetaCodeParser#init}. | ||
* @param ctx the parse tree | ||
*/ | ||
void exitInit(@NotNull MetaCodeParser.InitContext ctx); | ||
} |
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Generated from ../MetaCode.g4 by ANTLR 4.1 | ||
import org.antlr.v4.runtime.atn.*; | ||
import org.antlr.v4.runtime.dfa.DFA; | ||
import org.antlr.v4.runtime.*; | ||
import org.antlr.v4.runtime.misc.*; | ||
import org.antlr.v4.runtime.tree.*; | ||
import java.util.List; | ||
import java.util.Iterator; | ||
import java.util.ArrayList; | ||
|
||
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) | ||
public class MetaCodeParser extends Parser { | ||
protected static final DFA[] _decisionToDFA; | ||
protected static final PredictionContextCache _sharedContextCache = | ||
new PredictionContextCache(); | ||
public static final int | ||
WHITESPACE=1, NEWLINE=2, NUMBER=3; | ||
public static final String[] tokenNames = { | ||
"<INVALID>", "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<TerminalNode> 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<TerminalNode> 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> T accept(ParseTreeVisitor<? extends T> visitor) { | ||
if ( visitor instanceof MetaCodeVisitor ) return ((MetaCodeVisitor<? extends T>)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); | ||
} | ||
} | ||
} |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Generated from ../MetaCode.g4 by ANTLR 4.1 | ||
import org.antlr.v4.runtime.misc.NotNull; | ||
import org.antlr.v4.runtime.tree.ParseTreeVisitor; | ||
|
||
/** | ||
* This interface defines a complete generic visitor for a parse tree produced | ||
* by {@link MetaCodeParser}. | ||
* | ||
* @param <T> The return type of the visit operation. Use {@link Void} for | ||
* operations with no return type. | ||
*/ | ||
public interface MetaCodeVisitor<T> extends ParseTreeVisitor<T> { | ||
/** | ||
* Visit a parse tree produced by {@link MetaCodeParser#init}. | ||
* @param ctx the parse tree | ||
* @return the visitor result | ||
*/ | ||
T visitInit(@NotNull MetaCodeParser.InitContext ctx); | ||
} |
Oops, something went wrong.