Remove test code

This commit is contained in:
Peter Boyer 2016-05-25 10:22:13 -04:00
parent b93bdc33a1
commit 99d6b812c1
11 changed files with 0 additions and 264 deletions

View File

@ -1 +0,0 @@
package antlr

View File

@ -1,35 +0,0 @@
package main
import (
"antlr4"
"./parser"
"os"
)
type TreeShapeListener struct {
*parser.BaseExprListener
}
func NewTreeShapeListener() *TreeShapeListener {
return new(TreeShapeListener)
}
func (this *TreeShapeListener) EnterEveryRule(ctx antlr4.ParserRuleContext) {
for i := 0; i<ctx.GetChildCount(); i++ {
child := ctx.GetChild(i)
parentR,ok := child.GetParent().(antlr4.RuleNode)
if !ok || parentR.GetBaseRuleContext() != ctx.GetBaseRuleContext() {
panic("Invalid parse tree shape detected.")
}
}
}
func main() {
input := antlr4.NewFileStream(os.Args[1])
lexer := parser.NewExprLexer(input)
stream := antlr4.NewCommonTokenStream(lexer,0)
p := parser.NewExprParser(stream)
p.AddErrorListener(antlr4.NewDiagnosticErrorListener(true))
p.BuildParseTrees = true
tree := p.Prog()
antlr4.ParseTreeWalkerDefault.Walk(NewTreeShapeListener(), tree)
}

View File

@ -1 +0,0 @@
b = 6

View File

@ -1,3 +0,0 @@
*.js
*.tokens
*.go

View File

@ -1,101 +0,0 @@
grammar Arithmetic;
options { language = Go; }
equation
: expression relop expression
;
expression
: multiplyingExpression ((PLUS|MINUS) multiplyingExpression)*
;
multiplyingExpression
: powExpression ((TIMES|DIV) powExpression)*
;
powExpression
: atom (POW expression)?
;
atom
: scientific
| variable
| LPAREN expression RPAREN
;
scientific
: number (E number)?
;
relop
: EQ | GT | LT
;
number
: MINUS? DIGIT+ (POINT DIGIT+)?
;
variable
: MINUS? LETTER (LETTER | DIGIT)*;
LPAREN
: '('
;
RPAREN
: ')'
;
PLUS
: '+'
;
MINUS
: '-'
;
TIMES
: '*'
;
DIV
: '/'
;
GT
: '>'
;
LT
: '<'
;
EQ
: '='
;
POINT
: '.'
;
E
: 'e'
| 'E'
;
POW
: '^'
;
LETTER
: ('a'..'z') | ('A'..'Z')
;
DIGIT
: ('0'..'9')
;
WS
: [ \r\n\t]+ -> channel(HIDDEN)
;

View File

@ -1,21 +0,0 @@
grammar Expr;
prog: stat ;
stat: expr NEWLINE # printExpr
| ID '=' expr NEWLINE # assign
| NEWLINE # blank
;
expr: expr ('*'|'/') expr # MulDiv
| expr ('+'|'-') expr # AddSub
| INT # int
| ID # id
| '(' expr ')' # parens
;
MUL : '*' ; // assigns token name to '*' used above in grammar
DIV : '/' ;
ADD : '+' ;
SUB : '-' ;
ID : [a-zA-Z]+ ; // match identifiers
INT : [0-9]+ ; // match integers
NEWLINE:'\r'? '\n' ; // return newlines to parser (is end-statement signal)
WS : [ \t]+ -> skip ; // toss out whitespace

View File

@ -1,76 +0,0 @@
/** Taken from "The Definitive ANTLR 4 Reference" by Terence Parr */
// Derived from http://json.org
grammar JSON;
options { language = Go; }
json
: object
| array
;
object
: '{' pair (',' pair)* '}'
| '{' '}'
;
pair
: STRING ':' value
;
array
: '[' value (',' value)* ']'
| '[' ']'
;
value
: STRING
| NUMBER
| object
| array
| 'true'
| 'false'
| 'null'
;
STRING
: '"' (ESC | ~ ["\\])* '"'
;
fragment ESC
: '\\' (["\\/bfnrt] | UNICODE)
;
fragment UNICODE
: 'u' HEX HEX HEX HEX
;
fragment HEX
: [0-9a-fA-F]
;
NUMBER
: '-'? INT '.' [0-9] + EXP? | '-'? INT EXP | '-'? INT
;
fragment INT
: '0' | [1-9] [0-9]*
;
// no leading zeros
fragment EXP
: [Ee] [+\-]? INT
;
// \- since - means "range" inside [...]
WS
: [ \t\n\r] + -> skip
;

View File

@ -1,6 +0,0 @@
grammar M;
options { language = Go; }
import S;
s : a;
B : 'b';
WS : (' '|'\n') -> skip ;

View File

@ -1,2 +0,0 @@
parser grammar S;
a @after {int x = 0;} : B;

View File

@ -1,3 +0,0 @@
lexer grammar T;
options { language = Go; }
ZERO: '0';

View File

@ -1,15 +0,0 @@
grammar T;
prog
@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}
: expr_or_assign*;
expr_or_assign
: expr '++' {fmt.Println("fail.")}
| expr {fmt.Println("pass: "+$expr.text)}
;
expr: expr_primary ('<-' ID)?;
expr_primary
: '(' ID ')'
| ID '(' ID ')'
| ID
;
ID : [a-z]+ ;