Skip to content

Totktonada/management-game-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

==== Script language ====
* labels:    @[a-zA-Z_][a-zA-Z0-9_]*
* variables: $[a-zA-Z_][a-zA-Z0-9_]*
* arrays:    $[a-zA-Z_][a-zA-Z0-9_]*\[expression\]

* internal functions:
  1.  ?isWin()
  2.  ?getWinners()
  3.  ?myNick()
  4.  ?getPlayers()
  5.  ?getMarketRaws()
  6.  ?getRawPrice()
  7.  ?getMarketProductions()
  8.  ?getProductionPrice()
  9.  ?getMoney()
  10. ?getRaws()
  11. ?getProductions()
  12. ?getFactories()

* internal operators:
  1. set variable expression;
  2. goto label;
  3. if (expression) operator [else operator]
  4. while (expression) operator
  4. print "any symbols", expr1, expr2, "any symbols";

* game operators:
  1. buy amount, cost
  2. sell amount, cost
  3. make amount
  4. build amount
  5. turn

* operations (by priority):
  1. monadic: '+', '-', '!';
  2. arithmetic: '*', '/', '%';
  3. arithmetic: '+', '-';
  4. compare: '<', '>', '==';
  5. logic: '&&'
  5. logic: '||'

* More about operations:
  1. change priority by '(', ')';
  2. compare and logic operations
     '<', '>', '==', '&&', '||', '!'
     return 0 for false and 1 for true;
  3. logic operations '&&', '||', '!'
     mean 0 as false and any other as true;

==== Grammar for parser ====
Notes:
* First branch is more priority then second, second then third...
* Words in UPPER case is nonterminal symbols of grammar.
* Words in lower case in 'quotes' is keywords of language.
* Words in lower case without quotes is user-defined entity
  (label or variable names, numeric or string constants).
* Word "nothing" mean that new lexeme not readed and, therefore,
  must not checked.
* Figure brackets (e.g. {words}) similar to (words)* in PCRE.
  This mean that words must be repeated zero or more time.
* NONTERM(bool_value) mean that proper function invoked with
  different boolean arguments from different right expression
  (after "->").
* Argument def mean "must be defined". If def is true then
  undefined variable here would be touched error. Otherwise
  (def is false) variable would be defined (if already not).
//TODO: (eng grammar) будет определена
* Underline words in _UPPERCASE_ is set of some lexemes and
  using for more comfortable reading. It is not a nonterminal
  symbol.

PROGRAM -> LABEL_OPERATOR {LABEL_OPERATOR} 'eof'
LABEL_OPERATOR -> LABEL_PREFIX OPERATOR
OPERATOR -> '{' LABEL_OPERATOR {LABEL_OPERATOR} '}' |
            'if' ARGS_LIST_1 OPERATOR ELSE_SUFFIX |
            'while' ARGS_LIST_1 OPERATOR |
            SINGLE_OPERATOR ';'

SINGLE_OPERATOR -> 'set' VARIABLE(false) EXPR |
                   'array' ARRAY_DEFINE EXPR |
                   'goto' label |
                   'print' '(' PRINT_ARGS_LIST ')' |
                   'buy' ARGS_LIST_2 |
                   'sell' ARGS_LIST_2 |
                   'make' ARGS_LIST_1 |
                   'build' ARGS_LIST_1 |
                   'turn' ARGS_LIST_0 |
                   'join' ARGS_LIST_0

ELSE_SUFFIX -> 'else' OPERATOR | nothing

ARGS_LIST_0 -> '(' ')'
ARGS_LIST_1 -> '(' EXPR ')'
ARGS_LIST_2 -> '(' EXPR ',' EXPR ')'

PRINT_ARGS_LIST -> PRINT_ARG {',' PRINT_ARG}
PRINT_ARG -> string | EXPR

// branch depend on certain internal function.
EXPR_0 -> number | '(' EXPR ')' | function ARGS_LIST_0 |
          function ARGS_LIST_1 | VARIABLE(true)
EXPR_1 -> {_MONADIC_OP_} EXPR_0
EXPR_2 -> EXPR_1 {_ARITHMETIC_OP_1_ EXPR_1}
EXPR_3 -> EXPR_2 {_ARITHMETIC_OP_2_ EXPR_2}
EXPR_4 -> EXPR_3 {_COMPARE_OP_ EXPR_3}
EXPR_5 -> EXPR_4 {_LOGIC_OP_1_ EXPR_4}
EXPR -> EXPR_5 {_LOGIC_OP_2_ EXPR_5}

VARIABLE(def) -> variable ARRAY_SUFFIX(def)
ARRAY_SUFFIX(def) -> '[' EXPR ']' | nothing
// array name is lexeme with type variable.
ARRAY_DEFINE -> array_name

// define label
LABEL_PREFIX -> label ':' | nothing

_MONADIC_OP_ -> '+' | '-' | '!'
_ARITHMETIC_OP_1_ -> '*' | '/' | '%'
_ARITHMETIC_OP_2_ -> '+' | '-'
_COMPARE_OP_ -> '<' | '>' | '=='
_LOGIC_OP_1_ -> '&&'
_LOGIC_OP_2_ -> '||'

About

Bot for management-game-server. University task.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages