mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-07 10:21:31 +00:00
DIRECTOR: LINGO: Reimplement lists
This commit is contained in:
parent
38c0d5fddd
commit
a6cfb4e275
@ -47,6 +47,9 @@ struct IntNode;
|
||||
struct FloatNode;
|
||||
struct SymbolNode;
|
||||
struct StringNode;
|
||||
struct ListNode;
|
||||
struct PropListNode;
|
||||
struct PropPairNode;
|
||||
struct FuncNode;
|
||||
struct VarNode;
|
||||
struct ParensNode;
|
||||
@ -88,6 +91,9 @@ enum NodeType {
|
||||
kFloatNode,
|
||||
kSymbolNode,
|
||||
kStringNode,
|
||||
kListNode,
|
||||
kPropListNode,
|
||||
kPropPairNode,
|
||||
kFuncNode,
|
||||
kVarNode,
|
||||
kParensNode,
|
||||
@ -123,6 +129,9 @@ public:
|
||||
virtual void visitFloatNode(FloatNode *node) = 0;
|
||||
virtual void visitSymbolNode(SymbolNode *node) = 0;
|
||||
virtual void visitStringNode(StringNode *node) = 0;
|
||||
virtual void visitListNode(ListNode *node) = 0;
|
||||
virtual void visitPropListNode(PropListNode *node) = 0;
|
||||
virtual void visitPropPairNode(PropPairNode *node) = 0;
|
||||
virtual void visitFuncNode(FuncNode *node) = 0;
|
||||
virtual void visitVarNode(VarNode *node) = 0;
|
||||
virtual void visitParensNode(ParensNode *node) = 0;
|
||||
@ -497,6 +506,51 @@ struct StringNode : ExprNode {
|
||||
}
|
||||
};
|
||||
|
||||
/* ListNode */
|
||||
|
||||
struct ListNode : ExprNode {
|
||||
NodeList *items;
|
||||
|
||||
ListNode(NodeList *itemsIn) : ExprNode(kListNode), items(itemsIn) {}
|
||||
virtual ~ListNode() {
|
||||
deleteList(items);
|
||||
}
|
||||
virtual void accept(NodeVisitor *visitor) {
|
||||
visitor->visitListNode(this);
|
||||
}
|
||||
};
|
||||
|
||||
/* PropListNode */
|
||||
|
||||
struct PropListNode : ExprNode {
|
||||
NodeList *items;
|
||||
|
||||
PropListNode(NodeList *itemsIn) : ExprNode(kListNode), items(itemsIn) {}
|
||||
virtual ~PropListNode() {
|
||||
deleteList(items);
|
||||
}
|
||||
virtual void accept(NodeVisitor *visitor) {
|
||||
visitor->visitPropListNode(this);
|
||||
}
|
||||
};
|
||||
|
||||
/* PropPairNode */
|
||||
|
||||
struct PropPairNode : ExprNode {
|
||||
Node *key;
|
||||
Node *val;
|
||||
|
||||
PropPairNode(Node *keyIn, Node *valIn)
|
||||
: ExprNode(kPropPairNode), key(keyIn), val(valIn) {}
|
||||
virtual ~PropPairNode() {
|
||||
delete key;
|
||||
delete val;
|
||||
}
|
||||
virtual void accept(NodeVisitor *visitor) {
|
||||
visitor->visitPropPairNode(this);
|
||||
}
|
||||
};
|
||||
|
||||
/* FuncNode */
|
||||
|
||||
struct FuncNode : ExprNode {
|
||||
|
@ -693,6 +693,29 @@ void LingoCompiler::visitStringNode(StringNode *node) {
|
||||
codeString(node->val->c_str());
|
||||
}
|
||||
|
||||
/* ListNode */
|
||||
|
||||
void LingoCompiler::visitListNode(ListNode *node) {
|
||||
compileList(node->items);
|
||||
code1(LC::c_arraypush);
|
||||
codeInt(node->items->size());
|
||||
}
|
||||
|
||||
/* PropListNode */
|
||||
|
||||
void LingoCompiler::visitPropListNode(PropListNode *node) {
|
||||
compileList(node->items);
|
||||
code1(LC::c_proparraypush);
|
||||
codeInt(node->items->size());
|
||||
}
|
||||
|
||||
/* PropPairNode */
|
||||
|
||||
void LingoCompiler::visitPropPairNode(PropPairNode *node) {
|
||||
compile(node->key);
|
||||
compile(node->val);
|
||||
}
|
||||
|
||||
/* FuncNode */
|
||||
|
||||
void LingoCompiler::visitFuncNode(FuncNode *node) {
|
||||
|
@ -98,6 +98,9 @@ public:
|
||||
virtual void visitFloatNode(FloatNode *node);
|
||||
virtual void visitSymbolNode(SymbolNode *node);
|
||||
virtual void visitStringNode(StringNode *node);
|
||||
virtual void visitListNode(ListNode *node);
|
||||
virtual void visitPropListNode(PropListNode *node);
|
||||
virtual void visitPropPairNode(PropPairNode *node);
|
||||
virtual void visitFuncNode(FuncNode *node);
|
||||
virtual void visitVarNode(VarNode *node);
|
||||
virtual void visitParensNode(ParensNode *node);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -173,7 +173,8 @@ static void checkEnd(Common::String *token, Common::String *expect, bool require
|
||||
// EXPRESSION
|
||||
%type<node> simpleexprnoparens simpleexpr expr
|
||||
%type<node> var varorchunk varorthe
|
||||
%type<nodelist> exprlist nonemptyexprlist
|
||||
%type<node> list proppair
|
||||
%type<nodelist> proplist exprlist nonemptyexprlist
|
||||
|
||||
%left tAND tOR
|
||||
%left '<' tLE '>' tGE tEQ tNEQ tCONTAINS tSTARTS
|
||||
@ -453,6 +454,7 @@ simpleexprnoparens: tINT { $$ = new IntNode($tINT); }
|
||||
| tNOT simpleexpr[arg] %prec tUNARY { $$ = new UnaryOpNode(LC::c_not, $arg); }
|
||||
| ID '(' exprlist[args] ')' { $$ = new FuncNode($ID, $args); }
|
||||
| var
|
||||
| list
|
||||
;
|
||||
|
||||
var: ID { $$ = new VarNode($ID); } ;
|
||||
@ -469,6 +471,25 @@ simpleexpr: simpleexprnoparens
|
||||
| '(' expr ')' { $$ = $expr; }
|
||||
;
|
||||
|
||||
list: '[' exprlist ']' { $$ = new ListNode($exprlist); }
|
||||
| '[' ':' ']' { $$ = new PropListNode(new NodeList); }
|
||||
| '[' proplist ']' { $$ = new PropListNode($proplist); }
|
||||
;
|
||||
|
||||
proplist: proppair[item] {
|
||||
NodeList *list = new NodeList;
|
||||
list->push_back($item);
|
||||
$$ = list; }
|
||||
| proplist[prev] ',' proppair[item] {
|
||||
$prev->push_back($item);
|
||||
$$ = $prev; }
|
||||
;
|
||||
|
||||
proppair: tSYMBOL ':' expr { $$ = new PropPairNode(new SymbolNode($tSYMBOL), $expr); }
|
||||
| ID ':' expr { $$ = new PropPairNode(new SymbolNode($ID), $expr); }
|
||||
| tSTRING ':' expr { $$ = new PropPairNode(new StringNode($tSTRING), $expr); }
|
||||
;
|
||||
|
||||
expr: simpleexpr { $$ = $simpleexpr; }
|
||||
| expr[a] '+' expr[b] { $$ = new BinaryOpNode(LC::c_add, $a, $b); }
|
||||
| expr[a] '-' expr[b] { $$ = new BinaryOpNode(LC::c_sub, $a, $b); }
|
||||
|
Loading…
Reference in New Issue
Block a user