95 |
95 |
96 MustString (); |
96 MustString (); |
97 |
97 |
98 // State name must be a word. |
98 // State name must be a word. |
99 if (token.first (" ") != token.len()) |
99 if (token.first (" ") != token.len()) |
100 ParserError ("state name must be a single word! got `%s`", token.chars()); |
100 ParserError ("state name must be a single word, got `%s`", token.chars()); |
101 str statename = token; |
101 str statename = token; |
102 |
102 |
103 // stateSpawn is special - it *must* be defined. If we |
103 // stateSpawn is special - it *must* be defined. If we |
104 // encountered it, then mark down that we have it. |
104 // encountered it, then mark down that we have it. |
105 if (!token.icompare ("statespawn")) |
105 if (!token.icompare ("statespawn")) |
677 |
677 |
678 int curarg = 0; |
678 int curarg = 0; |
679 while (1) { |
679 while (1) { |
680 if (!token.compare (")")) { |
680 if (!token.compare (")")) { |
681 if (curarg < comm->numargs) |
681 if (curarg < comm->numargs) |
682 ParserError ("too few arguments passed to %s\n", comm->name.chars()); |
682 ParserError ("too few arguments passed to %s\n\tprototype: %s", |
|
683 comm->name.chars(), GetCommandPrototype (comm).chars()); |
683 break; |
684 break; |
684 curarg++; |
685 curarg++; |
685 } |
686 } |
686 |
687 |
687 if (curarg >= comm->maxargs) |
688 if (curarg >= comm->maxargs) |
688 ParserError ("too many arguments passed to %s\n", comm->name.chars()); |
689 ParserError ("too many arguments passed to %s\n\tprototype: %s", |
|
690 comm->name.chars(), GetCommandPrototype (comm).chars()); |
689 |
691 |
690 r->Merge (ParseExpression (comm->argtypes[curarg])); |
692 r->Merge (ParseExpression (comm->argtypes[curarg])); |
691 MustNext (); |
693 MustNext (); |
692 |
694 |
693 if (curarg < comm->numargs - 1) { |
695 if (curarg < comm->numargs - 1) { |
795 |
797 |
796 // Parse any and all operators we get |
798 // Parse any and all operators we get |
797 int oper; |
799 int oper; |
798 while ((oper = ParseOperator (true)) != -1) { |
800 while ((oper = ParseOperator (true)) != -1) { |
799 // We peeked the operator, move forward now |
801 // We peeked the operator, move forward now |
800 MustNext(); |
802 Next (); |
801 |
803 |
802 // Can't be an assignement operator, those belong in assignments. |
804 // Can't be an assignement operator, those belong in assignments. |
803 if (IsAssignmentOperator (oper)) |
805 if (IsAssignmentOperator (oper)) |
804 ParserError ("assignment operator inside expression"); |
806 ParserError ("assignment operator inside expression"); |
805 |
807 |
806 // Parse the right operand, |
808 // Parse the right operand. |
807 MustNext (); |
809 MustNext (); |
808 DataBuffer* rb = ParseExprValue (reqtype); |
810 DataBuffer* rb = ParseExprValue (reqtype); |
809 |
811 |
810 if (oper == OPER_TERNARY) { |
812 if (oper == OPER_TERNARY) { |
811 // Ternary operator requires - naturally - a third operand. |
813 // Ternary operator requires - naturally - a third operand. |
941 // If nothing else, check for literal |
943 // If nothing else, check for literal |
942 switch (reqtype) { |
944 switch (reqtype) { |
943 case TYPE_VOID: |
945 case TYPE_VOID: |
944 ParserError ("unknown identifier `%s` (expected keyword, function or variable)", token.chars()); |
946 ParserError ("unknown identifier `%s` (expected keyword, function or variable)", token.chars()); |
945 break; |
947 break; |
|
948 case TYPE_BOOL: |
946 case TYPE_INT: { |
949 case TYPE_INT: { |
947 MustNumber (true); |
950 MustNumber (true); |
948 |
951 |
949 // All values are written unsigned - thus we need to write the value's |
952 // All values are written unsigned - thus we need to write the value's |
950 // absolute value, followed by an unary minus if it was negative. |
953 // absolute value, followed by an unary minus if it was negative. |
1067 if (ScriptVar* var = FindGlobalVariable (token)) { |
1070 if (ScriptVar* var = FindGlobalVariable (token)) { |
1068 DataBuffer* b = ParseAssignment (var); |
1071 DataBuffer* b = ParseAssignment (var); |
1069 return b; |
1072 return b; |
1070 } |
1073 } |
1071 |
1074 |
1072 // If it's not a keyword, parse it as an expression. |
1075 ParserError ("bad statement"); |
1073 DataBuffer* b = ParseExpression (TYPE_VOID); |
1076 return NULL; |
1074 return b; |
|
1075 } |
1077 } |
1076 |
1078 |
1077 void ScriptReader::AddSwitchCase (ObjWriter* w, DataBuffer* b) { |
1079 void ScriptReader::AddSwitchCase (ObjWriter* w, DataBuffer* b) { |
1078 ScopeInfo* info = &SCOPE(0); |
1080 ScopeInfo* info = &SCOPE(0); |
1079 |
1081 |