source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer.cpp@ 616

Last change on this file since 616 was 546, checked in by dai_9181, 17 years ago

LexicalAnalyzerのソースコードの記述位置を整理。

File size: 2.3 KB
Line 
1#include "stdafx.h"
2
3using namespace ActiveBasic::Compiler;
4
5LexicalAnalyzer::SourceTemplate::SourceTemplate( const std::string &filePath )
6{
7 Jenga::Common::File file = Jenga::Common::File( GetApplicationBaseFullPath( filePath ) );
8 source = file.Read();
9}
10std::string LexicalAnalyzer::SourceTemplate::GetResult( const std::map<std::string,std::string> &values )
11{
12 std::string result = source;
13
14 std::map<std::string,std::string>::const_iterator it = values.begin();
15 while( it != values.end() )
16 {
17 while( true )
18 {
19 std::string::size_type index = result.find( it->first );
20 if( index == std::string::npos )
21 {
22 break;
23 }
24
25 result = result.substr( 0, index ) + it->second + result.substr( index + it->first.length() );
26 }
27 it++;
28 }
29
30 return result;
31}
32
33
34bool LexicalAnalyzer::CollectNamespaces( const char *source, NamespaceScopesCollection &namespaceScopesCollection )
35{
36 int i, i2;
37 char temporary[1024];
38
39 bool isSuccessful = true;
40
41 // 名前空間管理
42 NamespaceScopes namespaceScopes;
43
44 for(i=0;;i++){
45 if(source[i]=='\0') break;
46
47 if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
48 for(i+=2,i2=0;;i2++,i++){
49 if( IsCommandDelimitation( source[i] ) ){
50 temporary[i2]=0;
51 break;
52 }
53 temporary[i2]=source[i];
54 }
55 namespaceScopes.push_back( temporary );
56
57 if( !namespaceScopesCollection.IsExist( namespaceScopes ) ){
58 namespaceScopesCollection.push_back( namespaceScopes );
59 }
60
61 continue;
62 }
63 else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
64 if( namespaceScopes.size() <= 0 ){
65 compiler.errorMessenger.Output( 12, "End Namespace", i );
66 isSuccessful = false;
67 }
68 else{
69 namespaceScopes.pop_back();
70 }
71
72 i += 2;
73 continue;
74 }
75 }
76
77 if( namespaceScopes.size() > 0 ){
78 compiler.errorMessenger.Output( 63, NULL, cp );
79 isSuccessful = false;
80 }
81
82 return isSuccessful;
83}
84
85Symbol LexicalAnalyzer::FullNameToSymbol( const char *fullName )
86{
87 char areaName[VN_SIZE] = ""; //オブジェクト変数
88 char nestName[VN_SIZE] = ""; //入れ子メンバ
89 bool isNest = SplitMemberName( fullName, areaName, nestName );
90
91 return Symbol( NamespaceScopes( areaName ), nestName );
92}
93
94Symbol LexicalAnalyzer::FullNameToSymbol( const std::string &fullName )
95{
96 return FullNameToSymbol( fullName.c_str() );
97}
Note: See TracBrowser for help on using the repository browser.