-
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
0 parents
commit 1c222f5
Showing
5 changed files
with
100 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,12 @@ | ||
.PHONY: test clean | ||
|
||
PERParser.py : | ||
antlr4 -Dlanguage=Python3 PER.g4 | ||
|
||
test : export CLASSPATH = /usr/share/java/stringtemplate4.jar:/usr/share/java/antlr4.jar:/usr/share/java/antlr4-runtime.jar:/usr/share/java/antlr3-runtime.jar/:/usr/share/java/treelayout.jar | ||
test : | ||
antlr4 PER.g4 && javac *.java | ||
grun PER per testinput -tokens | ||
|
||
clean : | ||
rm -f *.java *.class PERParser.py PERLexer.py PERListener.py *.interp *.tokens |
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,40 @@ | ||
grammar PER; | ||
|
||
/* | ||
* Parser | ||
*/ | ||
|
||
per : (statement | comment | WHITESPACE)+ EOF ; | ||
statement : OPEN command CLOSE ; | ||
comment : COMMENT ; | ||
command : ( defrule | defconst ) ; | ||
defrule : DEFRULE WHITESPACE+ proposition_list DEFRULE_SEPARATOR WHITESPACE* action_list ; | ||
proposition_list : ( proposition WHITESPACE+ )+ ; | ||
proposition : OPEN SYMBOL ( WHITESPACE (REL_OP | SYMBOL | SHORT) )+ WHITESPACE? CLOSE ; | ||
action_list : ( action WHITESPACE+ )+ ; | ||
action : OPEN SYMBOL ( WHITESPACE (SYMBOL | SHORT | STRING) )+ WHITESPACE? CLOSE ; | ||
defconst : DEFCONST WHITESPACE+ SYMBOL WHITESPACE+ SHORT ; | ||
|
||
/* | ||
* Lexer | ||
*/ | ||
|
||
OPEN : '(' ; | ||
CLOSE : ')' ; | ||
WHITESPACE : ( ' ' | '\t' | NEWLINE ) ; | ||
NEWLINE : ( '\n' | '\r\n' ) ; | ||
|
||
COMMENT : ';' ~[\r\n]* NEWLINE ; | ||
|
||
DEFRULE : 'defrule' ; | ||
DEFRULE_SEPARATOR : '=>' ; | ||
|
||
REL_OP : ( REL_OP_FULL | REL_OP_SHORT ) ; | ||
REL_OP_FULL : ( 'less-than' | 'less-or-equal' | 'greater-than' | 'greater-or-equal' | 'equal' | 'not-equal' ) ; | ||
REL_OP_SHORT : ( '<' | '<=' | '>' | '>=' | '==' | '!=' ) ; | ||
|
||
DEFCONST : 'defconst' ; | ||
|
||
STRING : '"' ~["]* '"' ; | ||
SHORT : '-'? [0-9]+ ; // This needs to go at the bottom to make it lowere precedence than FACT_ARG... but that probably breaks defconst... FIXME | ||
SYMBOL : [a-z0-9\-]+ ; // This is likely too restrictive, but covers all of the values actually defined in the TC guide |
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,12 @@ | ||
[[source]] | ||
name = "pypi" | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
|
||
[dev-packages] | ||
|
||
[packages] | ||
antlr4-python3-runtime = "*" | ||
|
||
[requires] | ||
python_version = "3.6" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,8 @@ | ||
(defrule | ||
(player-in-game 1) | ||
(player-human 1) | ||
(goal 1 1) | ||
=> | ||
(chat-to-player 1 "3 Train villagers, build 2 houses, and send 6 to sheep [7 pop](6 sheep)") | ||
(set-goal 1 2) | ||
) |