Language: C++

#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;

string S;
map<string,int> M;
int size;
int pos=0;
vector<vector<int> > V;

bool rev;

int gcd(int a, int b){ return a%b ? gcd(b, a%b) : b; }
int lcm(int a, int b){ return a/gcd(a,b)*b; }

vector<int> read(){
	vector<int> res(size,0);
	if(S[pos]=='+' || S[pos]==')' ||S[pos]=='-'){pos++;return res;}
	if(S[pos]=='.'){return res;}

	vector<int> now(size,0);
	string s="";
	if(S[pos]=='('){pos++;res=read();}
	else{
		s+=S[pos];
		if(islower(S[pos+1]))
			s+=S[++pos];
		pos++;
		res[M[s]-1]=1;
	}
	int num=1;
	if(isdigit(S[pos])){
		num=S[pos]-'0';
		if(isdigit(S[pos+1])){
			num*=10;
			num+=S[++pos]-'0';
		}
		pos++;
	}
	for(int i=0;i<res.size();i++) res[i]*=num;
	vector<int> next=read();
	for(int i=0;i<next.size();i++)
		res[i]+=next[i];
	return res;
}

void print(){
	
	for(int y=0;y<V.size();y++){
		for(int x=0;x<V[y].size();x++)
			cout<<V[y][x]<<" ";
		cout<<endl;
	}
	cout<<endl;
}

void solve()
{
	size=0; M.clear(); pos=0;V.clear(); rev=false;
	while(S[pos]!='.'){
		string s;
		if(!isalpha(S[pos])){pos++; continue;}
		s+=S[pos];
		if(islower(S[pos+1])){s+=S[pos+1];pos++;}
		pos++;
		if(M[s]==0){M[s]=++size;}
	}
	V.resize(size);
	pos=0;
	while(S[pos]!='.'){
		if(S[pos]=='>'){rev=true;pos++;}
		vector<int> res=read();
		for(int i=0;i<res.size();i++)
			V[i].push_back(rev? -res[i]:res[i]);
	}
	// verifyed!

	for(int i=0;i<V[0].size()-1;i++){
		if(V[i][i]==0){
			int z=i+1;
			while(V[z][i]==0) z++;
			swap(V[i],V[z]);
		}
		if(V[i][i]<0){
			for(int z=0;z<V[i].size();z++)
				V[i][z]*=-1;
		}

		for(int j=0;j<V.size();j++){
			if(V[j][i]==0 || i==j) continue;
			if(V[j][i]<0)
				for(int z=0;z<V[j].size();z++)
					V[j][z]*=-1;
			int l=lcm(V[i][i],V[j][i]);
			int mul=l/V[i][i];
			for(int z=0;z<V[i].size();z++)
				V[i][z]*=mul;
			mul=l/V[j][i];
			for(int z=0;z<V[j].size();z++)
				V[j][z]*=mul;
			for(int z=0;z<V[i].size();z++)
				V[j][z]-=V[i][z];
		}
		for(int j=0;j<V.size();j++){
			int l=0;
			for(int z=0;z<V[j].size();z++){
				if(V[j][z]==0) continue;
				if(l==0)l=abs(V[j][z]);
				else l=gcd(abs(V[j][z]),l);
			}
			if(l!=0){
				for(int z=0;z<V[j].size();z++)
					V[j][z]/=l;
			}
		}
	}

	print();

	int l=abs(V[0][0]);
	for(int i=0;i<V[0].size()-1;i++)
		l=lcm(l,abs(V[i][i]));

	for(int i=0;i<V[0].size()-1;i++){
		int mul=l/abs(V[i][i]);
		cout<<mul*abs(V[i][V[i].size()-1])<<" ";
	}

	cout<<l<<endl;;
}

int main()
{
	while(cin>>S){
		if(S==".") break;
		solve();
	}
	return 0;
}

Compiler output:
a.cc: In function 'std::vector<int> read()':
a.cc:19:25: error: reference to 'size' is ambiguous
   19 |         vector<int> res(size,0);
      |                         ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:9:5: note:                 'int size'
    9 | int size;
      |     ^~~~
a.cc:23:25: error: reference to 'size' is ambiguous
   23 |         vector<int> now(size,0);
      |                         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:9:5: note:                 'int size'
    9 | int size;
      |     ^~~~
a.cc: In function 'void solve()':
a.cc:61:9: error: reference to 'size' is ambiguous
   61 |         size=0; M.clear(); pos=0;V.clear(); rev=false;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:9:5: note:                 'int size'
    9 | int size;
      |     ^~~~
a.cc:68:36: error: reference to 'size' is ambiguous
   68 |                 if(M[s]==0){M[s]=++size;}
      |                                    ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:9:5: note:                 'int size'
    9 | int size;
      |     ^~~~
a.cc:70:18: error: reference to 'size' is ambiguous
   70 |         V.resize(size);
      |                  ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:9:5: note:                 'int size'
    9 | int size;
      |     ^~~~