📄 syntax.cs
字号:
stack.Pop(1);
stack.Push(new Type(PrimitiveType.Real));
break;
case 12: // <Primitive_Type> ::= char
// Create an character type object.
stack.Pop(1);
stack.Push(new Type(PrimitiveType.Character));
break;
case 13: // <Primitive_Type> ::= void
// Create an void type object.
stack.Pop(1);
stack.Push(new Type(PrimitiveType.Void));
break;
case 14: // <Array_Type> ::= <Structure_Type> '[' ']'
// Create a structure array type.
stack.Pop(2);
stack.Push(Type.CreateArrayFromType(stack.PopType()));
break;
case 15: // <Array_Type> ::= <Primitive_Type> '[' ']'
// Create a primitive array type.
stack.Pop(2);
stack.Push(Type.CreateArrayFromType(stack.PopType()));
break;
case 16: // <Module> ::= module identifier <Body>
// Create a module object.
stack.Remove(2);
stack.Push(new Module(stack.PopBody(),stack.PopString()));
break;
case 17: // <Body> ::= '{' <Statements> '}'
// Create a body object.
stack.Pop(1);
Body body = new Body((StatementCollection)stack.Pop());
stack.Pop(1);
stack.Push(body);
break;
case 18: // <Body> ::= '{' '}'
// Create a null body object.
stack.Pop(2);
stack.Push(new Body(null));
break;
case 19: // <Name> ::= identifier
// !!! DO NOTHING !!!
break;
case 20: // <Name> ::= <Name> . identifier
// Append name section to top of stack.
string identifer = stack.PopString();
stack.Pop(1);
string name = stack.PopString();
stack.Push(name + "." + identifer);
break;
case 21: // <Variable_Declarations> ::= <Variable_Declaration>
// Create a variable collection containing the variable on top of the stack.
stack.Push(new VariableCollection((Variable)stack.Pop()));
break;
case 22: // <Variable_Declarations> ::= <Variable_Declarations> <Variable_Declaration>
// Add the variable on top of the stack to the variable collection.
Variable variable = (Variable)stack.Pop();
((VariableCollection)stack.Peek()).Add(variable);
break;
case 23: // <Variable_Declaration> ::= <Type> identifier ;
// Create a variable object with a null value.
stack.Pop(1);
stack.Push(new Variable(null,stack.PopString(),stack.PopType()));
break;
case 24: // <Variable_Declaration> ::= <Type> identifier = <Expression> ;
// Create a variable object with an expression value.
stack.Pop(1);
stack.Remove(1);
stack.Push(new Variable(stack.PopExpression(), stack.PopString(),stack.PopType()));
break;
case 25: // <Variable_Declaration> ::= <Type> identifier = new '[' <Expression> ']' ;
// Create a variable object with an expression value.
stack.Pop(2); stack.Remove(1); stack.Remove(1); stack.Remove(1);
stack.Push(new Variable(stack.PopExpression(), stack.PopString(),stack.PopType()));
break;
case 26: // <Variable_Declaration> ::= <Type> identifier = '{' <Elements> '}' ;
// Create a variable object with an element collection value.
stack.Pop(2); stack.Remove(1); stack.Remove(1);
stack.Push(new Variable(stack.Pop(), stack.PopString(),stack.PopType()));
break;
case 27: // <Elements> ::= <Element>
// Create an element collection containing the element on top of the stack.
stack.Push(new ElementCollection((Element)stack.Pop()));
break;
case 28: // <Elements> ::= <Elements> , <Element>
// Add the element on top of the stack to the current element collection.
Element element = (Element)stack.Pop();
stack.Pop(1);
((ElementCollection)stack.Peek()).Add(element);
break;
case 29: // <Element> ::= <Expression>
// Create a new element object.
stack.Push(new Element(stack.PopExpression()));
break;
case 30: // <Element> ::= '{' <Elements> '}'
// Create a new element object with elements inside of it.
stack.Pop(1); stack.Remove(1);
stack.Push(new Element((ElementCollection)stack.Pop()));
break;
case 31: // <Function_Declaration> ::= <Type> identifier '(' ')' <Body>
// Create a function object.
stack.Remove(1); stack.Remove(1);
stack.Push(new Function(stack.PopBody(),null,stack.PopString(),stack.PopType()));
break;
case 32: // <Function_Declaration> ::= <Type> identifier '(' <Parameters> ')' <Body>
// Create a function object.
stack.Remove(1); stack.Remove(2);
stack.Push(new Function(stack.PopBody(),(ParameterCollection)stack.Pop(),stack.PopString(),stack.PopType()));
break;
case 33: // <Parameters> ::= <Parameter>
// Create a parameter collection containing the parameter on top of the stack.
stack.Push(new ParameterCollection((Parameter)stack.Pop()));
break;
case 34: // <Parameters> ::= <Parameters> , <Parameter>
// Add parameter to parameter collection.
Parameter parameter = (Parameter)stack.Pop();
stack.Pop(1);
((ParameterCollection)stack.Peek()).Add(parameter);
break;
case 35: // <Parameter> ::= <Type> identifier
// Create a parameter object.
stack.Push(new Parameter(stack.PopString(),stack.PopType(),PassMethod.ByValue));
break;
case 36: // <Parameter> ::= ref <Type> identifier
// Create a parameter object.
stack.Remove(2);
stack.Push(new Parameter(stack.PopString(),stack.PopType(),PassMethod.ByReference));
((Parameter)stack.Peek()).Type.IsRef = true;
break;
case 37: // <Function_Call> ::= <Name> '(' ')'
// Create a function call object.
stack.Pop(2);
stack.Push(new Call(null,stack.PopString()));
break;
case 38: // <Function_Call> ::= <Name> '(' <Arguments> ')'
// Create a function call object.
stack.Pop(1); stack.Remove(1);
stack.Push(new Call((ArgumentCollection)stack.Pop(),stack.PopString()));
break;
case 39: // <Arguments> ::= <Argument>
// Create an argument collection containing the argument on top of stack.
stack.Push(new ArgumentCollection((Argument)stack.Pop()));
break;
case 40: // <Arguments> ::= <Arguments> , <Argument>
// Add argument to argument collection.
Argument argument = (Argument)stack.Pop();
stack.Pop(1);
((ArgumentCollection)stack.Peek()).Add(argument);
break;
case 41: // <Argument> ::= <Expression>
// Create argument object.
stack.Push(new Argument(stack.PopExpression(),PassMethod.ByValue));
break;
case 42: // <Argument> ::= ref <Expression>
// Create argument object.
stack.Remove(1);
stack.Push(new Argument(stack.PopExpression(),PassMethod.ByReference));
break;
case 43: // <Structure_Declaration> ::= struct identifier '{' <Variable_Declarations> '}'
// Create structure object.
stack.Pop(1); stack.Remove(1); stack.Remove(2);
stack.Push(new Structure((VariableCollection)stack.Pop(),stack.PopString()));
break;
case 44: // <Structure_Declaration> ::= struct identifier '{' '}'
// Create structure object.
stack.Pop(2); stack.Remove(1);
stack.Push(new Structure(null,stack.PopString()));
break;
case 45: // <Statements> ::= <Statement>
// Create statement collection containing statement on stack.
stack.Push(new StatementCollection(stack.PopStatement()));
break;
case 46: // <Statements> ::= <Statements> <Statement>
// Add current statement to collection.
Statement statement = stack.PopStatement();
((StatementCollection)stack.Peek()).Add(statement);
break;
case 47: // <Statement> ::= <Variable_Declaration>
// !!! DO NOTHING !!!
break;
case 48: // <Statement> ::= <Function_Declaration>
// !!! DO NOTHING !!!
break;
case 49: // <Statement> ::= <Structure_Declaration>
// !!! DO NOTHING !!!
break;
case 50: // <Statement> ::= <Function_Call> ;
// Remove ';'
stack.Pop(1);
Call call = (Call)stack.Pop();
stack.Push(new CallStatement(call.Arguments,call.Name));
break;
case 51: // <Statement> ::= <Assignment> ;
// Remove ';'
stack.Pop(1);
break;
case 52: // <Statement> ::= return <Expression> ;
// Create return object.
stack.Pop(1); stack.Remove(1);
stack.Push(new Return(stack.PopExpression()));
break;
case 53: // <Statement> ::= return ;
// Create return object.
stack.Pop(2);
stack.Push(new Return(null));
break;
case 54: // <Statement> ::= if '(' <Expression> ')' <Body>
// Create if statement.
stack.Remove(1); stack.Remove(2); stack.Remove(2);
stack.Push(new If(null,stack.PopBody(),stack.PopExpression()));
break;
case 55: // <Statement> ::= if '(' <Expression> ')' <Body> else <Body>
// Create if statement.
stack.Remove(1); stack.Remove(2); stack.Remove(3); stack.Remove(3);
stack.Push(new If(stack.PopBody(),stack.PopBody(),stack.PopExpression()));
break;
case 56: // <Statement> ::= while '(' <Expression> ')' <Body>
// Create while statement.
stack.Remove(1); stack.Remove(2); stack.Remove(2);
stack.Push(new While(stack.PopBody(),stack.PopExpression()));
break;
case 57: // <Statement> ::= do <Body> while '(' <Expression> ')'
/// Create do statement.
stack.Pop(1); stack.Remove(1); stack.Remove(1); stack.Remove(2);
stack.Push(new Do(stack.PopExpression(),stack.PopBody()));
break;
case 58: // <Statement> ::= for '(' <Assignment> ; <Expression> ; <Assignment> ')' <Body>
// Create for statement.
stack.Remove(1); stack.Remove(2); stack.Remove(3); stack.Remove(4); stack.Remove(4);
stack.Push(new For(stack.PopBody(),stack.PopAssignment(),stack.PopExpression(),stack.PopAssignment()));
break;
case 59: // <Assignment> ::= set <Name> = <Expression>
// Create assignment statement.
stack.Remove(1);
stack.Remove(2);
stack.Push(new Assignment(stack.PopExpression(),null,stack.PopString()));
break;
case 60: // <Assignment> ::= set <Name> [ <Expression> ] = <Expression>
// Create assignment statement.
stack.Remove(1);
stack.Remove(1);
stack.Remove(2);
stack.Remove(3);
stack.Push(new Assignment(stack.PopExpression(),stack.PopExpression(),stack.PopString()));
break;
case 61: // <Assignment> ::= set <Name> '++'
// TO DO:
break;
case 62: // <Assignment> ::= set <Name> '--'
// TO DO:
break;
case 63: // <Expression> ::= <Expression_Term>
// !!! DO NOTHING !!!
break;
case 64: // <Expression> ::= <Expression> '+' <Expression_Term>
// Create binary expression.
stack.Remove(1);
stack.Push(new BinaryExpression(stack.PopExpression(),stack.PopExpression(),BinaryOperatorType.Add));
break;
case 65: // <Expression> ::= <Expression> '-' <Expression_Term>
// Create binary expression.
stack.Remove(1);
stack.Push(new BinaryExpression(stack.PopExpression(),stack.PopExpression(),BinaryOperatorType.Subtract));
break;
case 66: // <Expression_Term> ::= <Expression_Factor>
// !!! DO NOTHING !!!
break;
case 67: // <Expression_Term> ::= <Expression_Term> '*' <Expression_Factor>
// Create binary expression.
stack.Remove(1);
stack.Push(new BinaryExpression(stack.PopExpression(),stack.PopExpression(),BinaryOperatorType.Multiply));
break;
case 68: // <Expression_Term> ::= <Expression_Term> / <Expression_Factor>
// Create binary expression.
stack.Remove(1);
stack.Push(new BinaryExpression(stack.PopExpression(),stack.PopExpression(),BinaryOperatorType.Divide));
break;
case 69: // <Expression_Factor> ::= <Expression_Binary>
// !!! DO NOTHING !!!
break;
case 70: // <Expression_Factor> ::= <Expression_Factor> % <Expression_Binary>
// Create binary expression.
stack.Remove(1);
stack.Push(new BinaryExpression(stack.PopExpression(),stack.PopExpression(),BinaryOperatorType.Modulo));
break;
case 71: // <Expression_Factor> ::= <Expression_Factor> '>' <Expression_Binary>
// Create binary expression.
stack.Remove(1);
stack.Push(new BinaryExpression(stack.PopExpression(),stack.PopExpression(),BinaryOperatorType.GreaterThen));
break;
case 72: // <Expression_Factor> ::= <Expression_Factor> '<' <Expression_Binary>
// Create binary expression.
stack.Remove(1);
stack.Push(new BinaryExpression(stack.PopExpression(),stack.PopExpression(),BinaryOperatorType.LessThen));
break;
case 73: // <Expression_Factor> ::= <Expression_Factor> '>=' <Expression_Binary>
// Create binary expression.
stack.Remove(1);
stack.Push(new BinaryExpression(stack.PopExpression(),stack.PopExpression(),BinaryOperatorType.GraterOrEqualTo));
break;
case 74: // <Expression_Factor> ::= <Expression_Factor> '<=' <Expression_Binary>
// Create binary expression.
stack.Remove(1);
stack.Push(new BinaryExpression(stack.PopExpression(),stack.PopExpression(),BinaryOperatorType.LessOrEqualTo));
break;
case 75: // <Expression_Factor> ::= <Expression_Factor> == <Expression_Binary>
// Create binary expression.
stack.Remove(1);
stack.Push(new BinaryExpression(stack.PopExpression(),stack.PopExpression(),BinaryOperatorType.Equal));
break;
case 76: // <Expression_Factor> ::= <Expression_Factor> '!=' <Expression_Binary>
// Create binary expression.
stack.Remove(1);
stack.Push(new BinaryExpression(stack.PopExpression(),stack.PopExpression(),BinaryOperatorType.NotEqual));
break;
case 77: // <Expression_Binary> ::= <Expression_Unary>
// !!! DO NOTHING !!!
break;
case 78: // <Expression_Binary> ::= <Expression_Binary> && <Expression_Unary>
// Create binary expression.
stack.Remove(1);
stack.Push(new BinaryExpression(stack.PopExpression(),stack.PopExpression(),BinaryOperatorType.And));
break;
case 79: // <Expression_Binary> ::= <Expression_Binary> '||' <Expression_Unary>
// Create binary expression.
stack.Remove(1);
stack.Push(new BinaryExpression(stack.PopExpression(),stack.PopExpression(),BinaryOperatorType.Or));
break;
case 80: // <Expression_Unary> ::= '+' <Expression_Primary>
// Create unary expression.
stack.Remove(1);
stack.Push(new UnaryExpression(null,stack.PopExpression(),UnaryOperatorType.Positive));
break;
case 81: // <Expression_Unary> ::= '-' <Expression_Primary>
// Create unary expression.
stack.Remove(1);
stack.Push(new UnaryExpression(null,stack.PopExpression(),UnaryOperatorType.Negative));
break;
case 82: // <Expression_Unary> ::= '!' <Expression_Primary>
// Create unary expression.
stack.Remove(1);
stack.Push(new UnaryExpression(null,stack.PopExpression(),UnaryOperatorType.Not));
break;
case 83: // <Expression_Unary> ::= <Expression_Primary>
// !!! DO NOTHING !!!
break;
case 84: // <Expression_Unary> ::= <Expression_Primary> '[' <Expression> ']'
// Create unary expression.
stack.Pop(1); stack.Remove(1);
stack.Push(new UnaryExpression(stack.PopExpression(),stack.PopExpression(),UnaryOperatorType.Indexer));
break;
case 85: // <Expression_Primary> ::= <Name>
// Create name expression.
stack.Push(new Name(stack.PopString()));
break;
case 86: // <Expression_Primary> ::= <Function_Call>
// !!! DO NOTHING !!!
break;
case 87: // <Expression_Primary> ::= <Literal>
// !!! DO NOTHING !!!
break;
case 88: // <Expression_Primary> ::= '(' <Expression> ')'
// Remove pharanthesis
stack.Pop(1); stack.Remove(1);
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -