⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 foo_output.cpp

📁 用于词法分析的词法分析器
💻 CPP
字号:
/*  $Id: foo_output.cpp,v 1.10 1997/05/18 10:59:53 matt Exp $  Foo model output function.  (c) May 1996 Matt Phillips.  */#include <ctype.h>#include "foo_output.h"#include "FooObject.h"static void doObject (ostream &s, const FooObject &object,		      int indent);static void newlineAndIndent (ostream &s, int indent){  s << endl;  for (int c = 0; c < indent; c++)    s << "  ";}static void doString (ostream &s, const string &str){  s << '"';  for (int i = 0; i < str.length (); i++)  {    unsigned char chr = str[i];    if (chr == '"')      s << "\\\"";    else if (chr == '\\')      s << "\\\\";    else if (isprint (chr))      s << chr;    else      s.form ("\\%02x", unsigned (chr));  }  s << '"';   }static void doAttr (ostream &s, const string &attr,		    const FooObject::Objects &values, int indent){  s << attr;  if (values.nItems () == 1)  {				// no []'s if a single value for attr.    FooObject &value = values.peekHead ();        // atomics go on same line as attr name.    if (value.isAtomic ())      s << '\t';    else      newlineAndIndent (s, indent);        doObject (s, value, indent);  } else  {    // output values enclosed in []'s.    FooObject::Objects::Iterator i (values);    newlineAndIndent (s, indent);    s << "[ ";        if (i)    {      doObject (s, i.ref (), indent + 1);      i++;    }    for ( ; i; i++)    {      newlineAndIndent (s, indent + 1);      doObject (s, i.ref (), indent + 1);    }    newlineAndIndent (s, indent);    s << ']';  }}static void doObject (ostream &s, const FooObject &object,		      int indent){  if (object.isAtomic ())  {    doString (s, object.getAttr ());  } else  {    // output object enclosed in ()'s.    s << "( ";    if (object.nAttrs () > 0)    {      FooObject::Iterator i (object.getIter ());            if (i)      {	doAttr (s, i.refKey (), i.ref (), indent + 1);	i++;      }            for ( ; i; i++)      {	newlineAndIndent (s, indent + 1);	doAttr (s, i.refKey (), i.ref (), indent + 1);      }    }    newlineAndIndent (s, indent);    s << ')';  }}ostream &operator << (ostream &s, const FooObject &object){  doObject (s, object, 0);  return s;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -