Exemplo n.º 1
0
 public virtual void Visit(ProcedureSequence node)
 {
 }
 void Program()
 {
     StatementSequence statements = null;
     ProcedureSequence procs = new ProcedureSequence();
     Token startTok = null, endTok = null;
     if (IsProcProgram()) {
     Expect(3);
     startTok = t;
     Proc(procs);
     while (la.kind == 5) {
         Proc(procs);
     }
     StmtSeq(out statements);
     Expect(4);
     endTok = t;
     } else if (StartOf(1)) {
     StmtSeq(out statements);
     } else SynErr(50);
     WhileProgram.Instance = new WhileProgram(procs, statements);
     if (startTok != null && endTok != null) {
     WhileProgram.Instance.AddSequencePoint(startTok);
     WhileProgram.Instance.AddSequencePoint(endTok);
     }
 }
Exemplo n.º 3
0
 public WhileProgram(ProcedureSequence procs, StatementSequence stmts)
 {
     AddChild(procs);
     AddChild(stmts);
 }
 void Proc(ProcedureSequence procs)
 {
     StatementSequence statements;
     string name;
     VariableSequence valArgs = new VariableSequence();
     Variable resultArg = null;
     Expect(5);
     Token ptok = t;
     Expect(1);
     name = t.val;
     Expect(6);
     if (la.kind == 7 || la.kind == 8) {
     if (la.kind == 7) {
         Get();
         Expect(1);
         Variable v = new Variable(t.val);
         v.IsValueArg = true;
         valArgs.AddVariable(v);
         SymbolTable.DefineArgument(t.val);
         if (la.kind == 12) {
             Args(valArgs, out resultArg);
         }
     } else {
         Get();
         Expect(1);
         resultArg = new Variable(t.val);
         resultArg.IsResultArg = true;
         SymbolTable.DefineResultArgument(t.val);
     }
     }
     Expect(9);
     SequencePoint seq1 = new SequencePoint(ptok.line,ptok.col, t.line,t.col+t.val.Length);
     Expect(10);
     StmtSeq(out statements);
     Expect(4);
     SequencePoint seq2 = new SequencePoint(t.line, t.col, t.line, t.col+t.val.Length);
     Expect(11);
     if (procs.ContainsProcedure(name)) {
     errors.SemErr(ptok.line, ptok.col, "Procedure '" + name + "' is already declared");
     } else {
     Procedure proc = new Procedure(name, valArgs, resultArg, statements);
     proc.AddSequencePoint(seq1);
     proc.AddSequencePoint(seq2);
     procs.AddProcedure(proc);
     }
     SymbolTable.Clear();
 }