Created
January 14, 2014 19:52
-
-
Save balazsgrill/8424526 to your computer and use it in GitHub Desktop.
Parsing with IncQuery
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
package hu.textualmodeler.query.infix | |
import "http://textualmodeler.hu/grammar" | |
import "http://textualmodeler.hu/tokens" | |
pattern terminal(t : Token, s){ | |
Token.terminal(t, terminal); | |
Terminal.name(terminal, s); | |
} | |
private pattern notEOF(t : Token){ | |
Token.terminal(t, _terminal); | |
} | |
private pattern EOF(t : Token){ | |
neg find notEOF(t); | |
} | |
pattern START(first : Token, eof : Token){ | |
find E(first, eof); | |
find EOF(eof); | |
} | |
pattern E(first : Token, next : Token){ | |
find E1(first, next); | |
} | |
pattern E1(first : Token, next : Token){ | |
find E2(first, next); | |
}or{ | |
find E2(first, o1); | |
find terminal(o1, "PLUS"); | |
Token.tail(o1, o2); | |
find E1(o2, next); | |
}or{ | |
find E2(first, o1); | |
find terminal(o1, "MINUS"); | |
Token.tail(o1, o2); | |
find E1(o2, next); | |
} | |
pattern E2(first : Token, next : Token){ | |
find E3(first, next); | |
}or{ | |
find E3(first, o1); | |
find terminal(o1, "MULTI"); | |
Token.tail(o1, o2); | |
find E2(o2, next); | |
}or{ | |
find E3(first, o1); | |
find terminal(o1, "DIVIDE"); | |
Token.tail(o1, o2); | |
find E2(o2, next); | |
} | |
pattern E3(first : Token, next : Token){ | |
find terminal(first, "QUALIFIEDID"); | |
Token.tail(first, next); | |
}or{ | |
find terminal(first, "DECIMAL_NUMBER"); | |
Token.tail(first, next); | |
} |
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
grammar infix <E>; | |
import basics; | |
terminal PLUS "\+"; | |
terminal MINUS "\-"; | |
terminal MULTI "\*"; | |
terminal DIVIDE "\/"; | |
<E> :- <E1>; | |
<E1> :- <E2>; | |
<E1> :- <E2> PLUS <E1>; | |
<E1> :- <E2> MINUS <E1>; | |
<E2> :- <E3>; | |
<E2> :- <E3> MULTI <E2>; | |
<E2> :- <E3> DIVIDE <E2>; | |
<E3> :- QUALIFIEDID; | |
<E3> :- DECIMAL_NUMBER; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment